Class SocketCommNIO
- All Implemented Interfaces:
- ISocketComm,- IWorkerTimeout
- Direct Known Subclasses:
- SocketComm
For proxy and/or WebSocket, an authenticator must/should be used to support user authentication with the proxy or destination (for WebSocket).
For SSL/TLS, client certificates can be added, discrete or from system, and if so, an password callback might be have to be registered to provide a password for a keystore or a certificate, unless preset in the properties.
For SSL/TLS, server certificates validator can be provided in order to check server certificates and/or the destinations host name.
- Author:
- Christopher Mindus
- Nested Class SummaryNested ClassesModifier and TypeClassDescription- static enumThe state of the communication link.
- Field SummaryFields
- Constructor SummaryConstructorsModifierConstructorDescription- protected- SocketCommNIO- (WorkerNIO worker, SocketChannel socketChannel, SocketCommListener listener, boolean isVerbose) Creates a new Socket Client Communication channel from a Server Socket Accept.- SocketCommNIO- (String host, int port, String bindAddress, WorkerNIO worker, SocketCommListener listener, boolean isVerbose, SSLEngine engine) Creates a new Socket Client Communication channel as UNINITIALIZED.
- Method SummaryModifier and TypeMethodDescription- void- checkTimeout- (long timeNow) Performs a timeout check for the socket channel.- boolean- close()Call this method to close the socket.- boolean- close- (boolean rightNow) Call this method to close the socket.- void- enterSecureMode- (SSLEngine engine, ByteBuffer remainingBuffer) Enters SSL mode for a plain connection from another protocol, e.g.- longGets the read time-out value for the connection before the state enters CONNECTED.- longGets the read time-out value for the connection.- long- getRemainingTimeout- (long timeNow) Gets the socket timeout value remaining.Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.Returns the fully qualified name of the client or the last proxy that sent the request.Returns the remote address to which this channel's socket is connected.Gets the SSL communication layer.- getState()Gets the state of the connection.- longSets the read time-out value for the connection.- booleanChecks if the session has been opened, and if so cannot be reopened but needs to have a new instance.- boolean- isClosed()Checks if the connection is disposed of.- boolean- isSecure()Checks if this is a secure communication link.- void- open()Opens the communication.- void- process- (ByteBuffer buffer) Processes the SelectionKey as it has generated an event.- void- send- (ByteBuffer sendBuf) Adds the byte buffer to the send queue without blocking.- static voidSets a new logger.- void- setNonConnectedReadTimeout- (long timeout) Sets the read time-out value for the connection before the state enters CONNECTED.- void- setReadTimeout- (long timeout) Sets the read time-out value for the connection.- protected SocketSets up the socket.- void- setWriteTimeout- (long timeout) Sets the read time-out value for the connection.
- Field Details- hostThe host name.
- portpublic final int portThe port.
- bindAddressThe bind address, null for none.
- doResolveHostNamespublic boolean doResolveHostNamesFlag for resolving host names.
 
- Constructor Details- SocketCommNIOpublic SocketCommNIO- (String host, int port, String bindAddress, WorkerNIO worker, SocketCommListener listener, boolean isVerbose, SSLEngine engine) Creates a new Socket Client Communication channel as UNINITIALIZED.- Parameters:
- host- The destination host.
- port- The destination port.
- bindAddress- The bind address or null for none.
- worker- The worker thread for socket processing.
- listener- The listener for socket events.
- isVerbose- Flag for logging.
 
- SocketCommNIOprotected SocketCommNIO- (WorkerNIO worker, SocketChannel socketChannel, SocketCommListener listener, boolean isVerbose) throws IOException Creates a new Socket Client Communication channel from a Server Socket Accept.- Throws:
- IOException- For I/O errors.
 
 
- Method Details- setLoggerSets a new logger.
- isSecurepublic boolean isSecure()Checks if this is a secure communication link.
- getSSLCommLayerGets the SSL communication layer.- Returns:
- The instance of the SSL communication layer, or null if not secure.
 
- setupSocketSets up the socket.- Throws:
- SocketException- For socket errors.
 
- hasBeenOpenpublic boolean hasBeenOpen()Checks if the session has been opened, and if so cannot be reopened but needs to have a new instance.
- openOpens the communication.- Throws:
- IOException
 
- enterSecureModeEnters SSL mode for a plain connection from another protocol, e.g. Telnet.- Parameters:
- engine- The SSL engine.
- remainingBuffer- Remaining buffer to process, null for none.
- Throws:
- IOException- if an I/O error occurs.
 
- processProcesses the SelectionKey as it has generated an event.- Specified by:
- processin interface- ISocketComm
- Parameters:
- buffer- The direct buffer allocated by the worker.
 
- setNonConnectedReadTimeoutpublic void setNonConnectedReadTimeout- (long timeout) Sets the read time-out value for the connection before the state enters CONNECTED.- Parameters:
- timeout- The timeout value in milliseconds, 0 for indefinite.
 
- getNonConnectedReadTimeoutpublic long getNonConnectedReadTimeout()Gets the read time-out value for the connection before the state enters CONNECTED.- Returns:
- The timeout value in milliseconds, 0 for indefinite.
 
- setReadTimeoutpublic void setReadTimeout- (long timeout) Sets the read time-out value for the connection.- Parameters:
- timeout- The timeout value in milliseconds, 0 for indefinite.
 
- getReadTimeoutpublic long getReadTimeout()Gets the read time-out value for the connection.- Returns:
- The timeout value in milliseconds, 0 for indefinite.
 
- setWriteTimeoutpublic void setWriteTimeout- (long timeout) Sets the read time-out value for the connection.- Parameters:
- timeout- The timeout value in milliseconds, 0 for indefinite.
 
- getWriteTimeoutpublic long getWriteTimeout()Sets the read time-out value for the connection.- Returns:
- The timeout value in milliseconds, 0 for indefinite.
 
- getRemainingTimeoutpublic long getRemainingTimeout- (long timeNow) Gets the socket timeout value remaining.- Specified by:
- getRemainingTimeoutin interface- IWorkerTimeout
- Parameters:
- timeNow- The current time.
- Returns:
- Time in milliseconds until timeout, NOTE! -1 for indefinite timeout.
 
- checkTimeoutpublic void checkTimeout- (long timeNow) Performs a timeout check for the socket channel. This is called to all channels, so each channel must check its own state.- Specified by:
- checkTimeoutin interface- IWorkerTimeout
- Parameters:
- timeNow- The current time.
 
- sendAdds the byte buffer to the send queue without blocking.- Parameters:
- sendBuf- The buffer to send.
- Throws:
- IOException- for failures, e.g. socket is closed, not open, not connected.
 
- getStateGets the state of the connection.
- getRemoteAddrReturns the Internet Protocol (IP) address of the client or last proxy that sent the request. The IP address format depends if it is an IPv4 or IPv6 address.- Returns:
- a String containing the IP address of the client that sent the request.
 
- getRemoteHostReturns the fully qualified name of the client or the last proxy that sent the request. If the engine cannot or chooses not to resolve the host name (to improve performance), this method returns the dotted-string form of the IP address (if IPv4, colon'ed-string for IPv6).- The resolving is done once only, if the - doResolveHostNamesis true.- Returns:
- a String containing the fully qualified name of the client.
 
- getSocketAddressReturns the remote address to which this channel's socket is connected.- Where the channel is bound and connected to an Internet Protocol socket address then the return value from this method is of type - InetSocketAddress.- Returns:
- The remote address; nullif the channel's socket is not connected.
 
- isClosedpublic boolean isClosed()Checks if the connection is disposed of.
- closepublic boolean close()Call this method to close the socket.- A call to this method will return true while flushing pending send operations and then close the socket when that is completed. If no send operations are pending, the socket is closed immediately. - Returns:
- true if closed completed successfully, false if already closed. Note that true is returned even if the socket is entering or is in CLOSING state.
 
- closepublic boolean close- (boolean rightNow) Call this method to close the socket.- If the parameter "rightNow" is false, a call to this method will return true while flushing pending send operations and then close the socket when that is completed. If no send operations are pending, the socket is closed immediately. - Specified by:
- closein interface- ISocketComm
- Parameters:
- rightNow- If false, a flush of pending send operations will be performed.
- Returns:
- true if closed, false if already closed.