Package com.barchart.udt.nio
Class SelectionKeyUDT
java.lang.Object
java.nio.channels.SelectionKey
com.barchart.udt.nio.SelectionKeyUDT
- All Implemented Interfaces:
Comparable<SelectionKeyUDT>
UDT selection key implementation.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ChannelUDTChannel bound to the key.private EpollUDT.OptRequested interest in epoll format.protected static final intJDK interest to Epoll READ mapping.protected static final intJDK interest to Epoll WRITE mapping.private intRequested interest in JDK format.private booleanKey validity state.protected static final org.slf4j.Loggerprivate intReported ready interest.private intCorrelation index fordoRead(int)vsdoWrite(int)private final SelectorUDTSelector bound to the key.Fields inherited from class java.nio.channels.SelectionKey
OP_ACCEPT, OP_CONNECT, OP_READ, OP_WRITE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSelectionKeyUDT(SelectorUDT selectorUDT, ChannelUDT channelUDT, Object attachment) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidEnsure key is NOT canceled.protected voidassertValidOps(int interestOps) Ensure only permitted interest mask bits are present.voidcancel()channel()protected ChannelUDTUnderlying UDT channel.intcompareTo(SelectionKeyUDT that) protected booleandoRead(int resultIndex) Apply READ readiness according toKindUDTchannel role.protected booleandoWrite(int resultIndex) Apply WRITE readiness according toKindUDTchannel role.protected EpollUDT.OptepollOpt()Requested interest in epoll format.protected EpollUDTepollUDT()Epoll bound to this key.booleanKey equality based on socket-id.protected static EpollUDT.Optfrom(int interestOps) Convert select options : from jdk into epoll.(package private) booleanhasError()Check socket error condition.inthashCode()Key hach code based on socket-id.intinterestOps(int interestOps) protected booleanCheck socket termination status.booleanisValid()protected KindUDTkindUDT()Channel role.protected voidKey processing logic error logger.protected voidmakeValid(boolean isValid) Change socket registration with epoll, and change key validity status.intreadyOps()protected voidreadyOps(int ops) selector()protected intsocketId()Id of a socket bound to this key.protected SocketUDTSocket bound to this key.toString()static final StringtoStringOps(int selectOps) Render select options.Methods inherited from class java.nio.channels.SelectionKey
attach, attachment, interestOpsAnd, interestOpsOr, isAcceptable, isConnectable, isReadable, isWritable
-
Field Details
-
HAS_READ
protected static final int HAS_READJDK interest to Epoll READ mapping.- See Also:
-
HAS_WRITE
protected static final int HAS_WRITEJDK interest to Epoll WRITE mapping.- See Also:
-
log
protected static final org.slf4j.Logger log -
channelUDT
Channel bound to the key. -
epollOpt
Requested interest in epoll format. -
interestOps
private volatile int interestOpsRequested interest in JDK format. -
isValid
private volatile boolean isValidKey validity state. Key is valid when created, and invalid when canceled. -
readyOps
private volatile int readyOpsReported ready interest. -
resultIndex
private volatile int resultIndexCorrelation index fordoRead(int)vsdoWrite(int) -
selectorUDT
Selector bound to the key.
-
-
Constructor Details
-
SelectionKeyUDT
-
-
Method Details
-
from
Convert select options : from jdk into epoll. -
toStringOps
Render select options. -
assertValidKey
Ensure key is NOT canceled.- Throws:
CancelledKeyException
-
assertValidOps
protected void assertValidOps(int interestOps) Ensure only permitted interest mask bits are present. -
cancel
public void cancel()- Specified by:
cancelin classSelectionKey
-
channel
- Specified by:
channelin classSelectionKey
-
channelUDT
Underlying UDT channel. -
compareTo
- Specified by:
compareToin interfaceComparable<SelectionKeyUDT>
-
doRead
protected boolean doRead(int resultIndex) Apply READ readiness according toKindUDTchannel role.Note:
doRead(int)is invoked beforedoWrite(int)Sockets with exceptions are returned to both read and write sets.
- Returns:
- Should report ready-state change?
-
doWrite
protected boolean doWrite(int resultIndex) Apply WRITE readiness according toKindUDTchannel role.Note:
doRead(int)is invoked beforedoWrite(int)Sockets with exceptions are returned to both read and write sets.
- Returns:
- Should report ready-state change?
-
epollOpt
Requested interest in epoll format. -
epollUDT
Epoll bound to this key. -
equals
Key equality based on socket-id. -
hasError
Check socket error condition.- Throws:
ExceptionUDT
-
hashCode
public int hashCode()Key hach code based on socket-id. -
interestOps
public int interestOps()- Specified by:
interestOpsin classSelectionKey
-
interestOps
- Specified by:
interestOpsin classSelectionKey
-
isSocketBroken
protected boolean isSocketBroken()Check socket termination status.- Returns:
- true if status is
StatusUDT.BROKENor worse
-
isValid
public boolean isValid()- Specified by:
isValidin classSelectionKey
-
kindUDT
Channel role. -
logError
Key processing logic error logger. -
makeValid
protected void makeValid(boolean isValid) Change socket registration with epoll, and change key validity status. -
readyOps
public int readyOps()- Specified by:
readyOpsin classSelectionKey
-
readyOps
protected void readyOps(int ops) -
selector
- Specified by:
selectorin classSelectionKey
-
socketId
protected int socketId()Id of a socket bound to this key. -
socketUDT
Socket bound to this key. -
toString
-