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 {