Package org.omegazero.net.client
Class TCPClientManager
java.lang.Object
org.omegazero.net.common.SelectorHandler
org.omegazero.net.common.ConnectionSelectorHandler
org.omegazero.net.client.TCPClientManager
- All Implemented Interfaces:
Runnable,NetClientManager,NetworkApplication
- Direct Known Subclasses:
PlainTCPClientManager,TLSClientManager
public abstract class TCPClientManager
extends ConnectionSelectorHandler
implements NetClientManager
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this application, closing all bound and connected sockets and stopping the main loop, causing a call toNetworkApplication.start()to return.connection(ConnectionParameters params) Creates a new connection instance based on the given parameters to be managed by thisNetClientManager.
SocketConnection.connect(int)will need to be called on the returned connection instance to initiate the connection.protected abstract ChannelConnectioncreateConnection(SelectionKey selectionKey, ConnectionParameters params) protected abstract voidCalled when a connection was established.protected voidCalled when a key was selected in a select call in theSelectorHandler.runSelectorLoop()method.voidinit()Initializes this application.protected voidCalled every loop iteration inSelectorHandler.runSelectorLoop(), which is every timeSelector.select()returns, either because aSelectionKeywas selected or the selector was woken up for any other reason (for example after a call toSelectorHandler.selectorWakeup()).
This method does nothing by default.voidstart()Runs the main loop of this instance.Methods inherited from class org.omegazero.net.common.ConnectionSelectorHandler
handleConnectionClosed, onConnectionClosedMethods inherited from class org.omegazero.net.common.SelectorHandler
closeSelector, initSelector, isRunning, registerChannel, registerChannel, runSelectorLoop, selectorKeys, selectorWakeupMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.omegazero.net.common.NetworkApplication
run
-
Field Details
-
worker
-
-
Constructor Details
-
TCPClientManager
public TCPClientManager() -
TCPClientManager
-
-
Method Details
-
createConnection
protected abstract ChannelConnection createConnection(SelectionKey selectionKey, ConnectionParameters params) throws IOException - Throws:
IOException
-
handleConnect
Called when a connection was established.- Parameters:
conn- TheChannelConnectionobject representing the connection that was established
-
init
Description copied from interface:NetworkApplicationInitializes this application.- Specified by:
initin interfaceNetworkApplication- Throws:
IOException- If an IO error occurs during initialization
-
close
Description copied from interface:NetworkApplicationCloses this application, closing all bound and connected sockets and stopping the main loop, causing a call toNetworkApplication.start()to return.- Specified by:
closein interfaceNetworkApplication- Throws:
IOException- If an IO error occurs
-
start
Description copied from interface:NetworkApplicationRuns the main loop of this instance. This loop processes incoming or outgoing connection requests and network traffic.
Under normal circumstances, should never return beforeNetworkApplication.close()is called. Afterclose()is called, this function should return as soon as possible.
If this method is called beforeNetworkApplication.init(), the behavior is undefined.- Specified by:
startin interfaceNetworkApplication- Throws:
IOException- If an IO error occurs during any networking operation
-
connection
Description copied from interface:NetClientManagerCreates a new connection instance based on the given parameters to be managed by thisNetClientManager.
SocketConnection.connect(int)will need to be called on the returned connection instance to initiate the connection.- Specified by:
connectionin interfaceNetClientManager- Parameters:
params- Parameters for this connection- Returns:
- The new connection instance
- Throws:
IOException
-
loopIteration
Description copied from class:SelectorHandlerCalled every loop iteration inSelectorHandler.runSelectorLoop(), which is every timeSelector.select()returns, either because aSelectionKeywas selected or the selector was woken up for any other reason (for example after a call toSelectorHandler.selectorWakeup()).
This method does nothing by default. Subclasses may override this method to perform additional required operations.- Overrides:
loopIterationin classConnectionSelectorHandler- Throws:
IOException- If an IO error occurs
-
handleSelectedKey
Description copied from class:SelectorHandlerCalled when a key was selected in a select call in theSelectorHandler.runSelectorLoop()method.- Specified by:
handleSelectedKeyin classSelectorHandler- Parameters:
key- The selected key- Throws:
IOException- If an IO error occurs
-