|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.progeeks.util.thread.StateCollector
public class StateCollector
Can track state among multiple threads and wait on consensus or for a certain number of participants to have set their state. This is useful for loose coordination between separate processes where majority votes and such can be sufficient. Actors can leave and join and the overall state calculation will adjusted accordingly.
Constructor Summary | |
---|---|
StateCollector()
|
Method Summary | |
---|---|
void |
addActor(java.lang.Object actor)
Adds the specified actor to the state collector. |
void |
clearAllActors()
Removes all of the actors from the map. |
void |
clearAllStates()
Clears all of the states for all of the actors. |
void |
clearState(java.lang.Object actor)
|
boolean |
containsActor(java.lang.Object actor)
Returns true if this collector is monitoring the specified actor. |
int |
getActorCount()
Returns the total number of actors. |
java.util.Collection |
getActors()
Returns a new collection containing all of the current actor objects. |
java.lang.Object |
getState(java.lang.Object actor)
Returns the state for the specified actor. |
int |
getStateCount()
Returns the number of actors that have their states set. |
java.util.Collection |
getStates()
Returns a new collection containing all of the current state objects. |
boolean |
hasState(java.lang.Object actor)
|
void |
interrupt()
|
void |
removeActor(java.lang.Object actor)
Removes the specified actor from this collector. |
void |
setState(java.lang.Object actor,
java.lang.Object state)
Sets the state for the specified actor. |
boolean |
waitForStates(double fraction,
long timeout)
Waits until a certain percentage of states have been collected or until the specified timeout. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public StateCollector()
Method Detail |
---|
public void addActor(java.lang.Object actor)
public void removeActor(java.lang.Object actor)
public boolean containsActor(java.lang.Object actor)
public void setState(java.lang.Object actor, java.lang.Object state)
public java.lang.Object getState(java.lang.Object actor)
public boolean hasState(java.lang.Object actor)
public void clearState(java.lang.Object actor)
public java.util.Collection getStates()
public java.util.Collection getActors()
public int getStateCount()
public int getActorCount()
public void clearAllStates()
public void clearAllActors()
public void interrupt()
public boolean waitForStates(double fraction, long timeout) throws java.lang.InterruptedException
fraction
- A value of 0 to 1.0 representing the number of
states relative to the total number of actors
to be collected before the method returns.timeout
- Number of milliseconds to wait. 0 for infinity.
java.lang.InterruptedException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |