74 |
74 |
|
75 |
75 |
import java.io.*;
|
76 |
76 |
import java.util.*;
|
|
77 |
import java.util.concurrent.atomic.*;
|
77 |
78 |
import java.util.logging.*;
|
|
79 |
|
|
80 |
import com.goldencode.p2j.persist.*;
|
78 |
81 |
import com.goldencode.p2j.security.*;
|
79 |
82 |
import com.goldencode.p2j.security.SecurityManager;
|
80 |
83 |
import com.goldencode.p2j.util.*;
|
... | ... | |
94 |
97 |
implements Session,
|
95 |
98 |
MessageTypes
|
96 |
99 |
{
|
|
100 |
/** Session ID generator */
|
|
101 |
private static final AtomicInteger SESSION_ID = new AtomicInteger();
|
|
102 |
|
97 |
103 |
/** Logger */
|
98 |
104 |
protected static final Logger LOG =
|
99 |
105 |
LogHelper.getLogger(Session.class.getName());
|
|
106 |
|
|
107 |
/** Unique Session Id */
|
|
108 |
private final int sessionId = SESSION_ID.incrementAndGet();
|
100 |
109 |
|
101 |
110 |
/** List of objects to receive event notifications. */
|
102 |
111 |
private final List<SessionListener> listeners =
|
103 |
112 |
new LinkedList<SessionListener>();
|
104 |
113 |
|
|
114 |
/** Session databases */
|
|
115 |
private final Set<Database> sessionDb = new HashSet<>();
|
|
116 |
|
105 |
117 |
/** Message transport queue */
|
106 |
118 |
private final Queue queue;
|
107 |
119 |
|
... | ... | |
239 |
251 |
}
|
240 |
252 |
|
241 |
253 |
/**
|
|
254 |
* Register session database
|
|
255 |
* @param db
|
|
256 |
* database to registered
|
|
257 |
* @return <code>true</code> if the database was not registered before
|
|
258 |
*/
|
|
259 |
@Override
|
|
260 |
public boolean registerDb(Database db)
|
|
261 |
{
|
|
262 |
return sessionDb.add(db);
|
|
263 |
}
|
|
264 |
|
|
265 |
/**
|
|
266 |
* Get the <code>Iterable</code> over the session databases.
|
|
267 |
* @return the <code>Iterable</code> over the session databases.
|
|
268 |
*/
|
|
269 |
@Override
|
|
270 |
public Iterable<Database> sessionDbs()
|
|
271 |
{
|
|
272 |
return sessionDb;
|
|
273 |
}
|
|
274 |
|
|
275 |
/**
|
|
276 |
* Generate string representation of the session.
|
|
277 |
*
|
|
278 |
* @return string representation of the session.
|
|
279 |
*/
|
|
280 |
@Override
|
|
281 |
public String toString()
|
|
282 |
{
|
|
283 |
return this.getClass().getSimpleName() +
|
|
284 |
" [sessionId=" + sessionId + ", contextID=" + contextID + "]";
|
|
285 |
}
|
|
286 |
|
|
287 |
/**
|
242 |
288 |
* Preprocess the given message and then send it as a synchronous request
|
243 |
289 |
* and wait for reply. Return message payload as a result.
|
244 |
290 |
* <p>
|
... | ... | |
392 |
438 |
return queue.getException();
|
393 |
439 |
}
|
394 |
440 |
|
|
441 |
@Override
|
|
442 |
public int hashCode()
|
|
443 |
{
|
|
444 |
final int prime = 31;
|
|
445 |
int result = 1;
|
|
446 |
result = prime * result + sessionId;
|
|
447 |
return result;
|
|
448 |
}
|
|
449 |
|
|
450 |
@Override
|
|
451 |
public boolean equals(Object obj)
|
|
452 |
{
|
|
453 |
if (this == obj)
|
|
454 |
return true;
|
|
455 |
if (obj == null)
|
|
456 |
return false;
|
|
457 |
if (getClass() != obj.getClass())
|
|
458 |
return false;
|
|
459 |
BaseSession other = (BaseSession) obj;
|
|
460 |
if (sessionId != other.sessionId)
|
|
461 |
return false;
|
|
462 |
return true;
|
|
463 |
}
|
|
464 |
|
395 |
465 |
/**
|
396 |
466 |
* Preprocess a message before it is delivered.
|
397 |
467 |
*
|