org.jppf.server.app
Class JPPFApplicationServer

java.lang.Object
  extended by java.lang.Thread
      extended by org.jppf.server.app.JPPFApplicationServer
All Implemented Interfaces:
Runnable

public class JPPFApplicationServer
extends Thread

Instances of this class listens for incoming connections from client applications.
For each incoming connection, a new connection thread is created. This thread listens to incoming connection requests and puts them on the execution queue.

Author:
Laurent Cohen, Domingos Creado

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
protected  List<org.jppf.server.app.JPPFConnection> connections
          The list of connections accepted by this server.
protected  int port
          The port this socket server is listening to.
protected  ServerSocket server
          Server socket listening for requests on the configured port.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
JPPFApplicationServer(int port)
          Initialize this socket server with a specified execution service and port number.
 
Method Summary
protected  org.jppf.server.app.JPPFConnection createConnection(Socket socket)
          Instanciate a wrapper for the socket connection opened by this socket server.
 void end()
          Close the underlying server socket and stop this socket server.
protected  void init(int port)
          Initialize the underlying server socket with a specified port.
protected  boolean isStopped()
          Get the stopped state of this server.
 void removeAllConnections()
          Close and remove all connections accepted by this server.
 void removeConnection(org.jppf.server.app.JPPFConnection connection)
          Remove the specified connection from the list of active connections of this server.
 void run()
          Start the underlying server socket by making it accept incoming connections.
protected  void serve(Socket socket)
          Start serving a new incoming connection.
protected  void setStopped(boolean stopped)
          Set this server in the specified stopped state.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

server

protected ServerSocket server
Server socket listening for requests on the configured port.


port

protected int port
The port this socket server is listening to.


connections

protected List<org.jppf.server.app.JPPFConnection> connections
The list of connections accepted by this server.

Constructor Detail

JPPFApplicationServer

public JPPFApplicationServer(int port)
                      throws JPPFException
Initialize this socket server with a specified execution service and port number.

Parameters:
port - the port this socket server is listening to.
Throws:
JPPFException - if the underlying server socket can't be opened.
Method Detail

createConnection

protected org.jppf.server.app.JPPFConnection createConnection(Socket socket)
                                                       throws JPPFException
Instanciate a wrapper for the socket connection opened by this socket server. Subclasses must implement this method.

Parameters:
socket - the socket connection obtained through a call to ServerSocket.accept().
Returns:
a JPPFServerConnection instance.
Throws:
JPPFException - if an exception is raised while creating the socket handler.

run

public void run()
Start the underlying server socket by making it accept incoming connections.

Specified by:
run in interface Runnable
Overrides:
run in class Thread
See Also:
Runnable.run()

serve

protected void serve(Socket socket)
              throws Exception
Start serving a new incoming connection.

Parameters:
socket - the socket connecting with this socket server.
Throws:
Exception - if the new connection can't be initialized.

init

protected void init(int port)
             throws JPPFException
Initialize the underlying server socket with a specified port.

Parameters:
port - the port the underlying server listens to.
Throws:
JPPFException - if the server socket can't be opened on the specified port.

end

public void end()
Close the underlying server socket and stop this socket server.


removeConnection

public void removeConnection(org.jppf.server.app.JPPFConnection connection)
Remove the specified connection from the list of active connections of this server.

Parameters:
connection - the connection to remove.

removeAllConnections

public void removeAllConnections()
Close and remove all connections accepted by this server.


setStopped

protected void setStopped(boolean stopped)
Set this server in the specified stopped state.

Parameters:
stopped - true if this server is stopped, false otherwise.

isStopped

protected boolean isStopped()
Get the stopped state of this server.

Returns:
true if this server is stopped, false otherwise.


Copyright © 2005-2010 JPPF Team.