Skip to content

Commit

Permalink
pushed untested code dun dun dun
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanpullano committed Apr 8, 2012
1 parent c5aa2a2 commit aba74ef
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions request/Form.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public void doGet(HttpServletRequest request,
throws ServletException, IOException {
FormManager.getInstance().newRequest();
Cookie cookie = SessionManager.getCookie(getServletContext(), request, response);
System.out.println(cookie.getValue().toString());

CookieVal cookieVal = CookieVal.getCookieVal(cookie.getValue());
boolean found = SessionManager.readRequest(response, cookieVal.getSid(), cookieVal.getSvn());
Expand Down
4 changes: 2 additions & 2 deletions rpc/RpcServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ public RpcMessageReply SessionRead(RpcMessageCall call) {
int changeCount = (Integer)call.getArguments().get(1);
SessionTable table = SessionTable.getInstance();

Entry entry = table.get(sid);
Entry entry = table.get(sid, changeCount);
ArrayList<Object> results = null;
if(entry.version == changeCount) {
if(entry.version >= changeCount) {
results = new ArrayList<Object>();
results.add(entry.message);
results.add(entry.expiration);
Expand Down
7 changes: 4 additions & 3 deletions server/SessionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public static Cookie getCookie(ServletContext context, HttpServletRequest reques
if(ourCookie != null) {
SessionTable table = SessionTable.getInstance();
if(DEBUG) System.out.println("Cookie was found and here it is (" + ourCookie.getValue() + ")");
SessionTable.Entry entry = table.get(CookieVal.getCookieVal(ourCookie.getValue()).getSid());
CookieVal cookieVal = CookieVal.getCookieVal(ourCookie.getValue());
SessionTable.Entry entry = table.get(cookieVal.getSid(), cookieVal.getSvn().getChangeCount());
//if(DEBUG) System.out.println("SessionTable Cookie version (" + entry.message + ")");

if(entry == null) {
Expand Down Expand Up @@ -138,7 +139,7 @@ public static boolean readRequest(HttpServletResponse response, SID sid, SVN svn

if(ippPrimary.equals(ippLocal)) {
//We are the primary server, so return the data
Entry entry = SessionTable.getInstance().get(sid);
Entry entry = SessionTable.getInstance().get(sid, svn.getChangeCount());
data.setLoc(Location.ippPrimary);
data.setIppPrimary(ippPrimary);
data.setMessage(entry.message);
Expand All @@ -155,7 +156,7 @@ public static boolean readRequest(HttpServletResponse response, SID sid, SVN svn
response.addCookie(new Cookie(COOKIE_NAME, new CookieVal(newSid, newSvn).toString()));
} else if(ippBackup.equals(ippLocal)) {
//We are the backup server, so return the data
Entry entry = SessionTable.getInstance().get(sid);
Entry entry = SessionTable.getInstance().get(sid, svn.getChangeCount());
data.setLoc(Location.ippBackup);
data.setIppBackup(ippBackup);
data.setMessage(entry.message);
Expand Down
21 changes: 15 additions & 6 deletions server/SessionTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,23 @@ public String toString() {
* @param sessionID
* @return
*/
public synchronized Entry get(SID sessionID) {
if(sessionTable.containsKey(sessionID))
return sessionTable.get(sessionID);
public synchronized Entry get(SID sessionID, int changeCount) {
if(sessionTable.containsKey(sessionID)) {
Entry entry = sessionTable.get(sessionID);
if(entry.version >= changeCount)
return sessionTable.get(sessionID);
}

if(DEBUG) System.out.println("Returning a cached entry");
if(DEBUG) System.out.println("Cache entry: " + cacheTable.get(sessionID));
if(cacheTable.containsKey(sessionID))
FormManager.getInstance().getData().setLoc(Location.cache);
return cacheTable.get(sessionID);
if(cacheTable.containsKey(sessionID)) {
Entry entry = sessionTable.get(sessionID);
if(entry.version >= changeCount) {
FormManager.getInstance().getData().setLoc(Location.cache);
return cacheTable.get(sessionID);
}
}
return null;
}

public synchronized void cache(SID sessionID, ReadResult result, int changeCount) {
Expand Down

0 comments on commit aba74ef

Please sign in to comment.