Yuta HIGUCHI

DeviceIdSerializer

Change-Id: Ic0f4474c88b8eabca76e382d737bddb7cb2d7112
1 +package org.onlab.onos.store.device.impl;
2 +
3 +import java.net.URI;
4 +
5 +import org.onlab.onos.net.DeviceId;
6 +
7 +import com.esotericsoftware.kryo.Kryo;
8 +import com.esotericsoftware.kryo.Serializer;
9 +import com.esotericsoftware.kryo.io.Input;
10 +import com.esotericsoftware.kryo.io.Output;
11 +
12 +//TODO move to util, etc.
13 +/**
14 +* Kryo Serializer for {@link DeviceId}.
15 +*/
16 +public final class DeviceIdSerializer extends Serializer<DeviceId> {
17 +
18 + @Override
19 + public void write(Kryo kryo, Output output, DeviceId object) {
20 + kryo.writeObject(output, object.uri());
21 + }
22 +
23 + @Override
24 + public DeviceId read(Kryo kryo, Input input, Class<DeviceId> type) {
25 + final URI uri = kryo.readObject(input, URI.class);
26 + return DeviceId.deviceId(uri);
27 + }
28 +}
...@@ -44,10 +44,6 @@ import org.onlab.onos.store.StoreService; ...@@ -44,10 +44,6 @@ import org.onlab.onos.store.StoreService;
44 import org.onlab.util.KryoPool; 44 import org.onlab.util.KryoPool;
45 import org.slf4j.Logger; 45 import org.slf4j.Logger;
46 46
47 -import com.esotericsoftware.kryo.Kryo;
48 -import com.esotericsoftware.kryo.Serializer;
49 -import com.esotericsoftware.kryo.io.Input;
50 -import com.esotericsoftware.kryo.io.Output;
51 import com.google.common.base.Optional; 47 import com.google.common.base.Optional;
52 import com.google.common.cache.CacheBuilder; 48 import com.google.common.cache.CacheBuilder;
53 import com.google.common.cache.CacheLoader; 49 import com.google.common.cache.CacheLoader;
...@@ -444,20 +440,6 @@ public class DistributedDeviceStore implements DeviceStore { ...@@ -444,20 +440,6 @@ public class DistributedDeviceStore implements DeviceStore {
444 return POOL.deserialize(bytes); 440 return POOL.deserialize(bytes);
445 } 441 }
446 442
447 - public static final class DeviceIdSerializer extends Serializer<DeviceId> {
448 -
449 - @Override
450 - public void write(Kryo kryo, Output output, DeviceId object) {
451 - kryo.writeObject(output, object.uri());
452 - }
453 -
454 - @Override
455 - public DeviceId read(Kryo kryo, Input input, Class<DeviceId> type) {
456 - final URI uri = kryo.readObject(input, URI.class);
457 - return DeviceId.deviceId(uri);
458 - }
459 - }
460 -
461 /** 443 /**
462 * An IMap EntryListener, which reflects each remote event to cache. 444 * An IMap EntryListener, which reflects each remote event to cache.
463 * 445 *
......
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
2 * Common abstractions and facilities for implementing distributed store 2 * Common abstractions and facilities for implementing distributed store
3 * using Hazelcast. 3 * using Hazelcast.
4 */ 4 */
5 -package org.onlab.onos.store;
...\ No newline at end of file ...\ No newline at end of file
5 +package org.onlab.onos.store;
......