org.opensubsystems.patterns.backgroundtask.www
Class BackgroundTaskListener

java.lang.Object
  extended by org.opensubsystems.patterns.backgroundtask.www.BackgroundTaskListener
All Implemented Interfaces:
java.util.EventListener, javax.servlet.ServletContextListener

public abstract class BackgroundTaskListener
extends java.lang.Object
implements javax.servlet.ServletContextListener

BackgroundTaskListener is responsible for initialization and starting of tasks which in background, that is without user interaction, periodically execute some functionality. This class is useful for starting such tasks in web environment when the application is running as managed application on the application server and therefore it's lifecycle is controlled by the application server.

Version:
$Id: BackgroundTaskListener.java,v 1.9 2007/01/07 06:15:34 bastafidli Exp $
Author:
Miro Halas
Code reviewer:
Miro Halas
Code reviewed:
1.6 2006/04/20 13:59:45 bastafidli

Field Summary
protected  java.util.Map m_tasks
          Map with all tasks created by this listener.
protected  java.util.Map m_tasksTimers
          Timer which periodically execute receiver tasks threads.
 
Constructor Summary
BackgroundTaskListener()
          Creates a new instance of FileProcessorListener
 
Method Summary
 void contextDestroyed(javax.servlet.ServletContextEvent servletContextEvent)
          
 void contextInitialized(javax.servlet.ServletContextEvent servletContextEvent)
          
protected abstract  BackgroundTask createTask(int iId)
          Create task with given id.
protected abstract  java.lang.String getBaseProperty()
          Get base property which will be used to construct identification of the task.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_tasks

protected java.util.Map m_tasks
Map with all tasks created by this listener. Key is task name read from properties, value is BackgroundTask derived object for this name.


m_tasksTimers

protected java.util.Map m_tasksTimers
Timer which periodically execute receiver tasks threads. Key is task name, value is task timer.

Constructor Detail

BackgroundTaskListener

public BackgroundTaskListener()
Creates a new instance of FileProcessorListener

Method Detail

contextInitialized

public void contextInitialized(javax.servlet.ServletContextEvent servletContextEvent)

Specified by:
contextInitialized in interface javax.servlet.ServletContextListener

contextDestroyed

public void contextDestroyed(javax.servlet.ServletContextEvent servletContextEvent)

Specified by:
contextDestroyed in interface javax.servlet.ServletContextListener

createTask

protected abstract BackgroundTask createTask(int iId)
                                      throws org.opensubsystems.core.error.OSSException
Create task with given id. Derived class will implement this by creation of specific task based on the business logic of the derived class.

Parameters:
iId - - id of the task to create
Returns:
BackgroundTask - newly created task
Throws:
org.opensubsystems.core.error.OSSException - - error during creation of task

getBaseProperty

protected abstract java.lang.String getBaseProperty()
Get base property which will be used to construct identification of the task. The identification of task will be property.X where X goes sequentially from 0 to x and can have value 1 for enabled task or 0 for disabled task.

Returns:
String - name of the base property for task


Copyright © 2003 - 2006 OpenSubsystems s.r.o.