Package net.sf.freecol.server.model
Class Session
- java.lang.Object
-
- net.sf.freecol.server.model.Session
-
- Direct Known Subclasses:
LootSession
,MonarchSession
,NativeTradeSession
,TimedSession
public abstract class Session extends java.lang.Object
Root class for sessions.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Map<java.lang.String,Session>
allSessions
A map of all active sessions.private boolean
completed
Has this session been completed?private java.lang.String
key
The key to this session.private static java.util.logging.Logger
logger
-
Constructor Summary
Constructors Modifier Constructor Description protected
Session(java.lang.String key)
Protected constructor, we only really instantiate specific types of transactions.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
clearAll()
Clear all sessions.protected boolean
complete(ChangeSet cs)
All transaction types must implement a completion action.static void
completeAll(ChangeSet cs)
Complete all transactions.static Session
findSession(java.util.function.Predicate<Session> pred)
Find a session matching a predicate.java.lang.String
getKey()
Get the session key.private static Session
getSession(java.lang.String key)
Get the session with a given key.private boolean
isComplete()
Is this session complete?static <T extends Session>
Tlookup(java.lang.Class<T> type, java.lang.String key)
Look up a session given its key.static <T extends Session>
Tlookup(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.static <T extends Session>
Tlookup(java.lang.Class<T> type, FreeColGameObject o1, FreeColGameObject o2)
Look up a session of specified type given the game objects involved.protected static java.lang.String
makeSessionKey(java.lang.Class type, java.lang.String o1, java.lang.String o2)
Make a transaction session key.protected static java.lang.String
makeSessionKey(java.lang.Class type, FreeColGameObject o1, FreeColGameObject o2)
Make a transaction session key given two game objects.void
register()
Register a new session.
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
allSessions
private static final java.util.Map<java.lang.String,Session> allSessions
A map of all active sessions.
-
key
private java.lang.String key
The key to this session.
-
completed
private boolean completed
Has this session been completed?
-
-
Method Detail
-
getKey
public java.lang.String getKey()
Get the session key.- Returns:
- The key for this session.
-
register
public void register()
Register a new session.
-
getSession
private static Session getSession(java.lang.String key)
Get the session with a given key.- Parameters:
key
- The session key.- Returns:
- The
session
found.
-
isComplete
private boolean isComplete()
Is this session complete?- Returns:
- True if the session is complete.
-
complete
protected boolean complete(ChangeSet cs)
All transaction types must implement a completion action. This is called by the controller at the end of turn to complete any sessions that have not yet completed, or if the controller gets the required response to complete the session.- Parameters:
cs
- AChangeSet
to update with changes that occur when completing this session.- Returns:
- True if the session was already complete.
-
makeSessionKey
protected static java.lang.String makeSessionKey(java.lang.Class type, java.lang.String o1, java.lang.String o2)
Make a transaction session key. Note: sort the keys to make session key independent of argument order.- 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
- AFreeColGameObject
involved in the session.o2
- AnotherFreeColGameObject
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
- AChangeSet
to update.
-
clearAll
public static void clearAll()
Clear all sessions.
-
findSession
public static Session findSession(java.util.function.Predicate<Session> pred)
Find a session matching a predicate.- Parameters:
pred
- ThePredicate
to match.- Returns:
- The
Session
found if any.
-
lookup
public static <T extends Session> T lookup(java.lang.Class<T> type, FreeColGameObject o1, FreeColGameObject o2)
Look up a session of specified type given the game objects involved.- Type Parameters:
T
- The actual session class found.- Parameters:
type
- The class of session.o1
- The firstFreeColGameObject
in the session.o2
- The secondFreeColGameObject
in the session.- Returns:
- A session of the specified type, or null if not found.
-
lookup
public static <T extends Session> 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.- Type Parameters:
T
- The actual session class found.- Parameters:
type
- The class of session.s1
- The identifier of the first object in the session.s2
- The identifier of the second object in the session.- Returns:
- A session of the specified type, or null if not found.
-
lookup
public static <T extends Session> T lookup(java.lang.Class<T> type, java.lang.String key)
Look up a session given its key.- Type Parameters:
T
- The actual session class found.- Parameters:
type
- The class of session.key
- The session key.- Returns:
- A session of the specified type, or null if not found.
-
-