|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface IMultithreadedServer
A server accepts new incomming connections, and delegates the handling of the
INonBlockingConnection
to the assigned handler.
The server includes dispatchers, which are responsible to perform the
socket I/O operations. A connection is assigned to one dispatcher.
To handle application-relevant events like onData
,
onClose
or onConnect
the appropriated callback method
of the assigned IHandler
will be called. The supported callback
methods of the handler will be analysed by using reflection during the server start-up
phase. The callback method will be marked by implementing the specifc interface
like IDataHandler
or IConnectHandler
. Often a
handler will implement serveral handler interfaces.
If a handler implements the IConnectionScoped
interface, a clone of
the registered handler will be created for each new incomming connection.
E.g.
... IMultithreadedConnectionServer smtpServer = new MultithreadedTcpServer(port, new SmtpProtcolHandler()); StreamUtils.start(server); ... // Handler definition class SmtpProtcolHandler implements IDataHandler, IConnectHandler, IConnectionScoped { private ArrayListrcptTos = new ArrayList (); ... public boolean onConnect(INonBlockingConnection connection) throws IOException { connection.setAutoflush(false); connection.setFlushmode(FlushMode.ASYNC); connection.write("220 this is the example smtp server" + LINE_DELIMITER); connection.flush(); return true; } public boolean onData(INonBlockingConnection connection) throws IOException, BufferUnderflowException { switch (state) { case COMMAND_HANDLING: handleCommand(connection); break; case MESSAGE_DATA_HANDLING: handleMessageData(connection); break; } return true; } private void handleCommand(INonBlockingConnection connection) throws IOException, BufferUnderflowException { ... @Override public Object clone() throws CloneNotSupportedException { SmtpProtocolHandler copy = (SmtpProtocolHandler) super.clone(); copy.rcptTos = new ArrayList (); // deep copy! return copy; } }
Field Summary | |
---|---|
static int |
DEFAULT_CONNECTION_TIMEOUT_SEC
the default connection timeout |
static int |
DEFAULT_IDLE_TIMEOUT_SEC
the default idle timeout |
static int |
DEFAULT_RECEIVE_BUFFER_PREALLOCATION_SIZE
Deprecated. |
static java.lang.String |
SO_RCVBUF
|
static java.lang.String |
SO_REUSEADDR
|
Method Summary | |
---|---|
void |
addListener(IMutlithreadedServerListener listener)
adds a listener |
int |
getConnectionTimeoutSec()
gets the connection timeout |
int |
getDispatcherPoolSize()
get the dispatcher pool size |
int |
getIdleTimeoutSec()
returns the idle timeout in sec. |
java.net.InetAddress |
getLocalAddress()
get the local address |
int |
getLocalPort()
get the server port |
java.lang.Object |
getOption(java.lang.String name)
returns the vlaue of a option |
java.util.Map<java.lang.String,java.lang.Class> |
getOptions()
Returns an unmodifiable map of the options supported by this endpont. |
int |
getReceiveBufferPreallocationSize()
Deprecated. on replacement |
java.util.concurrent.Executor |
getWorkerpool()
return the worker pool |
IWorkerPool |
getWorkerPool()
Deprecated. use getWorkerpool() instead |
boolean |
isOpen()
signals, if service is running |
boolean |
removeListener(IMutlithreadedServerListener listener)
removes a listener |
void |
setConnectionTimeoutSec(int timeoutSec)
sets the max time for a connections. |
void |
setDispatcherPoolSize(int size)
Deprecated. |
void |
setHandler(IHandler handler)
set the handler. |
void |
setIdleTimeoutSec(int timeoutInSec)
sets the idle timeout in sec |
void |
setReceiveBufferPreallocationSize(int size)
Deprecated. use System.property instead. see IoProvider |
void |
setWorkerPool(IWorkerPool workerPool)
Deprecated. worker pool should only be set by calling the constructor |
Methods inherited from interface java.lang.Runnable |
---|
run |
Methods inherited from interface java.io.Closeable |
---|
close |
Field Detail |
---|
static final int DEFAULT_RECEIVE_BUFFER_PREALLOCATION_SIZE
static final int DEFAULT_IDLE_TIMEOUT_SEC
static final int DEFAULT_CONNECTION_TIMEOUT_SEC
static final java.lang.String SO_RCVBUF
static final java.lang.String SO_REUSEADDR
Method Detail |
---|
boolean isOpen()
void setHandler(IHandler handler)
handler
- the handler. (supported: IConnectHandler, IDisconnectHandler, IDataHandler, ITimeoutHandler, IConnectionScoped, ILifeCycle)void setWorkerPool(IWorkerPool workerPool)
null
the
worker pool will be deactivated. The callback handler will be executed by the main
dispatching thread. If the handler performs blocking operations, the disptaching will
also be blocked!
workerPool
- the worker pool to set or null
to deactivate the worker poolIWorkerPool getWorkerPool()
getWorkerpool()
instead
java.util.concurrent.Executor getWorkerpool()
void setReceiveBufferPreallocationSize(int size)
IoProvider
size
- preallocation buffer sizeint getReceiveBufferPreallocationSize()
int getIdleTimeoutSec()
void setIdleTimeoutSec(int timeoutInSec)
timeoutInSec
- idle timeout in secvoid addListener(IMutlithreadedServerListener listener)
listener
- gthe listener to addboolean removeListener(IMutlithreadedServerListener listener)
listener
- the listener to remove
int getConnectionTimeoutSec()
void setConnectionTimeoutSec(int timeoutSec)
timeoutSec
- the connection timeout in secint getLocalPort()
java.net.InetAddress getLocalAddress()
void setDispatcherPoolSize(int size)
size
- the dispatcher pool sizeint getDispatcherPoolSize()
java.lang.Object getOption(java.lang.String name) throws java.io.IOException
name
- the name of the option
java.io.IOException
- In an I/O error occursjava.util.Map<java.lang.String,java.lang.Class> getOptions()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |