org.gcube.common.core.utils.handlers
Class GCUBEParallelHandler<HANDLED>

java.lang.Object
  extended by org.gcube.common.core.utils.handlers.GCUBEHandler<HANDLED>
      extended by org.gcube.common.core.utils.handlers.GCUBEComplexHandler<HANDLED>
          extended by org.gcube.common.core.utils.handlers.GCUBEParallelHandler<HANDLED>
Type Parameters:
HANDLED - the type of the handled object of the component handlers.
All Implemented Interfaces:
GCUBEIHandler<HANDLED>, Lifetime<HANDLED>

public class GCUBEParallelHandler<HANDLED>
extends GCUBEComplexHandler<HANDLED>
implements Lifetime<HANDLED>

An extension of GCUBEComplexHandler which parallelises the execution of the component handlers. A GCUBEParallelHandler propagates its state to all the component handlers (non-destructively). Failures are handled in accordance with either one of the two modes enumerated by GCUBEParallelHandler.Mode.

Author:
Fabio Simeoni (University of Strathclyde)

Nested Class Summary
static class GCUBEParallelHandler.Mode
          Enumeration of the two failure handling modes of a GCUBEParallelHandler.
protected  class GCUBEParallelHandler.SlaveThread
          An extension of Thread which executes a component handler and records its potential errors.
protected  class GCUBEParallelHandler.SweeperThread
          An extension of Thread which waits for all component handlers to terminate before invoking GCUBEComplexHandler.undo().
 
Field Summary
protected  Map<GCUBEIHandler<? extends HANDLED>,Exception> failedHandlers
          Component handlers which have failed during the execution of the handler.
protected  List<GCUBEParallelHandler.SlaveThread> failedSlaves
          Per-component handler threads which have failed during the execution of the handler.
protected  GCUBEParallelHandler.Mode mode
          Failure mode for the execution of the handler.
protected  List<GCUBEParallelHandler.SlaveThread> runningSlaves
          Per-component handler threads spawned by the handler.
 
Fields inherited from class org.gcube.common.core.utils.handlers.GCUBEHandler
handled, logger, producer
 
Constructor Summary
GCUBEParallelHandler(GCUBEIHandler<? extends HANDLED>... components)
          Creates an instance with a list of component handlers.
GCUBEParallelHandler(GCUBEParallelHandler.Mode mode)
          Creates an handler with a given failure handling mode.
 
Method Summary
 Map<GCUBEIHandler<? extends HANDLED>,Exception> getFailedHandlers()
          Returns the component handlers which have failed during execution of the handler, along with the corresponding failures.
 GCUBEParallelHandler.Mode getMode()
          Returns the failure handling mode of the handler.
 void run()
          Executes the task implemented by the handler.
 void setMode(GCUBEParallelHandler.Mode mode)
          Sets the failure handling mode of the handler.
 
Methods inherited from class org.gcube.common.core.utils.handlers.GCUBEComplexHandler
addHandlers, getHandlers, removeHandler, setLogger, undo
 
Methods inherited from class org.gcube.common.core.utils.handlers.GCUBEHandler
clearBlackboard, getBlackboard, getHandled, getId, getLogger, getName, getScopeManager, getSecurityManager, getState, notify, setBlackboard, setHandled, setName, setScopeManager, setSecurityManager, setState, subscribe, unsubscribe
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.gcube.common.core.utils.handlers.lifetime.Lifetime
getState
 
Methods inherited from interface org.gcube.common.core.utils.handlers.GCUBEIHandler
clearBlackboard, getBlackboard, getHandled, getId, getLogger, getName, getScopeManager, getSecurityManager, setBlackboard, setHandled, setLogger, setName, setScopeManager, setSecurityManager, subscribe, undo, unsubscribe
 

Field Detail

mode

protected GCUBEParallelHandler.Mode mode
Failure mode for the execution of the handler.


failedSlaves

protected List<GCUBEParallelHandler.SlaveThread> failedSlaves
Per-component handler threads which have failed during the execution of the handler.


runningSlaves

protected List<GCUBEParallelHandler.SlaveThread> runningSlaves
Per-component handler threads spawned by the handler.


failedHandlers

protected Map<GCUBEIHandler<? extends HANDLED>,Exception> failedHandlers
Component handlers which have failed during the execution of the handler.

Constructor Detail

GCUBEParallelHandler

public GCUBEParallelHandler(GCUBEIHandler<? extends HANDLED>... components)
Creates an instance with a list of component handlers.

Parameters:
components - the component handlers.

GCUBEParallelHandler

public GCUBEParallelHandler(GCUBEParallelHandler.Mode mode)
Creates an handler with a given failure handling mode.

Parameters:
mode - the failure handling mode.
Method Detail

getMode

public GCUBEParallelHandler.Mode getMode()
Returns the failure handling mode of the handler.

Returns:
the mode.

setMode

public void setMode(GCUBEParallelHandler.Mode mode)
Sets the failure handling mode of the handler.

Parameters:
mode - the mode.

getFailedHandlers

public Map<GCUBEIHandler<? extends HANDLED>,Exception> getFailedHandlers()
Returns the component handlers which have failed during execution of the handler, along with the corresponding failures.

Returns:
a list of (handler,exception) pairs.

run

public void run()
         throws Exception
Executes the task implemented by the handler.

Specified by:
run in interface GCUBEIHandler<HANDLED>
Specified by:
run in class GCUBEHandler<HANDLED>
Throws:
Exception - if the execution of the task does not complete normally.


Copyright © 2012. All Rights Reserved.