Class ZStar
- java.lang.Object
-
- org.zeromq.ZStar
-
- All Implemented Interfaces:
ZAgent
- Direct Known Subclasses:
ZActor
public class ZStar extends java.lang.Object implements ZAgent
First implementation for the base of a remotely controlled background service for 0MQ.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 cansend
andreceive
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 Ø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 callagent()
to get the agent or directly callsend(ZMsg)
orrecv()
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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class 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.-
Nested classes/interfaces inherited from interface org.zeromq.ZAgent
ZAgent.Creator, ZAgent.SelectorCreator, ZAgent.SimpleAgent
-
-
Constructor Summary
Constructors Constructor Description ZStar(ZAgent.SelectorCreator selector, ZStar.Fortune fortune, java.lang.String motdelafin, java.lang.Object... bags)
Deprecated.useZStar(Fortune, String, Object...)
instead.ZStar(ZContext context, ZAgent.SelectorCreator selector, ZStar.Fortune fortune, java.lang.String motdelafin, java.lang.Object... bags)
Deprecated.useZStar(ZContext, 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, ZStar.Fortune fortune, java.lang.String motdelafin, java.lang.Object... bags)
Creates a new ZStar.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(ZStar.Fortune fortune, java.lang.String motdelafin, java.lang.Object... bags)
Creates a new ZStar.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method 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.
-
-
-
Field Detail
-
context
private final ZContext context
-
agent
private final ZAgent agent
-
plateau
private final ZStar.Plateau plateau
-
-
Constructor Detail
-
ZStar
@Deprecated public ZStar(ZAgent.SelectorCreator selector, ZStar.Fortune fortune, java.lang.String motdelafin, java.lang.Object... bags)
Deprecated.useZStar(Fortune, String, Object...)
instead.Creates a new ZStar.- Parameters:
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 star
-
ZStar
public ZStar(ZStar.Fortune fortune, java.lang.String motdelafin, java.lang.Object... bags)
Creates a new ZStar.- Parameters:
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
-
ZStar
@Deprecated public ZStar(ZContext context, ZAgent.SelectorCreator selector, ZStar.Fortune fortune, java.lang.String motdelafin, java.lang.Object... bags)
Deprecated.useZStar(ZContext, Fortune, String, Object...)
instead.Creates a new ZStar.- Parameters:
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 star
-
ZStar
public ZStar(ZContext context, ZStar.Fortune fortune, java.lang.String motdelafin, java.lang.Object... bags)
Creates a new ZStar.- Parameters:
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
-
ZStar
@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)
Deprecated.Creates a new ZStar.- Parameters:
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 star
-
ZStar
public 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.- Parameters:
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 star
-
-
Method Detail
-
party
public static void party(long time, java.util.concurrent.TimeUnit unit)
-
agent
public ZAgent agent()
Returns the Corbeille endpoint. Can be used to send or receive control messages to the distant star via Backstage.- Returns:
- the agent/mailbox used to send and receive control messages to and from the star.
-
exit
public ZStar.Exit exit()
Returns the control of the proper exit of the remote operations.- Returns:
- a structure used for checking the end of the remote operations.
-
agent
@Deprecated protected ZAgent agent(ZMQ.Socket phone, java.lang.String secret)
Deprecated.Creates a new agent for the star.- Parameters:
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.- Returns:
- the newly created agent for the star.
-
recv
public ZMsg recv()
Description copied from interface:ZAgent
Receives a control message sent from the Plateau in the Corbeille. The call is blocking.
-
recv
public ZMsg recv(int timeout)
Description copied from interface:ZAgent
Receives a control message sent from the Plateau in the Corbeille. The call times out if there is no message after the elapsed time.
-
recv
public ZMsg recv(boolean wait)
Description copied from interface:ZAgent
Receives a control message sent from the Plateau in the Corbeille. The call is blocking depending on the parameter.
-
send
public boolean send(ZMsg message)
Description copied from interface:ZAgent
Sends a control message from the Corbeille to the Plateau.
-
send
public boolean send(ZMsg msg, boolean destroy)
Description copied from interface:ZAgent
Sends a control message from Corbeille side to the Plateau side.
-
send
public boolean send(java.lang.String word)
Description copied from interface:ZAgent
Sends a control message from the Corbeille to the Plateau side.
-
send
public boolean send(java.lang.String word, boolean more)
Description copied from interface:ZAgent
Sends a control message from the Corbeille to the Plateau side.
-
pipe
public ZMQ.Socket pipe()
Description copied from interface:ZAgent
Returns the socket used for communication. For advanced usage.
-
sign
public boolean sign()
Description copied from interface:ZAgent
Gives a sign if the distant Star is here.
-
-