com.scalagent.kjoram.util.Daemon Class Reference

Inherited by com.scalagent.kjoram.ConnectionConsumer.CCDaemon, com.scalagent.kjoram.Driver, com.scalagent.kjoram.SessionDaemon, and com.scalagent.kjoram.util.TimerDaemon.

Inheritance diagram for com.scalagent.kjoram.util.Daemon:

Inheritance graph
[legend]
List of all members.

Public Member Functions

synchronized boolean isRunning ()
final String getName ()
String toString ()
void setDaemon (boolean daemon)
void setPriority (int newPriority)
synchronized void start ()
synchronized void stop ()

Protected Member Functions

 Daemon (String name)
abstract void close ()
abstract void shutdown ()
final void finish ()

Protected Attributes

volatile boolean running
volatile boolean canStop
Thread thread = null
int priority = Thread.NORM_PRIORITY

Detailed Description

The Daemon class represents a basic active component in a server. It provides usefull code to start and safely stop inner Thread.

Main loop of daemon:


<blockquote>
  try {
    while (running) {
	canStop = true;

	// Get a notification, then execute the right reaction.
	try {
	  // Get a request
	  ...
	} catch (InterruptedException exc) {
	  continue;
	}

	canStop = false;

	// executes the request
	...
    }
  } finally {
    finish();
  }
 
</blockquote>

Definition at line 57 of file Daemon.java.


Constructor & Destructor Documentation

com.scalagent.kjoram.util.Daemon.Daemon ( String  name  )  [protected]

Allocates a new Daemon object.

Parameters:
name the name of the new Daemon

Definition at line 122 of file Daemon.java.

References com.scalagent.kjoram.util.Daemon.canStop, com.scalagent.kjoram.util.Daemon.running, and com.scalagent.kjoram.util.Daemon.thread.


Member Function Documentation

synchronized boolean com.scalagent.kjoram.util.Daemon.isRunning (  ) 

Tests if this daemon is alive.

Returns:
true if this daemon is alive; false otherwise.

Definition at line 63 of file Daemon.java.

References com.scalagent.kjoram.util.Daemon.thread.

final String com.scalagent.kjoram.util.Daemon.getName (  ) 

Returns this daemon's name.

Returns:
this daemon's name.

Definition at line 96 of file Daemon.java.

Referenced by com.scalagent.kjoram.util.Daemon.finish(), com.scalagent.kjoram.util.Daemon.start(), com.scalagent.kjoram.util.Daemon.stop(), and com.scalagent.kjoram.util.Daemon.toString().

String com.scalagent.kjoram.util.Daemon.toString (  ) 

Returns a string representation of this daemon.

Returns:
A string representation of this daemon.

Reimplemented in com.scalagent.kjoram.Driver.

Definition at line 105 of file Daemon.java.

References com.scalagent.kjoram.util.Daemon.canStop, com.scalagent.kjoram.util.Daemon.getName(), com.scalagent.kjoram.util.Daemon.running, and com.scalagent.kjoram.util.Daemon.thread.

Here is the call graph for this function:

synchronized void com.scalagent.kjoram.util.Daemon.start (  ) 

Causes this daemon to begin execution. A new thread is created to execute the run method.

Exceptions:
IllegalThreadStateException If the daemon was already started.

Reimplemented in com.scalagent.kjoram.util.TimerDaemon.

Definition at line 153 of file Daemon.java.

References com.scalagent.kjoram.util.Daemon.canStop, com.scalagent.kjoram.util.Daemon.getName(), com.scalagent.kjoram.util.Daemon.priority, com.scalagent.kjoram.util.Daemon.running, and com.scalagent.kjoram.util.Daemon.thread.

Referenced by com.scalagent.kjoram.Connection.Connection(), com.scalagent.kjoram.ConnectionConsumer.ConnectionConsumer(), com.scalagent.kjoram.MessageConsumer.setMessageListener(), and com.scalagent.kjoram.Session.start().

Here is the call graph for this function:

abstract void com.scalagent.kjoram.util.Daemon.close (  )  [protected, pure virtual]

Releases any resources attached to this daemon. Be careful, its method should be called more than one time.

Implemented in com.scalagent.kjoram.ConnectionConsumer.CCDaemon, com.scalagent.kjoram.Driver, com.scalagent.kjoram.SessionDaemon, and com.scalagent.kjoram.util.TimerDaemon.

Referenced by com.scalagent.kjoram.util.Daemon.finish().

abstract void com.scalagent.kjoram.util.Daemon.shutdown (  )  [protected, pure virtual]

Interupts a thread that waits for long periods. In some cases, we must use application specific tricks. For example, if a thread is waiting on a known socket, we have to close the socket to cause the thread to return immediately. Unfortunately, there really isn't any technique that works in general.

Implemented in com.scalagent.kjoram.ConnectionConsumer.CCDaemon, com.scalagent.kjoram.Driver, com.scalagent.kjoram.ksoap.SoapDriver, com.scalagent.kjoram.SessionDaemon, and com.scalagent.kjoram.util.TimerDaemon.

Referenced by com.scalagent.kjoram.util.Daemon.stop().

final void com.scalagent.kjoram.util.Daemon.finish (  )  [protected]

Interrupts this daemon.

Definition at line 196 of file Daemon.java.

References com.scalagent.kjoram.util.Daemon.close(), com.scalagent.kjoram.util.Daemon.getName(), and com.scalagent.kjoram.util.Daemon.running.

Referenced by com.scalagent.kjoram.util.TimerDaemon.run(), com.scalagent.kjoram.SessionDaemon.run(), com.scalagent.kjoram.Driver.run(), com.scalagent.kjoram.ConnectionConsumer.CCDaemon.run(), and com.scalagent.kjoram.util.Daemon.stop().

Here is the call graph for this function:

synchronized void com.scalagent.kjoram.util.Daemon.stop (  ) 

Forces the daemon to stop executing. This method notifies thread that it should stop running, if the thread is waiting it is first interupted then the shutdown method is called to close all ressources.

Definition at line 209 of file Daemon.java.

References com.scalagent.kjoram.util.Daemon.canStop, com.scalagent.kjoram.util.Daemon.finish(), com.scalagent.kjoram.util.Daemon.getName(), com.scalagent.kjoram.util.Daemon.running, com.scalagent.kjoram.util.Daemon.shutdown(), and com.scalagent.kjoram.util.Daemon.thread.

Referenced by com.scalagent.kjoram.ConnectionConsumer.close(), com.scalagent.kjoram.Connection.close(), com.scalagent.kjoram.util.TimerDaemon.interrupt(), com.scalagent.kjoram.MessageConsumer.setMessageListener(), and com.scalagent.kjoram.Session.stop().

Here is the call graph for this function:


Member Data Documentation

volatile boolean com.scalagent.kjoram.util.Daemon.running [protected]

Boolean variable used to stop the daemon properly. The daemon tests this variable between each request, and stops if it is false.

See also:
start

stop

Definition at line 73 of file Daemon.java.

Referenced by com.scalagent.kjoram.util.Daemon.Daemon(), com.scalagent.kjoram.util.Daemon.finish(), com.scalagent.kjoram.util.TimerDaemon.run(), com.scalagent.kjoram.SessionDaemon.run(), com.scalagent.kjoram.Driver.run(), com.scalagent.kjoram.ConnectionConsumer.CCDaemon.run(), com.scalagent.kjoram.util.Daemon.setDaemon(), com.scalagent.kjoram.util.Daemon.setPriority(), com.scalagent.kjoram.util.Daemon.start(), com.scalagent.kjoram.util.Daemon.stop(), and com.scalagent.kjoram.util.Daemon.toString().

volatile boolean com.scalagent.kjoram.util.Daemon.canStop [protected]

Boolean variable used to stop the daemon properly. If this variable is true then the daemon is waiting for a long time and it can interupted, else it handles a request and it will exit after (it tests the running variable between each reaction)

Definition at line 81 of file Daemon.java.

Referenced by com.scalagent.kjoram.util.Daemon.Daemon(), com.scalagent.kjoram.util.TimerDaemon.run(), com.scalagent.kjoram.SessionDaemon.run(), com.scalagent.kjoram.Driver.run(), com.scalagent.kjoram.ConnectionConsumer.CCDaemon.run(), com.scalagent.kjoram.util.Daemon.start(), com.scalagent.kjoram.util.Daemon.stop(), and com.scalagent.kjoram.util.Daemon.toString().

Thread com.scalagent.kjoram.util.Daemon.thread = null [protected]

The active component of this daemon.

Definition at line 83 of file Daemon.java.

Referenced by com.scalagent.kjoram.util.Daemon.Daemon(), com.scalagent.kjoram.util.Daemon.isRunning(), com.scalagent.kjoram.util.Daemon.setDaemon(), com.scalagent.kjoram.util.Daemon.setPriority(), com.scalagent.kjoram.util.Daemon.start(), com.scalagent.kjoram.util.Daemon.stop(), and com.scalagent.kjoram.util.Daemon.toString().

int com.scalagent.kjoram.util.Daemon.priority = Thread.NORM_PRIORITY [protected]

The priority that is assigned to the daemon.

Definition at line 89 of file Daemon.java.

Referenced by com.scalagent.kjoram.util.Daemon.setPriority(), and com.scalagent.kjoram.util.Daemon.start().


The documentation for this class was generated from the following file:
Generated on Tue Sep 16 16:15:42 2008 for joram by  doxygen 1.5.0