Joram 5.0.7

org.objectweb.joram.kclient
Class Daemon

java.lang.Object
  extended by org.objectweb.joram.kclient.Daemon
All Implemented Interfaces:
java.lang.Runnable

public abstract class Daemon
extends java.lang.Object
implements java.lang.Runnable

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:


  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();
  }
 


Field Summary
protected  boolean canStop
          Boolean variable used to stop the daemon properly.
protected  int priority
          The priority that is assigned to the daemon.
protected  boolean running
          Boolean variable used to stop the daemon properly.
protected  java.lang.Thread thread
          The active component of this daemon.
 
Constructor Summary
protected Daemon(java.lang.String name)
          Allocates a new Daemon object.
 
Method Summary
protected abstract  void close()
          Releases any resources attached to this daemon.
protected  void finish()
           
 java.lang.String getName()
          Returns this daemon's name.
 void interrupt()
          Interrupts this daemon.
 boolean isCurrentThread()
          Tests if the daemon's thread is the current one.
 boolean isRunning()
          Tests if this daemon is alive.
 void setPriority(int newPriority)
          Changes the priority of this daemon.
protected abstract  void shutdown()
          Interupts a thread that waits for long periods.
 void start()
          Causes this daemon to begin execution.
 void stop()
          Forces the daemon to stop executing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.lang.Runnable
run
 

Field Detail

running

protected volatile boolean running
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

canStop

protected volatile boolean canStop
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)


thread

protected java.lang.Thread thread
The active component of this daemon.


priority

protected int priority
The priority that is assigned to the daemon.

Constructor Detail

Daemon

protected Daemon(java.lang.String name)
Allocates a new Daemon object.

Parameters:
name - the name of the new Daemon
Method Detail

isRunning

public boolean isRunning()
Tests if this daemon is alive.

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

getName

public final java.lang.String getName()
Returns this daemon's name.

Returns:
this daemon's name.

setPriority

public void setPriority(int newPriority)
Changes the priority of this daemon. If the daemon is running calls the setPriority method on corresponding thread, else stores value for next start.

See Also:
Thread.setPriority

start

public void start()
Causes this daemon to begin execution. A new thread is created to execute the run method.

Throws:
java.lang.IllegalThreadStateException - If the daemon was already started.

close

protected abstract void close()
Releases any resources attached to this daemon. Be careful, its method should be called more than one time.


shutdown

protected abstract void shutdown()
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.


interrupt

public void interrupt()
Interrupts this daemon.


finish

protected final void finish()

stop

public void 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.


isCurrentThread

public boolean isCurrentThread()
Tests if the daemon's thread is the current one.


Joram 5.0.7

Copyright © 2005 Scalagent - All rights reserved