public class StateAndConnectionManager
extends java.lang.Object
Constructor and Description |
---|
StateAndConnectionManager(IReality reality,
java.util.concurrent.Executor executor) |
Modifier and Type | Method and Description |
---|---|
boolean |
acceptParticipant(org.apache.mina.core.session.IoSession session,
ISimulationObject object,
ObjectCommandHandler objectHandler)
once all the participants information has been received, we officially add
them to the simulation and make sure its state is consistent with the
simulations
|
boolean |
credentialsAreValid(ICredentials credentials)
return true if these credentials are valid or if we are promiscuous.
|
long |
getAcknowledgementTimeout() |
IIdentifier |
getActiveParticipant(ICredentials credentials)
return the identifier for the participant with the provided credentials, or
null
|
java.util.Collection<IIdentifier> |
getActiveParticipants(java.util.Collection<IIdentifier> participantContainer)
return all the participants that are actively connected.
|
java.util.Collection<org.apache.mina.core.session.IoSession> |
getActiveSessions(java.util.Collection<org.apache.mina.core.session.IoSession> container)
return all the active iosessions
|
ICredentials |
getParticipantCredentials(org.apache.mina.core.session.IoSession session) |
IIdentifier |
getParticipantIdentifier(org.apache.mina.core.session.IoSession session) |
org.apache.mina.core.session.IoSession |
getParticipantSession(IIdentifier participantId)
return the
IoSession for the participant. |
org.apache.mina.core.session.IoSession |
getPendingParticipantSession(IIdentifier participantId) |
java.util.concurrent.locks.ReentrantReadWriteLock |
getStateLock() |
void |
grantCredentials(ICredentials credentials,
boolean wantsClockOwnership)
adds the credentials to the set of acceptable credentials.
|
protected boolean |
isAddressingInfoValid(org.apache.mina.core.session.IoSession session,
IAddressingInformation addressing)
this should, ultimately, check to be sure that the location they report for
connecting too is consistent with where they actually are (cheap spoofing
measure)
|
boolean |
isClockOwner(ICredentials credentials) |
boolean |
isPromiscuous() |
void |
participantConnected(org.apache.mina.core.session.IoSession session,
IConnectionRequest request)
called when a participant connects and asks to be added to the simulation.
|
IIdentifier |
participantDisconnected(org.apache.mina.core.session.IoSession session)
called when a participant leaves the simulation, cleanly or not
|
void |
revokeCredentials(ICredentials credentials)
revoke the credentials.
|
void |
setAcknowledgementTimeout(long timeout) |
void |
setPromiscuous(boolean promiscuous)
if promiscuous is true, all participants will be allowed to connect
regardless of their credentials.
|
java.util.Collection<IIdentifier> |
setState(IParticipant.State state)
will send message to all participants and wait at most timeToWait
milliseconds for acknowledgements from them.
|
public StateAndConnectionManager(IReality reality, java.util.concurrent.Executor executor)
public java.util.concurrent.locks.ReentrantReadWriteLock getStateLock()
public void setAcknowledgementTimeout(long timeout)
public long getAcknowledgementTimeout()
public void setPromiscuous(boolean promiscuous)
promiscuous
- public boolean isPromiscuous()
public void grantCredentials(ICredentials credentials, boolean wantsClockOwnership)
credentials
- wantsClockOwnership
- public void revokeCredentials(ICredentials credentials)
credentials
- public boolean credentialsAreValid(ICredentials credentials)
credentials
- public boolean isClockOwner(ICredentials credentials)
public java.util.Collection<IIdentifier> getActiveParticipants(java.util.Collection<IIdentifier> participantContainer)
public java.util.Collection<org.apache.mina.core.session.IoSession> getActiveSessions(java.util.Collection<org.apache.mina.core.session.IoSession> container)
container
- public IIdentifier getActiveParticipant(ICredentials credentials)
credentials
- public org.apache.mina.core.session.IoSession getParticipantSession(IIdentifier participantId)
IoSession
for the participant. This IIdentifier
must be in the current set returned by #getActiveParticipants()
,
otherwise it will return null, signaling that the participant has
disconnected.public org.apache.mina.core.session.IoSession getPendingParticipantSession(IIdentifier participantId)
public IIdentifier getParticipantIdentifier(org.apache.mina.core.session.IoSession session)
public ICredentials getParticipantCredentials(org.apache.mina.core.session.IoSession session)
public java.util.Collection<IIdentifier> setState(IParticipant.State state)
getParticipantSession(IIdentifier)
returns
null for any identifier (disconnected), it will be ignored and added to the
list of nonresponders.participants
- message
- timeToWait
- or 0 if indefiniteprotected boolean isAddressingInfoValid(org.apache.mina.core.session.IoSession session, IAddressingInformation addressing)
session
- addressing
- public void participantConnected(org.apache.mina.core.session.IoSession session, IConnectionRequest request)
#acceptParticipant()
will be calledpublic boolean acceptParticipant(org.apache.mina.core.session.IoSession session, ISimulationObject object, ObjectCommandHandler objectHandler)
public IIdentifier participantDisconnected(org.apache.mina.core.session.IoSession session)