use of org.onlab.util.KryoNamespace in project onos by opennetworkinglab.
the class DistributedRouteStore method activate.
/**
* Sets up distributed route store.
*/
public void activate() {
routeTables = new ConcurrentHashMap<>();
executor = Executors.newSingleThreadExecutor(groupedThreads("onos/route", "store", log));
KryoNamespace masterRouteTableSerializer = KryoNamespace.newBuilder().register(RouteTableId.class).build();
masterRouteTable = storageService.<RouteTableId>setBuilder().withName("onos-master-route-table").withSerializer(Serializer.using(masterRouteTableSerializer)).build().asDistributedSet();
masterRouteTable.addListener(masterRouteTableListener);
// Add default tables (add is idempotent)
masterRouteTable.add(IPV4);
masterRouteTable.add(IPV6);
masterRouteTable.forEach(this::createRouteTable);
log.info("Started");
}
use of org.onlab.util.KryoNamespace in project onos by opennetworkinglab.
the class FpmManager method activate.
@Activate
protected void activate(ComponentContext context) {
componentConfigService.preSetProperty("org.onosproject.incubator.store.routing.impl.RouteStoreImpl", "distributed", "true");
componentConfigService.registerProperties(getClass());
KryoNamespace serializer = KryoNamespace.newBuilder().register(KryoNamespaces.API).register(FpmPeer.class).register(FpmConnectionInfo.class).build();
peers = storageService.<FpmPeer, Set<FpmConnectionInfo>>consistentMapBuilder().withName("fpm-connections").withSerializer(Serializer.using(serializer)).build();
modified(context);
startServer();
appId = coreService.registerApplication(APP_NAME, peers::destroy);
asyncLock = storageService.lockBuilder().withName(LOCK_NAME).build();
clusterEventExecutor = Executors.newSingleThreadExecutor(groupedThreads("fpm-event-main", "%d", log));
clusterService.addListener(clusterListener);
log.info("Started");
}
use of org.onlab.util.KryoNamespace in project onos by opennetworkinglab.
the class PortLoadBalancerManager method activate.
@Activate
public void activate() {
appId = coreService.registerApplication(APP_NAME);
portLoadBalancerEventExecutor = Executors.newSingleThreadExecutor(groupedThreads("portloadbalancer-event", "%d", log));
portLoadBalancerProvExecutor = Executors.newSingleThreadExecutor(groupedThreads("portloadbalancer-prov", "%d", log));
deviceEventExecutor = Executors.newSingleThreadScheduledExecutor(groupedThreads("portloadbalancer-dev-event", "%d", log));
portLoadBalancerStoreListener = new PortLoadBalancerStoreListener();
portLoadBalancerNextStoreListener = new PortLoadBalancerNextStoreListener();
portLoadBalancerResStoreListener = new PortLoadBalancerResStoreListener();
KryoNamespace serializer = KryoNamespace.newBuilder().register(KryoNamespaces.API).register(PortLoadBalancer.class).register(PortLoadBalancerId.class).register(PortLoadBalancerMode.class).build();
portLoadBalancerStore = storageService.<PortLoadBalancerId, PortLoadBalancer>consistentMapBuilder().withName("onos-portloadbalancer-store").withRelaxedReadConsistency().withSerializer(Serializer.using(serializer)).build();
portLoadBalancerStore.addListener(portLoadBalancerStoreListener);
portLoadBalancerNextStore = storageService.<PortLoadBalancerId, Integer>consistentMapBuilder().withName("onos-portloadbalancer-next-store").withRelaxedReadConsistency().withSerializer(Serializer.using(serializer)).build();
portLoadBalancerNextStore.addListener(portLoadBalancerNextStoreListener);
portLoadBalancerResStore = storageService.<PortLoadBalancerId, ApplicationId>consistentMapBuilder().withName("onos-portloadbalancer-res-store").withRelaxedReadConsistency().withSerializer(Serializer.using(serializer)).build();
portLoadBalancerResStore.addListener(portLoadBalancerResStoreListener);
deviceService.addListener(deviceListener);
log.info("Started");
}
use of org.onlab.util.KryoNamespace in project onos by opennetworkinglab.
the class Serializer method using.
/**
* Creates a new Serializer instance from a list of KryoNamespaces and some additional classes.
*
* @param namespaces kryo namespaces
* @param classes variable length array of classes to register
* @return Serializer instance
*/
static Serializer using(List<KryoNamespace> namespaces, Class<?>... classes) {
KryoNamespace.Builder builder = new KryoNamespace.Builder();
namespaces.forEach(builder::register);
Lists.newArrayList(classes).forEach(builder::register);
KryoNamespace namespace = builder.build();
return new Serializer() {
@Override
public <T> byte[] encode(T object) {
return namespace.serialize(object);
}
@Override
public <T> T decode(byte[] bytes) {
return namespace.deserialize(bytes);
}
@Override
public <T> T copy(T object) {
return namespace.run(kryo -> kryo.copy(object));
}
};
}
use of org.onlab.util.KryoNamespace in project onos by opennetworkinglab.
the class WallClockTimestampTest method testKryoSerializable.
@Test
public final void testKryoSerializable() {
WallClockTimestamp ts1 = new WallClockTimestamp();
WallClockTimestamp ts2 = new WallClockTimestamp(System.currentTimeMillis() + 10000);
final ByteBuffer buffer = ByteBuffer.allocate(1 * 1024 * 1024);
final KryoNamespace kryos = KryoNamespace.newBuilder().register(WallClockTimestamp.class).build();
kryos.serialize(ts1, buffer);
buffer.flip();
Timestamp copy = kryos.deserialize(buffer);
new EqualsTester().addEqualityGroup(ts1, copy).addEqualityGroup(ts2).testEquals();
}
Aggregations