Package zmq.io
Class StreamEngine
- java.lang.Object
-
- zmq.io.StreamEngine
-
- All Implemented Interfaces:
IEngine,IPollEvents
public class StreamEngine extends java.lang.Object implements IEngine, IPollEvents
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStreamEngine.ErrorReasonprivate classStreamEngine.ProducePongMessageprivate static classStreamEngine.Protocol
-
Field Summary
Fields Modifier and Type Field Description private Function<Msg,java.lang.Boolean>decodeAndPushprivate IDecoderdecoderprivate IEncoderencoderprivate java.lang.Stringendpointprivate Errnoerrnoprivate java.nio.channels.SocketChannelfdprivate java.nio.ByteBuffergreetingRecvprivate java.nio.ByteBuffergreetingSendprivate intgreetingSizeprivate Poller.Handlehandleprivate static intHANDSHAKE_TIMER_IDprivate booleanhandshakingprivate booleanhasHandshakeTimerprivate booleanhasHeartbeatTimerprivate booleanhasTimeoutTimerprivate booleanhasTtlTimerprivate static intHEARTBEAT_IVL_TIMER_IDprivate static intHEARTBEAT_TIMEOUT_TIMER_IDprivate static intHEARTBEAT_TTL_TIMER_IDprivate byte[]heartbeatContextprivate intheartbeatTimeoutprivate java.nio.ByteBufferinposprivate booleaninputStoppedprivate intinsizeprivate booleanioErrorprivate IOObjectioObjectprivate Mechanismmechanismprivate Metadatametadataprivate Supplier<Msg>nextHandshakeCommandprivate Supplier<Msg>nextIdentityprivate Supplier<Msg>nextMsgprivate Optionsoptionsprivate ValueReference<java.nio.ByteBuffer>outposprivate booleanoutputStoppedprivate intoutsizeprivate AddresspeerAddressprivate booleanpluggedprivate Function<Msg,java.lang.Boolean>processHandshakeCommandprivate Function<Msg,java.lang.Boolean>processIdentityprivate Function<Msg,java.lang.Boolean>processMsgprivate Supplier<Msg>producePingMessageprivate Supplier<Msg>pullAndEncodeprivate Supplier<Msg>pullMsgFromSessionprivate Function<Msg,java.lang.Boolean>pushMsgToSessionprivate Function<Msg,java.lang.Boolean>pushOneThenDecodeAndPushprivate Function<Msg,java.lang.Boolean>pushRawMsgToSessionprivate SessionBasesessionprivate static intSIGNATURE_SIZEprivate SocketBasesocketprivate booleansubscriptionRequiredprivate static intV2_GREETING_SIZEprivate static intV3_GREETING_SIZEprivate Function<Msg,java.lang.Boolean>writeCredentialprivate StreamEngine.ProtocolzmtpVersion
-
Constructor Summary
Constructors Constructor Description StreamEngine(java.nio.channels.SocketChannel fd, Options options, java.lang.String endpoint)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private booleandecodeAndPush(Msg msg)private booleandecodeCurrentInputs()private voiddecodeDataAfterHandshake(int greetingSize)voiddestroy()private voiderror(StreamEngine.ErrorReason error)java.lang.StringgetEndPoint()private booleanhandshake()private intheartbeatTimeout()private MsgidentityMsg()voidinEvent()Called by I/O thread when file descriptor is ready for reading.private <T> Tinstantiate(java.lang.Class<T> clazz, int size, long max)private voidmechanismReady()private MsgnextHandshakeCommand()voidoutEvent()Called by I/O thread when file descriptor is ready for writing.voidplug(IOThread ioThread, SessionBase session)private booleanprocessCommand(Msg msg)private booleanprocessHandshakeCommand(Msg msg)private booleanprocessHeartbeatMessage(Msg msg)private booleanprocessIdentityMsg(Msg msg)private MsgproducePingMessage()private MsgproducePongMessage(byte[] pingContext)private MsgpullAndEncode()private MsgpullMsgFromSession()private booleanpushMsgToSession(Msg msg)private booleanpushOneThenDecodeAndPush(Msg msg)private booleanpushRawMsgToSession(Msg msg)private intread(java.nio.ByteBuffer buf)voidrestartInput()voidrestartOutput()private voidsetHandshakeTimer()voidterminate()voidtimerEvent(int id)Called when timer expires.java.lang.StringtoString()private voidunplug()private intwrite(java.nio.ByteBuffer outbuf)private booleanwriteCredential(Msg msg)voidzapMsgAvailable()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface zmq.poll.IPollEvents
acceptEvent, connectEvent
-
-
-
-
Field Detail
-
ioObject
private IOObject ioObject
-
fd
private java.nio.channels.SocketChannel fd
-
handle
private Poller.Handle handle
-
inpos
private java.nio.ByteBuffer inpos
-
insize
private int insize
-
decoder
private IDecoder decoder
-
outpos
private final ValueReference<java.nio.ByteBuffer> outpos
-
outsize
private int outsize
-
encoder
private IEncoder encoder
-
metadata
private Metadata metadata
-
handshaking
private boolean handshaking
-
SIGNATURE_SIZE
private static final int SIGNATURE_SIZE
- See Also:
- Constant Field Values
-
V2_GREETING_SIZE
private static final int V2_GREETING_SIZE
- See Also:
- Constant Field Values
-
V3_GREETING_SIZE
private static final int V3_GREETING_SIZE
- See Also:
- Constant Field Values
-
greetingSize
private int greetingSize
-
greetingRecv
private final java.nio.ByteBuffer greetingRecv
-
greetingSend
private final java.nio.ByteBuffer greetingSend
-
zmtpVersion
private StreamEngine.Protocol zmtpVersion
-
session
private SessionBase session
-
options
private final Options options
-
endpoint
private final java.lang.String endpoint
-
plugged
private boolean plugged
-
ioError
private boolean ioError
-
subscriptionRequired
private boolean subscriptionRequired
-
mechanism
private Mechanism mechanism
-
inputStopped
private boolean inputStopped
-
outputStopped
private boolean outputStopped
-
HANDSHAKE_TIMER_ID
private static final int HANDSHAKE_TIMER_ID
- See Also:
- Constant Field Values
-
HEARTBEAT_TTL_TIMER_ID
private static final int HEARTBEAT_TTL_TIMER_ID
- See Also:
- Constant Field Values
-
HEARTBEAT_IVL_TIMER_ID
private static final int HEARTBEAT_IVL_TIMER_ID
- See Also:
- Constant Field Values
-
HEARTBEAT_TIMEOUT_TIMER_ID
private static final int HEARTBEAT_TIMEOUT_TIMER_ID
- See Also:
- Constant Field Values
-
hasHandshakeTimer
private boolean hasHandshakeTimer
-
hasTtlTimer
private boolean hasTtlTimer
-
hasTimeoutTimer
private boolean hasTimeoutTimer
-
hasHeartbeatTimer
private boolean hasHeartbeatTimer
-
heartbeatTimeout
private final int heartbeatTimeout
-
heartbeatContext
private final byte[] heartbeatContext
-
socket
private SocketBase socket
-
peerAddress
private final Address peerAddress
-
errno
private final Errno errno
-
-
Constructor Detail
-
StreamEngine
public StreamEngine(java.nio.channels.SocketChannel fd, Options options, java.lang.String endpoint)
-
-
Method Detail
-
heartbeatTimeout
private int heartbeatTimeout()
-
destroy
public void destroy()
-
plug
public void plug(IOThread ioThread, SessionBase session)
-
instantiate
private <T> T instantiate(java.lang.Class<T> clazz, int size, long max)
-
unplug
private void unplug()
-
inEvent
public void inEvent()
Description copied from interface:IPollEventsCalled by I/O thread when file descriptor is ready for reading.- Specified by:
inEventin interfaceIPollEvents
-
outEvent
public void outEvent()
Description copied from interface:IPollEventsCalled by I/O thread when file descriptor is ready for writing.- Specified by:
outEventin interfaceIPollEvents
-
restartOutput
public void restartOutput()
- Specified by:
restartOutputin interfaceIEngine
-
restartInput
public void restartInput()
- Specified by:
restartInputin interfaceIEngine
-
decodeCurrentInputs
private boolean decodeCurrentInputs()
-
handshake
private boolean handshake()
-
decodeDataAfterHandshake
private void decodeDataAfterHandshake(int greetingSize)
-
identityMsg
private Msg identityMsg()
-
processIdentityMsg
private boolean processIdentityMsg(Msg msg)
-
nextHandshakeCommand
private Msg nextHandshakeCommand()
-
processHandshakeCommand
private boolean processHandshakeCommand(Msg msg)
-
zapMsgAvailable
public void zapMsgAvailable()
- Specified by:
zapMsgAvailablein interfaceIEngine
-
mechanismReady
private void mechanismReady()
-
pullMsgFromSession
private Msg pullMsgFromSession()
-
pushMsgToSession
private boolean pushMsgToSession(Msg msg)
-
pushRawMsgToSession
private boolean pushRawMsgToSession(Msg msg)
-
writeCredential
private boolean writeCredential(Msg msg)
-
pullAndEncode
private Msg pullAndEncode()
-
decodeAndPush
private boolean decodeAndPush(Msg msg)
-
pushOneThenDecodeAndPush
private boolean pushOneThenDecodeAndPush(Msg msg)
-
error
private void error(StreamEngine.ErrorReason error)
-
setHandshakeTimer
private void setHandshakeTimer()
-
timerEvent
public void timerEvent(int id)
Description copied from interface:IPollEventsCalled when timer expires.- Specified by:
timerEventin interfaceIPollEvents- Parameters:
id- the ID of the expired timer.
-
producePingMessage
private Msg producePingMessage()
-
producePongMessage
private Msg producePongMessage(byte[] pingContext)
-
processCommand
private boolean processCommand(Msg msg)
-
processHeartbeatMessage
private boolean processHeartbeatMessage(Msg msg)
-
write
private int write(java.nio.ByteBuffer outbuf)
-
read
private int read(java.nio.ByteBuffer buf)
-
getEndPoint
public java.lang.String getEndPoint()
- Specified by:
getEndPointin interfaceIEngine
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-