com.anabas.sharedlet
Interface TokenService
- public interface TokenService
- extends SharedletService
The token service provides a semaphore like service for collaborative
applications.
There are two modes to the service: Master & Slave.
Master Mode
------------
In master mode, the token service can take any token away from another instance
of the token service in the system. If a master tries to grab a token and
none are left, one of the current holders of the token will lose it.
In essence the master will always have the right of way. If two master are
fighting for a token, the behavior is undefined.
The master is the creator and owner of token. If the master pass the token
to someone else, and that instance releases the token, the token will be given
back to the last master that released the token.
Slave Mode
------------
In slave mode, trying to grab a token will only work if there are tokens
available. If not, the token is not gained.
MASTER_MODE
public static final short MASTER_MODE
SLAVE_MODE
public static final short SLAVE_MODE
s_modeNames
public static final java.lang.String[] s_modeNames
giveToken
public void giveToken(java.lang.String token,
java.lang.String dst)
- Gives the token to a particular destination String. The destination string
is implmementation dependent.
- Parameters:
token
- The token to give.dst
- The destination to give to.
createToken
public void createToken(java.lang.String name)
throws PermissionDeniedException
- Creates a token. Only a token service in the master mode may create tokens.
Once created, when tokens are released, it will revert to the master.
- Parameters:
name
- The unique name of the token.
releaseToken
public void releaseToken(java.lang.String name)
- A friendly user will release tokens when not needed. Otherwise, the service
should still release the token in case of abnormal disconnects.
- Parameters:
name
- The name of the token.
isOwned
public boolean isOwned(java.lang.String tokenName)
- Returns:
- true if the token is currently owned by me.
getToken
public Token getToken(java.lang.String tokenName)
- Returns:
- null if the Token is not owned. The token otherwise.
requestToken
public void requestToken(java.lang.String name)
- Attempt to grab one instance of a token.
- Returns:
- null if the token can not be grabbed. Otherwise, the token grabbed.
getMode
public short getMode()
- Returns:
- The current mode of the token service.
addTokenListener
public void addTokenListener(TokenListener l)
- Adds a token listener. This is the only way that token status changes
will be notified.
removeTokenListener
public void removeTokenListener(TokenListener l)
- Removes a token listener.