hu.mta.sztaki.lpds.cloud.simulator
Class DeferredEvent

java.lang.Object
  extended by hu.mta.sztaki.lpds.cloud.simulator.DeferredEvent
Direct Known Subclasses:
PhysicalMachine.ResourceAllocation

public abstract class DeferredEvent
extends Object

Offers the event handling mechanism for non-recurring but time dependent events. Implementors should provide an implementation of the event action function which will be called once the specified ticks pass. Aggregates the events that should happen at a single time instance. This approach allows that only one Timed event is registered for a bunch of non-recurring events.

Author:
"Gabor Kecskemeti, Distributed and Parallel Systems Group, University of Innsbruck (c) 2013" "Gabor Kecskemeti, Laboratory of Parallel and Distributed Systems, MTA SZTAKI (c) 2015"

Nested Class Summary
private static class DeferredEvent.AggregatedEventDispatcher
          handles the event aggregations, actual subscriptions to timed events and dispatches the events if Timed notifies for time instance at which the non-recurring events should be fired Improves the performance of deferred events significantly if multiple events should occur at once
 
Field Summary
private  boolean cancelled
          Shows if the event in question was cancelled by the user
private static DeferredEvent.AggregatedEventDispatcher dispatcherSingleton
          the aggregator that handles the event list stored in toSweep.
private  long eventArrival
          The time instance at which this event should be delivered
private  boolean received
          Shows if the event was dispatched already
private static gnu.trove.map.hash.TLongObjectHashMap<org.apache.commons.lang3.tuple.MutablePair<Integer,DeferredEvent[]>> toSweep
          All deferred events that are due in the future are listed here.
 
Constructor Summary
DeferredEvent(long delay)
          Allows constructing objects that will receive an eventAction() call from Timed after delay ticks.
 
Method Summary
 void cancel()
          If the call for eventAction() is no longer necessary at the previously specified time then the user can cancel this call to arrive with this function.
protected abstract  void eventAction()
          When creating a deferred event, implement this function for the actual event handling mechanism of yours.
 boolean isCancelled()
          Allows to determine whether the actual event was cancelled already or not.
(package private) static void reset()
          Allows the cleanup of all events registered with the aggregator.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

toSweep

private static final gnu.trove.map.hash.TLongObjectHashMap<org.apache.commons.lang3.tuple.MutablePair<Integer,DeferredEvent[]>> toSweep
All deferred events that are due in the future are listed here. The map is indexed by expected event arrivals. The stored objects in the map are MutablePairs where the left item of the pair is the length of the right item (which is actually the list of events that should be delivered at the particular time instance identified by the key of the map).


dispatcherSingleton

private static final DeferredEvent.AggregatedEventDispatcher dispatcherSingleton
the aggregator that handles the event list stored in toSweep.


cancelled

private boolean cancelled
Shows if the event in question was cancelled by the user


received

private boolean received
Shows if the event was dispatched already


eventArrival

private final long eventArrival
The time instance at which this event should be delivered

Constructor Detail

DeferredEvent

public DeferredEvent(long delay)
Allows constructing objects that will receive an eventAction() call from Timed after delay ticks.

Parameters:
delay - the number of ticks that should pass before this deferred event object's eventAction() will be called.
Method Detail

cancel

public void cancel()
If the call for eventAction() is no longer necessary at the previously specified time then the user can cancel this call to arrive with this function. Calling this function will have no effect on events that are already past due.


isCancelled

public boolean isCancelled()
Allows to determine whether the actual event was cancelled already or not.

Returns:
  • true if the event will not arrive in the future as it was cancelled,
  • false otherwise

eventAction

protected abstract void eventAction()
When creating a deferred event, implement this function for the actual event handling mechanism of yours.


reset

static void reset()
Allows the cleanup of all events registered with the aggregator. WARNING: This is not supposed to be called by user code directly.



Copyright © 2012–2015 University of Innsbruck & MTA SZTAKI. All rights reserved.