org.keridwen.core.messaging
Class DefaultBundleController

java.lang.Object
  extended by org.keridwen.core.messaging.DefaultBundleController
All Implemented Interfaces:
BundleController, ConditionListener

public class DefaultBundleController
extends Object
implements BundleController, ConditionListener

This abstract class defines the default behaviour of a BundleController. Each bundle then has to implement how the controller deals with the model.


Constructor Summary
DefaultBundleController(DataModel applicationModel, DataModel bundleModel)
          Creates a bundle controller for the given application data model and bundle data model.
 
Method Summary
 void clean()
          Removes all registered Events/Commands associations.
 boolean containsEventKey(EventKey key)
          Checks whether the given key is registered in the controller.
 DataModel getApplicationModel()
          Gets the data model of the application.
 DataModel getBundleModel()
          Gets the data model of the bundle.
<ReturnType,MessageType>
Command<ReturnType,MessageType>
getCommandForEvent(Event<ReturnType,MessageType> event)
          Gets the Command (if any) associated with the given Event.
 void registerEvent(DefaultEventKey<?,?>... keyArray)
          Registers the given EventKey array.
 void registerEvent(String keyId, Class<? extends Command<?,?>> commandClass)
           
<ReturnType,MessageType>
ScheduledFuture<?>
runAfterDelay(Command<ReturnType,MessageType> command, MessageType message, long delay, TimeUnit unit)
          Runs the given Command after the given delay.
<ReturnType,MessageType>
Future<ReturnType>
runAsynchronously(Command<ReturnType,MessageType> command, MessageType message)
          Runs the given Command asynchronously.
<ReturnType,MessageType>
Future<ReturnType>
runAsynchronously(Command<ReturnType,MessageType> command, MessageType message, int nbThreads)
           
<ReturnType,MessageType>
ScheduledFuture<?>
runAtFixedRate(Command<ReturnType,MessageType> command, MessageType message, long initialDelay, long period, TimeUnit unit)
          Runs the gievn Command after the given delay and at a given period.
<ReturnType,MessageType>
Future<ReturnType>
runOnCondition(Command<ReturnType,MessageType> command, MessageType message, Condition condition)
          Runs the given Command as soon as the Condition becomes valid.
<ReturnType,MessageType>
ScheduledFuture<?>
runWithFixedDelay(Command<ReturnType,MessageType> command, MessageType message, long initialDelay, long delay, TimeUnit unit)
          Runs the given Command after the given delay with the given delay between two executions.
 void terminate()
          Terminates all threads running in the controller.
 void unregisterEvent(EventKey... keyArray)
          Unregisters the Command associated to the given EventKeys.
 void validityChanged(Condition condition, boolean validity)
          Method called when the validity of a Condition has changed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultBundleController

public DefaultBundleController(DataModel applicationModel,
                               DataModel bundleModel)
Creates a bundle controller for the given application data model and bundle data model.

Parameters:
applicationModel - the application data model
bundleModel - the bundle data model
Method Detail

registerEvent

public void registerEvent(DefaultEventKey<?,?>... keyArray)
Description copied from interface: BundleController
Registers the given EventKey array.

Specified by:
registerEvent in interface BundleController
Parameters:
keyArray - the array of unique keys of the Events triggering an associated Commands

registerEvent

public void registerEvent(String keyId,
                          Class<? extends Command<?,?>> commandClass)
Specified by:
registerEvent in interface BundleController

unregisterEvent

public void unregisterEvent(EventKey... keyArray)
Description copied from interface: BundleController
Unregisters the Command associated to the given EventKeys.

Specified by:
unregisterEvent in interface BundleController
Parameters:
keyArray - the unique keys of the Events triggering the associated Commands

clean

public final void clean()
Description copied from interface: BundleController
Removes all registered Events/Commands associations.

Specified by:
clean in interface BundleController

containsEventKey

public final boolean containsEventKey(EventKey key)
Description copied from interface: BundleController
Checks whether the given key is registered in the controller.

Specified by:
containsEventKey in interface BundleController
Parameters:
key - the event key to check
Returns:
true is the event key is registered

getCommandForEvent

public <ReturnType,MessageType> Command<ReturnType,MessageType> getCommandForEvent(Event<ReturnType,MessageType> event)
Description copied from interface: BundleController
Gets the Command (if any) associated with the given Event.

Specified by:
getCommandForEvent in interface BundleController
Type Parameters:
ReturnType - the return type of the command
MessageType - the type of the message transported by the Event
Parameters:
event - the event
Returns:
the Command (if any)

runAsynchronously

public final <ReturnType,MessageType> Future<ReturnType> runAsynchronously(Command<ReturnType,MessageType> command,
                                                                           MessageType message)
Description copied from interface: BundleController
Runs the given Command asynchronously.

Specified by:
runAsynchronously in interface BundleController
Type Parameters:
ReturnType - type of the data returned by the command.
MessageType - type of the message to handle
Parameters:
command - the command to execute
message - the message to be handled by the command
Returns:
a future representing the pending completion of the command

runAsynchronously

public final <ReturnType,MessageType> Future<ReturnType> runAsynchronously(Command<ReturnType,MessageType> command,
                                                                           MessageType message,
                                                                           int nbThreads)
Specified by:
runAsynchronously in interface BundleController

runOnCondition

public final <ReturnType,MessageType> Future<ReturnType> runOnCondition(Command<ReturnType,MessageType> command,
                                                                        MessageType message,
                                                                        Condition condition)
Description copied from interface: BundleController
Runs the given Command as soon as the Condition becomes valid.

Specified by:
runOnCondition in interface BundleController
Type Parameters:
ReturnType - type of the data returned by the command.
MessageType - type of the message to handle
Parameters:
command - the command to execute
message - the message to be handled by the command
condition - the Condition to watch
Returns:
a future representing the pending completion of the command

validityChanged

public final void validityChanged(Condition condition,
                                  boolean validity)
Description copied from interface: ConditionListener
Method called when the validity of a Condition has changed.

Specified by:
validityChanged in interface ConditionListener
Parameters:
condition - the watched condition.
validity - the new validity of the condition.

runAfterDelay

public final <ReturnType,MessageType> ScheduledFuture<?> runAfterDelay(Command<ReturnType,MessageType> command,
                                                                       MessageType message,
                                                                       long delay,
                                                                       TimeUnit unit)
Description copied from interface: BundleController
Runs the given Command after the given delay.

Specified by:
runAfterDelay in interface BundleController
Type Parameters:
ReturnType - type of the data returned by the command.
MessageType - type of the message to handle
Parameters:
command - the command to execute
message - the message to be handled by the command
delay - the time from now to delay execution
unit - the time unit of the delay parameter
Returns:
a scheduled future representing the pending completion of the scheduled command and whose get() method will return null upon completion

runWithFixedDelay

public final <ReturnType,MessageType> ScheduledFuture<?> runWithFixedDelay(Command<ReturnType,MessageType> command,
                                                                           MessageType message,
                                                                           long initialDelay,
                                                                           long delay,
                                                                           TimeUnit unit)
Description copied from interface: BundleController
Runs the given Command after the given delay with the given delay between two executions.

Specified by:
runWithFixedDelay in interface BundleController
Type Parameters:
ReturnType - type of the data returned by the command.
MessageType - type of the message to handle
Parameters:
command - the command to execute
message - the message to be handled by the command
initialDelay - the time from now to delay the first execution
delay - the delay between termination of one execution and the commencement of the next
unit - the time unit of the parameters
Returns:
scheduled future representing the pending completion of the scheduled command

runAtFixedRate

public final <ReturnType,MessageType> ScheduledFuture<?> runAtFixedRate(Command<ReturnType,MessageType> command,
                                                                        MessageType message,
                                                                        long initialDelay,
                                                                        long period,
                                                                        TimeUnit unit)
Description copied from interface: BundleController
Runs the gievn Command after the given delay and at a given period.

Specified by:
runAtFixedRate in interface BundleController
Type Parameters:
ReturnType - type of the data returned by the command.
MessageType - type of the message to handle
Parameters:
command - the command to execute
message - the message to be handled by the command
initialDelay - the time from now to delay the first execution
period - the period between two consecutive executions
unit - the time unit of the parameters
Returns:
scheduled future representing the pending completion of the scheduled command

terminate

public final void terminate()
Description copied from interface: BundleController
Terminates all threads running in the controller.

Specified by:
terminate in interface BundleController

getApplicationModel

public final DataModel getApplicationModel()
Description copied from interface: BundleController
Gets the data model of the application.

Specified by:
getApplicationModel in interface BundleController
Returns:
the data model of the application

getBundleModel

public final DataModel getBundleModel()
Description copied from interface: BundleController
Gets the data model of the bundle.

Specified by:
getBundleModel in interface BundleController
Returns:
the data model of the bundle


Copyright © 2010-2013 Artenum. All Rights Reserved.