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.Closeable
The 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 class
ZMonitor.Event
Enumerates types of monitoring events.private static class
ZMonitor.MonitorActor
static class
ZMonitor.ProtocolCode
The code returned by handshake events, as generated byeventHandshakeXXX
.static class
ZMonitor.ZEvent
High-level representation of an event.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
ADD_EVENTS
private ZAgent
agent
private static java.lang.String
CLOSE
private ZStar.Exit
exit
private static java.lang.String
REMOVE_EVENTS
private static java.lang.String
START
private boolean
started
private static java.lang.String
VERBOSE
-
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 ZMonitor
add(ZMonitor.Event... events)
Adds event types to monitor.void
close()
Stops the monitoring and closes the actor.void
destroy()
Stops the monitoring and closes the actor.ZMonitor.ZEvent
nextEvent()
Gets the next event, blocking for it until available.ZMonitor.ZEvent
nextEvent(boolean wait)
Gets the next event, blocking for it until available if requested.ZMonitor.ZEvent
nextEvent(int timeout)
Gets the next event, blocking for it until available if requested.ZMonitor
remove(ZMonitor.Event... events)
Removes event types from monitor.ZMonitor
start()
Starts the monitoring.ZMonitor
verbose(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.IOException
Stops the monitoring and closes the actor. When returning from that call, ZMonitor will be no more active.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in 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.
-
-