Java Reference
In-Depth Information
protected void activateEvent(String eventName,
long lifetime, Object value) {
clock.activate( this , eventName, lifetime, value);
protected abstract void notifyEvent(DiscreteEvent event);
Class DiscreteClock implements the event clock. The inner class Subscription
records the association among an event, a subscriber process and a publisher
process. The clock maintains a list of subscriptions and offers the subscribe()
method to register new subscriptions. It also maintains a list of events and
offers the activate() method to schedule a new event.
import java.util.ArrayList;
import java.util.Collections;
public class DiscreteClock {
// definition of the class Subscription.
class Subscription {
String eventName; // the name of an event
DiscreteProcess subscriber; // the process listening to
// the event
DiscreteProcess publisher; // the process that
// broadcast the event
public Subscription(DiscreteProcess s, String event,
DiscreteProcess p) {
this .subscriber # s;
this .eventName # event;
this .publisher # p;
public void notifyEvent(DiscreteEvent event) {
// Verifies if "subscriber" is listening to "event".
// If event name is equal to "any","subscriber" is
// listening to all the events raised by "publisher"
if ( (eventName.equals( ||
eventName.equals("any")) && )
} // end of class Subscription
ArrayList subscriptions # new ArrayList();
// list of process subscriptions
ArrayList eventQueue # new ArrayList();
// list of active events
public long currentTime # 0; // the current global time
public DiscreteClock() {} // the constructor
Search WWH ::

Custom Search