Class NetworkConnectorConfig<T>
- java.lang.Object
-
- io.hekate.network.NetworkConnectorConfig<T>
-
- Type Parameters:
T
- Base type of messages that can be supported by thisNetworkConnector
.
public class NetworkConnectorConfig<T> extends Object
Configuration forNetworkConnector
.Instances of this class can be registered within the
NetworkService
viaNetworkServiceFactory.setConnectors(List)
method.For more details about connectors and networking please see the documentation of
NetworkService
.
-
-
Constructor Summary
Constructors Constructor Description NetworkConnectorConfig()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
getIdleSocketTimeout()
Returns the timeout in milliseconds forNetworkClient
s to stay idle before being automatically disconnected (seesetIdleSocketTimeout(long)
).String
getLogCategory()
Returns the log category that should be used by the connector (seesetLogCategory(String)
).CodecFactory<T>
getMessageCodec()
Returns theCodecFactory
that should be used for messages serialization (seesetMessageCodec(CodecFactory)
).int
getNioThreads()
Returns the thread pool size that should be used for NIO events processing (seesetNioThreads(int)
).String
getProtocol()
Returns the connector's protocol identifier (seesetProtocol(String)
).NetworkServerHandler<T>
getServerHandler()
Returns the handler that should be used to accept connections and process messages from remote connectors (seesetServerHandler(NetworkServerHandler)
).void
setIdleSocketTimeout(long idleSocketTimeout)
Sets the timeout in milliseconds forNetworkClient
s to stay idle before being automatically disconnected.void
setLogCategory(String logCategory)
Sets the log category that should be used by the connector.void
setMessageCodec(CodecFactory<T> messageCodec)
Sets codec factory that should be used for messages serialization.void
setNioThreads(int nioThreads)
Sets the thread pool size that should be used for NIO events processing.void
setProtocol(String protocol)
Sets the connector's protocol identifier.void
setServerHandler(NetworkServerHandler<T> serverHandler)
Sets the server handler that should be used to accept connections and process messages from remote connectors.String
toString()
NetworkConnectorConfig<T>
withIdleSocketTimeout(long idleTimeout)
Fluent-style version ofsetIdleSocketTimeout(long)
.NetworkConnectorConfig<T>
withLogCategory(String logCategory)
Fluent-style version ofsetLogCategory(String)
.NetworkConnectorConfig<T>
withMessageCodec(CodecFactory<T> codecFactory)
Fluent-style version ofsetMessageCodec(CodecFactory)
.NetworkConnectorConfig<T>
withNioThreads(int nioThreads)
Fluent-style version ofsetNioThreads(int)
.NetworkConnectorConfig<T>
withProtocol(String protocol)
Fluent-style version ofsetProtocol(String)
.NetworkConnectorConfig<T>
withServerHandler(NetworkServerHandler<T> serverHandler)
Fluent-style version ofsetServerHandler(NetworkServerHandler)
.
-
-
-
Method Detail
-
getProtocol
public String getProtocol()
Returns the connector's protocol identifier (seesetProtocol(String)
).- Returns:
- Protocol identifier.
-
setProtocol
public void setProtocol(String protocol)
Sets the connector's protocol identifier. Can contain only alpha-numeric characters and non-repeatable dots/hyphens.This protocol identifier can be used to obtain references to
NetworkConnector
instances viaNetworkService.connector(String)
method.This parameter is mandatory and doesn't have a default value.
Note: Protocol identifier must be unique across all registered
NetworkConnector
s within theNetworkService
.- Parameters:
protocol
- Protocol identifier (can contain only alpha-numeric characters and non-repeatable dots/hyphens).
-
withProtocol
public NetworkConnectorConfig<T> withProtocol(String protocol)
Fluent-style version ofsetProtocol(String)
.- Parameters:
protocol
- Protocol identifier.- Returns:
- This instance.
-
getIdleSocketTimeout
public long getIdleSocketTimeout()
Returns the timeout in milliseconds forNetworkClient
s to stay idle before being automatically disconnected (seesetIdleSocketTimeout(long)
).- Returns:
- Timeout in milliseconds.
-
setIdleSocketTimeout
public void setIdleSocketTimeout(long idleSocketTimeout)
Sets the timeout in milliseconds forNetworkClient
s to stay idle before being automatically disconnected.NetworkClient
s are considered to be idle if no messages are send/received for the specified time interval. When idle client is detected it will be automaticallydisconnected
.If value of this parameter is less than or equals to zero then idle clients tracking is disabled.
Default value of this parameter is 0.
- Parameters:
idleSocketTimeout
- Timeout in milliseconds.
-
withIdleSocketTimeout
public NetworkConnectorConfig<T> withIdleSocketTimeout(long idleTimeout)
Fluent-style version ofsetIdleSocketTimeout(long)
.- Parameters:
idleTimeout
- Timeout in milliseconds.- Returns:
- This instance.
-
getMessageCodec
public CodecFactory<T> getMessageCodec()
Returns theCodecFactory
that should be used for messages serialization (seesetMessageCodec(CodecFactory)
).- Returns:
- Codec factory.
-
setMessageCodec
public void setMessageCodec(CodecFactory<T> messageCodec)
Sets codec factory that should be used for messages serialization.Only messages that are supported by the specified
CodecFactory
can be sent/received by thisNetworkConnector
.If not specified then the default general-purpose codec will be used (see
HekateBootstrap.setDefaultCodec(CodecFactory)
).- Parameters:
messageCodec
- Codec factory.
-
withMessageCodec
public NetworkConnectorConfig<T> withMessageCodec(CodecFactory<T> codecFactory)
Fluent-style version ofsetMessageCodec(CodecFactory)
.- Parameters:
codecFactory
- Codec factory.- Returns:
- This instance.
-
getNioThreads
public int getNioThreads()
Returns the thread pool size that should be used for NIO events processing (seesetNioThreads(int)
).- Returns:
- Thread pool size.
-
setNioThreads
public void setNioThreads(int nioThreads)
Sets the thread pool size that should be used for NIO events processing.If value of this parameter is above zero then a new thread pool of that size will be initialized and used by the
NetworkConnector
to handle all NIO events of its connections. If value of this parameter is less than or equals to zero thenNetworkService
's core thread pool will be used (seeNetworkServiceFactory.setNioThreads(int)
).Default value of this parameter is 0.
- Parameters:
nioThreads
- Thread pool size.- See Also:
NetworkServiceFactory.setNioThreads(int)
-
withNioThreads
public NetworkConnectorConfig<T> withNioThreads(int nioThreads)
Fluent-style version ofsetNioThreads(int)
.- Parameters:
nioThreads
- Thread pool size.- Returns:
- This instance.
-
getLogCategory
public String getLogCategory()
Returns the log category that should be used by the connector (seesetLogCategory(String)
).- Returns:
- Log category.
-
setLogCategory
public void setLogCategory(String logCategory)
Sets the log category that should be used by the connector.- Parameters:
logCategory
- Log category.
-
withLogCategory
public NetworkConnectorConfig<T> withLogCategory(String logCategory)
Fluent-style version ofsetLogCategory(String)
.- Parameters:
logCategory
- Log category.- Returns:
- This instance.
-
getServerHandler
public NetworkServerHandler<T> getServerHandler()
Returns the handler that should be used to accept connections and process messages from remote connectors (seesetServerHandler(NetworkServerHandler)
).- Returns:
- Handler that should be used to accept connections and process messages from remote connectors.
-
setServerHandler
public void setServerHandler(NetworkServerHandler<T> serverHandler)
Sets the server handler that should be used to accept connections and process messages from remote connectors.This parameter is optional and if not specified then connector will work in client-only mode. In this mode it will be able to create new
NetworkClient
connections but will not be able to accept such connections from remote connectors.- Parameters:
serverHandler
- Handler that should be used to accept connections and process messages from remote connectors.
-
withServerHandler
public NetworkConnectorConfig<T> withServerHandler(NetworkServerHandler<T> serverHandler)
Fluent-style version ofsetServerHandler(NetworkServerHandler)
.- Parameters:
serverHandler
- Handler that should be used to accept connections and process messages from remote connectors.- Returns:
- This instance.
-
-