Package org.zeromq
Class ZMonitor
- java.lang.Object
-
- org.zeromq.ZMonitor
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class ZMonitor extends java.lang.Object implements java.io.CloseableThe ZMonitor actor provides an API for obtaining socket events such as connected, listen, disconnected, etc. Socket events are only available for sockets connecting or bound to ipc:// and tcp:// endpoints.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classZMonitor.EventEnumerates types of monitoring events.private static classZMonitor.MonitorActorstatic classZMonitor.ProtocolCodeThe code returned by handshake events, as generated byeventHandshakeXXX.static classZMonitor.ZEventHigh-level representation of an event.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringADD_EVENTSprivate ZAgentagentprivate static java.lang.StringCLOSEprivate ZStar.Exitexitprivate static java.lang.StringREMOVE_EVENTSprivate static java.lang.StringSTARTprivate booleanstartedprivate static java.lang.StringVERBOSE
-
Constructor Summary
Constructors Constructor Description ZMonitor(ZContext ctx, ZMQ.Socket socket)Creates a monitoring actor for the given socket.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ZMonitoradd(ZMonitor.Event... events)Adds event types to monitor.voidclose()Stops the monitoring and closes the actor.voiddestroy()Stops the monitoring and closes the actor.ZMonitor.ZEventnextEvent()Gets the next event, blocking for it until available.ZMonitor.ZEventnextEvent(boolean wait)Gets the next event, blocking for it until available if requested.ZMonitor.ZEventnextEvent(int timeout)Gets the next event, blocking for it until available if requested.ZMonitorremove(ZMonitor.Event... events)Removes event types from monitor.ZMonitorstart()Starts the monitoring.ZMonitorverbose(boolean verbose)Sets verbosity of the monitor.
-
-
-
Field Detail
-
started
private boolean started
-
START
private static final java.lang.String START
- See Also:
- Constant Field Values
-
CLOSE
private static final java.lang.String CLOSE
- See Also:
- Constant Field Values
-
VERBOSE
private static final java.lang.String VERBOSE
- See Also:
- Constant Field Values
-
ADD_EVENTS
private static final java.lang.String ADD_EVENTS
- See Also:
- Constant Field Values
-
REMOVE_EVENTS
private static final java.lang.String REMOVE_EVENTS
- See Also:
- Constant Field Values
-
agent
private final ZAgent agent
-
exit
private final ZStar.Exit exit
-
-
Constructor Detail
-
ZMonitor
public ZMonitor(ZContext ctx, ZMQ.Socket socket)
Creates a monitoring actor for the given socket.- Parameters:
ctx- the context relative to this actor. Not null.socket- the socket to monitor for events. Not null.
-
-
Method Detail
-
start
public final ZMonitor start()
Starts the monitoring. Event types have to be added before the start, or they will take no effect.- Returns:
- this instance.
-
close
public final void close() throws java.io.IOExceptionStops the monitoring and closes the actor. When returning from that call, ZMonitor will be no more active.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
destroy
public final void destroy()
Stops the monitoring and closes the actor. When returning from that call, ZMonitor will be no more active.
-
verbose
public final ZMonitor verbose(boolean verbose)
Sets verbosity of the monitor.- Parameters:
verbose- true for monitor to be verbose, otherwise false.- Returns:
- this instance.
-
add
public final ZMonitor add(ZMonitor.Event... events)
Adds event types to monitor.- Parameters:
events- the types of events to monitor.- Returns:
- this instance.
-
remove
public final ZMonitor remove(ZMonitor.Event... events)
Removes event types from monitor.- Parameters:
events- the types of events to stop monitoring.- Returns:
- this instance.
-
nextEvent
public final ZMonitor.ZEvent nextEvent()
Gets the next event, blocking for it until available.- Returns:
- the next monitored event or null if closed.
-
nextEvent
public final ZMonitor.ZEvent nextEvent(boolean wait)
Gets the next event, blocking for it until available if requested.- Parameters:
wait- true to block until next event is available, false to immediately return with null if there is no event.- Returns:
- the next event or null if there is currently none.
-
nextEvent
public final ZMonitor.ZEvent nextEvent(int timeout)
Gets the next event, blocking for it until available if requested.- Parameters:
timeout- the time in milliseconds to wait for a message before returning null, -1 to block.- Returns:
- the next event or null if there is currently none after the specified timeout.
-
-