public class Instructor
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected java.util.List<Loop<?,?>> |
loops
Loops that linked to this.
|
protected java.util.List<java.util.function.BiFunction<Instructor,Loop<?,?>,java.lang.Boolean>> |
posts
All undone posts of this group.
|
protected java.util.concurrent.atomic.AtomicReference<java.lang.String> |
state
The first position of any further loop get started by this.
|
Constructor and Description |
---|
Instructor() |
Modifier and Type | Method and Description |
---|---|
java.util.List<Loop<?,?>> |
getLoops()
Get the
loops of this loop. |
Instructor |
getLoops(java.util.function.Consumer<java.util.List<Loop<?,?>>> action)
Do the given action to the
loops of this. |
java.util.List<java.util.function.BiFunction<Instructor,Loop<?,?>,java.lang.Boolean>> |
getPosts()
Get the
posts of this loop. |
Instructor |
getPosts(java.util.function.Consumer<java.util.List<java.util.function.BiFunction<Instructor,Loop<?,?>,java.lang.Boolean>>> action)
Do the given action to the
posts of this. |
java.util.concurrent.atomic.AtomicReference<java.lang.String> |
getState()
Get the
state of this loop. |
Instructor |
getState(java.util.function.Consumer<java.lang.String> action)
Do the given action to the
state of this. |
boolean |
isAlive()
Get if this group is alive or not.
|
Instructor |
join()
Waits for all loops of this group to die.
|
Instructor |
join(java.util.function.Consumer<Instructor> alter,
long millis)
Waits at most millis milliseconds for all loops of this group to die.
|
Instructor |
notify(java.lang.String state)
Update the state of every currently or further running loops in this group.
|
Instructor |
pair()
Wait until make sure that there is a running loop on this group.
|
Instructor |
post(java.util.function.BiFunction<Instructor,Loop<?,?>,java.lang.Boolean> action)
Make a loop of this group do the given action.
|
Instructor |
post(java.util.function.BiFunction<Instructor,Loop<?,?>,java.lang.Boolean> action,
java.util.function.Consumer<Instructor> alter)
Make a loop of this group do the given action.
|
Instructor |
post(java.util.function.BiFunction<Instructor,Loop<?,?>,java.lang.Boolean> action,
java.util.function.Consumer<Instructor> alter,
long timeout)
Make a loop of this group do the given action.
|
Instructor |
start(Loop<?,?> loop)
Start a loop using this
Instructor . |
Instructor |
synchronously(java.util.function.BiConsumer<Instructor,Loop<?,?>> action)
Make a loop of this group do the given action.
|
Instructor |
synchronously(java.util.function.BiConsumer<Instructor,Loop<?,?>> action,
java.util.function.Consumer<Instructor> alter)
Make a loop of this group do the given action.
|
Instructor |
synchronously(java.util.function.BiConsumer<Instructor,Loop<?,?>> action,
java.util.function.Consumer<Instructor> alter,
long timeout)
Make a loop of this group do the given action.
|
Instructor |
thread(Loop<?,?> loop)
Start the given loop with a new thread.
|
Instructor |
tick()
Do the posts posted on this group.
|
Instructor |
tick(Loop<?,?> caller)
Do the posts posted on this group.
|
protected final java.util.List<Loop<?,?>> loops
Note: synchronized use only.
protected final java.util.List<java.util.function.BiFunction<Instructor,Loop<?,?>,java.lang.Boolean>> posts
Note: synchronized use only.
protected final java.util.concurrent.atomic.AtomicReference<java.lang.String> state
Note: synchronized use only.
public java.util.List<Loop<?,?>> getLoops()
loops
of this loop.getLoops(Consumer)
public Instructor getLoops(java.util.function.Consumer<java.util.List<Loop<?,?>>> action)
loops
of this. with a locked access.
Note: this may not be useful if this loop rapidly starts and finishes
action
- to be done to the loops list of thisjava.lang.NullPointerException
- if the given 'action' is nullgetLoops()
public java.util.List<java.util.function.BiFunction<Instructor,Loop<?,?>,java.lang.Boolean>> getPosts()
posts
of this loop.getPosts(Consumer)
public Instructor getPosts(java.util.function.Consumer<java.util.List<java.util.function.BiFunction<Instructor,Loop<?,?>,java.lang.Boolean>>> action)
posts
of this. with a locked access.action
- to be done to the posts list of thisjava.lang.NullPointerException
- if the given 'action' is nullgetPosts()
public java.util.concurrent.atomic.AtomicReference<java.lang.String> getState()
state
of this loop.getState(Consumer)
public Instructor getState(java.util.function.Consumer<java.lang.String> action)
state
of this. with a locked access.action
- to be done to the state instance of thisjava.lang.NullPointerException
- if the given 'action' is nullgetState()
public boolean isAlive()
Note: this may not be useful if this loop rapidly starts and finishes
Loop.isAlive()
public Instructor join()
Note: this may not be useful if this loop rapidly starts and finishes
Loop.join()
public Instructor join(java.util.function.Consumer<Instructor> alter, long millis)
Note: this may not be useful if this loop rapidly starts and finishes
alter
- what to do when the timeout is donemillis
- the time to wait in millisecondsjava.lang.IllegalArgumentException
- if the value of millis is negativejava.lang.NullPointerException
- if the given alter is nullLoop.join(Consumer, long)
public Instructor notify(java.lang.String state)
state
- the new statejava.lang.NullPointerException
- if the given state is nullLoop.notify(String)
public Instructor pair()
Loop.pair()
public Instructor post(java.util.function.BiFunction<Instructor,Loop<?,?>,java.lang.Boolean> action)
action
- to be done by a loop of this group (return false to remove the action)java.lang.NullPointerException
- if the given action is nullLoop.post(Function)
public Instructor post(java.util.function.BiFunction<Instructor,Loop<?,?>,java.lang.Boolean> action, java.util.function.Consumer<Instructor> alter)
Note: no matter what. One (AND JUST ONE) of the given actions should be invoked.
action
- to be done by a loop of this (return false to remove the action)alter
- the action to be done if this group don't have a running loopjava.lang.NullPointerException
- if ether the given 'action' or the given 'alter' is nullLoop.post(Function, Consumer)
public Instructor post(java.util.function.BiFunction<Instructor,Loop<?,?>,java.lang.Boolean> action, java.util.function.Consumer<Instructor> alter, long timeout)
Note: no matter what. One (AND JUST ONE) of the given actions should be invoked.
action
- to be done by a loop of this groupalter
- to do when timeout and the action has not been donetimeout
- the timeout (in milli seconds)java.lang.NullPointerException
- if ether the given 'action' or 'alter' is nulljava.lang.IllegalArgumentException
- if ether the given 'timeout' is negativeLoop.post(Function, Consumer, long)
public Instructor start(Loop<?,?> loop)
Instructor
.loop
- to be startedjava.lang.NullPointerException
- if the given loop is nullLoop.start()
public Instructor synchronously(java.util.function.BiConsumer<Instructor,Loop<?,?>> action)
action
- to be done by a loop of this groupjava.lang.NullPointerException
- if the given 'action' is nullLoop.synchronously(Consumer)
public Instructor synchronously(java.util.function.BiConsumer<Instructor,Loop<?,?>> action, java.util.function.Consumer<Instructor> alter)
Note: this may not be useful if this group rapidly starts and finishes loops
Note: no matter what. One (AND JUST ONE) of the given actions should be invoked once (also, JUST ONCE).
Note: action SHOULDN'T be synchronously invoked on ANY non-local object
action
- to be done by a loop of this groupalter
- to be done if there is no loop on this group (currently)java.lang.NullPointerException
- if ether the given 'action' or 'alter' is nullLoop.synchronously(Consumer, Consumer)
public Instructor synchronously(java.util.function.BiConsumer<Instructor,Loop<?,?>> action, java.util.function.Consumer<Instructor> alter, long timeout)
Note: no matter what. One (AND JUST ONE) of the given actions should be invoked once (also, JUST ONCE).
action
- to be done by a loop of this groupalter
- to be done if the timeout endedtimeout
- to wait for the action to be invoked (milli seconds)java.lang.NullPointerException
- if ether the given 'action' or 'alter' is nulljava.lang.IllegalArgumentException
- if the given 'timeout' is negativeLoop.synchronously(Consumer, Consumer, long)
public Instructor thread(Loop<?,?> loop)
loop
- to be startedjava.lang.NullPointerException
- if the given loop is nullLoop.thread()
public Instructor tick()
Note: this designed to be called by a loop of this instructor
java.lang.NullPointerException
- when a post tris doing anything to the caller without doing a null checkpublic Instructor tick(Loop<?,?> caller)
caller
- the caller loopjava.lang.NullPointerException
- when the 'caller' is null and a post tris doing anything to the caller without doing a null checkIllegalThreadException
- if the 'caller' isn't null and the caller thread ins't the thread of the given loop