|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sun.akuma.Daemon
com.sun.akuma.NetworkServer
public abstract class NetworkServer
Multi-process network server that accepts connections on the same TCP port.
This class lets you write a Unix-like multi-process network daemon. The first process acts as the frontend. This creates a new socket, then fork several worker processes, which inherits this socket.
Worker threads will all accept connections on this port, so even when one of the worker processes die off, your clients won't notice that there's a problem.
The user of this class needs to override this class and implement abstract methods.
Several protected methods can be also overridden to customize the behaviors.
See EchoServer
source code as an example.
This class also inherits from Daemon
to support the daemonization.
From your main method, call into run()
method. Depending on whether the current process
is started as a front end or a worker process, the run method behave accordingly.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.sun.akuma.Daemon |
---|
Daemon.WithoutChdir |
Field Summary | |
---|---|
protected java.util.List<java.lang.String> |
arguments
Java arguments. |
Constructor Summary | |
---|---|
protected |
NetworkServer(java.lang.String[] args)
|
Method Summary | |
---|---|
protected abstract java.net.ServerSocket |
createServerSocket()
Creates a bound ServerSocket that will be shared by all worker processes. |
protected abstract void |
forkWorkers(JavaVMArguments args)
Forks the worker thread with the given JVM args. |
protected void |
forkWorkerThreads(JavaVMArguments arguments,
int n)
Called by the front-end code to fork a number of worker processes into the background. |
protected void |
frontend()
Front-end. |
void |
run()
Entry point. |
protected boolean |
shouldBeDaemonized()
Determine if we should daemonize ourselves. |
protected void |
worker()
|
protected abstract void |
worker(java.net.ServerSocket ss)
Worker thread main code. |
Methods inherited from class com.sun.akuma.Daemon |
---|
all, chdirToRoot, closeDescriptors, daemonize, daemonize, getCurrentExecutable, init, init, isDaemonized, selfExec, writePidFile |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final java.util.List<java.lang.String> arguments
Constructor Detail |
---|
protected NetworkServer(java.lang.String[] args)
Method Detail |
---|
public void run() throws java.lang.Exception
java.lang.Exception
protected boolean shouldBeDaemonized()
protected void frontend() throws java.lang.Exception
java.lang.Exception
protected abstract void forkWorkers(JavaVMArguments args) throws java.lang.Exception
forkWorkerThreads(JavaVMArguments, int)
.
java.lang.Exception
protected void forkWorkerThreads(JavaVMArguments arguments, int n) throws java.lang.Exception
java.lang.Exception
protected abstract java.net.ServerSocket createServerSocket() throws java.lang.Exception
ServerSocket
that will be shared by all worker processes.
This method is called in the frontend process.
java.lang.Exception
protected void worker() throws java.lang.Exception
java.lang.Exception
protected abstract void worker(java.net.ServerSocket ss) throws java.lang.Exception
ss
- The server socket that the frontend process created.
java.lang.Exception
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |