aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/incubator/rpc/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/onos/incubator/rpc/src/main')
-rw-r--r--framework/src/onos/incubator/rpc/src/main/java/org/onosproject/incubator/rpc/impl/AbstractProviderRegistry.java73
-rw-r--r--framework/src/onos/incubator/rpc/src/main/java/org/onosproject/incubator/rpc/impl/LocalRemoteServiceProvider.java124
-rw-r--r--framework/src/onos/incubator/rpc/src/main/java/org/onosproject/incubator/rpc/impl/RemoteServiceManager.java80
-rw-r--r--framework/src/onos/incubator/rpc/src/main/java/org/onosproject/incubator/rpc/impl/package-info.java20
4 files changed, 297 insertions, 0 deletions
diff --git a/framework/src/onos/incubator/rpc/src/main/java/org/onosproject/incubator/rpc/impl/AbstractProviderRegistry.java b/framework/src/onos/incubator/rpc/src/main/java/org/onosproject/incubator/rpc/impl/AbstractProviderRegistry.java
new file mode 100644
index 00000000..2a8dda32
--- /dev/null
+++ b/framework/src/onos/incubator/rpc/src/main/java/org/onosproject/incubator/rpc/impl/AbstractProviderRegistry.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed 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.onosproject.incubator.rpc.impl;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.onosproject.incubator.rpc.RemoteServiceContextProvider;
+import org.onosproject.incubator.rpc.RemoteServiceContextProviderService;
+import org.onosproject.incubator.rpc.RemoteServiceProviderRegistry;
+import org.onosproject.net.provider.ProviderId;
+
+import com.google.common.annotations.Beta;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Maps;
+
+// Probably should change name or add missing feature (provider from scheme) to
+// org.onosproject.net.provider.AbstractProviderRegistry<P, S>
+@Beta
+abstract class AbstractProviderRegistry
+ implements RemoteServiceProviderRegistry {
+
+
+ private final Map<ProviderId, RemoteServiceContextProvider> pidToProvider = Maps.newConcurrentMap();
+ private final Map<String, RemoteServiceContextProvider> schemeToProvider = Maps.newConcurrentMap();
+
+ public AbstractProviderRegistry() {
+ super();
+ }
+
+ protected abstract RemoteServiceContextProviderService createProviderService(RemoteServiceContextProvider provider);
+
+ @Override
+ public synchronized RemoteServiceContextProviderService register(RemoteServiceContextProvider provider) {
+ // TODO check if it already exists
+ pidToProvider.put(provider.id(), provider);
+ schemeToProvider.put(provider.id().scheme(), provider);
+ return createProviderService(provider);
+ }
+
+ @Override
+ public synchronized void unregister(RemoteServiceContextProvider provider) {
+ pidToProvider.remove(provider.id(), provider);
+ schemeToProvider.remove(provider.id().scheme(), provider);
+ }
+
+ @Override
+ public Set<ProviderId> getProviders() {
+ return ImmutableSet.copyOf(pidToProvider.keySet());
+ }
+
+ protected RemoteServiceContextProvider getProvider(ProviderId pid) {
+ return pidToProvider.get(pid);
+ }
+
+ protected RemoteServiceContextProvider getProvider(String scheme) {
+ return schemeToProvider.get(scheme);
+ }
+
+}
diff --git a/framework/src/onos/incubator/rpc/src/main/java/org/onosproject/incubator/rpc/impl/LocalRemoteServiceProvider.java b/framework/src/onos/incubator/rpc/src/main/java/org/onosproject/incubator/rpc/impl/LocalRemoteServiceProvider.java
new file mode 100644
index 00000000..d38248ab
--- /dev/null
+++ b/framework/src/onos/incubator/rpc/src/main/java/org/onosproject/incubator/rpc/impl/LocalRemoteServiceProvider.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed 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.onosproject.incubator.rpc.impl;
+
+import static com.google.common.base.Preconditions.checkArgument;
+
+import java.net.URI;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.ConcurrentHashMap;
+
+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.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onlab.osgi.DefaultServiceDirectory;
+import org.onlab.osgi.ServiceDirectory;
+import org.onosproject.incubator.rpc.RemoteServiceContext;
+import org.onosproject.incubator.rpc.RemoteServiceContextProvider;
+import org.onosproject.incubator.rpc.RemoteServiceContextProviderService;
+import org.onosproject.incubator.rpc.RemoteServiceProviderRegistry;
+import org.onosproject.net.provider.ProviderId;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.Beta;
+
+/**
+ * Sample implementation of RemoteServiceContextProvider.
+ *
+ * Scheme: "local", calling corresponding local service on request.
+ * Only expected for testing until real RPC implementation is ready.
+ *
+ * Note: This is expected to be removed or separated out as separate bundle
+ * once other RPC implementaion became available.
+ */
+@Beta
+@Component(immediate = true)
+public class LocalRemoteServiceProvider implements RemoteServiceContextProvider {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ private RemoteServiceContext theOne = new LocalServiceContext();
+
+ private static final ProviderId PID = new ProviderId("local", "org.onosproject.rpc.provider.local");
+
+ @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+ protected RemoteServiceProviderRegistry rpcRegistry;
+
+ private final Map<Class<? extends Object>, Object> services = new ConcurrentHashMap<>();
+
+ private RemoteServiceContextProviderService providerService;
+
+ @Activate
+ protected void activate() {
+
+ services.put(SomeOtherService.class, new SomeOtherServiceImpl());
+
+ providerService = rpcRegistry.register(this);
+ log.info("Started");
+ }
+
+ @Deactivate
+ protected void deactivate() {
+ rpcRegistry.unregister(this);
+ log.info("Stopped");
+ }
+
+ @Override
+ public ProviderId id() {
+ return PID;
+ }
+
+ @Override
+ public RemoteServiceContext get(URI uri) {
+ checkArgument(Objects.equals(uri.getScheme(), "local"));
+ return theOne;
+ }
+
+ private final class LocalServiceContext implements RemoteServiceContext {
+
+ private final ServiceDirectory directory = new DefaultServiceDirectory();
+
+ @Override
+ public <T> T get(Class<T> serviceClass) {
+ @SuppressWarnings("unchecked")
+ T service = (T) services.get(serviceClass);
+ if (service != null) {
+ return service;
+ }
+ // look up OSGi services on this host.
+ // provided to unblock development depending on RPC.
+ return directory.get(serviceClass);
+ }
+ }
+
+ // Service provided by RPC can be non-OSGi Service
+ public static interface SomeOtherService {
+ String hello();
+ }
+
+ public static class SomeOtherServiceImpl implements SomeOtherService {
+
+ @Override
+ public String hello() {
+ return "Goodbye";
+ }
+ }
+
+}
diff --git a/framework/src/onos/incubator/rpc/src/main/java/org/onosproject/incubator/rpc/impl/RemoteServiceManager.java b/framework/src/onos/incubator/rpc/src/main/java/org/onosproject/incubator/rpc/impl/RemoteServiceManager.java
new file mode 100644
index 00000000..3b851739
--- /dev/null
+++ b/framework/src/onos/incubator/rpc/src/main/java/org/onosproject/incubator/rpc/impl/RemoteServiceManager.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed 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.onosproject.incubator.rpc.impl;
+
+import java.net.URI;
+
+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.onosproject.incubator.rpc.RemoteServiceContext;
+import org.onosproject.incubator.rpc.RemoteServiceDirectory;
+import org.onosproject.incubator.rpc.RemoteServiceContextProvider;
+import org.onosproject.incubator.rpc.RemoteServiceContextProviderService;
+import org.onosproject.incubator.rpc.RemoteServiceProviderRegistry;
+import org.onosproject.net.provider.AbstractProviderService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.annotations.Beta;
+
+/**
+ * Provides RemoteService related APIs.
+ */
+@Beta
+@Component(immediate = true)
+@Service
+public class RemoteServiceManager extends AbstractProviderRegistry
+ implements RemoteServiceDirectory, RemoteServiceProviderRegistry {
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ @Activate
+ protected void activate() {
+ log.info("Started");
+ }
+
+ @Deactivate
+ protected void deactivate() {
+ log.info("Stopped");
+ }
+
+ @Override
+ public RemoteServiceContext get(URI uri) {
+ RemoteServiceContextProvider factory = getProvider(uri.getScheme());
+ if (factory != null) {
+ return factory.get(uri);
+ }
+ throw new UnsupportedOperationException(uri.getScheme() + " not supported");
+ }
+
+ private final class InternalRemoteServiceContextProviderService
+ extends AbstractProviderService<RemoteServiceContextProvider>
+ implements RemoteServiceContextProviderService {
+
+ public InternalRemoteServiceContextProviderService(RemoteServiceContextProvider provider) {
+ super(provider);
+ }
+ }
+
+ // make this abstract method if slicing out
+ @Override
+ protected RemoteServiceContextProviderService createProviderService(RemoteServiceContextProvider provider) {
+ return new InternalRemoteServiceContextProviderService(provider);
+ }
+
+}
diff --git a/framework/src/onos/incubator/rpc/src/main/java/org/onosproject/incubator/rpc/impl/package-info.java b/framework/src/onos/incubator/rpc/src/main/java/org/onosproject/incubator/rpc/impl/package-info.java
new file mode 100644
index 00000000..c77b4bec
--- /dev/null
+++ b/framework/src/onos/incubator/rpc/src/main/java/org/onosproject/incubator/rpc/impl/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed 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 the inter-cluster RPC service.
+ */
+package org.onosproject.incubator.rpc.impl;