Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Open Networking Laboratory |
| 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.store.hz; |
Yuta HIGUCHI | a97b5e4 | 2014-10-13 14:04:58 -0700 | [diff] [blame] | 17 | |
| 18 | import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | |
| 20 | import java.util.ArrayList; |
| 21 | import java.util.Collection; |
| 22 | import java.util.Collections; |
| 23 | import java.util.HashMap; |
| 24 | import java.util.HashSet; |
| 25 | import java.util.IdentityHashMap; |
| 26 | import java.util.Map; |
| 27 | import java.util.Set; |
| 28 | import java.util.concurrent.Future; |
| 29 | import java.util.concurrent.TimeUnit; |
| 30 | |
| 31 | import org.apache.commons.lang3.tuple.Pair; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 32 | import org.onosproject.store.serializers.StoreSerializer; |
Yuta HIGUCHI | a97b5e4 | 2014-10-13 14:04:58 -0700 | [diff] [blame] | 33 | |
| 34 | import com.google.common.base.Function; |
| 35 | import com.google.common.util.concurrent.Futures; |
| 36 | import com.hazelcast.core.EntryEvent; |
| 37 | import com.hazelcast.core.EntryListener; |
| 38 | import com.hazelcast.core.EntryView; |
| 39 | import com.hazelcast.core.ExecutionCallback; |
| 40 | import com.hazelcast.core.IMap; |
| 41 | import com.hazelcast.core.MapEvent; |
| 42 | import com.hazelcast.map.EntryProcessor; |
| 43 | import com.hazelcast.map.MapInterceptor; |
| 44 | import com.hazelcast.mapreduce.JobTracker; |
| 45 | import com.hazelcast.mapreduce.aggregation.Aggregation; |
| 46 | import com.hazelcast.mapreduce.aggregation.Supplier; |
| 47 | import com.hazelcast.monitor.LocalMapStats; |
| 48 | import com.hazelcast.query.Predicate; |
| 49 | |
Yuta HIGUCHI | a97b5e4 | 2014-10-13 14:04:58 -0700 | [diff] [blame] | 50 | /** |
Thomas Vachuska | 4b42077 | 2014-10-30 16:46:17 -0700 | [diff] [blame] | 51 | * Wrapper around IMap<byte[], byte[]> which serializes/deserializes |
| 52 | * key and value using StoreSerializer. |
Yuta HIGUCHI | a97b5e4 | 2014-10-13 14:04:58 -0700 | [diff] [blame] | 53 | * |
| 54 | * @param <K> key type |
| 55 | * @param <V> value type |
| 56 | */ |
| 57 | public class SMap<K, V> implements IMap<K, V> { |
| 58 | |
| 59 | private final IMap<byte[], byte[]> m; |
| 60 | private final StoreSerializer serializer; |
| 61 | |
| 62 | /** |
| 63 | * Creates a SMap instance. |
| 64 | * |
| 65 | * @param baseMap base IMap to use |
| 66 | * @param serializer serializer to use for both key and value |
| 67 | */ |
| 68 | public SMap(IMap<byte[], byte[]> baseMap, StoreSerializer serializer) { |
| 69 | this.m = checkNotNull(baseMap); |
| 70 | this.serializer = checkNotNull(serializer); |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public int size() { |
| 75 | return m.size(); |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public boolean isEmpty() { |
| 80 | return m.isEmpty(); |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public void putAll(Map<? extends K, ? extends V> map) { |
| 85 | Map<byte[], byte[]> sm = new IdentityHashMap<>(map.size()); |
| 86 | for (java.util.Map.Entry<? extends K, ? extends V> e : map.entrySet()) { |
| 87 | sm.put(serializeKey(e.getKey()), serializeVal(e.getValue())); |
| 88 | } |
| 89 | m.putAll(sm); |
| 90 | } |
| 91 | |
| 92 | @Deprecated |
| 93 | @Override |
| 94 | public Object getId() { |
| 95 | return m.getId(); |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public String getPartitionKey() { |
| 100 | return m.getPartitionKey(); |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public String getName() { |
| 105 | return m.getName(); |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public String getServiceName() { |
| 110 | return m.getServiceName(); |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public void destroy() { |
| 115 | m.destroy(); |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public boolean containsKey(Object key) { |
| 120 | return m.containsKey(serializeKey(key)); |
| 121 | } |
| 122 | |
| 123 | @Override |
| 124 | public boolean containsValue(Object value) { |
| 125 | return m.containsValue(serializeVal(value)); |
| 126 | } |
| 127 | |
| 128 | @Override |
| 129 | public V get(Object key) { |
| 130 | return deserializeVal(m.get(serializeKey(key))); |
| 131 | } |
| 132 | |
| 133 | @Override |
| 134 | public V put(K key, V value) { |
| 135 | return deserializeVal(m.put(serializeKey(key), serializeVal(value))); |
| 136 | } |
| 137 | |
| 138 | @Override |
| 139 | public V remove(Object key) { |
| 140 | return deserializeVal(m.remove(serializeKey(key))); |
| 141 | } |
| 142 | |
| 143 | @Override |
| 144 | public boolean remove(Object key, Object value) { |
| 145 | return m.remove(serializeKey(key), serializeVal(value)); |
| 146 | } |
| 147 | |
| 148 | @Override |
| 149 | public void delete(Object key) { |
| 150 | m.delete(serializeKey(key)); |
| 151 | } |
| 152 | |
| 153 | @Override |
| 154 | public void flush() { |
| 155 | m.flush(); |
| 156 | } |
| 157 | |
| 158 | @Override |
| 159 | public Map<K, V> getAll(Set<K> keys) { |
| 160 | Set<byte[]> sk = serializeKeySet(keys); |
| 161 | Map<byte[], byte[]> bm = m.getAll(sk); |
| 162 | Map<K, V> dsm = new HashMap<>(bm.size()); |
| 163 | for (java.util.Map.Entry<byte[], byte[]> e : bm.entrySet()) { |
| 164 | dsm.put(deserializeKey(e.getKey()), deserializeVal(e.getValue())); |
| 165 | } |
| 166 | return dsm; |
| 167 | } |
| 168 | |
| 169 | @Override |
| 170 | public void loadAll(boolean replaceExistingValues) { |
| 171 | m.loadAll(replaceExistingValues); |
| 172 | } |
| 173 | |
| 174 | @Override |
| 175 | public void loadAll(Set<K> keys, boolean replaceExistingValues) { |
| 176 | Set<byte[]> sk = serializeKeySet(keys); |
| 177 | m.loadAll(sk, replaceExistingValues); |
| 178 | } |
| 179 | |
| 180 | @Override |
| 181 | public void clear() { |
| 182 | m.clear(); |
| 183 | } |
| 184 | |
| 185 | @Override |
| 186 | public Future<V> getAsync(K key) { |
| 187 | Future<byte[]> f = m.getAsync(serializeKey(key)); |
| 188 | return Futures.lazyTransform(f, new DeserializeVal()); |
| 189 | } |
| 190 | |
| 191 | @Override |
| 192 | public Future<V> putAsync(K key, V value) { |
| 193 | Future<byte[]> f = m.putAsync(serializeKey(key), serializeVal(value)); |
| 194 | return Futures.lazyTransform(f, new DeserializeVal()); |
| 195 | } |
| 196 | |
| 197 | @Override |
| 198 | public Future<V> putAsync(K key, V value, long ttl, TimeUnit timeunit) { |
| 199 | Future<byte[]> f = m.putAsync(serializeKey(key), serializeVal(value), ttl, timeunit); |
| 200 | return Futures.lazyTransform(f, new DeserializeVal()); |
| 201 | } |
| 202 | |
| 203 | @Override |
| 204 | public Future<V> removeAsync(K key) { |
| 205 | Future<byte[]> f = m.removeAsync(serializeKey(key)); |
| 206 | return Futures.lazyTransform(f, new DeserializeVal()); |
| 207 | } |
| 208 | |
| 209 | @Override |
| 210 | public boolean tryRemove(K key, long timeout, TimeUnit timeunit) { |
| 211 | return m.tryRemove(serializeKey(key), timeout, timeunit); |
| 212 | } |
| 213 | |
| 214 | @Override |
| 215 | public boolean tryPut(K key, V value, long timeout, TimeUnit timeunit) { |
| 216 | return m.tryPut(serializeKey(key), serializeVal(value), timeout, timeunit); |
| 217 | } |
| 218 | |
| 219 | @Override |
| 220 | public V put(K key, V value, long ttl, TimeUnit timeunit) { |
| 221 | return deserializeVal(m.put(serializeKey(key), serializeVal(value), ttl, timeunit)); |
| 222 | } |
| 223 | |
| 224 | @Override |
| 225 | public void putTransient(K key, V value, long ttl, TimeUnit timeunit) { |
| 226 | m.putTransient(serializeKey(key), serializeVal(value), ttl, timeunit); |
| 227 | } |
| 228 | |
| 229 | @Override |
| 230 | public V putIfAbsent(K key, V value) { |
| 231 | return deserializeVal(m.putIfAbsent(serializeKey(key), serializeVal(value))); |
| 232 | } |
| 233 | |
| 234 | @Override |
| 235 | public V putIfAbsent(K key, V value, long ttl, TimeUnit timeunit) { |
| 236 | return deserializeVal(m.putIfAbsent(serializeKey(key), serializeVal(value), ttl, timeunit)); |
| 237 | } |
| 238 | |
| 239 | @Override |
| 240 | public boolean replace(K key, V oldValue, V newValue) { |
| 241 | return m.replace(serializeKey(key), serializeVal(oldValue), serializeVal(newValue)); |
| 242 | } |
| 243 | |
| 244 | @Override |
| 245 | public V replace(K key, V value) { |
| 246 | return deserializeVal(m.replace(serializeKey(key), serializeVal(value))); |
| 247 | } |
| 248 | |
| 249 | @Override |
| 250 | public void set(K key, V value) { |
| 251 | m.set(serializeKey(key), serializeVal(value)); |
| 252 | } |
| 253 | |
| 254 | @Override |
| 255 | public void set(K key, V value, long ttl, TimeUnit timeunit) { |
| 256 | m.set(serializeKey(key), serializeVal(value), ttl, timeunit); |
| 257 | } |
| 258 | |
| 259 | @Override |
| 260 | public void lock(K key) { |
| 261 | m.lock(serializeKey(key)); |
| 262 | } |
| 263 | |
| 264 | @Override |
| 265 | public void lock(K key, long leaseTime, TimeUnit timeUnit) { |
| 266 | m.lock(serializeKey(key), leaseTime, timeUnit); |
| 267 | } |
| 268 | |
| 269 | @Override |
| 270 | public boolean isLocked(K key) { |
| 271 | return m.isLocked(serializeKey(key)); |
| 272 | } |
| 273 | |
| 274 | @Override |
| 275 | public boolean tryLock(K key) { |
| 276 | return m.tryLock(serializeKey(key)); |
| 277 | } |
| 278 | |
| 279 | @Override |
| 280 | public boolean tryLock(K key, long time, TimeUnit timeunit) |
| 281 | throws InterruptedException { |
| 282 | return m.tryLock(serializeKey(key), time, timeunit); |
| 283 | } |
| 284 | |
| 285 | @Override |
| 286 | public void unlock(K key) { |
| 287 | m.unlock(serializeKey(key)); |
| 288 | } |
| 289 | |
| 290 | @Override |
| 291 | public void forceUnlock(K key) { |
| 292 | m.forceUnlock(serializeKey(key)); |
| 293 | } |
| 294 | |
| 295 | @Override |
| 296 | public String addLocalEntryListener(EntryListener<K, V> listener) { |
| 297 | return m.addLocalEntryListener(new BaseEntryListener(listener)); |
| 298 | } |
| 299 | |
Yuta HIGUCHI | 24d483d | 2014-12-17 10:36:12 -0800 | [diff] [blame] | 300 | /** |
| 301 | * {@inheritDoc} |
| 302 | * |
| 303 | * @deprecated not implemented yet |
| 304 | * @throws UnsupportedOperationException not implemented yet |
| 305 | */ |
| 306 | @Deprecated |
Yuta HIGUCHI | a97b5e4 | 2014-10-13 14:04:58 -0700 | [diff] [blame] | 307 | @Override |
| 308 | public String addLocalEntryListener(EntryListener<K, V> listener, |
| 309 | Predicate<K, V> predicate, boolean includeValue) { |
| 310 | throw new UnsupportedOperationException(); |
| 311 | } |
| 312 | |
Yuta HIGUCHI | 24d483d | 2014-12-17 10:36:12 -0800 | [diff] [blame] | 313 | /** |
| 314 | * {@inheritDoc} |
| 315 | * |
| 316 | * @deprecated not implemented yet |
| 317 | * @throws UnsupportedOperationException not implemented yet |
| 318 | */ |
| 319 | @Deprecated |
Yuta HIGUCHI | a97b5e4 | 2014-10-13 14:04:58 -0700 | [diff] [blame] | 320 | @Override |
| 321 | public String addLocalEntryListener(EntryListener<K, V> listener, |
| 322 | Predicate<K, V> predicate, K key, boolean includeValue) { |
| 323 | throw new UnsupportedOperationException(); |
| 324 | } |
| 325 | |
Yuta HIGUCHI | 24d483d | 2014-12-17 10:36:12 -0800 | [diff] [blame] | 326 | /** |
| 327 | * {@inheritDoc} |
| 328 | * |
| 329 | * @deprecated not implemented yet |
| 330 | * @throws UnsupportedOperationException not implemented yet |
| 331 | */ |
| 332 | @Deprecated |
Yuta HIGUCHI | a97b5e4 | 2014-10-13 14:04:58 -0700 | [diff] [blame] | 333 | @Override |
| 334 | public String addInterceptor(MapInterceptor interceptor) { |
| 335 | throw new UnsupportedOperationException(); |
| 336 | } |
| 337 | |
| 338 | @Override |
| 339 | public void removeInterceptor(String id) { |
| 340 | m.removeInterceptor(id); |
| 341 | } |
| 342 | |
| 343 | @Override |
| 344 | public String addEntryListener(EntryListener<K, V> listener, |
| 345 | boolean includeValue) { |
| 346 | return m.addEntryListener(new BaseEntryListener(listener), includeValue); |
| 347 | } |
| 348 | |
| 349 | @Override |
| 350 | public boolean removeEntryListener(String id) { |
| 351 | return m.removeEntryListener(id); |
| 352 | } |
| 353 | |
| 354 | @Override |
| 355 | public String addEntryListener(EntryListener<K, V> listener, K key, |
| 356 | boolean includeValue) { |
| 357 | return m.addEntryListener(new BaseEntryListener(listener), |
| 358 | serializeKey(key), includeValue); |
| 359 | } |
| 360 | |
Yuta HIGUCHI | 24d483d | 2014-12-17 10:36:12 -0800 | [diff] [blame] | 361 | /** |
| 362 | * {@inheritDoc} |
| 363 | * |
| 364 | * @deprecated not implemented yet |
| 365 | * @throws UnsupportedOperationException not implemented yet |
| 366 | */ |
| 367 | @Deprecated |
Yuta HIGUCHI | a97b5e4 | 2014-10-13 14:04:58 -0700 | [diff] [blame] | 368 | @Override |
| 369 | public String addEntryListener(EntryListener<K, V> listener, |
| 370 | Predicate<K, V> predicate, boolean includeValue) { |
| 371 | throw new UnsupportedOperationException(); |
| 372 | } |
| 373 | |
Yuta HIGUCHI | 24d483d | 2014-12-17 10:36:12 -0800 | [diff] [blame] | 374 | /** |
| 375 | * {@inheritDoc} |
| 376 | * |
| 377 | * @deprecated not implemented yet |
| 378 | * @throws UnsupportedOperationException not implemented yet |
| 379 | */ |
| 380 | @Deprecated |
Yuta HIGUCHI | a97b5e4 | 2014-10-13 14:04:58 -0700 | [diff] [blame] | 381 | @Override |
| 382 | public String addEntryListener(EntryListener<K, V> listener, |
| 383 | Predicate<K, V> predicate, K key, boolean includeValue) { |
| 384 | throw new UnsupportedOperationException(); |
| 385 | } |
| 386 | |
Yuta HIGUCHI | 24d483d | 2014-12-17 10:36:12 -0800 | [diff] [blame] | 387 | /** |
| 388 | * {@inheritDoc} |
| 389 | * |
| 390 | * @deprecated not implemented yet |
| 391 | * @throws UnsupportedOperationException not implemented yet |
| 392 | */ |
| 393 | @Deprecated |
Yuta HIGUCHI | a97b5e4 | 2014-10-13 14:04:58 -0700 | [diff] [blame] | 394 | @Override |
| 395 | public EntryView<K, V> getEntryView(K key) { |
| 396 | throw new UnsupportedOperationException(); |
| 397 | } |
| 398 | |
| 399 | @Override |
| 400 | public boolean evict(K key) { |
| 401 | return m.evict(serializeKey(key)); |
| 402 | } |
| 403 | |
| 404 | @Override |
| 405 | public void evictAll() { |
| 406 | m.evictAll(); |
| 407 | } |
| 408 | |
| 409 | @Override |
| 410 | public Set<K> keySet() { |
| 411 | return deserializeKeySet(m.keySet()); |
| 412 | } |
| 413 | |
| 414 | @Override |
| 415 | public Collection<V> values() { |
| 416 | return deserializeVal(m.values()); |
| 417 | } |
| 418 | |
| 419 | @Override |
| 420 | public Set<java.util.Map.Entry<K, V>> entrySet() { |
| 421 | return deserializeEntrySet(m.entrySet()); |
| 422 | } |
| 423 | |
Yuta HIGUCHI | 24d483d | 2014-12-17 10:36:12 -0800 | [diff] [blame] | 424 | /** |
| 425 | * {@inheritDoc} |
| 426 | * |
| 427 | * @deprecated not implemented yet |
| 428 | * @throws UnsupportedOperationException not implemented yet |
| 429 | */ |
| 430 | @Deprecated |
Yuta HIGUCHI | a97b5e4 | 2014-10-13 14:04:58 -0700 | [diff] [blame] | 431 | @SuppressWarnings("rawtypes") |
| 432 | @Override |
| 433 | public Set<K> keySet(Predicate predicate) { |
| 434 | throw new UnsupportedOperationException(); |
| 435 | } |
| 436 | |
Yuta HIGUCHI | 24d483d | 2014-12-17 10:36:12 -0800 | [diff] [blame] | 437 | /** |
| 438 | * {@inheritDoc} |
| 439 | * |
| 440 | * @deprecated not implemented yet |
| 441 | * @throws UnsupportedOperationException not implemented yet |
| 442 | */ |
| 443 | @Deprecated |
Yuta HIGUCHI | a97b5e4 | 2014-10-13 14:04:58 -0700 | [diff] [blame] | 444 | @SuppressWarnings("rawtypes") |
| 445 | @Override |
| 446 | public Set<java.util.Map.Entry<K, V>> entrySet(Predicate predicate) { |
| 447 | throw new UnsupportedOperationException(); |
| 448 | } |
| 449 | |
Yuta HIGUCHI | 24d483d | 2014-12-17 10:36:12 -0800 | [diff] [blame] | 450 | /** |
| 451 | * {@inheritDoc} |
| 452 | * |
| 453 | * @deprecated not implemented yet |
| 454 | * @throws UnsupportedOperationException not implemented yet |
| 455 | */ |
| 456 | @Deprecated |
Yuta HIGUCHI | a97b5e4 | 2014-10-13 14:04:58 -0700 | [diff] [blame] | 457 | @SuppressWarnings("rawtypes") |
| 458 | @Override |
| 459 | public Collection<V> values(Predicate predicate) { |
| 460 | throw new UnsupportedOperationException(); |
| 461 | } |
| 462 | |
| 463 | @Override |
| 464 | public Set<K> localKeySet() { |
| 465 | return deserializeKeySet(m.localKeySet()); |
| 466 | } |
| 467 | |
Yuta HIGUCHI | 24d483d | 2014-12-17 10:36:12 -0800 | [diff] [blame] | 468 | /** |
| 469 | * {@inheritDoc} |
| 470 | * |
| 471 | * @deprecated not implemented yet |
| 472 | * @throws UnsupportedOperationException not implemented yet |
| 473 | */ |
| 474 | @Deprecated |
Yuta HIGUCHI | a97b5e4 | 2014-10-13 14:04:58 -0700 | [diff] [blame] | 475 | @SuppressWarnings("rawtypes") |
| 476 | @Override |
| 477 | public Set<K> localKeySet(Predicate predicate) { |
| 478 | throw new UnsupportedOperationException(); |
| 479 | } |
| 480 | |
Yuta HIGUCHI | 24d483d | 2014-12-17 10:36:12 -0800 | [diff] [blame] | 481 | /** |
| 482 | * {@inheritDoc} |
| 483 | * |
| 484 | * @deprecated not implemented yet |
| 485 | * @throws UnsupportedOperationException not implemented yet |
| 486 | */ |
| 487 | @Deprecated |
Yuta HIGUCHI | a97b5e4 | 2014-10-13 14:04:58 -0700 | [diff] [blame] | 488 | @Override |
| 489 | public void addIndex(String attribute, boolean ordered) { |
| 490 | throw new UnsupportedOperationException(); |
| 491 | } |
| 492 | |
| 493 | @Override |
| 494 | public LocalMapStats getLocalMapStats() { |
| 495 | return m.getLocalMapStats(); |
| 496 | } |
| 497 | |
Yuta HIGUCHI | 24d483d | 2014-12-17 10:36:12 -0800 | [diff] [blame] | 498 | /** |
| 499 | * {@inheritDoc} |
| 500 | * |
| 501 | * @deprecated not implemented yet |
| 502 | * @throws UnsupportedOperationException not implemented yet |
| 503 | */ |
| 504 | @Deprecated |
Yuta HIGUCHI | a97b5e4 | 2014-10-13 14:04:58 -0700 | [diff] [blame] | 505 | @SuppressWarnings("rawtypes") |
| 506 | @Override |
| 507 | public Object executeOnKey(K key, EntryProcessor entryProcessor) { |
| 508 | throw new UnsupportedOperationException(); |
| 509 | } |
| 510 | |
Yuta HIGUCHI | 24d483d | 2014-12-17 10:36:12 -0800 | [diff] [blame] | 511 | /** |
| 512 | * {@inheritDoc} |
| 513 | * |
| 514 | * @deprecated not implemented yet |
| 515 | * @throws UnsupportedOperationException not implemented yet |
| 516 | */ |
| 517 | @Deprecated |
Yuta HIGUCHI | a97b5e4 | 2014-10-13 14:04:58 -0700 | [diff] [blame] | 518 | @SuppressWarnings("rawtypes") |
| 519 | @Override |
| 520 | public Map<K, Object> executeOnKeys(Set<K> keys, |
| 521 | EntryProcessor entryProcessor) { |
| 522 | throw new UnsupportedOperationException(); |
| 523 | } |
| 524 | |
Yuta HIGUCHI | 24d483d | 2014-12-17 10:36:12 -0800 | [diff] [blame] | 525 | /** |
| 526 | * {@inheritDoc} |
| 527 | * |
| 528 | * @deprecated not implemented yet |
| 529 | * @throws UnsupportedOperationException not implemented yet |
| 530 | */ |
| 531 | @Deprecated |
Yuta HIGUCHI | a97b5e4 | 2014-10-13 14:04:58 -0700 | [diff] [blame] | 532 | @SuppressWarnings("rawtypes") |
| 533 | @Override |
| 534 | public void submitToKey(K key, EntryProcessor entryProcessor, |
| 535 | ExecutionCallback callback) { |
| 536 | throw new UnsupportedOperationException(); |
| 537 | } |
| 538 | |
Yuta HIGUCHI | 24d483d | 2014-12-17 10:36:12 -0800 | [diff] [blame] | 539 | /** |
| 540 | * {@inheritDoc} |
| 541 | * |
| 542 | * @deprecated not implemented yet |
| 543 | * @throws UnsupportedOperationException not implemented yet |
| 544 | */ |
| 545 | @Deprecated |
Yuta HIGUCHI | a97b5e4 | 2014-10-13 14:04:58 -0700 | [diff] [blame] | 546 | @SuppressWarnings("rawtypes") |
| 547 | @Override |
| 548 | public Future submitToKey(K key, EntryProcessor entryProcessor) { |
| 549 | throw new UnsupportedOperationException(); |
| 550 | } |
| 551 | |
Yuta HIGUCHI | 24d483d | 2014-12-17 10:36:12 -0800 | [diff] [blame] | 552 | /** |
| 553 | * {@inheritDoc} |
| 554 | * |
| 555 | * @deprecated not implemented yet |
| 556 | * @throws UnsupportedOperationException not implemented yet |
| 557 | */ |
| 558 | @Deprecated |
Yuta HIGUCHI | a97b5e4 | 2014-10-13 14:04:58 -0700 | [diff] [blame] | 559 | @SuppressWarnings("rawtypes") |
| 560 | @Override |
| 561 | public Map<K, Object> executeOnEntries(EntryProcessor entryProcessor) { |
| 562 | throw new UnsupportedOperationException(); |
| 563 | } |
| 564 | |
Yuta HIGUCHI | 24d483d | 2014-12-17 10:36:12 -0800 | [diff] [blame] | 565 | /** |
| 566 | * {@inheritDoc} |
| 567 | * |
| 568 | * @deprecated not implemented yet |
| 569 | * @throws UnsupportedOperationException not implemented yet |
| 570 | */ |
| 571 | @Deprecated |
Yuta HIGUCHI | a97b5e4 | 2014-10-13 14:04:58 -0700 | [diff] [blame] | 572 | @SuppressWarnings("rawtypes") |
| 573 | @Override |
| 574 | public Map<K, Object> executeOnEntries(EntryProcessor entryProcessor, |
| 575 | Predicate predicate) { |
| 576 | throw new UnsupportedOperationException(); |
| 577 | } |
| 578 | |
Yuta HIGUCHI | 24d483d | 2014-12-17 10:36:12 -0800 | [diff] [blame] | 579 | /** |
| 580 | * {@inheritDoc} |
| 581 | * |
| 582 | * @deprecated not implemented yet |
| 583 | * @throws UnsupportedOperationException not implemented yet |
| 584 | */ |
| 585 | @Deprecated |
Yuta HIGUCHI | a97b5e4 | 2014-10-13 14:04:58 -0700 | [diff] [blame] | 586 | @Override |
| 587 | public <SuppliedValue, Result> Result aggregate( |
| 588 | Supplier<K, V, SuppliedValue> supplier, |
| 589 | Aggregation<K, SuppliedValue, Result> aggregation) { |
| 590 | |
| 591 | throw new UnsupportedOperationException(); |
| 592 | } |
| 593 | |
Yuta HIGUCHI | 24d483d | 2014-12-17 10:36:12 -0800 | [diff] [blame] | 594 | /** |
| 595 | * {@inheritDoc} |
| 596 | * |
| 597 | * @deprecated not implemented yet |
| 598 | * @throws UnsupportedOperationException not implemented yet |
| 599 | */ |
| 600 | @Deprecated |
Yuta HIGUCHI | a97b5e4 | 2014-10-13 14:04:58 -0700 | [diff] [blame] | 601 | @Override |
| 602 | public <SuppliedValue, Result> Result aggregate( |
| 603 | Supplier<K, V, SuppliedValue> supplier, |
| 604 | Aggregation<K, SuppliedValue, Result> aggregation, |
| 605 | JobTracker jobTracker) { |
| 606 | |
| 607 | throw new UnsupportedOperationException(); |
| 608 | } |
| 609 | |
| 610 | private byte[] serializeKey(Object key) { |
| 611 | return serializer.encode(key); |
| 612 | } |
| 613 | |
| 614 | private K deserializeKey(byte[] key) { |
| 615 | return serializer.decode(key); |
| 616 | } |
| 617 | |
| 618 | private byte[] serializeVal(Object val) { |
| 619 | return serializer.encode(val); |
| 620 | } |
| 621 | |
| 622 | private V deserializeVal(byte[] val) { |
Yuta HIGUCHI | 87102541 | 2014-10-23 11:58:56 -0700 | [diff] [blame] | 623 | if (val == null) { |
| 624 | return null; |
| 625 | } |
| 626 | return serializer.decode(val.clone()); |
Yuta HIGUCHI | a97b5e4 | 2014-10-13 14:04:58 -0700 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | private Set<byte[]> serializeKeySet(Set<K> keys) { |
| 630 | Set<byte[]> sk = Collections.newSetFromMap(new IdentityHashMap<byte[], Boolean>(keys.size())); |
| 631 | for (K key : keys) { |
| 632 | sk.add(serializeKey(key)); |
| 633 | } |
| 634 | return sk; |
| 635 | } |
| 636 | |
| 637 | private Set<K> deserializeKeySet(Set<byte[]> keys) { |
| 638 | Set<K> dsk = new HashSet<>(keys.size()); |
| 639 | for (byte[] key : keys) { |
| 640 | dsk.add(deserializeKey(key)); |
| 641 | } |
| 642 | return dsk; |
| 643 | } |
| 644 | |
| 645 | private Collection<V> deserializeVal(Collection<byte[]> vals) { |
| 646 | Collection<V> dsl = new ArrayList<>(vals.size()); |
| 647 | for (byte[] val : vals) { |
| 648 | dsl.add(deserializeVal(val)); |
| 649 | } |
| 650 | return dsl; |
| 651 | } |
| 652 | |
| 653 | private Set<java.util.Map.Entry<K, V>> deserializeEntrySet( |
| 654 | Set<java.util.Map.Entry<byte[], byte[]>> entries) { |
| 655 | |
| 656 | Set<java.util.Map.Entry<K, V>> dse = new HashSet<>(entries.size()); |
| 657 | for (java.util.Map.Entry<byte[], byte[]> entry : entries) { |
| 658 | dse.add(Pair.of(deserializeKey(entry.getKey()), |
| 659 | deserializeVal(entry.getValue()))); |
| 660 | } |
| 661 | return dse; |
| 662 | } |
| 663 | |
| 664 | private final class BaseEntryListener |
| 665 | implements EntryListener<byte[], byte[]> { |
| 666 | |
| 667 | private final EntryListener<K, V> listener; |
| 668 | |
| 669 | public BaseEntryListener(EntryListener<K, V> listener) { |
| 670 | this.listener = listener; |
| 671 | } |
| 672 | |
| 673 | @Override |
| 674 | public void mapEvicted(MapEvent event) { |
| 675 | listener.mapEvicted(event); |
| 676 | } |
| 677 | |
| 678 | @Override |
| 679 | public void mapCleared(MapEvent event) { |
| 680 | listener.mapCleared(event); |
| 681 | } |
| 682 | |
| 683 | @Override |
| 684 | public void entryUpdated(EntryEvent<byte[], byte[]> event) { |
| 685 | EntryEvent<K, V> evt = new EntryEvent<K, V>( |
| 686 | event.getSource(), |
| 687 | event.getMember(), |
| 688 | event.getEventType().getType(), |
| 689 | deserializeKey(event.getKey()), |
| 690 | deserializeVal(event.getOldValue()), |
| 691 | deserializeVal(event.getValue())); |
| 692 | |
| 693 | listener.entryUpdated(evt); |
| 694 | } |
| 695 | |
| 696 | @Override |
| 697 | public void entryRemoved(EntryEvent<byte[], byte[]> event) { |
| 698 | EntryEvent<K, V> evt = new EntryEvent<K, V>( |
| 699 | event.getSource(), |
| 700 | event.getMember(), |
| 701 | event.getEventType().getType(), |
| 702 | deserializeKey(event.getKey()), |
| 703 | deserializeVal(event.getOldValue()), |
| 704 | null); |
| 705 | |
| 706 | listener.entryRemoved(evt); |
| 707 | } |
| 708 | |
| 709 | @Override |
| 710 | public void entryEvicted(EntryEvent<byte[], byte[]> event) { |
| 711 | EntryEvent<K, V> evt = new EntryEvent<K, V>( |
| 712 | event.getSource(), |
| 713 | event.getMember(), |
| 714 | event.getEventType().getType(), |
| 715 | deserializeKey(event.getKey()), |
| 716 | deserializeVal(event.getOldValue()), |
| 717 | deserializeVal(event.getValue())); |
| 718 | |
| 719 | listener.entryEvicted(evt); |
| 720 | } |
| 721 | |
| 722 | @Override |
| 723 | public void entryAdded(EntryEvent<byte[], byte[]> event) { |
| 724 | EntryEvent<K, V> evt = new EntryEvent<K, V>( |
| 725 | event.getSource(), |
| 726 | event.getMember(), |
| 727 | event.getEventType().getType(), |
| 728 | deserializeKey(event.getKey()), |
| 729 | null, |
| 730 | deserializeVal(event.getValue())); |
| 731 | |
| 732 | listener.entryAdded(evt); |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | private final class DeserializeVal implements Function<byte[], V> { |
| 737 | @Override |
| 738 | public V apply(byte[] input) { |
| 739 | return deserializeVal(input); |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | } |