001 /*
002 * Copyright 2009-2013 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package griffon.core;
017
018 import griffon.util.RunnableWithArgs;
019 import groovy.lang.Closure;
020
021 import java.util.List;
022
023 /**
024 * Base contract for classes that can publish events using their own
025 * event bus.
026 *
027 * @author Andres Almiray
028 * @since 0.9.3
029 */
030 public interface EventPublisher {
031 /**
032 * Adds an event listener.<p>
033 * Accepted types are: Script, Map and Object.
034 *
035 * @param listener an event listener
036 */
037 void addEventListener(Object listener);
038
039 /**
040 * Adds a closure as an event listener.<p>
041 *
042 * @param eventName the name of the event
043 * @param listener an event listener
044 */
045 void addEventListener(String eventName, Closure listener);
046
047 /**
048 * Adds a runnable as an event listener.<p>
049 *
050 * @param eventName the name of the event
051 * @param listener an event listener
052 */
053 void addEventListener(String eventName, RunnableWithArgs listener);
054
055 /**
056 * Removes an event listener.<p>
057 * Accepted types are: Script, Map and Object.
058 *
059 * @param listener an event listener
060 */
061 void removeEventListener(Object listener);
062
063 /**
064 * Removes a closure as an event listener.<p>
065 *
066 * @param eventName the name of the event
067 * @param listener an event listener
068 */
069 void removeEventListener(String eventName, Closure listener);
070
071 /**
072 * Removes a runnable as an event listener.<p>
073 *
074 * @param eventName the name of the event
075 * @param listener an event listener
076 */
077 void removeEventListener(String eventName, RunnableWithArgs listener);
078
079 /**
080 * Publishes an event.<p>
081 * Listeners will be notified in the same thread as the publisher.
082 *
083 * @param eventName the name of the event
084 */
085 void publishEvent(String eventName);
086
087 /**
088 * Publishes an event.<p>
089 * Listeners will be notified in the same thread as the publisher.
090 *
091 * @param eventName the name of the event
092 * @param args event arguments sent to listeners
093 */
094 void publishEvent(String eventName, List args);
095
096 /**
097 * Publishes an event.<p>
098 * Listeners will be notified outside of the UI thread.
099 *
100 * @param eventName the name of the event
101 */
102 void publishEventOutsideUI(String eventName);
103
104 /**
105 * Publishes an event.<p>
106 * Listeners will be notified outside of the UI thread.
107 *
108 * @param eventName the name of the event
109 * @param args event arguments sent to listeners
110 */
111 void publishEventOutsideUI(String eventName, List args);
112
113 /**
114 * Publishes an event.<p>
115 * Listeners will be notified in a different thread.
116 *
117 * @param eventName the name of the event
118 */
119 void publishEventAsync(String eventName);
120
121 /**
122 * Publishes an event.<p>
123 * Listeners will be notified in a different thread.
124 *
125 * @param eventName the name of the event
126 * @param args event arguments sent to listeners
127 */
128 void publishEventAsync(String eventName, List args);
129
130 /**
131 * Returns whether events will be published by the event bus or not.
132 *
133 * @return true if event publishing is enabled; false otherwise.
134 */
135 boolean isEventPublishingEnabled();
136
137 /**
138 * Sets the enabled state for event publishing.</p>
139 * Events will be automatically discarded when the enabled state is set to false.
140 *
141 * @param enabled the value fot the enabled state.
142 */
143 void setEventPublishingEnabled(boolean enabled);
144 }
|