public class DefaultSession extends Object implements Session
onEvent(Event)
method and for sending it uses the
EventDispatcher
fireEvent method. The Method setId(Object)
will throw IllegalArgumentException
in this implementation class.Modifier and Type | Class and Description |
---|---|
static class |
DefaultSession.SessionBuilder
This class is roughly based on Joshua Bloch's Builder pattern.
|
Session.Status
Modifier and Type | Field and Description |
---|---|
protected long |
creationTime |
protected EventDispatcher |
eventDispatcher
event dispatcher
|
protected Object |
id
session id
|
protected boolean |
isShuttingDown
Life cycle variable to check if the session is shutting down.
|
protected boolean |
isUDPEnabled |
protected boolean |
isWriteable |
protected long |
lastReadWriteTime |
protected Map<String,Object> |
sessionAttributes
session parameters
|
protected Session.Status |
status |
protected MessageSender.Reliable |
tcpSender |
protected MessageSender.Fast |
udpSender |
Modifier | Constructor and Description |
---|---|
protected |
DefaultSession(DefaultSession.SessionBuilder sessionBuilder) |
Modifier and Type | Method and Description |
---|---|
void |
addHandler(EventHandler eventHandler) |
void |
close() |
boolean |
equals(Object obj) |
Object |
getAttribute(String key) |
long |
getCreationTime() |
EventDispatcher |
getEventDispatcher() |
List<EventHandler> |
getEventHandlers(int eventType) |
Object |
getId() |
long |
getLastReadWriteTime() |
Map<String,Object> |
getSessionAttributes() |
Session.Status |
getStatus() |
MessageSender.Reliable |
getTcpSender() |
MessageSender.Fast |
getUdpSender() |
int |
hashCode() |
boolean |
isConnected() |
boolean |
isShuttingDown() |
boolean |
isUDPEnabled()
Not synchronized because default implementation does not care whether a
duplicated message sender is created.
|
boolean |
isWriteable() |
void |
onEvent(Event event) |
void |
removeAttribute(String key) |
void |
removeHandler(EventHandler eventHandler) |
void |
setAttribute(String key,
Object value) |
void |
setId(Object id) |
void |
setLastReadWriteTime(long lastReadWriteTime) |
void |
setStatus(Session.Status status) |
void |
setTcpSender(MessageSender.Reliable tcpSender) |
void |
setUDPEnabled(boolean isEnabled)
A session would not have UDP capability when created.
|
void |
setUdpSender(MessageSender.Fast udpSender) |
void |
setWriteable(boolean isWriteable) |
protected final Object id
protected EventDispatcher eventDispatcher
protected final long creationTime
protected long lastReadWriteTime
protected Session.Status status
protected boolean isWriteable
protected volatile boolean isShuttingDown
protected boolean isUDPEnabled
protected MessageSender.Reliable tcpSender
protected MessageSender.Fast udpSender
protected DefaultSession(DefaultSession.SessionBuilder sessionBuilder)
public EventDispatcher getEventDispatcher()
getEventDispatcher
in interface Session
public void addHandler(EventHandler eventHandler)
addHandler
in interface Session
public void removeHandler(EventHandler eventHandler)
removeHandler
in interface Session
public List<EventHandler> getEventHandlers(int eventType)
getEventHandlers
in interface Session
public Object getAttribute(String key)
getAttribute
in interface Session
public void removeAttribute(String key)
removeAttribute
in interface Session
public void setAttribute(String key, Object value)
setAttribute
in interface Session
public long getCreationTime()
getCreationTime
in interface Session
public long getLastReadWriteTime()
getLastReadWriteTime
in interface Session
public void setLastReadWriteTime(long lastReadWriteTime)
public Session.Status getStatus()
public void setStatus(Session.Status status)
public boolean isConnected()
isConnected
in interface Session
public boolean isWriteable()
isWriteable
in interface Session
public void setWriteable(boolean isWriteable)
setWriteable
in interface Session
public boolean isUDPEnabled()
isUDPEnabled
in interface Session
MessageSender
instance is
attached to this session, else false.Session.isUDPEnabled()
public void setUDPEnabled(boolean isEnabled)
Session
Events
class. Once UDP MessageSender
instance is attached to the
session, this method should be called with flag to true to signal that
the session is now UDP enabled.setUDPEnabled
in interface Session
isEnabled
- Should be true in most use cases. It is used to signal that
the UDP MessageSender
has been attached to session.public boolean isShuttingDown()
isShuttingDown
in interface Session
public MessageSender.Reliable getTcpSender()
getTcpSender
in interface Session
public void setTcpSender(MessageSender.Reliable tcpSender)
setTcpSender
in interface Session
public MessageSender.Fast getUdpSender()
getUdpSender
in interface Session
public void setUdpSender(MessageSender.Fast udpSender)
setUdpSender
in interface Session
Copyright © 2013. All Rights Reserved.