org.glite.ce.monitorapij.resource
Class ResourceHolder

java.lang.Object
  extended byjava.util.TimerTask
      extended byorg.glite.ce.monitorapij.resource.ResourceHolder
All Implemented Interfaces:
java.lang.Runnable

public abstract class ResourceHolder
extends java.util.TimerTask

A class used to handle a list of Resources placed in a specified directory as plugins. An XML config file is used to store and retrieve information about these resources. The task of checking if resources are added or removed or modified can be scheduled for repeated executions.

Author:
Luigi Zangrando (zangrando@pd.infn.it)

Constructor Summary
ResourceHolder(org.apache.axis.MessageContext context, java.net.URI resourcePath)
          Creates a new ResourceHolder object specifying the current MessageContext and the resource path.
ResourceHolder(org.apache.axis.MessageContext context, java.net.URI resourcePath, java.net.URI configFilePath)
          Creates a new ResourceHolder object specifying the current MessageContext, the resource path and the config file path.
 
Method Summary
 void addResource(Resource resource)
          Add a Resource to the list of handled resources.
 void addResourceListener(ResourceListener l)
          Adds a ResourceListener to the holder.
protected  boolean checkNewResources()
          Check if any resources has been added or modified by checking last modification time of the dir containing the resources.
 void clear()
          Clear the list of handled resources.
protected  void fireResourceEvent(ResourceEvent event)
          Notifies all listeners that have registered interest for notification on this event type.
 java.net.URI getConfigFileURI()
          Get the URI specifying the config file path.
 Resource getResource(int id)
          Get the Resource specified by its ID.
 Resource[] getResourceByJARPath(org.apache.axis.types.URI path)
          Get the CEMonResources with the specified jar path.
 Resource[] getResourceByName(java.lang.String name)
          Get the CEMonResources with the specified name.
 Resource[] getResourceByType(java.lang.String type)
          Get the all Resource of the specified type.
protected  java.io.File[] getResourceFileList()
          Get the list of jar files contained in the resource directory.
 Resource[] getResources()
          Get all the handled resources.
 java.net.URI getResourceURI()
          Get the URI specifying the resource path.
 ResourceListener[] getSensorListeners()
          Returns an array of all the SensorListener s added to this holder with addSensorListener().
protected  java.lang.Class makeResourceClass(java.io.File resourceJarFile)
          Get an instance of the Resource class packed in the jar file.
protected  Resource makeResourceInstance(java.io.File resourceJarFile)
          DOCUMENT ME!
 void removeResource(Resource resource)
          Remove the specified Resource.
 void removeResourceListener(ResourceListener l)
          Removes a ResourceListener from the holder.
 void run()
          This is the scheduled method checking if new resources are added or if already present resources has been updated.
 void setResources(Resource[] resources)
          Add an array of Resources to the list of handled resources.
 
Methods inherited from class java.util.TimerTask
cancel, scheduledExecutionTime
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceHolder

public ResourceHolder(org.apache.axis.MessageContext context,
                      java.net.URI resourcePath)
Creates a new ResourceHolder object specifying the current MessageContext and the resource path. The path of the config file is considered null; this means that no xml describing the present resources has been created yet.

Parameters:
context - The current MessageContext.
resourcePath - The path where new resources are placed.

ResourceHolder

public ResourceHolder(org.apache.axis.MessageContext context,
                      java.net.URI resourcePath,
                      java.net.URI configFilePath)
Creates a new ResourceHolder object specifying the current MessageContext, the resource path and the config file path.

Parameters:
context - The current MessageContext.
resourcePath - The path where new resources are placed.
configFilePath - The path of the config file.
Method Detail

getResourceURI

public java.net.URI getResourceURI()
Get the URI specifying the resource path.

Returns:
The URI specifying the resource path.

getConfigFileURI

public java.net.URI getConfigFileURI()
Get the URI specifying the config file path.

Returns:
The URI specifying the config file path.

addResource

public void addResource(Resource resource)
Add a Resource to the list of handled resources.

Parameters:
resource - The Resource to add. This must have a defined ID.

removeResource

public void removeResource(Resource resource)
Remove the specified Resource.

Parameters:
resource - The resource to be removed.

getResource

public Resource getResource(int id)
Get the Resource specified by its ID.

Parameters:
id - The ID int of the Resource searched.
Returns:
The Resource searched if present in the list of handled resources, null otherwise.

getResources

public Resource[] getResources()
Get all the handled resources.

Returns:
An array containing all the handled resources.

getResourceByType

public Resource[] getResourceByType(java.lang.String type)
Get the all Resource of the specified type.

Returns:
An Array containing the Resources searched if present in the list of handled resources, an empty array otherwise.

getResourceByJARPath

public Resource[] getResourceByJARPath(org.apache.axis.types.URI path)
Get the CEMonResources with the specified jar path.

Parameters:
path - The path of the jar of the resource.
Returns:
An array containing the searched resources if present in the list of handled resources.

getResourceByName

public Resource[] getResourceByName(java.lang.String name)
Get the CEMonResources with the specified name.

Parameters:
name - The name of the searched resource.
Returns:
An array containing the searched resources if present in the list of handled resources.

setResources

public void setResources(Resource[] resources)
Add an array of Resources to the list of handled resources.

Parameters:
resources - An array containing the resources to add.

clear

public void clear()
Clear the list of handled resources.


checkNewResources

protected boolean checkNewResources()
Check if any resources has been added or modified by checking last modification time of the dir containing the resources.

Returns:
true if new resources has been added or old resources has been changed, false otherwise.

getResourceFileList

protected java.io.File[] getResourceFileList()
                                      throws java.lang.Exception
Get the list of jar files contained in the resource directory.

Returns:
An array of Files filled of the jar files contained in the resource directory.
Throws:
java.lang.Exception

makeResourceInstance

protected Resource makeResourceInstance(java.io.File resourceJarFile)
                                 throws java.lang.Exception
DOCUMENT ME!

Parameters:
resourceJarFile - DOCUMENT ME!
Returns:
DOCUMENT ME!
Throws:
java.lang.Exception - DOCUMENT ME!

makeResourceClass

protected java.lang.Class makeResourceClass(java.io.File resourceJarFile)
                                     throws java.lang.Exception
Get an instance of the Resource class packed in the jar file.

Parameters:
resourceJarFile - The jar file containing the class of a Resource. It must contain the "Main-Class" attribute into its MANIFEST.MF specifying the name of the Resource class.
Returns:
The class contained in the jar file.
Throws:
java.lang.Exception - If the jar file does not contain a main class the "Main-Class" attribute into its MANIFEST.MF or if the instance cannot be created.

run

public void run()
This is the scheduled method checking if new resources are added or if already present resources has been updated. If this is the case handles the new or updated resources.


getSensorListeners

public ResourceListener[] getSensorListeners()
Returns an array of all the SensorListener s added to this holder with addSensorListener().

Returns:
all of the SensorListener s added or an empty array if no listeners have been added

addResourceListener

public void addResourceListener(ResourceListener l)
Adds a ResourceListener to the holder.

Parameters:
l - the ResourceListener to be added

removeResourceListener

public void removeResourceListener(ResourceListener l)
Removes a ResourceListener from the holder.

Parameters:
l - the listener to be removed

fireResourceEvent

protected void fireResourceEvent(ResourceEvent event)
Notifies all listeners that have registered interest for notification on this event type.