Class TCPServer
java.lang.Object
com.epam.common.transport.server.AbstractServer
com.epam.common.transport.server.tcp.TCPServer
- All Implemented Interfaces:
Server
- Direct Known Subclasses:
NIOTCPServer
,SSLTCPServer
TCP server implementation.
-
Field Summary
FieldsFields inherited from class com.epam.common.transport.server.AbstractServer
autoClose, DEFAULT_PORT, port, sessionRefCounter, started
-
Constructor Summary
ConstructorsConstructorDescriptionCreates server with default port.TCPServer
(int port) Creates server.TCPServer
(int port, boolean enableNagle) Creates server.Creates server.Creates server.TCPServer
(int port, ServerSocketFactory serverSocketFactory) Creates server. -
Method Summary
Modifier and TypeMethodDescriptionprotected ServerSocket
createServerSocket
(int port) protected ServerSocket
createServerSocket
(int port, int backlog, InetAddress address) void
setIncomingConnectionExecutor
(ExecutorService executorService) Set custom executor service.void
Sets the connection listener.void
setServerSocketFactory
(ServerSocketFactory serverSocketFactory) Sets server socket factory.void
start()
Start the server.void
stop()
Stop server.toString()
Methods inherited from class com.epam.common.transport.server.AbstractServer
decrementRefCounter, getPort, incrementRefCounter, isAutoClose, isStarted, setAutoClose, setPort, setStarted
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.epam.common.transport.server.Server
asAbstract, isAbstract
-
Field Details
-
DEFAULT_BACKLOG
public static final int DEFAULT_BACKLOG- See Also:
-
-
Constructor Details
-
TCPServer
public TCPServer()Creates server with default port. The default value for port is 3001 -
TCPServer
public TCPServer(int port) Creates server.- Parameters:
port
- - server port
-
TCPServer
Creates server.- Parameters:
port
- - server port
-
TCPServer
public TCPServer(int port, boolean enableNagle) Creates server.- Parameters:
port
- - server portenableNagle
- - enable/disable nagle algorithm
-
TCPServer
public TCPServer(int port, boolean enableNagle, String nic, int sendBufferSize, int receiveBufferSize) Creates server.- Parameters:
port
- - server portenableNagle
- - enable/disable nagle algorithmsendBufferSize
- send buffer sizereceiveBufferSize
- receive buffer size
-
TCPServer
Creates server.- Parameters:
port
- - server portenableNagle
- - enable/disable nagle algorithmnic
- - specific connection address
-
-
Method Details
-
setServerSocketFactory
Sets server socket factory. User can replace default socket factory with own implementation.- Parameters:
serverSocketFactory
- - socket factory
-
setIncomingConnectionListener
Description copied from interface:Server
Sets the connection listener.- Specified by:
setIncomingConnectionListener
in interfaceServer
- Parameters:
listener
- the connection listener- See Also:
-
setIncomingConnectionExecutor
Set custom executor service. If the custom executor is not set, Executors.newWorkStealingPool() will be used.- Specified by:
setIncomingConnectionExecutor
in interfaceServer
- Parameters:
executorService
- the executor will be used for working with incoming connections.
-
start
Description copied from interface:Server
Start the server.- Specified by:
start
in interfaceServer
- Throws:
IOException
- - if error occurred- See Also:
-
createServerSocket
protected ServerSocket createServerSocket(int port, int backlog, InetAddress address) throws IOException - Throws:
IOException
-
createServerSocket
- Throws:
IOException
-
stop
Description copied from interface:Server
Stop server.- Specified by:
stop
in interfaceServer
- Throws:
IOException
- - if error occurred- See Also:
-
toString
-