public class ZStar extends java.lang.Object implements ZAgent
A side or endpoint designates the same thing: the thread where lives one of the two parts of the system.
A Star
has 2 sides (with a trial to use theater terms for fun (: and hopefully clarity :)
send
and receive
control messages to the underneath star via the ZStar agent.
Communication between the 2 sides is ensured by pipes
that SHALL NEVER be mixed between background and control sides.
Instead, each side use its own pipe to communicate with the other one, transmitting only ØMQ messages.
The main purpose of this class is to ease this separation and to provide contracts, responsibilities and action levers for each side.
For example, instead of using pipe() which is useful to have more control, fast users would want to call agent()
to get the agent
or directly call send(ZMsg)
or recv()
from the ZStar as the ZStar is itself an agent!
The ZStar takes care of the establishment of the background processing, calling the provided star
at appropriate times. It can also manage the exited
state on the control side,
if providing a non-null "Mot de la Fin".
It also takes care of the closing of sockets and context if it had to create one.
A star
is basically a contract interface that anyone who uses this ZStar to create a background service SHALL comply to.
PS: Je sais qu'il y a une différence entre acteur et comédien :)
PPS: I know nothing about theater!
For an example of code, please refer to the ZActor
source code.
Modifier and Type | Class and Description |
---|---|
static interface |
ZStar.Entourage
Utility class with calls surrounding the execution of the Star.
|
static interface |
ZStar.Exit
Control for the end of the remote operations.
|
static interface |
ZStar.Fortune |
private static class |
ZStar.Plateau |
static interface |
ZStar.Set |
static class |
ZStar.SimpleSet |
static interface |
ZStar.Star
Contract interface when acting in plain sight.
|
static interface |
ZStar.TimeTaker
Utility class with callback for when the Star has finished its performances.
|
ZAgent.Creator, ZAgent.SelectorCreator, ZAgent.SimpleAgent
Modifier and Type | Field and Description |
---|---|
private ZAgent |
agent |
private ZContext |
context |
private ZStar.Plateau |
plateau |
Constructor and Description |
---|
ZStar(ZAgent.SelectorCreator selector,
ZStar.Fortune fortune,
java.lang.String motdelafin,
java.lang.Object... bags)
Deprecated.
use
ZStar(Fortune, String, Object...) instead. |
ZStar(ZContext context,
ZAgent.SelectorCreator selector,
ZStar.Fortune fortune,
BiFunction<ZMQ.Socket,java.lang.String,ZAgent> agent,
java.lang.String motdelafin,
java.lang.Object... bags)
Deprecated.
|
ZStar(ZContext context,
ZAgent.SelectorCreator selector,
ZStar.Fortune fortune,
java.lang.String motdelafin,
java.lang.Object... bags)
Deprecated.
use
ZStar(ZContext, Fortune, String, Object...) instead. |
ZStar(ZContext context,
ZStar.Fortune fortune,
BiFunction<ZMQ.Socket,java.lang.String,ZAgent> agent,
java.lang.String motdelafin,
java.lang.Object... bags)
Creates a new ZStar.
|
ZStar(ZContext context,
ZStar.Fortune fortune,
java.lang.String motdelafin,
java.lang.Object... bags)
Creates a new ZStar.
|
ZStar(ZStar.Fortune fortune,
java.lang.String motdelafin,
java.lang.Object... bags)
Creates a new ZStar.
|
Modifier and Type | Method and Description |
---|---|
ZAgent |
agent()
Returns the Corbeille endpoint.
|
protected ZAgent |
agent(ZMQ.Socket phone,
java.lang.String secret)
Deprecated.
|
void |
close()
Closes the pipe.
|
ZStar.Exit |
exit()
Returns the control of the proper exit of the remote operations.
|
static void |
party(long time,
java.util.concurrent.TimeUnit unit) |
ZMQ.Socket |
pipe()
Returns the socket used for communication.
|
ZMsg |
recv()
Receives a control message sent from the Plateau in the Corbeille.
|
ZMsg |
recv(boolean wait)
Receives a control message sent from the Plateau in the Corbeille.
|
ZMsg |
recv(int timeout)
Receives a control message sent from the Plateau in the Corbeille.
|
boolean |
send(java.lang.String word)
Sends a control message from the Corbeille to the Plateau side.
|
boolean |
send(java.lang.String word,
boolean more)
Sends a control message from the Corbeille to the Plateau side.
|
boolean |
send(ZMsg message)
Sends a control message from the Corbeille to the Plateau.
|
boolean |
send(ZMsg msg,
boolean destroy)
Sends a control message from Corbeille side to the Plateau side.
|
boolean |
sign()
Gives a sign if the distant Star is here.
|
private final ZContext context
private final ZAgent agent
private final ZStar.Plateau plateau
@Deprecated public ZStar(ZAgent.SelectorCreator selector, ZStar.Fortune fortune, java.lang.String motdelafin, java.lang.Object... bags)
ZStar(Fortune, String, Object...)
instead.selector
- the creator of the selector used on the Plateau.fortune
- the creator of stars on the Plateaumotdelafin
- the final word used to mark the end of the star. Null to disable this mechanism.bags
- the optional arguments that will be passed to the distant starpublic ZStar(ZStar.Fortune fortune, java.lang.String motdelafin, java.lang.Object... bags)
fortune
- the creator of stars on the Plateaumotdelafin
- the final word used to mark the end of the star. Null to disable this mechanism.bags
- the optional arguments that will be passed to the distant star@Deprecated public ZStar(ZContext context, ZAgent.SelectorCreator selector, ZStar.Fortune fortune, java.lang.String motdelafin, java.lang.Object... bags)
ZStar(ZContext, Fortune, String, Object...)
instead.context
- the main context used. If null, a new context will be created
and closed at the stop of the operation.
If not null, it is the responsibility of the caller to close it.selector
- the creator of the selector used on the Plateau.fortune
- the creator of stars on the Plateaumotdelafin
- the final word used to mark the end of the star. Null to disable this mechanism.bags
- the optional arguments that will be passed to the distant starpublic ZStar(ZContext context, ZStar.Fortune fortune, java.lang.String motdelafin, java.lang.Object... bags)
context
- the main context used. If null, a new context will be created
and closed at the stop of the operation.
If not null, it is the responsibility of the caller to close it.fortune
- the creator of stars on the Plateaumotdelafin
- the final word used to mark the end of the star. Null to disable this mechanism.bags
- the optional arguments that will be passed to the distant star@Deprecated public ZStar(ZContext context, ZAgent.SelectorCreator selector, ZStar.Fortune fortune, BiFunction<ZMQ.Socket,java.lang.String,ZAgent> agent, java.lang.String motdelafin, java.lang.Object... bags)
ZStar(ZContext, Fortune, BiFunction, String, Object...)
instead.context
- the main context used. If null, a new context will be created
and closed at the stop of the operation.
If not null, it is the responsibility of the caller to close it.selector
- the creator of the selector used on the Plateau.fortune
- the creator of stars on the Plateau. Not null.agent
- the creator of the agent. Not null.motdelafin
- the final word used to mark the end of the star. Null to disable this mechanism.bags
- the optional arguments that will be passed to the distant starpublic ZStar(ZContext context, ZStar.Fortune fortune, BiFunction<ZMQ.Socket,java.lang.String,ZAgent> agent, java.lang.String motdelafin, java.lang.Object... bags)
context
- the main context used. If null, a new context will be created
and closed at the stop of the operation.
If not null, it is the responsibility of the caller to close it.fortune
- the creator of stars on the Plateau. Not null.agent
- the creator of the agent. Not null.motdelafin
- the final word used to mark the end of the star. Null to disable this mechanism.bags
- the optional arguments that will be passed to the distant starpublic static void party(long time, java.util.concurrent.TimeUnit unit)
public ZAgent agent()
public ZStar.Exit exit()
@Deprecated protected ZAgent agent(ZMQ.Socket phone, java.lang.String secret)
phone
- the socket used to communicate with the starsecret
- the specific keyword indicating the death of the star and locking the agent. Null to override the lock mechanism.public ZMsg recv()
ZAgent
public ZMsg recv(int timeout)
ZAgent
public ZMsg recv(boolean wait)
ZAgent
public boolean send(ZMsg message)
ZAgent
public boolean send(ZMsg msg, boolean destroy)
ZAgent
public boolean send(java.lang.String word)
ZAgent
public boolean send(java.lang.String word, boolean more)
ZAgent
public ZMQ.Socket pipe()
ZAgent
public boolean sign()
ZAgent