1 2 24 25 package com.lutris.appserver.server.sessionEnhydra; 26 27 import com.lutris.appserver.server.session.SessionException; 28 import com.lutris.util.PersistentStore; 29 30 41 class PagedSessionHandle { 42 43 47 private boolean sessionIsNew; 48 49 52 private long sessionTimeCreate; 53 54 57 private PersistentStore store; 58 59 62 private PagedSession session; 63 64 67 private String sessionKey; 68 69 73 private Object [] transientData; 74 75 83 PagedSessionHandle(PagedSession session, PersistentStore store) { 84 this.session = session; 85 this.store = store; 86 87 this.sessionIsNew = session.isNew(); 89 this.sessionTimeCreate = session.getTimeCreated(); 90 this.sessionKey = session.getSessionKey(); 91 94 this.transientData = session.getTransientData(); 95 } 96 97 102 synchronized void write() throws SessionException { 103 try { 104 transientData = session.getTransientData(); 105 store.store(sessionKey, session); 106 session = null; 109 } catch (Exception e) { 110 throw new SessionException("Unable to write session to persistent store.", e); 111 } 112 } 113 114 121 synchronized PagedSession read() throws SessionException { 122 if (session != null) { 123 return session; 124 } 125 try { 126 session = (PagedSession)store.remove(sessionKey); 127 session.restoreTransientData(transientData); 128 return session; 129 } catch (Exception e) { 130 throw new SessionException("Unable to read session from persistent store.", e); 131 } 132 } 133 134 139 synchronized void delete() throws SessionException { 140 try { 141 store.delete(sessionKey); 142 } catch (Exception e) { 143 throw new SessionException("Unable to delete session from persistent store.", e); 144 } 145 } 146 147 153 boolean isNew() { 154 return sessionIsNew; 155 } 156 157 165 long getTimeCreated() { 166 return sessionTimeCreate; 167 } 168 169 175 String getSessionKey() { 176 return sessionKey; 177 } 178 179 } 180 181 | Popular Tags |