org.mmbase.module.builders.vwms
Class Vwm

java.lang.Object
  extended by org.mmbase.module.builders.vwms.Vwm
All Implemented Interfaces:
Runnable, VwmInterface, VwmProbeInterface, MMBaseObserver
Direct Known Subclasses:
ImageMaster, PageMaster

public class Vwm
extends Object
implements VwmInterface, VwmProbeInterface, Runnable

Virtual Web Master base object. Most VWM's inherit fromt his base class. The Vwm contains routines for performing tasks at certain intervals. The interval is determined from the maintime value in the Vwms builder (Maintenance time in seconds), Each interval, the vwm invokes the ProbeCall() method. VWMs perform periodic maintenance by overrideing the probeCall method (the default doesn't do anything). A VWM is also called a 'Bot'.

Version:
$Id: Vwm.java 35335 2009-05-21 08:14:41Z michiel $
Author:
Daniel Ockeloen, Pierre van Rooden (javadocs)
Application:
VWMs

Field Summary
(package private)  Vector<VwmCallBackInterface> clients
          What clients are using this VWM.
(package private)  Thread kicker
          Thread in which the VWM runs.
protected  String name
          Name of the VWM.
protected  VwmProbe probe
          Scheduler of tasks depending on VWMtask nodes associated with this Vwm.
protected  int sleeptime
          Sleep time in seconds.
protected  Vwms Vwms
          The VWMs builder that holds the VWM's node.
protected  MMObjectNode wvmnode
          The creation node of this VWM.
 
Constructor Summary
Vwm()
           
 
Method Summary
 boolean addClient(VwmCallBackInterface client)
          Add a client to the listen queue of the wvm.
protected  boolean claim(MMObjectNode node)
          Signals that the task node is claimed.
protected  void debug(String msg)
           
protected  boolean failed(MMObjectNode node)
          Signals that the task to be performed failed.
 String getName()
          Returns the name of the VWM.
 MMObjectNode getVwmNode()
          Retrieves the creation node of this VWM.
 void init(MMObjectNode vwmnode, Vwms Vwms)
          Initialize the Vwm.
 boolean nodeLocalChanged(String machine, String number, String builder, String ctype)
          Called when a remote node is changed.
 boolean nodeRemoteChanged(String machine, String number, String builder, String ctype)
          Called when a local node is changed.
protected  Hashtable parseProperties(String props)
          Converts a string of properties to a Hashtable.
protected  boolean performed(MMObjectNode node)
          Signals that the task to be performed was successful and has finished.
 boolean performTask(MMObjectNode node)
          Performs maintenance based on a Vwmtasknode.
 boolean probeCall()
          Performs periodic maintenance.
 boolean putTask(MMObjectNode node)
          Adds a new task to the list of taks to perform.
 boolean releaseClient(VwmCallBackInterface client)
          Release a client from the listen queue of the wvm.
protected  boolean rollback(MMObjectNode node)
          Signals that the task should be performed again (possibly after an initial failure).
 void run()
          VWM maintenance scheduler.
 void start()
          Starts the thread for the Vwm.
 void stop()
          Stops the Vwm's thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

probe

protected VwmProbe probe
Scheduler of tasks depending on VWMtask nodes associated with this Vwm.


sleeptime

protected int sleeptime
Sleep time in seconds. This is the interval in which the VWM performs it's maintenance probes.


wvmnode

protected MMObjectNode wvmnode
The creation node of this VWM. Used to retrieve the maintenance time and to maintain VWM state information.


name

protected String name
Name of the VWM. Retrieved from the node from the VWMs builder, but can also be set manually by the VWM's overriding class.


Vwms

protected Vwms Vwms
The VWMs builder that holds the VWM's node. The same as the parent attribute of the vwm node (but a bit easier in use).

See Also:
getVwmNode()

kicker

Thread kicker
Thread in which the VWM runs. This field can be used to stop the VWM. Setting kicker to null (either from outside the thread or within) will cause the VWM to terminate it's run() method.


clients

Vector<VwmCallBackInterface> clients
What clients are using this VWM. Each client implements the VwmCallBackInterface, and can be invoked when important changes occur.

Constructor Detail

Vwm

public Vwm()
Method Detail

debug

protected void debug(String msg)

init

public void init(MMObjectNode vwmnode,
                 Vwms Vwms)
Initialize the Vwm. Called by the Vwms builder that starts the VWM. Sets a few fields, creates a new probe instance, and starts a new thread.

Specified by:
init in interface VwmInterface
Parameters:
vwmnode -
Vwms - The VWMs builder. It is not really necessary as this is the same as the parent attribute of vwmnode.

start

public void start()
Starts the thread for the Vwm.


stop

public void stop()
Stops the Vwm's thread. Sets the kicker field to null, which causes the run method to terminate.


run

public void run()
VWM maintenance scheduler. Calls the probeCall() method, after which the thread sleeps for a number of seconds as set in sleeptime.

Specified by:
run in interface Runnable

addClient

public boolean addClient(VwmCallBackInterface client)
Add a client to the listen queue of the wvm.

Specified by:
addClient in interface VwmInterface
Parameters:
client - The client-object to add
Returns:
true if the client was added, false if it already existed in the queue.

releaseClient

public boolean releaseClient(VwmCallBackInterface client)
Release a client from the listen queue of the wvm.

Specified by:
releaseClient in interface VwmInterface
Parameters:
client - The client-object to release
Returns:
true if the client was released, false if it did not exist in the queue.

probeCall

public boolean probeCall()
Performs periodic maintenance. This method is called by the VWM's own run() method. Since this does not actually do anything, perhaps this method should be abstract.

Specified by:
probeCall in interface VwmProbeInterface
Returns:
true if maintenance was performed, false otherwise

putTask

public boolean putTask(MMObjectNode node)
Adds a new task to the list of taks to perform. Passes the task to the VWM's probe, which handles the of tasks.

Parameters:
node - the node describing the task (from the Vwmtasks builder)
Returns:
true is the task was succesfully added.

getName

public String getName()
Returns the name of the VWM.

Specified by:
getName in interface VwmProbeInterface

performTask

public boolean performTask(MMObjectNode node)
Performs maintenance based on a Vwmtasknode. This method is called by the probe object assoviated with the VWM. the default method sets a status field to indicate an error, and sends an error email. Perhaps this method should be abstract.

Specified by:
performTask in interface VwmProbeInterface
Parameters:
node - The Vwmtask node that describes the task to be performed.
Returns:
true if maintenance was performed, false if it failed

claim

protected boolean claim(MMObjectNode node)
Signals that the task node is claimed. Sets the status of the task to 'claimed', as well as the machinename that is claiming the task. Setting a task to 'claimed' prevents it from being scheduled for performance by the Vwmtask builder.

Parameters:
node - The VwmTask node that describes the task
Returns:
true if teh task's state was cahnged, false if it fails.

rollback

protected boolean rollback(MMObjectNode node)
Signals that the task should be performed again (possibly after an initial failure). Sets the status of the task to 'request'. Setting a task to 'request' allows it to be scheduled for performance by the Vwmtask builder.

Parameters:
node - The VwmTask node that describes the task
Returns:
true if teh task's state was cahnged, false if it fails.

failed

protected boolean failed(MMObjectNode node)
Signals that the task to be performed failed. Sets the status of the task to 'error'. Setting a task to 'error' prevents it from being scheduled for performance by the Vwmtask builder.

Parameters:
node - The VwmTask node that describes the task
Returns:
true if the task's state was cahnged, false if it fails.

performed

protected boolean performed(MMObjectNode node)
Signals that the task to be performed was successful and has finished. Sets the status of the task to 'done'. Setting a task to 'done' prevents it from being scheduled for performance by the Vwmtask builder.

Parameters:
node - The VwmTask node that describes the task
Returns:
true if teh task's state was cahnged, false if it fails.

parseProperties

protected Hashtable parseProperties(String props)
Converts a string of properties to a Hashtable. Used to parse the 'data' field of a VwmTask node. The property format is a string with a property on each line in the format: name = value Very generic, should probably be moved to the MMObjectNode class (as in getPropertiesValue(fieldname) ).

Parameters:
props - the properties string
Returns:
a hashtable with the property name=value pairs.

getVwmNode

public MMObjectNode getVwmNode()
Retrieves the creation node of this VWM.


nodeRemoteChanged

public boolean nodeRemoteChanged(String machine,
                                 String number,
                                 String builder,
                                 String ctype)
Called when a local node is changed.

Specified by:
nodeRemoteChanged in interface MMBaseObserver
Parameters:
machine - Name of the machine that changed the node.
number - Number of the changed node as a String
builder - type of the changed node
ctype - command type, 'c'=changed, 'd'=deleted', 'r'=relations changed, 'n'=new
Returns:
true if maintenance was performed, false (the default) otherwise

nodeLocalChanged

public boolean nodeLocalChanged(String machine,
                                String number,
                                String builder,
                                String ctype)
Called when a remote node is changed.

Specified by:
nodeLocalChanged in interface MMBaseObserver
Parameters:
machine - Name of the machine that changed the node.
number - Number of the changed node as a String
builder - type of the changed node
ctype - command type, 'c'=changed, 'd'=deleted', 'r'=relations changed, 'n'=new
Returns:
true if maintenance was performed, false (the default) otherwise


MMBase 2.0-SNAPSHOT - null