public class ZStar extends 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 :)
- the Corbeille side, or control side
This is where one can send
and receive
control messages to the underneath star via the ZStar agent.
The ZStar lives on this side and is a way to safely communicate with the distant provided star.
Note: Corbeille is a french word designing the most privileged places in the theater where the King was standing,
1st floor, just above the orchestra (Wikipedia...).
- the Plateau side, or background side where all the performances are made by the provided star.
The provided star is living on the Plateau.
The Plateau is made of the Stage where effective acting takes place and of the Wings
where the provided star can perform control decisions to stop or continue the acting.
From this side, the work is done via callbacks using the template-method pattern, applied with interfaces (?)
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 0MQ 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 |
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, ZAgent.VerySimpleSelectorCreator
Constructor and Description |
---|
ZStar(ZAgent.SelectorCreator selector,
ZStar.Fortune fortune,
String motdelafin,
Object... args)
Creates a new ZStar.
|
ZStar(ZContext context,
ZAgent.SelectorCreator selector,
ZStar.Fortune fortune,
String motdelafin,
Object[] bags)
Creates a new ZStar.
|
ZStar(ZStar.Fortune actor,
String lock,
Object... args)
Creates a new ZStar.
|
Modifier and Type | Method and Description |
---|---|
ZAgent |
agent()
Returns the Corbeille endpoint.
|
protected ZAgent |
agent(ZMQ.Socket phone,
String secret)
Creates a new agent for the star.
|
ZStar.Exit |
exit()
Returns the control of the proper exit of the remote operations.
|
void |
nova()
Forcely destroys the Star.
|
static void |
party(long time,
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.
|
boolean |
send(String word)
Sends a control message from the Corbeille to the Plateau side.
|
boolean |
send(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.
|
public ZStar(ZStar.Fortune actor, String lock, Object... args)
actor
- the creator of stars on the Plateaulock
- the final word used to mark the end of the star. Null to disable this mechanism.args
- the optional arguments that will be passed to the distant starpublic ZStar(ZAgent.SelectorCreator selector, ZStar.Fortune fortune, String motdelafin, Object... args)
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.args
- the optional arguments that will be passed to the distant starpublic ZStar(ZContext context, ZAgent.SelectorCreator selector, ZStar.Fortune fortune, String motdelafin, 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.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 static void party(long time, TimeUnit unit)
public ZAgent agent()
public ZStar.Exit exit()
protected ZAgent agent(ZMQ.Socket phone, 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(boolean wait)
ZAgent
public boolean send(ZMsg message)
ZAgent
public boolean send(ZMsg msg, boolean destroy)
ZAgent
public boolean send(String word)
ZAgent
public boolean send(String word, boolean more)
ZAgent
public ZMQ.Socket pipe()
ZAgent
public boolean sign()
ZAgent
Copyright © 2021. All rights reserved.