|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--org.szegedi.nioserver.NioServer
The runtime class for non-blocking servers. Every NioServer manages a number of threads for accepting connections, reading, and writing. In the basic case, you will have a single thread for accepting connections and another single thread for processing read and write operations. However, if you are running the code on a multiprocessor machine, you can create more initial threads to improve CPU utilization. Also, when running on Windows, the server will spawn new threads when all current threads service 63 channels - the maximum number of channels a single thread (more precisely "the maximum number of keys a single selector") can service under this OS family. Note that any number of different services (that is, server sockets) bound to any IP address and any port on the local machine can be serviced by a single server instance - the non-blocking nature allows accepting connections from multiple server sockets on a single thread.
An implementation note: the server by default operates in "half-duplex" mode. This means that read and write notifications for each connection are serviced on a single thread, therefore the server will never both read and write a connection concurrently - if the connection is ready for both reading and writing, read will occur before write. You can force the server into a "full-duplex" mode where read and write operations are serviced on separate threads by seting the org.szegedi.nio.fullDuplex system property to true. Note however, that some combinations of a JVM and OS cause erroneous operation in full-duplex mode, so test for yourself. Since most protocols follow some kind of request-response semantics, this is usually not a big problem. Also note that half-duplex applies only to a single connection; if you have multiple read-write threads, then the connections on separate threads are still serviced concurrently. The term half-duplex applies exclusively to serialization of read and write operations in a context of single connection.
| Field Summary |
| Fields inherited from interface org.szegedi.nioserver.Log |
DEBUG, ERROR, INFO, LEVELNAMES, WARNING |
| Constructor Summary | |
NioServer()
Creates a new non-blocking server that will use one permanent thread for accepting connections and two permanent thread for read/write operations. |
|
NioServer(int permanentAcceptThreads,
int permanentTransferThreads)
Creates a new non-blocking server that will use the specified number of permanent threads for accepting connections and for read/write operations. |
|
| Method Summary | |
void |
log(java.lang.String message,
int level)
|
void |
log(java.lang.String message,
java.lang.Throwable t,
int level)
|
Service |
registerService(ProtocolHandlerFactory factory,
ServerSocketConfiguration ssconf)
Adds a service to this server. |
void |
stop()
Stops this server. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public NioServer()
throws java.io.IOException
public NioServer(int permanentAcceptThreads,
int permanentTransferThreads)
throws java.io.IOException
permanentAcceptThreads - number of threads that are always
available for accepting connections, regardless of the server load.
One thread will usually be sufficient, however on a SMP machine with
several network interfaces you can achieve better throughput with
more threads.permanentTransferThreads - number of threads that are always
available for servicing socket reads and writes, regardless of server
load. Using two threads per CPU should yield satisfactory results.| Method Detail |
public void stop()
public Service registerService(ProtocolHandlerFactory factory,
ServerSocketConfiguration ssconf)
throws java.io.IOException
factory - the protocol handler factory that will create protocol
handlers for servicing connectionsssconf - a ServerSocketConfiguration object that specifies server
socket address, port, timeout behavior, etc.
java.io.IOException
public void log(java.lang.String message,
int level)
log in interface Log
public void log(java.lang.String message,
java.lang.Throwable t,
int level)
log in interface Log
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||