| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||

public interface IServer
A server accepts new incoming 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 analyzed by using reflection during  the server start-up
 phase. The callback method will be marked by implementing the specific interface
 like IDataHandler or IConnectHandler. Often a
 handler will implement several handler interfaces.
 
 E.g.
 
   ...
   IServer smtpServer = new Server(25, new SmtpProtcolHandler());
   smtpServer.setFlushmode(FlushMode.ASYNC);
   
   smtpServer.start();
   ...
   // Handler definition
   class SmtpProtcolHandler implements IDataHandler, IConnectHandler {
      SessionData sessionData = (SessionData) connection.getAttachment();
      
      String cmd = connection.readStringByDelimiter("\r\n").toUpperCase();
      
      if (cmd.startsWith("HELO")) {
         connection.write("250 SMTP Service\r\n");
         
      } else if(cmd.equals("DATA")) {
         String msgId = connection.getId() + "." + sessionData.nextId();
         File msgFile = new File(msgFileDir + File.separator + msgId + ".msg");
         
         connection.setHandler(new DataHandler(msgFile, this));
         connection.write("354 Enter message, ending with \".\"\r\n");
         
      } else {
       
         ...         
      }
      
      ...
   }
 
| Field Summary | |
|---|---|
| static int | DEFAULT_CONNECTION_TIMEOUT_SECthe default connection timeout | 
| static String | DEFAULT_HOST_ADDRESSthe dafault host address | 
| static int | DEFAULT_IDLE_TIMEOUT_SECthe default idle timeout | 
| static int | DEFAULT_READ_TRANSFER_PREALLOCATION_MIN_SIZE | 
| static int | DEFAULT_READ_TRANSFER_PREALLOCATION_SIZE | 
| static boolean | DEFAULT_READ_TRANSFER_USE_DIRECT | 
| static String | SO_RCVBUF | 
| static String | SO_REUSEADDR | 
| Method Summary | |
|---|---|
|  void | addListener(IServerListener listener)adds a listener | 
|  boolean | getAutoflush()get autoflush. | 
|  long | getConnectionTimeoutMillis()gets the connection timeout | 
|  IConnection.FlushMode | getFlushMode()return the flush mode for new connections | 
|  IHandler | getHandler()gets the handler | 
|  long | getIdleTimeoutMillis()returns the idle timeout in millis. | 
|  InetAddress | getLocalAddress()get the local address | 
|  int | getLocalPort()get the server port | 
|  Object | getOption(String name)returns the vlaue of a option | 
|  Map<String,Class> | getOptions()Returns an unmodifiable map of the options supported by this endpont. | 
|  String | getStartUpLogMessage()returns the startUp log message | 
|  Executor | getWorkerpool()return the worker pool | 
|  boolean | isOpen()signals, if service is running | 
|  boolean | removeListener(IServerListener listener)removes a listener | 
|  void | setAutoflush(boolean autoflush)set autoflush for new connections. | 
|  void | setConnectionTimeoutMillis(long timeoutMillis)sets the max time for a connections. | 
|  void | setFlushMode(IConnection.FlushMode flusmode)sets the flush mode for new connections. | 
|  void | setIdleTimeoutMillis(long timeoutInMillis)sets the idle timeout in millis | 
|  void | setStartUpLogMessage(String message)set the log message, which will be printed out during the start up | 
|  void | setWorkerpool(Executor workerpool)sets the worker pool | 
|  void | setWriteTransferRate(int bytesPerSecond)set the send delay time for a connection. | 
|  void | start()starts the given server within a dedicated thread. | 
| Methods inherited from interface java.lang.Runnable | 
|---|
| run | 
| Methods inherited from interface java.io.Closeable | 
|---|
| close | 
| Field Detail | 
|---|
static final int DEFAULT_IDLE_TIMEOUT_SEC
static final int DEFAULT_CONNECTION_TIMEOUT_SEC
static final String DEFAULT_HOST_ADDRESS
static final String SO_RCVBUF
static final String SO_REUSEADDR
static final int DEFAULT_READ_TRANSFER_PREALLOCATION_SIZE
static final int DEFAULT_READ_TRANSFER_PREALLOCATION_MIN_SIZE
static final boolean DEFAULT_READ_TRANSFER_USE_DIRECT
| Method Detail | 
|---|
boolean isOpen()
void start()
           throws IOException
SocketTimeoutException - is the timeout has been reached
IOExceptionlong getIdleTimeoutMillis()
void setIdleTimeoutMillis(long timeoutInMillis)
timeoutInSec - idle timeout in millislong getConnectionTimeoutMillis()
void setConnectionTimeoutMillis(long timeoutMillis)
timeoutSec - the connection timeout in millis
void setWriteTransferRate(int bytesPerSecond)
                          throws IOException
INonBlockingConnection#setFlushmode(org.xsocket.connection.IConnection.FlushMode))
bytesPerSecond - the transfer rate of the outgoing data
IOException - If some other I/O error occursint getLocalPort()
Executor getWorkerpool()
void setWorkerpool(Executor workerpool)
workerpool - the workerpoolIHandler getHandler()
void setFlushMode(IConnection.FlushMode flusmode)
INonBlockingConnection#setFlushmode(FlushMode) 
 for more information
flusmode - the flush modeIConnection.FlushMode getFlushMode()
void setAutoflush(boolean autoflush)
IReadWriteableConnection#setAutoflush(boolean) 
 for more information
autoflush - true if autoflush should be activatedboolean getAutoflush()
IReadWriteableConnection#setAutoflush(boolean) 
 for more information
void addListener(IServerListener listener)
listener - gthe listener to addboolean removeListener(IServerListener listener)
listener - the listener to remove
InetAddress getLocalAddress()
Object getOption(String name)
                 throws IOException
name - the name of the option
IOException - In an I/O error occursvoid setStartUpLogMessage(String message)
message - the startUp log messageString getStartUpLogMessage()
Map<String,Class> getOptions()
| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||