Jonathan Hart | 6df9017 | 2014-04-03 10:13:11 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.datagrid; |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 2 | |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 3 | import java.util.Collection; |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 4 | import java.util.LinkedList; |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 5 | import java.util.Set; |
Pavlin Radoslavov | 1c8d809 | 2014-02-14 15:47:24 -0800 | [diff] [blame] | 6 | import java.util.concurrent.CopyOnWriteArrayList; |
Pavlin Radoslavov | bcf1433 | 2014-03-27 18:15:30 -0700 | [diff] [blame] | 7 | import java.util.concurrent.TimeUnit; |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 8 | |
Jonathan Hart | a99ec67 | 2014-04-03 11:30:34 -0700 | [diff] [blame] | 9 | import net.onrc.onos.core.util.serializers.KryoFactory; |
| 10 | |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 11 | import com.esotericsoftware.kryo.Kryo; |
| 12 | import com.esotericsoftware.kryo.io.Input; |
| 13 | import com.esotericsoftware.kryo.io.Output; |
| 14 | import com.hazelcast.core.EntryEvent; |
| 15 | import com.hazelcast.core.EntryListener; |
| 16 | import com.hazelcast.core.HazelcastInstance; |
| 17 | import com.hazelcast.core.IMap; |
| 18 | |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 19 | /** |
| 20 | * A datagrid event channel that uses Hazelcast as a datagrid. |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 21 | * |
| 22 | * @param <K> The class type of the key. |
| 23 | * @param <V> The class type of the value. |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 24 | */ |
| 25 | public class HazelcastEventChannel<K, V> implements IEventChannel<K, V> { |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 26 | private final HazelcastInstance hazelcastInstance; // The Hazelcast instance |
| 27 | private final String channelName; // The event channel name |
Pavlin Radoslavov | e561a4c | 2014-04-01 14:10:55 -0700 | [diff] [blame] | 28 | private final Class<K> typeK; // The class type of the key |
| 29 | private final Class<V> typeV; // The class type of the value |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 30 | private IMap<K, byte[]> channelMap; // The Hazelcast channel map |
Pavlin Radoslavov | 1c8d809 | 2014-02-14 15:47:24 -0800 | [diff] [blame] | 31 | // The channel listeners |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 32 | private final CopyOnWriteArrayList<IEventChannelListener<K, V>> listeners = |
| 33 | new CopyOnWriteArrayList<>(); |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 34 | |
| 35 | // The map entry listener |
Pavlin Radoslavov | e561a4c | 2014-04-01 14:10:55 -0700 | [diff] [blame] | 36 | private final EntryListener<K, byte[]> mapEntryListener = new MapEntryListener(); |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 37 | private String mapListenerId; // The map listener ID |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 38 | |
| 39 | // TODO: We should use a single global KryoFactory instance |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 40 | private final KryoFactory kryoFactory = new KryoFactory(); |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 41 | |
| 42 | // Maximum serialized event size |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 43 | private static final int MAX_BUFFER_SIZE = 64 * 1024; |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 44 | |
| 45 | /** |
| 46 | * Constructor for a given event channel name. |
| 47 | * |
Ray Milkey | 9c8a213 | 2014-04-02 15:16:42 -0700 | [diff] [blame] | 48 | * @param newHazelcastInstance the Hazelcast instance to use. |
| 49 | * @param newChannelName the event channel name. |
| 50 | * @param newTypeK the type of the Key in the Key-Value store. |
| 51 | * @param newTypeV the type of the Value in the Key-Value store. |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 52 | */ |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 53 | public HazelcastEventChannel(HazelcastInstance newHazelcastInstance, |
| 54 | String newChannelName, Class<K> newTypeK, |
| 55 | Class<V> newTypeV) { |
| 56 | hazelcastInstance = newHazelcastInstance; |
| 57 | channelName = newChannelName; |
| 58 | typeK = newTypeK; |
| 59 | typeV = newTypeV; |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Verify the key and value types of a channel. |
| 64 | * |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 65 | * @param typeKToVerify the type of the key to verify. |
| 66 | * @param typeVToVerify the type of the value to verify. |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 67 | * @return true if the key and value types of the channel match, |
| 68 | * otherwise false. |
| 69 | */ |
| 70 | @Override |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 71 | public boolean verifyKeyValueTypes(Class typeKToVerify, |
| 72 | Class typeVToVerify) { |
Ray Milkey | 7301965 | 2014-03-24 11:12:44 -0700 | [diff] [blame] | 73 | return (typeK.equals(typeKToVerify)) && (typeV.equals(typeVToVerify)); |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Cleanup and destroy the channel. |
| 78 | */ |
| 79 | @Override |
| 80 | protected void finalize() { |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 81 | shutdown(); |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Startup the channel operation. |
| 86 | */ |
| 87 | @Override |
| 88 | public void startup() { |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 89 | if (channelMap == null) { |
| 90 | channelMap = hazelcastInstance.getMap(channelName); |
| 91 | mapListenerId = channelMap.addEntryListener(mapEntryListener, |
| 92 | true); |
| 93 | } |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Shutdown the channel operation. |
| 98 | */ |
| 99 | @Override |
| 100 | public void shutdown() { |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 101 | if (channelMap != null) { |
| 102 | channelMap.removeEntryListener(mapListenerId); |
| 103 | channelMap = null; |
| 104 | mapListenerId = null; |
| 105 | } |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Add event channel listener. |
| 110 | * |
| 111 | * @param listener the listener to add. |
| 112 | */ |
| 113 | @Override |
| 114 | public void addListener(IEventChannelListener<K, V> listener) { |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 115 | if (listeners.contains(listener)) { |
| 116 | return; // Nothing to do: already a listener |
| 117 | } |
| 118 | listeners.add(listener); |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Remove event channel listener. |
| 123 | * |
| 124 | * @param listener the listener to remove. |
| 125 | */ |
| 126 | @Override |
| 127 | public void removeListener(IEventChannelListener<K, V> listener) { |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 128 | listeners.remove(listener); |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Add an entry to the channel. |
| 133 | * |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 134 | * @param key the key of the entry to add. |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 135 | * @param value the value of the entry to add. |
| 136 | */ |
| 137 | @Override |
| 138 | public void addEntry(K key, V value) { |
Pavlin Radoslavov | bcf1433 | 2014-03-27 18:15:30 -0700 | [diff] [blame] | 139 | byte[] valueBytes = serializeValue(value); |
| 140 | // |
| 141 | // Put the entry in the map: |
| 142 | // - Key : Type <K> |
| 143 | // - Value : Serialized Value (byte[]) |
| 144 | // |
| 145 | channelMap.putAsync(key, valueBytes); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Add a transient entry to the channel. |
Ray Milkey | 9c8a213 | 2014-04-02 15:16:42 -0700 | [diff] [blame] | 150 | * <p/> |
Pavlin Radoslavov | bcf1433 | 2014-03-27 18:15:30 -0700 | [diff] [blame] | 151 | * The added entry is transient and will automatically timeout after 1ms. |
| 152 | * |
| 153 | * @param key the key of the entry to add. |
| 154 | * @param value the value of the entry to add. |
| 155 | */ |
| 156 | @Override |
| 157 | public void addTransientEntry(K key, V value) { |
| 158 | byte[] valueBytes = serializeValue(value); |
| 159 | // |
| 160 | // Put the entry in the map: |
| 161 | // - Key : Type <K> |
| 162 | // - Value : Serialized Value (byte[]) |
| 163 | // - Timeout: 1ms |
| 164 | // |
| 165 | channelMap.putAsync(key, valueBytes, 1L, TimeUnit.MILLISECONDS); |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Serialize the value. |
| 170 | * |
| 171 | * @param value the value to serialize. |
| 172 | * @return the serialized value. |
| 173 | */ |
| 174 | private byte[] serializeValue(V value) { |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 175 | // |
| 176 | // Encode the value |
| 177 | // |
| 178 | byte[] buffer = new byte[MAX_BUFFER_SIZE]; |
| 179 | Kryo kryo = kryoFactory.newKryo(); |
| 180 | Output output = new Output(buffer, -1); |
| 181 | kryo.writeObject(output, value); |
| 182 | byte[] valueBytes = output.toBytes(); |
| 183 | kryoFactory.deleteKryo(kryo); |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 184 | |
Pavlin Radoslavov | bcf1433 | 2014-03-27 18:15:30 -0700 | [diff] [blame] | 185 | return valueBytes; |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | /** |
| 189 | * Remove an entry from the channel. |
| 190 | * |
| 191 | * @param key the key of the entry to remove. |
| 192 | */ |
| 193 | @Override |
| 194 | public void removeEntry(K key) { |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 195 | // |
| 196 | // Remove the entry: |
| 197 | // - Key : Type <K> |
| 198 | // - Value : Serialized Value (byte[]) |
| 199 | // |
| 200 | channelMap.removeAsync(key); |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | /** |
| 204 | * Update an entry in the channel. |
| 205 | * |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 206 | * @param key the key of the entry to update. |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 207 | * @param value the value of the entry to update. |
| 208 | */ |
| 209 | @Override |
| 210 | public void updateEntry(K key, V value) { |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 211 | // NOTE: Adding an entry with an existing key automatically updates it |
| 212 | addEntry(key, value); |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | /** |
| 216 | * Get an entry from the channel. |
| 217 | * |
| 218 | * @param key the key of the entry to get. |
| 219 | * @return the entry if found, otherwise null. |
| 220 | */ |
| 221 | @Override |
| 222 | @Deprecated |
| 223 | public V getEntry(K key) { |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 224 | byte[] valueBytes = channelMap.get(key); |
| 225 | if (valueBytes == null) { |
| 226 | return null; |
| 227 | } |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 228 | |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 229 | Kryo kryo = kryoFactory.newKryo(); |
| 230 | // |
| 231 | // Decode the value |
| 232 | // |
| 233 | Input input = new Input(valueBytes); |
| 234 | V value = (V) kryo.readObject(input, typeV); |
| 235 | kryoFactory.deleteKryo(kryo); |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 236 | |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 237 | return value; |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Get all entries in the channel. |
| 242 | * |
| 243 | * @return all entries that are currently in the channel. |
| 244 | */ |
| 245 | @Override |
| 246 | @Deprecated |
| 247 | public Collection<V> getAllEntries() { |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 248 | Collection<V> allEntries = new LinkedList<V>(); |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 249 | |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 250 | if (channelMap == null) { |
| 251 | return allEntries; // Nothing found |
| 252 | } |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 253 | |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 254 | // |
| 255 | // Get all entries |
| 256 | // |
| 257 | Collection<byte[]> values = channelMap.values(); |
| 258 | Kryo kryo = kryoFactory.newKryo(); |
| 259 | for (byte[] valueBytes : values) { |
| 260 | // |
| 261 | // Decode the value |
| 262 | // |
| 263 | Input input = new Input(valueBytes); |
| 264 | V value = (V) kryo.readObject(input, typeV); |
| 265 | allEntries.add(value); |
| 266 | } |
| 267 | kryoFactory.deleteKryo(kryo); |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 268 | |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 269 | return allEntries; |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | /** |
| 273 | * Remove all entries in the channel. |
| 274 | */ |
| 275 | @Override |
| 276 | @Deprecated |
| 277 | public void removeAllEntries() { |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 278 | // |
| 279 | // Remove all entries |
| 280 | // |
| 281 | // NOTE: We remove the entries one-by-one so the per-entry |
| 282 | // notifications will be delivered. |
| 283 | // |
| 284 | // channelMap.clear(); |
| 285 | Set<K> keySet = channelMap.keySet(); |
| 286 | for (K key : keySet) { |
| 287 | channelMap.removeAsync(key); |
| 288 | } |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | /** |
| 292 | * Class for receiving event notifications for the channel. |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 293 | * <p/> |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 294 | * The datagrid map is: |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 295 | * - Key: Type K |
| 296 | * - Value: Serialized V (byte[]) |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 297 | */ |
Pavlin Radoslavov | e561a4c | 2014-04-01 14:10:55 -0700 | [diff] [blame] | 298 | private class MapEntryListener implements EntryListener<K, byte[]> { |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 299 | /** |
| 300 | * Receive a notification that an entry is added. |
| 301 | * |
| 302 | * @param event the notification event for the entry. |
| 303 | */ |
| 304 | @Override |
| 305 | public void entryAdded(EntryEvent<K, byte[]> event) { |
| 306 | // |
| 307 | // Decode the value |
| 308 | // |
| 309 | byte[] valueBytes = event.getValue(); |
| 310 | Kryo kryo = kryoFactory.newKryo(); |
| 311 | Input input = new Input(valueBytes); |
| 312 | V value = (V) kryo.readObject(input, typeV); |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 313 | |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 314 | // |
| 315 | // Deliver the notification |
| 316 | // |
| 317 | int index = 0; |
Pavlin Radoslavov | e561a4c | 2014-04-01 14:10:55 -0700 | [diff] [blame] | 318 | for (IEventChannelListener<K, V> listener : listeners) { |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 319 | V copyValue = value; |
| 320 | if (index++ > 0) { |
| 321 | // Each listener should get a deep copy of the value |
| 322 | copyValue = kryo.copy(value); |
| 323 | } |
| 324 | listener.entryAdded(copyValue); |
| 325 | } |
| 326 | kryoFactory.deleteKryo(kryo); |
| 327 | } |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 328 | |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 329 | /** |
| 330 | * Receive a notification that an entry is removed. |
| 331 | * |
| 332 | * @param event the notification event for the entry. |
| 333 | */ |
| 334 | @Override |
| 335 | public void entryRemoved(EntryEvent<K, byte[]> event) { |
| 336 | // |
| 337 | // Decode the value |
| 338 | // |
| 339 | byte[] valueBytes = event.getValue(); |
| 340 | Kryo kryo = kryoFactory.newKryo(); |
| 341 | Input input = new Input(valueBytes); |
| 342 | V value = (V) kryo.readObject(input, typeV); |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 343 | |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 344 | // |
| 345 | // Deliver the notification |
| 346 | // |
| 347 | int index = 0; |
Pavlin Radoslavov | e561a4c | 2014-04-01 14:10:55 -0700 | [diff] [blame] | 348 | for (IEventChannelListener<K, V> listener : listeners) { |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 349 | V copyValue = value; |
| 350 | if (index++ > 0) { |
| 351 | // Each listener should get a deep copy of the value |
| 352 | copyValue = kryo.copy(value); |
| 353 | } |
| 354 | listener.entryRemoved(copyValue); |
| 355 | } |
| 356 | kryoFactory.deleteKryo(kryo); |
| 357 | } |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 358 | |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 359 | /** |
| 360 | * Receive a notification that an entry is updated. |
| 361 | * |
| 362 | * @param event the notification event for the entry. |
| 363 | */ |
| 364 | @Override |
| 365 | public void entryUpdated(EntryEvent<K, byte[]> event) { |
| 366 | // |
| 367 | // Decode the value |
| 368 | // |
| 369 | byte[] valueBytes = event.getValue(); |
| 370 | Kryo kryo = kryoFactory.newKryo(); |
| 371 | Input input = new Input(valueBytes); |
| 372 | V value = (V) kryo.readObject(input, typeV); |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 373 | |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 374 | // |
| 375 | // Deliver the notification |
| 376 | // |
| 377 | int index = 0; |
Pavlin Radoslavov | e561a4c | 2014-04-01 14:10:55 -0700 | [diff] [blame] | 378 | for (IEventChannelListener<K, V> listener : listeners) { |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 379 | V copyValue = value; |
| 380 | if (index++ > 0) { |
| 381 | // Each listener should get a deep copy of the value |
| 382 | copyValue = kryo.copy(value); |
| 383 | } |
| 384 | listener.entryUpdated(copyValue); |
| 385 | } |
| 386 | kryoFactory.deleteKryo(kryo); |
| 387 | } |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 388 | |
Ray Milkey | e88b2b8 | 2014-03-21 11:40:04 -0700 | [diff] [blame] | 389 | /** |
| 390 | * Receive a notification that an entry is evicted. |
| 391 | * |
| 392 | * @param event the notification event for the entry. |
| 393 | */ |
| 394 | @Override |
| 395 | public void entryEvicted(EntryEvent<K, byte[]> event) { |
| 396 | // NOTE: We don't use eviction for this map |
| 397 | } |
Pavlin Radoslavov | 7940b65 | 2014-02-13 19:42:05 -0800 | [diff] [blame] | 398 | } |
| 399 | } |