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