Added application ID store; both trivial and distributed variants.
diff --git a/core/store/dist/src/main/java/org/onlab/onos/store/core/impl/AppIdEvent.java b/core/store/dist/src/main/java/org/onlab/onos/store/core/impl/AppIdEvent.java
new file mode 100644
index 0000000..3dd626c
--- /dev/null
+++ b/core/store/dist/src/main/java/org/onlab/onos/store/core/impl/AppIdEvent.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.onlab.onos.store.core.impl;
+
+import org.onlab.onos.core.ApplicationId;
+import org.onlab.onos.event.AbstractEvent;
+
+/**
+ * Application ID event.
+ */
+public class AppIdEvent extends AbstractEvent<AppIdEvent.Type, ApplicationId> {
+
+ public enum Type {
+ APP_REGISTERED
+ }
+
+ protected AppIdEvent(Type type, ApplicationId subject) {
+ super(type, subject);
+ }
+
+}
diff --git a/core/store/dist/src/main/java/org/onlab/onos/store/core/impl/AppIdStoreDelegate.java b/core/store/dist/src/main/java/org/onlab/onos/store/core/impl/AppIdStoreDelegate.java
new file mode 100644
index 0000000..e05daf2
--- /dev/null
+++ b/core/store/dist/src/main/java/org/onlab/onos/store/core/impl/AppIdStoreDelegate.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.onlab.onos.store.core.impl;
+
+import org.onlab.onos.store.StoreDelegate;
+
+/**
+ * Application ID store delegate.
+ */
+public interface AppIdStoreDelegate extends StoreDelegate<AppIdEvent> {
+}
diff --git a/core/store/dist/src/main/java/org/onlab/onos/store/core/impl/DistributedApplicationIdStore.java b/core/store/dist/src/main/java/org/onlab/onos/store/core/impl/DistributedApplicationIdStore.java
new file mode 100644
index 0000000..354ef49
--- /dev/null
+++ b/core/store/dist/src/main/java/org/onlab/onos/store/core/impl/DistributedApplicationIdStore.java
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.onlab.onos.store.core.impl;
+
+import com.google.common.collect.ImmutableSet;
+import com.hazelcast.core.EntryEvent;
+import com.hazelcast.core.EntryListener;
+import com.hazelcast.core.IAtomicLong;
+import com.hazelcast.core.MapEvent;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Service;
+import org.onlab.onos.core.ApplicationId;
+import org.onlab.onos.core.ApplicationIdStore;
+import org.onlab.onos.core.DefaultApplicationId;
+import org.onlab.onos.store.hz.AbstractHazelcastStore;
+import org.onlab.onos.store.hz.SMap;
+import org.onlab.onos.store.serializers.KryoNamespaces;
+import org.onlab.onos.store.serializers.KryoSerializer;
+import org.onlab.util.KryoNamespace;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Simple implementation of the application ID registry using in-memory
+ * structures.
+ */
+@Component(immediate = true)
+@Service
+public class DistributedApplicationIdStore
+ extends AbstractHazelcastStore<AppIdEvent, AppIdStoreDelegate>
+ implements ApplicationIdStore {
+
+ protected IAtomicLong lastAppId;
+ protected SMap<String, DefaultApplicationId> appIdsByName;
+
+ protected Map<Short, DefaultApplicationId> appIds = new ConcurrentHashMap<>();
+
+
+ @Override
+ @Activate
+ public void activate() {
+ super.activate();
+
+ this.serializer = new KryoSerializer() {
+ @Override
+ protected void setupKryoPool() {
+ serializerPool = KryoNamespace.newBuilder()
+ .register(KryoNamespaces.API)
+ .build()
+ .populate(1);
+ }
+ };
+
+ lastAppId = theInstance.getAtomicLong("applicationId");
+
+ appIdsByName = new SMap<>(theInstance.<byte[], byte[]>getMap("appIdsByName"), this.serializer);
+ appIdsByName.addEntryListener((new RemoteAppIdEventHandler()), true);
+
+ primeAppIds();
+
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ log.info("Stopped");
+ }
+
+ @Override
+ public Set<ApplicationId> getAppIds() {
+ return ImmutableSet.<ApplicationId>copyOf(appIds.values());
+ }
+
+ @Override
+ public ApplicationId getAppId(Short id) {
+ ApplicationId appId = appIds.get(id);
+ if (appId == null) {
+ primeAppIds();
+ }
+ return appId;
+ }
+
+ private synchronized void primeAppIds() {
+ for (DefaultApplicationId appId : appIdsByName.values()) {
+ appIds.put(appId.id(), appId);
+ }
+ }
+
+ @Override
+ public synchronized ApplicationId registerApplication(String name) {
+ DefaultApplicationId appId = appIdsByName.get(name);
+ if (appId == null) {
+ short id = (short) lastAppId.getAndIncrement();
+ appId = new DefaultApplicationId(id, name);
+ appIds.put(id, appId);
+ appIdsByName.put(name, appId);
+ }
+ return appId;
+ }
+
+ private class RemoteAppIdEventHandler implements EntryListener<String, DefaultApplicationId> {
+ @Override
+ public void entryAdded(EntryEvent<String, DefaultApplicationId> event) {
+ DefaultApplicationId appId = event.getValue();
+ appIds.put(appId.id(), appId);
+ }
+
+ @Override
+ public void entryRemoved(EntryEvent<String, DefaultApplicationId> event) {
+ }
+
+ @Override
+ public void entryUpdated(EntryEvent<String, DefaultApplicationId> event) {
+ entryAdded(event);
+ }
+
+ @Override
+ public void entryEvicted(EntryEvent<String, DefaultApplicationId> event) {
+ }
+
+ @Override
+ public void mapEvicted(MapEvent event) {
+ }
+
+ @Override
+ public void mapCleared(MapEvent event) {
+ }
+ }
+}
diff --git a/core/store/dist/src/main/java/org/onlab/onos/store/core/impl/package-info.java b/core/store/dist/src/main/java/org/onlab/onos/store/core/impl/package-info.java
new file mode 100644
index 0000000..7613a4f
--- /dev/null
+++ b/core/store/dist/src/main/java/org/onlab/onos/store/core/impl/package-info.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Implementation of a distributed application ID registry store using Hazelcast.
+ */
+package org.onlab.onos.store.core.impl;
diff --git a/core/store/dist/src/main/java/org/onlab/onos/store/mastership/impl/RoleValue.java b/core/store/dist/src/main/java/org/onlab/onos/store/mastership/impl/RoleValue.java
index 7447161..0a3de50 100644
--- a/core/store/dist/src/main/java/org/onlab/onos/store/mastership/impl/RoleValue.java
+++ b/core/store/dist/src/main/java/org/onlab/onos/store/mastership/impl/RoleValue.java
@@ -15,7 +15,7 @@
/**
* A structure that holds node mastership roles associated with a
- * {@link DeviceId}. This structure needs to be locked through IMap.
+ * {@link org.onlab.onos.net.DeviceId}. This structure needs to be locked through IMap.
*/
final class RoleValue {
diff --git a/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/DefaultApplicationIdSerializer.java b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/DefaultApplicationIdSerializer.java
new file mode 100644
index 0000000..87e9ba4
--- /dev/null
+++ b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/DefaultApplicationIdSerializer.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.onlab.onos.store.serializers;
+
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+import org.onlab.onos.core.DefaultApplicationId;
+
+/**
+ * Kryo Serializer for {@link org.onlab.onos.core.DefaultApplicationId}.
+ */
+public final class DefaultApplicationIdSerializer extends Serializer<DefaultApplicationId> {
+
+ /**
+ * Creates {@link org.onlab.onos.core.DefaultApplicationId} serializer instance.
+ */
+ public DefaultApplicationIdSerializer() {
+ // non-null, immutable
+ super(false, true);
+ }
+
+ @Override
+ public void write(Kryo kryo, Output output, DefaultApplicationId object) {
+ kryo.writeObject(output, object.id());
+ kryo.writeObject(output, object.name());
+ }
+
+ @Override
+ public DefaultApplicationId read(Kryo kryo, Input input, Class<DefaultApplicationId> type) {
+ short id = kryo.readObject(input, Short.class);
+ String name = kryo.readObject(input, String.class);
+ return new DefaultApplicationId(id, name);
+ }
+}
diff --git a/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/KryoNamespaces.java b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/KryoNamespaces.java
index 0e9e19c..c554372 100644
--- a/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/KryoNamespaces.java
+++ b/core/store/serializers/src/main/java/org/onlab/onos/store/serializers/KryoNamespaces.java
@@ -7,6 +7,7 @@
import java.util.HashSet;
import java.util.LinkedList;
+import org.onlab.onos.core.DefaultApplicationId;
import org.onlab.onos.cluster.ControllerNode;
import org.onlab.onos.cluster.DefaultControllerNode;
import org.onlab.onos.cluster.NodeId;
@@ -129,6 +130,7 @@
FlowRuleBatchEntry.class,
FlowRuleBatchEntry.FlowRuleOperation.class
)
+ .register(DefaultApplicationId.class, new DefaultApplicationIdSerializer())
.register(URI.class, new URISerializer())
.register(NodeId.class, new NodeIdSerializer())
.register(ProviderId.class, new ProviderIdSerializer())
diff --git a/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleApplicationIdStore.java b/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleApplicationIdStore.java
new file mode 100644
index 0000000..a242822
--- /dev/null
+++ b/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleApplicationIdStore.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.onlab.onos.store.trivial.impl;
+
+import com.google.common.collect.ImmutableSet;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Service;
+import org.onlab.onos.core.ApplicationId;
+import org.onlab.onos.core.ApplicationIdStore;
+import org.onlab.onos.core.DefaultApplicationId;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Simple implementation of the application ID registry using in-memory
+ * structures.
+ */
+@Component(immediate = true)
+@Service
+public class SimpleApplicationIdStore implements ApplicationIdStore {
+
+ private static final AtomicInteger ID_DISPENSER = new AtomicInteger(1);
+
+ private final Map<Short, DefaultApplicationId> appIds = new ConcurrentHashMap<>();
+ private final Map<String, DefaultApplicationId> appIdsByName = new ConcurrentHashMap<>();
+
+ @Override
+ public Set<ApplicationId> getAppIds() {
+ return ImmutableSet.<ApplicationId>copyOf(appIds.values());
+ }
+
+ @Override
+ public ApplicationId getAppId(Short id) {
+ return appIds.get(id);
+ }
+
+ @Override
+ public ApplicationId registerApplication(String name) {
+ DefaultApplicationId appId = appIdsByName.get(name);
+ if (appId == null) {
+ short id = (short) ID_DISPENSER.getAndIncrement();
+ appId = new DefaultApplicationId(id, name);
+ appIds.put(id, appId);
+ appIdsByName.put(name, appId);
+ }
+ return appId;
+ }
+
+}