Jonathan Hart | 6df9017 | 2014-04-03 10:13:11 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.datagrid; |
Pavlin Radoslavov | 1eee2c8 | 2013-10-15 02:30:32 -0700 | [diff] [blame] | 2 | |
| 3 | import java.io.FileNotFoundException; |
| 4 | import java.util.ArrayList; |
| 5 | import java.util.Collection; |
| 6 | import java.util.HashMap; |
| 7 | import java.util.Map; |
| 8 | |
| 9 | import net.floodlightcontroller.core.IFloodlightProviderService; |
| 10 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 11 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 12 | import net.floodlightcontroller.core.module.IFloodlightModule; |
| 13 | import net.floodlightcontroller.core.module.IFloodlightService; |
Pavlin Radoslavov | da7ef61 | 2013-10-30 16:12:14 -0700 | [diff] [blame] | 14 | import net.floodlightcontroller.restserver.IRestApiService; |
Jonathan Hart | 6df9017 | 2014-04-03 10:13:11 -0700 | [diff] [blame] | 15 | import net.onrc.onos.core.datagrid.web.DatagridWebRoutable; |
Pavlin Radoslavov | 1eee2c8 | 2013-10-15 02:30:32 -0700 | [diff] [blame] | 16 | import org.slf4j.Logger; |
| 17 | import org.slf4j.LoggerFactory; |
| 18 | |
| 19 | import com.hazelcast.config.Config; |
| 20 | import com.hazelcast.config.FileSystemXmlConfig; |
| 21 | import com.hazelcast.core.Hazelcast; |
| 22 | import com.hazelcast.core.HazelcastInstance; |
Pavlin Radoslavov | 1eee2c8 | 2013-10-15 02:30:32 -0700 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * A datagrid service that uses Hazelcast as a datagrid. |
| 26 | * The relevant data is stored in the Hazelcast datagrid and shared as |
| 27 | * appropriate in a multi-node cluster. |
| 28 | */ |
| 29 | public class HazelcastDatagrid implements IFloodlightModule, IDatagridService { |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 30 | static final Logger log = LoggerFactory.getLogger(HazelcastDatagrid.class); |
Yuta HIGUCHI | 6dfba39 | 2014-05-28 15:45:44 -0700 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * The name of Hazelcast instance in this JVM. |
| 34 | */ |
| 35 | public static final String ONOS_HAZELCAST_INSTANCE = "ONOS_HazelcastInstance"; |
| 36 | |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 37 | private IRestApiService restApi; |
Pavlin Radoslavov | 1eee2c8 | 2013-10-15 02:30:32 -0700 | [diff] [blame] | 38 | |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 39 | static final String HAZELCAST_CONFIG_FILE = "datagridConfig"; |
Yuta HIGUCHI | 3ebc948 | 2014-05-08 16:28:28 -0700 | [diff] [blame] | 40 | private static final String HAZELCAST_DEFAULT_XML = "conf/hazelcast.default.xml"; |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 41 | private HazelcastInstance hazelcastInstance; |
| 42 | private Config hazelcastConfig; |
Pavlin Radoslavov | 1eee2c8 | 2013-10-15 02:30:32 -0700 | [diff] [blame] | 43 | |
Pavlin Radoslavov | 07af5f2 | 2014-03-21 15:17:58 -0700 | [diff] [blame] | 44 | // |
| 45 | // NOTE: eventChannels is kept thread safe by using explicit "synchronized" |
| 46 | // blocks below. Those are needed to protect the integrity of each entry |
| 47 | // instance, and avoid preemption during channel creation/startup. |
| 48 | // |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 49 | private final Map<String, IEventChannel<?, ?>> eventChannels = new HashMap<>(); |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 50 | |
Pavlin Radoslavov | aaace7f | 2013-10-25 19:42:00 -0700 | [diff] [blame] | 51 | /** |
Yuta HIGUCHI | 3ebc948 | 2014-05-08 16:28:28 -0700 | [diff] [blame] | 52 | * Load the Hazelcast Datagrid configuration file. |
Pavlin Radoslavov | 1eee2c8 | 2013-10-15 02:30:32 -0700 | [diff] [blame] | 53 | * |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 54 | * @param configFilename the configuration filename. |
Pavlin Radoslavov | 1eee2c8 | 2013-10-15 02:30:32 -0700 | [diff] [blame] | 55 | */ |
Yuta HIGUCHI | 3ebc948 | 2014-05-08 16:28:28 -0700 | [diff] [blame] | 56 | public void loadHazelcastConfig(String configFilename) { |
Pavlin Radoslavov | 902fe52 | 2014-03-31 10:11:31 -0700 | [diff] [blame] | 57 | /* |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 58 | System.setProperty("hazelcast.socket.receive.buffer.size", "32"); |
| 59 | System.setProperty("hazelcast.socket.send.buffer.size", "32"); |
| 60 | */ |
| 61 | // System.setProperty("hazelcast.heartbeat.interval.seconds", "100"); |
Yuta HIGUCHI | 67a7a3e | 2014-01-03 14:51:34 -0800 | [diff] [blame] | 62 | |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 63 | // Init from configuration file |
| 64 | try { |
| 65 | hazelcastConfig = new FileSystemXmlConfig(configFilename); |
| 66 | } catch (FileNotFoundException e) { |
| 67 | log.error("Error opening Hazelcast XML configuration. File not found: " + configFilename, e); |
Yuta HIGUCHI | 3ebc948 | 2014-05-08 16:28:28 -0700 | [diff] [blame] | 68 | |
| 69 | // Fallback mechanism to support running unit test without setup. |
| 70 | log.error("Falling back to default Hazelcast XML {}", HAZELCAST_DEFAULT_XML); |
| 71 | try { |
| 72 | hazelcastConfig = new FileSystemXmlConfig(HAZELCAST_DEFAULT_XML); |
| 73 | } catch (FileNotFoundException e2) { |
| 74 | log.error("Error opening fall back Hazelcast XML configuration. " |
| 75 | + "File not found: " + HAZELCAST_DEFAULT_XML, e2); |
| 76 | // XXX probably should throw some exception to kill ONOS instead. |
| 77 | } |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 78 | } |
Yuta HIGUCHI | 6dfba39 | 2014-05-28 15:45:44 -0700 | [diff] [blame] | 79 | |
| 80 | // set the name of Hazelcast instance in this JVM. |
| 81 | hazelcastConfig.setInstanceName(ONOS_HAZELCAST_INSTANCE); |
| 82 | |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 83 | /* |
| 84 | hazelcastConfig.setProperty(GroupProperties.PROP_IO_THREAD_COUNT, "1"); |
| 85 | hazelcastConfig.setProperty(GroupProperties.PROP_OPERATION_THREAD_COUNT, "1"); |
| 86 | hazelcastConfig.setProperty(GroupProperties.PROP_EVENT_THREAD_COUNT, "1"); |
| 87 | */ |
Pavlin Radoslavov | 1eee2c8 | 2013-10-15 02:30:32 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Shutdown the Hazelcast Datagrid operation. |
| 92 | */ |
Yuta HIGUCHI | 67a7a3e | 2014-01-03 14:51:34 -0800 | [diff] [blame] | 93 | @Override |
| 94 | protected void finalize() { |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 95 | close(); |
Pavlin Radoslavov | 1eee2c8 | 2013-10-15 02:30:32 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Shutdown the Hazelcast Datagrid operation. |
| 100 | */ |
| 101 | public void close() { |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 102 | Hazelcast.shutdownAll(); |
Pavlin Radoslavov | 1eee2c8 | 2013-10-15 02:30:32 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Get the collection of offered module services. |
| 107 | * |
| 108 | * @return the collection of offered module services. |
| 109 | */ |
| 110 | @Override |
| 111 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
Yuta HIGUCHI | 67a7a3e | 2014-01-03 14:51:34 -0800 | [diff] [blame] | 112 | Collection<Class<? extends IFloodlightService>> l = |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 113 | new ArrayList<Class<? extends IFloodlightService>>(); |
Pavlin Radoslavov | 1eee2c8 | 2013-10-15 02:30:32 -0700 | [diff] [blame] | 114 | l.add(IDatagridService.class); |
| 115 | return l; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Get the collection of implemented services. |
| 120 | * |
| 121 | * @return the collection of implemented services. |
| 122 | */ |
| 123 | @Override |
Yuta HIGUCHI | 67a7a3e | 2014-01-03 14:51:34 -0800 | [diff] [blame] | 124 | public Map<Class<? extends IFloodlightService>, IFloodlightService> |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 125 | getServiceImpls() { |
Pavlin Radoslavov | 1eee2c8 | 2013-10-15 02:30:32 -0700 | [diff] [blame] | 126 | Map<Class<? extends IFloodlightService>, |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 127 | IFloodlightService> m = |
| 128 | new HashMap<Class<? extends IFloodlightService>, |
| 129 | IFloodlightService>(); |
Pavlin Radoslavov | 1eee2c8 | 2013-10-15 02:30:32 -0700 | [diff] [blame] | 130 | m.put(IDatagridService.class, this); |
| 131 | return m; |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Get the collection of modules this module depends on. |
| 136 | * |
| 137 | * @return the collection of modules this module depends on. |
| 138 | */ |
| 139 | @Override |
Yuta HIGUCHI | 67a7a3e | 2014-01-03 14:51:34 -0800 | [diff] [blame] | 140 | public Collection<Class<? extends IFloodlightService>> |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 141 | getModuleDependencies() { |
| 142 | Collection<Class<? extends IFloodlightService>> l = |
| 143 | new ArrayList<Class<? extends IFloodlightService>>(); |
| 144 | l.add(IFloodlightProviderService.class); |
| 145 | l.add(IRestApiService.class); |
Pavlin Radoslavov | 1eee2c8 | 2013-10-15 02:30:32 -0700 | [diff] [blame] | 146 | return l; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Initialize the module. |
| 151 | * |
| 152 | * @param context the module context to use for the initialization. |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 153 | * @throws FloodlightModuleException on error |
Pavlin Radoslavov | 1eee2c8 | 2013-10-15 02:30:32 -0700 | [diff] [blame] | 154 | */ |
| 155 | @Override |
| 156 | public void init(FloodlightModuleContext context) |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 157 | throws FloodlightModuleException { |
| 158 | restApi = context.getServiceImpl(IRestApiService.class); |
Pavlin Radoslavov | 1eee2c8 | 2013-10-15 02:30:32 -0700 | [diff] [blame] | 159 | |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 160 | // Get the configuration file name and configure the Datagrid |
| 161 | Map<String, String> configMap = context.getConfigParams(this); |
| 162 | String configFilename = configMap.get(HAZELCAST_CONFIG_FILE); |
Yuta HIGUCHI | 3ebc948 | 2014-05-08 16:28:28 -0700 | [diff] [blame] | 163 | this.loadHazelcastConfig(configFilename); |
Pavlin Radoslavov | 1eee2c8 | 2013-10-15 02:30:32 -0700 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Startup module operation. |
| 168 | * |
| 169 | * @param context the module context to use for the startup. |
| 170 | */ |
| 171 | @Override |
| 172 | public void startUp(FloodlightModuleContext context) { |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 173 | hazelcastInstance = Hazelcast.newHazelcastInstance(hazelcastConfig); |
Pavlin Radoslavov | da7ef61 | 2013-10-30 16:12:14 -0700 | [diff] [blame] | 174 | |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 175 | restApi.addRestletRoutable(new DatagridWebRoutable()); |
Pavlin Radoslavov | 1308dc6 | 2013-10-25 15:54:31 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | /** |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 179 | * Create an event channel. |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 180 | * <p/> |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 181 | * If the channel already exists, just return it. |
| 182 | * NOTE: The channel is started automatically. |
| 183 | * |
| 184 | * @param channelName the event channel name. |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 185 | * @param <K> the type of the Key in the Key-Value store. |
| 186 | * @param <V> the type of the Value in the Key-Value store. |
| 187 | * @param typeK the type of the Key in the Key-Value store. |
| 188 | * @param typeV the type of the Value in the Key-Value store. |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 189 | * @return the event channel for the channel name. |
| 190 | */ |
| 191 | @Override |
| 192 | public <K, V> IEventChannel<K, V> createChannel(String channelName, |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 193 | Class<K> typeK, Class<V> typeV) { |
Pavlin Radoslavov | 00fad59 | 2014-03-21 11:32:34 -0700 | [diff] [blame] | 194 | synchronized (eventChannels) { |
| 195 | IEventChannel<K, V> eventChannel = |
Ray Milkey | 9c8a213 | 2014-04-02 15:16:42 -0700 | [diff] [blame] | 196 | createChannelImpl(channelName, typeK, typeV); |
Pavlin Radoslavov | 00fad59 | 2014-03-21 11:32:34 -0700 | [diff] [blame] | 197 | eventChannel.startup(); |
| 198 | return eventChannel; |
Ray Milkey | 9c8a213 | 2014-04-02 15:16:42 -0700 | [diff] [blame] | 199 | } |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | /** |
| 203 | * Create an event channel implementation. |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 204 | * <p/> |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 205 | * If the channel already exists, just return it. |
| 206 | * NOTE: The caller must call IEventChannel.startup() to startup the |
| 207 | * channel operation. |
Pavlin Radoslavov | 00fad59 | 2014-03-21 11:32:34 -0700 | [diff] [blame] | 208 | * NOTE: The caller must own the lock on "eventChannels". |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 209 | * |
| 210 | * @param channelName the event channel name. |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 211 | * @param <K> the type of the Key in the Key-Value store. |
| 212 | * @param <V> the type of the Value in the Key-Value store. |
| 213 | * @param typeK the type of the Key in the Key-Value store. |
| 214 | * @param typeV the type of the Value in the Key-Value store. |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 215 | * @return the event channel for the channel name. |
| 216 | */ |
Pavlin Radoslavov | 00fad59 | 2014-03-21 11:32:34 -0700 | [diff] [blame] | 217 | private <K, V> IEventChannel<K, V> createChannelImpl( |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 218 | String channelName, |
| 219 | Class<K> typeK, Class<V> typeV) { |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 220 | IEventChannel<?, ?> genericEventChannel = |
| 221 | eventChannels.get(channelName); |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 222 | |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 223 | // Add the channel if the first listener |
| 224 | if (genericEventChannel == null) { |
Pavlin Radoslavov | e561a4c | 2014-04-01 14:10:55 -0700 | [diff] [blame] | 225 | IEventChannel<K, V> castedEventChannel = |
Ray Milkey | 9c8a213 | 2014-04-02 15:16:42 -0700 | [diff] [blame] | 226 | new HazelcastEventChannel<K, V>(hazelcastInstance, |
| 227 | channelName, typeK, typeV); |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 228 | eventChannels.put(channelName, castedEventChannel); |
Pavlin Radoslavov | e561a4c | 2014-04-01 14:10:55 -0700 | [diff] [blame] | 229 | return castedEventChannel; |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 230 | } |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 231 | |
Pavlin Radoslavov | e561a4c | 2014-04-01 14:10:55 -0700 | [diff] [blame] | 232 | // |
| 233 | // TODO: Find if we can use Java internal support to check for |
| 234 | // type mismatch. |
| 235 | // |
| 236 | if (!genericEventChannel.verifyKeyValueTypes(typeK, typeV)) { |
| 237 | throw new ClassCastException("Key-value type mismatch for event channel " + channelName); |
| 238 | } |
| 239 | @SuppressWarnings("unchecked") |
| 240 | IEventChannel<K, V> castedEventChannel = |
Ray Milkey | 9c8a213 | 2014-04-02 15:16:42 -0700 | [diff] [blame] | 241 | (IEventChannel<K, V>) genericEventChannel; |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 242 | return castedEventChannel; |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | /** |
| 246 | * Add event channel listener. |
Ray Milkey | 9c8a213 | 2014-04-02 15:16:42 -0700 | [diff] [blame] | 247 | * <p/> |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 248 | * NOTE: The channel is started automatically right after the listener |
| 249 | * is added. |
| 250 | * |
| 251 | * @param channelName the event channel name. |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 252 | * @param listener the listener to add. |
| 253 | * @param <K> the type of the Key in the Key-Value store. |
| 254 | * @param <V> the type of the Value in the Key-Value store. |
| 255 | * @param typeK the type of the Key in the Key-Value store. |
| 256 | * @param typeV the type of the Value in the Key-Value store. |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 257 | * @return the event channel for the channel name. |
| 258 | */ |
| 259 | @Override |
| 260 | public <K, V> IEventChannel<K, V> addListener(String channelName, |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 261 | IEventChannelListener<K, V> listener, |
| 262 | Class<K> typeK, Class<V> typeV) { |
Pavlin Radoslavov | 00fad59 | 2014-03-21 11:32:34 -0700 | [diff] [blame] | 263 | synchronized (eventChannels) { |
| 264 | IEventChannel<K, V> eventChannel = |
Ray Milkey | 9c8a213 | 2014-04-02 15:16:42 -0700 | [diff] [blame] | 265 | createChannelImpl(channelName, typeK, typeV); |
Pavlin Radoslavov | 00fad59 | 2014-03-21 11:32:34 -0700 | [diff] [blame] | 266 | eventChannel.addListener(listener); |
| 267 | eventChannel.startup(); |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 268 | |
Pavlin Radoslavov | 00fad59 | 2014-03-21 11:32:34 -0700 | [diff] [blame] | 269 | return eventChannel; |
Ray Milkey | 9c8a213 | 2014-04-02 15:16:42 -0700 | [diff] [blame] | 270 | } |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | /** |
| 274 | * Remove event channel listener. |
| 275 | * |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 276 | * @param <K> the type of the Key in the Key-Value store. |
| 277 | * @param <V> the type of the Value in the Key-Value store. |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 278 | * @param channelName the event channel name. |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 279 | * @param listener the listener to remove. |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 280 | */ |
| 281 | @Override |
| 282 | public <K, V> void removeListener(String channelName, |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 283 | IEventChannelListener<K, V> listener) { |
Ray Milkey | 9c8a213 | 2014-04-02 15:16:42 -0700 | [diff] [blame] | 284 | synchronized (eventChannels) { |
Pavlin Radoslavov | 00fad59 | 2014-03-21 11:32:34 -0700 | [diff] [blame] | 285 | IEventChannel<?, ?> genericEventChannel = |
Ray Milkey | 9c8a213 | 2014-04-02 15:16:42 -0700 | [diff] [blame] | 286 | eventChannels.get(channelName); |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 287 | |
Pavlin Radoslavov | 00fad59 | 2014-03-21 11:32:34 -0700 | [diff] [blame] | 288 | if (genericEventChannel != null) { |
| 289 | // |
| 290 | // TODO: Find if we can use Java internal support to check for |
| 291 | // type mismatch. |
| 292 | // NOTE: Using "ClassCastException" exception below doesn't |
| 293 | // work. |
| 294 | // |
Pavlin Radoslavov | e561a4c | 2014-04-01 14:10:55 -0700 | [diff] [blame] | 295 | @SuppressWarnings("unchecked") |
Pavlin Radoslavov | 00fad59 | 2014-03-21 11:32:34 -0700 | [diff] [blame] | 296 | IEventChannel<K, V> castedEventChannel = |
Ray Milkey | 9c8a213 | 2014-04-02 15:16:42 -0700 | [diff] [blame] | 297 | (IEventChannel<K, V>) genericEventChannel; |
Pavlin Radoslavov | 00fad59 | 2014-03-21 11:32:34 -0700 | [diff] [blame] | 298 | castedEventChannel.removeListener(listener); |
| 299 | } |
Ray Milkey | 0ab2d8a | 2014-03-20 14:30:10 -0700 | [diff] [blame] | 300 | } |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 301 | } |
Pavlin Radoslavov | 1eee2c8 | 2013-10-15 02:30:32 -0700 | [diff] [blame] | 302 | } |