net.sf.freecol.server.model
Class TransactionSession

java.lang.Object
  extended by net.sf.freecol.server.model.TransactionSession
Direct Known Subclasses:
DemandSession, DiplomacySession, LootSession, TradeSession

public abstract class TransactionSession
extends java.lang.Object

Root class for sessions.


Field Summary
protected static java.util.Map<java.lang.String,TransactionSession> allSessions
          A map of all active sessions.
private  boolean completed
          Has this session been completed?
private static java.util.logging.Logger logger
           
 
Constructor Summary
protected TransactionSession(java.lang.String key)
          Protected constructor, we only really instantiate specific types of transactions.
 
Method Summary
static void clearAll()
          Clear all transactions.
 void complete(ChangeSet cs)
          All transaction types must implement a completion action.
static void completeAll(ChangeSet cs)
          Complete all transactions.
static
<T extends TransactionSession>
T
lookup(java.lang.Class<T> type, FreeColGameObject o1, FreeColGameObject o2)
          Look up a session of specified type given the game objects involved.
static
<T extends TransactionSession>
T
lookup(java.lang.Class<T> type, java.lang.String s1, java.lang.String s2)
          Look up a session of specified type given the ids of the game objects involved.
protected static java.lang.String makeSessionKey(java.lang.Class type, FreeColGameObject o1, FreeColGameObject o2)
          Make a transaction session key given two game objects.
protected static java.lang.String makeSessionKey(java.lang.Class type, java.lang.String o1, java.lang.String o2)
          Make a transaction session key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static final java.util.logging.Logger logger

allSessions

protected static final java.util.Map<java.lang.String,TransactionSession> allSessions
A map of all active sessions.


completed

private boolean completed
Has this session been completed?

Constructor Detail

TransactionSession

protected TransactionSession(java.lang.String key)
Protected constructor, we only really instantiate specific types of transactions.

Parameters:
key - A unique key to lookup this transaction with.
Method Detail

complete

public void complete(ChangeSet cs)
All transaction types must implement a completion action. The last thing they should do is call this to remove reference to this transaction.

Parameters:
cs - A ChangeSet to update with changes that occur when completing this session.

makeSessionKey

protected static java.lang.String makeSessionKey(java.lang.Class type,
                                                 java.lang.String o1,
                                                 java.lang.String o2)
Make a transaction session key.

Parameters:
type - An identifier for the type of transaction.
o1 - A string to uniquely identify the transaction.
o2 - Another string to uniquely identify the transaction.
Returns:
A transaction session key.

makeSessionKey

protected static java.lang.String makeSessionKey(java.lang.Class type,
                                                 FreeColGameObject o1,
                                                 FreeColGameObject o2)
Make a transaction session key given two game objects.

Parameters:
type - An identifier for the type of transaction.
o1 - A FreeColGameObject involved in the session.
o2 - Another FreeColGameObject involved in the session.
Returns:
A transaction session key.

completeAll

public static void completeAll(ChangeSet cs)
Complete all transactions. Useful at the end of turn.

Parameters:
cs - A ChangeSet to update.

clearAll

public static void clearAll()
Clear all transactions.


lookup

public static <T extends TransactionSession> T lookup(java.lang.Class<T> type,
                                                      FreeColGameObject o1,
                                                      FreeColGameObject o2)
Look up a session of specified type given the game objects involved.

Parameters:
type - The class of session.
o1 - The first FreeColGameObject in the session.
o2 - The second FreeColGameObject in the session.
Returns:
A session of the specified type, or null if not found.

lookup

public static <T extends TransactionSession> T lookup(java.lang.Class<T> type,
                                                      java.lang.String s1,
                                                      java.lang.String s2)
Look up a session of specified type given the ids of the game objects involved. This version is needed for sessions where one of the objects may have already been disposed of while the session is still valid.

Parameters:
type - The class of session.
s1 - The id of the first object in the session.
s2 - The id of the second object in the session.
Returns:
A session of the specified type, or null if not found.