Search in sources :

Example 1 with KryoNamespace

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");
}
Also used : RouteTableId(org.onosproject.routeservice.RouteTableId) KryoNamespace(org.onlab.util.KryoNamespace)

Example 2 with KryoNamespace

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");
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) KryoNamespace(org.onlab.util.KryoNamespace) Activate(org.osgi.service.component.annotations.Activate)

Example 3 with KryoNamespace

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");
}
Also used : PortLoadBalancerMode(org.onosproject.portloadbalancer.api.PortLoadBalancerMode) KryoNamespace(org.onlab.util.KryoNamespace) PortLoadBalancer(org.onosproject.portloadbalancer.api.PortLoadBalancer) Activate(org.osgi.service.component.annotations.Activate)

Example 4 with KryoNamespace

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));
        }
    };
}
Also used : KryoNamespace(org.onlab.util.KryoNamespace)

Example 5 with KryoNamespace

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();
}
Also used : EqualsTester(com.google.common.testing.EqualsTester) KryoNamespace(org.onlab.util.KryoNamespace) ByteBuffer(java.nio.ByteBuffer) Timestamp(org.onosproject.store.Timestamp) Test(org.junit.Test)

Aggregations

KryoNamespace (org.onlab.util.KryoNamespace)11 Activate (org.osgi.service.component.annotations.Activate)5 EqualsTester (com.google.common.testing.EqualsTester)4 ByteBuffer (java.nio.ByteBuffer)4 Test (org.junit.Test)4 Timestamp (org.onosproject.store.Timestamp)3 WallClockTimestamp (org.onosproject.store.service.WallClockTimestamp)2 BaseJsonNode (com.fasterxml.jackson.databind.node.BaseJsonNode)1 BinaryNode (com.fasterxml.jackson.databind.node.BinaryNode)1 ContainerNode (com.fasterxml.jackson.databind.node.ContainerNode)1 DoubleNode (com.fasterxml.jackson.databind.node.DoubleNode)1 IntNode (com.fasterxml.jackson.databind.node.IntNode)1 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)1 LongNode (com.fasterxml.jackson.databind.node.LongNode)1 NullNode (com.fasterxml.jackson.databind.node.NullNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 POJONode (com.fasterxml.jackson.databind.node.POJONode)1 ValueNode (com.fasterxml.jackson.databind.node.ValueNode)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1