it.geosolutions.geobatch.flow.event.consumer
Class BaseEventConsumer<XEO extends java.util.EventObject,ECC extends EventConsumerConfiguration>

java.lang.Object
  extended by it.geosolutions.geobatch.catalog.impl.BaseIdentifiable
      extended by it.geosolutions.geobatch.catalog.impl.BaseResource
          extended by it.geosolutions.geobatch.flow.event.consumer.BaseEventConsumer<XEO,ECC>
All Implemented Interfaces:
Identifiable, Resource, EventConsumer<XEO,ECC>, Job, ListenerRegistry<EventConsumerListener>, java.lang.Cloneable, java.util.concurrent.Callable<java.util.Queue<XEO>>

public abstract class BaseEventConsumer<XEO extends java.util.EventObject,ECC extends EventConsumerConfiguration>
extends BaseResource
implements java.util.concurrent.Callable<java.util.Queue<XEO>>, EventConsumer<XEO,ECC>

Version:
r1 - date: 2007
r2 - date: 26 Aug 2011
Author:
Alessio Fabiani, GeoSolutions, Simone Giannecchini, GeoSolutions, (r2)Carlo Cancellieri - carlo.cancellieri@geo-solutions.it

Nested Class Summary
protected  class BaseEventConsumer.EventConsumerListenerForwarder
           
 
Field Summary
protected  java.util.List<BaseAction<XEO>> actions
           
protected  BaseAction<XEO> currentAction
           
protected  java.util.Queue<XEO> eventsQueue
          The MailBox
protected  BaseEventConsumer.EventConsumerListenerForwarder listenerForwarder
           
protected  PauseHandler pauseHandler
           
 
Constructor Summary
BaseEventConsumer(java.lang.String id, java.lang.String name, java.lang.String description)
           
 
Method Summary
protected  void addActions(java.util.List<BaseAction<XEO>> actions)
           
 void addListener(EventConsumerListener listener)
          Add listener to this consumer.
protected  java.util.Queue<XEO> applyActions(java.util.Queue<XEO> events)
          Once the configuring state has been successfully passed, by collecting all the necessary Events, the EventConsumer invokes this method in order to run the related actions.
 boolean consume(XEO event)
          EventConsumer
 void dispose()
          Clean up code for this EventConsumer.
 java.util.List<BaseAction<XEO>> getActions()
           
 java.util.Calendar getCreationTimestamp()
           
 Action<XEO> getCurrentAction()
           
protected  ProgressListenerForwarder getListenerForwarder()
           
 IProgressListener getProgressListener(java.lang.Class<IProgressListener> clazz)
           
 java.lang.String getRunningContext()
           
 EventConsumerStatus getStatus()
          Retrieves the status for this EventConsumer .
 boolean isPaused()
           
 boolean pause()
          Pause the execution of a Job.
Implementations may also completely ignore the pause() call -- for instance the job may not be split in execution steps, loop iterations and so on; in this case the pause() invocation may simply return false, indicating to the caller that the job was not paused.
 boolean pause(boolean sub)
          Pause the execution of a Job and optionally all of its subjobs.
 void removeListener(EventConsumerListener listener)
          Remove listener from this file monitor.
 void resume()
          Resume a previously paused job.
 void setRunningContext(java.lang.String runningContext)
           
protected  void setStatus(EventConsumerStatus eventConsumerStatus)
          Change status and fire events on listeners if status has really changed.
 
Methods inherited from class it.geosolutions.geobatch.catalog.impl.BaseIdentifiable
clone, getDescription, getId, getName, setDescription, setId, setName
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.concurrent.Callable
call
 
Methods inherited from interface it.geosolutions.geobatch.flow.event.consumer.EventConsumer
cancel, getConfiguration, isCanceled, setConfiguration
 
Methods inherited from interface it.geosolutions.geobatch.catalog.Identifiable
getDescription, getId, getName, setDescription, setId, setName
 

Field Detail

eventsQueue

protected final java.util.Queue<XEO extends java.util.EventObject> eventsQueue
The MailBox


actions

protected final java.util.List<BaseAction<XEO extends java.util.EventObject>> actions

currentAction

protected volatile BaseAction<XEO extends java.util.EventObject> currentAction

listenerForwarder

protected final BaseEventConsumer.EventConsumerListenerForwarder listenerForwarder

pauseHandler

protected PauseHandler pauseHandler
Constructor Detail

BaseEventConsumer

public BaseEventConsumer(java.lang.String id,
                         java.lang.String name,
                         java.lang.String description)
Method Detail

getRunningContext

public java.lang.String getRunningContext()
Returns:
the runningContext

setRunningContext

public void setRunningContext(java.lang.String runningContext)
Parameters:
runningContext - the runningContext to set

getCreationTimestamp

public java.util.Calendar getCreationTimestamp()

getStatus

public EventConsumerStatus getStatus()
Description copied from interface: EventConsumer
Retrieves the status for this EventConsumer .

Specified by:
getStatus in interface EventConsumer<XEO extends java.util.EventObject,ECC extends EventConsumerConfiguration>
Returns:
the status for this EventConsumer .

setStatus

protected void setStatus(EventConsumerStatus eventConsumerStatus)
Change status and fire events on listeners if status has really changed.


getCurrentAction

public Action<XEO> getCurrentAction()

consume

public boolean consume(XEO event)
EventConsumer

Specified by:
consume in interface EventConsumer<XEO extends java.util.EventObject,ECC extends EventConsumerConfiguration>
Parameters:
event - The event to consume
Returns:
true if we can consume the provided event, false otherwise.

applyActions

protected java.util.Queue<XEO> applyActions(java.util.Queue<XEO> events)
                                                                   throws ActionException
Once the configuring state has been successfully passed, by collecting all the necessary Events, the EventConsumer invokes this method in order to run the related actions.

FIXME: on action errors the flow used to go on. Now it bails out from the loop.
We may need to specify on a per-action basis if an error in the action should stop the whole flow.

Parameters:
events - The incoming event queue to pass to the first action
runningContext - The context in which the actions should be executed
Throws:
ActionException

pause

public boolean pause()
Description copied from interface: Job
Pause the execution of a Job.
Implementations may also completely ignore the pause() call -- for instance the job may not be split in execution steps, loop iterations and so on; in this case the pause() invocation may simply return false, indicating to the caller that the job was not paused.

Specified by:
pause in interface Job
Returns:
true if the Job has been successfully paused.

pause

public boolean pause(boolean sub)
Description copied from interface: Job
Pause the execution of a Job and optionally all of its subjobs.
A Job may control other subjobs running asynchronally.
When sub is true, also the subjobs will be paused.

pause(false) is equivalent to pause()

Specified by:
pause in interface Job
Parameters:
sub - when true, also subtasks will be paused.
Returns:
true if the Job has been successfully paused, disregarding any return values from its subjobs.

resume

public void resume()
Description copied from interface: Job
Resume a previously paused job.
If the instance does not support pausing or it was not paused, nothing will happen.

Specified by:
resume in interface Job

isPaused

public boolean isPaused()
Specified by:
isPaused in interface Job

getActions

public java.util.List<BaseAction<XEO>> getActions()
Returns:
the list of the Actions associated to this consumer. TODO: returned list should be unmodifiable

addActions

protected void addActions(java.util.List<BaseAction<XEO>> actions)

dispose

public void dispose()
Description copied from interface: EventConsumer
Clean up code for this EventConsumer.

Specified by:
dispose in interface Resource
Specified by:
dispose in interface EventConsumer<XEO extends java.util.EventObject,ECC extends EventConsumerConfiguration>
Overrides:
dispose in class BaseResource

addListener

public void addListener(EventConsumerListener listener)
Add listener to this consumer. If the listener is already registered, it won't be added again.

Specified by:
addListener in interface ListenerRegistry<EventConsumerListener>
Parameters:
fileListener - Listener to add.

removeListener

public void removeListener(EventConsumerListener listener)
Remove listener from this file monitor.

Specified by:
removeListener in interface ListenerRegistry<EventConsumerListener>
Parameters:
listener - Listener to remove.

getListenerForwarder

protected ProgressListenerForwarder getListenerForwarder()

getProgressListener

public IProgressListener getProgressListener(java.lang.Class<IProgressListener> clazz)


Copyright © 2008-2012 GeoSolutions. All Rights Reserved.