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 ServerSocketcreateServerSocket(int port) protected ServerSocketcreateServerSocket(int port, int backlog, InetAddress address) voidsetIncomingConnectionExecutor(ExecutorService executorService) Set custom executor service.voidSets the connection listener.voidsetServerSocketFactory(ServerSocketFactory serverSocketFactory) Sets server socket factory.voidstart()Start the server.voidstop()Stop server.toString()Methods inherited from class com.epam.common.transport.server.AbstractServer
decrementRefCounter, getPort, incrementRefCounter, isAutoClose, isStarted, setAutoClose, setPort, setStartedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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:ServerSets the connection listener.- Specified by:
setIncomingConnectionListenerin 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:
setIncomingConnectionExecutorin interfaceServer- Parameters:
executorService- the executor will be used for working with incoming connections.
-
start
Description copied from interface:ServerStart the server.- Specified by:
startin 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:ServerStop server.- Specified by:
stopin interfaceServer- Throws:
IOException- - if error occurred- See Also:
-
toString
-