View Javadoc

1   /*
2      Copyright 2007 Ramon Servadei
3   
4      Licensed under the Apache License, Version 2.0 (the "License");
5      you may not use this file except in compliance with the License.
6      You may obtain a copy of the License at
7   
8          http://www.apache.org/licenses/LICENSE-2.0
9   
10     Unless required by applicable law or agreed to in writing, software
11     distributed under the License is distributed on an "AS IS" BASIS,
12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13     See the License for the specific language governing permissions and
14     limitations under the License.
15   */
16  package fulmine.event;
17  
18  import java.util.Collection;
19  import java.util.TimerTask;
20  
21  import fulmine.ILifeCycle;
22  import fulmine.context.IFrameworkContext;
23  import fulmine.event.listener.IEventListener;
24  import fulmine.event.system.ISystemEvent;
25  import fulmine.event.system.ISystemEventSource;
26  
27  /**
28   * Manages events within a local context.
29   * 
30   * @see IFrameworkContext
31   * @author Ramon Servadei
32   */
33  public interface IEventManager extends ILifeCycle
34  {
35      /**
36       * Get an {@link ISystemEventSource} that is used to propagate a single
37       * specific type of {@link ISystemEvent}. The system event source will be
38       * created on the first invocation. The system event source is associated
39       * with the zeroth {@link EventProcessor}.
40       * 
41       * @param type
42       *            the type of the system events the system event source
43       *            generates
44       * @return the {@link ISystemEventSource} for the type of system event
45       */
46      ISystemEventSource getSystemEventSource(Class<? extends ISystemEvent> type);
47  
48      /**
49       * Bulk operation for queueing events.
50       * 
51       * @see #queueEvent(IEvent)
52       * @param event
53       *            the list of events to queue
54       */
55      void queueEvents(Collection<IEvent> events);
56  
57      /**
58       * Add the event to a queue for distribution to registered
59       * {@link IEventListener} instances for the event's {@link IEventSource}.
60       * 
61       * @param event
62       *            the event to queue
63       */
64      void queueEvent(IEvent event);
65  
66      /**
67       * Get the {@link ThreadGroup} for the event processors.
68       * 
69       * @return the thread group for the event processors
70       */
71      ThreadGroup getEventProcessorThreadGroup();
72  
73      /**
74       * Get the number of {@link EventProcessor} instances in this context
75       * 
76       * @return the number of event processors in this context
77       */
78      int getEventProcessorCount();
79  
80      /**
81       * Add the task to a queue to be executed by a single worker thread. This is
82       * provided as a utility to execute a "one-shot" asynchronous task.
83       * 
84       * @param runnable
85       *            the task to add to the execution queue
86       */
87      void execute(Runnable task);
88  
89      /**
90       * Schedule a timer task to be executed by a single worker thread.
91       * 
92       * @param task
93       *            task to be scheduled.
94       * @param delay
95       *            delay in milliseconds before task is to be executed.
96       * @param period
97       *            time in milliseconds between successive task executions.
98       */
99      void schedule(TimerTask task, long delay, long period);
100 
101 }