Committed by
Yuta HIGUCHI
ONOS-3322 Sketch of Remote Service
Change-Id: I9c16b56b8d02d7f3995eafb1bb96211089774ca7
Showing
13 changed files
with
675 additions
and
0 deletions
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +package org.onosproject.incubator.rpc; | ||
| 18 | + | ||
| 19 | +import com.google.common.annotations.Beta; | ||
| 20 | + | ||
| 21 | +// Implementation is expected to be a handler for RPC channel | ||
| 22 | +// and shim-layer to convert Java Service interface calls to/from RPC call | ||
| 23 | +/** | ||
| 24 | + * Context for Remote service. | ||
| 25 | + */ | ||
| 26 | +@Beta | ||
| 27 | +public interface RemoteServiceContext { | ||
| 28 | + | ||
| 29 | + // we may need a method to check connection state? | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * Returns implementation of the specified service class. | ||
| 33 | + * | ||
| 34 | + * @param serviceClass service class | ||
| 35 | + * @param <T> type of service | ||
| 36 | + * @return implementation class | ||
| 37 | + * @throws UnsupportedOperationException if this context does not support it. | ||
| 38 | + */ | ||
| 39 | + <T> T get(Class<T> serviceClass); | ||
| 40 | +} |
incubator/api/src/main/java/org/onosproject/incubator/rpc/RemoteServiceContextProvider.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.incubator.rpc; | ||
| 17 | + | ||
| 18 | +import java.net.URI; | ||
| 19 | + | ||
| 20 | +import org.onosproject.net.provider.Provider; | ||
| 21 | + | ||
| 22 | +import com.google.common.annotations.Beta; | ||
| 23 | + | ||
| 24 | +//Factory to create RemoteServiceContext | ||
| 25 | +/** | ||
| 26 | + * Abstraction of a remote service implementation provider. | ||
| 27 | + */ | ||
| 28 | +@Beta | ||
| 29 | +public interface RemoteServiceContextProvider extends Provider { | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * Returns {@link RemoteServiceContext} for given URI. | ||
| 33 | + * | ||
| 34 | + * @param uri URI for remote end point. | ||
| 35 | + * @return {@link RemoteServiceContext} | ||
| 36 | + */ | ||
| 37 | + RemoteServiceContext get(URI uri); | ||
| 38 | +} |
incubator/api/src/main/java/org/onosproject/incubator/rpc/RemoteServiceContextProviderService.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.incubator.rpc; | ||
| 17 | + | ||
| 18 | +import org.onosproject.net.provider.ProviderService; | ||
| 19 | + | ||
| 20 | +import com.google.common.annotations.Beta; | ||
| 21 | + | ||
| 22 | +// Not completely sure if we will make use of this at the moment | ||
| 23 | +// added to follow existing {@link ProviderRegistry} pattern | ||
| 24 | +@Beta | ||
| 25 | +public interface RemoteServiceContextProviderService | ||
| 26 | + extends ProviderService<RemoteServiceContextProvider> { | ||
| 27 | + | ||
| 28 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.incubator.rpc; | ||
| 17 | + | ||
| 18 | +import java.net.URI; | ||
| 19 | + | ||
| 20 | +import com.google.common.annotations.Beta; | ||
| 21 | + | ||
| 22 | +// This is actually the RPC Service, where consumers get | ||
| 23 | +// RemoteSericeContext (~= RPC Session) for given URI | ||
| 24 | +// expected to be implemented by some Manager class on Lower-side ONOS | ||
| 25 | +/** | ||
| 26 | + * Service for retrieving RPC session handler ({@link RemoteServiceContext}). | ||
| 27 | + */ | ||
| 28 | +@Beta | ||
| 29 | +public interface RemoteServiceDirectory { | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * Returns remote service context. | ||
| 33 | + * | ||
| 34 | + * @param uri URI representing remote end point. e.g., (grpc://hostname:port) | ||
| 35 | + * @return remote service context | ||
| 36 | + * @throws UnsupportedOperationException if URI scheme was not supported. | ||
| 37 | + */ | ||
| 38 | + RemoteServiceContext get(URI uri); | ||
| 39 | + | ||
| 40 | +} |
incubator/api/src/main/java/org/onosproject/incubator/rpc/RemoteServiceProviderRegistry.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.incubator.rpc; | ||
| 17 | + | ||
| 18 | +import org.onosproject.net.provider.ProviderRegistry; | ||
| 19 | + | ||
| 20 | +import com.google.common.annotations.Beta; | ||
| 21 | + | ||
| 22 | +/** | ||
| 23 | + * Abstraction of a remote service provider registry. | ||
| 24 | + */ | ||
| 25 | +@Beta | ||
| 26 | +public interface RemoteServiceProviderRegistry | ||
| 27 | + extends ProviderRegistry<RemoteServiceContextProvider, | ||
| 28 | + RemoteServiceContextProviderService> { | ||
| 29 | + | ||
| 30 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * Incubating inter-cluster RPC APIs. | ||
| 19 | + */ | ||
| 20 | +package org.onosproject.incubator.rpc; |
incubator/rpc/pom.xml
0 → 100644
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<!-- | ||
| 3 | + ~ Copyright 2015 Open Networking Laboratory | ||
| 4 | + ~ | ||
| 5 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 6 | + ~ you may not use this file except in compliance with the License. | ||
| 7 | + ~ You may obtain a copy of the License at | ||
| 8 | + ~ | ||
| 9 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
| 10 | + ~ | ||
| 11 | + ~ Unless required by applicable law or agreed to in writing, software | ||
| 12 | + ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
| 13 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 14 | + ~ See the License for the specific language governing permissions and | ||
| 15 | + ~ limitations under the License. | ||
| 16 | + --> | ||
| 17 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| 18 | + <modelVersion>4.0.0</modelVersion> | ||
| 19 | + <parent> | ||
| 20 | + <artifactId>onos-incubator</artifactId> | ||
| 21 | + <groupId>org.onosproject</groupId> | ||
| 22 | + <version>1.4.0-SNAPSHOT</version> | ||
| 23 | + </parent> | ||
| 24 | + | ||
| 25 | + <artifactId>onos-incubator-rpc</artifactId> | ||
| 26 | + <packaging>bundle</packaging> | ||
| 27 | + | ||
| 28 | + <description>ONOS inter-cluster RPC service</description> | ||
| 29 | + <url>http://onosproject.org</url> | ||
| 30 | + | ||
| 31 | + <properties> | ||
| 32 | + <onos.app.name>org.onosproject.incubator.rpc</onos.app.name> | ||
| 33 | + </properties> | ||
| 34 | + | ||
| 35 | + <dependencies> | ||
| 36 | + <dependency> | ||
| 37 | + <groupId>org.onosproject</groupId> | ||
| 38 | + <artifactId>onos-api</artifactId> | ||
| 39 | + </dependency> | ||
| 40 | + | ||
| 41 | + <dependency> | ||
| 42 | + <groupId>org.onosproject</groupId> | ||
| 43 | + <artifactId>onlab-osgi</artifactId> | ||
| 44 | + </dependency> | ||
| 45 | + | ||
| 46 | + <dependency> | ||
| 47 | + <groupId>junit</groupId> | ||
| 48 | + <artifactId>junit</artifactId> | ||
| 49 | + <scope>test</scope> | ||
| 50 | + </dependency> | ||
| 51 | + | ||
| 52 | + <dependency> | ||
| 53 | + <groupId>org.onosproject</groupId> | ||
| 54 | + <artifactId>onos-api</artifactId> | ||
| 55 | + <scope>test</scope> | ||
| 56 | + <classifier>tests</classifier> | ||
| 57 | + </dependency> | ||
| 58 | + | ||
| 59 | + <dependency> | ||
| 60 | + <groupId>org.onosproject</groupId> | ||
| 61 | + <artifactId>onos-incubator-api</artifactId> | ||
| 62 | + </dependency> | ||
| 63 | + | ||
| 64 | + <dependency> | ||
| 65 | + <groupId>org.apache.felix</groupId> | ||
| 66 | + <artifactId>org.apache.felix.scr.annotations</artifactId> | ||
| 67 | + <scope>provided</scope> | ||
| 68 | + </dependency> | ||
| 69 | + | ||
| 70 | + </dependencies> | ||
| 71 | + | ||
| 72 | + <build> | ||
| 73 | + <plugins> | ||
| 74 | + <plugin> | ||
| 75 | + <groupId>org.apache.felix</groupId> | ||
| 76 | + <artifactId>maven-bundle-plugin</artifactId> | ||
| 77 | + <extensions>true</extensions> | ||
| 78 | + </plugin> | ||
| 79 | + <plugin> | ||
| 80 | + <groupId>org.apache.maven.plugins</groupId> | ||
| 81 | + <artifactId>maven-compiler-plugin</artifactId> | ||
| 82 | + <configuration> | ||
| 83 | + <source>1.8</source> | ||
| 84 | + <target>1.8</target> | ||
| 85 | + </configuration> | ||
| 86 | + </plugin> | ||
| 87 | + <plugin> | ||
| 88 | + <groupId>org.apache.felix</groupId> | ||
| 89 | + <artifactId>maven-scr-plugin</artifactId> | ||
| 90 | + <executions> | ||
| 91 | + <execution> | ||
| 92 | + <id>generate-scr-srcdescriptor</id> | ||
| 93 | + <goals> | ||
| 94 | + <goal>scr</goal> | ||
| 95 | + </goals> | ||
| 96 | + </execution> | ||
| 97 | + </executions> | ||
| 98 | + <configuration> | ||
| 99 | + <supportedProjectTypes> | ||
| 100 | + <supportedProjectType>bundle</supportedProjectType> | ||
| 101 | + <supportedProjectType>war</supportedProjectType> | ||
| 102 | + </supportedProjectTypes> | ||
| 103 | + </configuration> | ||
| 104 | + </plugin> | ||
| 105 | + <plugin> | ||
| 106 | + <groupId>org.onosproject</groupId> | ||
| 107 | + <artifactId>onos-maven-plugin</artifactId> | ||
| 108 | + <executions> | ||
| 109 | + <execution> | ||
| 110 | + <id>cfg</id> | ||
| 111 | + <phase>generate-resources</phase> | ||
| 112 | + <goals> | ||
| 113 | + <goal>cfg</goal> | ||
| 114 | + </goals> | ||
| 115 | + </execution> | ||
| 116 | + <execution> | ||
| 117 | + <id>swagger</id> | ||
| 118 | + <phase>generate-sources</phase> | ||
| 119 | + <goals> | ||
| 120 | + <goal>swagger</goal> | ||
| 121 | + </goals> | ||
| 122 | + </execution> | ||
| 123 | + <execution> | ||
| 124 | + <id>app</id> | ||
| 125 | + <phase>package</phase> | ||
| 126 | + <goals> | ||
| 127 | + <goal>app</goal> | ||
| 128 | + </goals> | ||
| 129 | + </execution> | ||
| 130 | + </executions> | ||
| 131 | + </plugin> | ||
| 132 | + </plugins> | ||
| 133 | + </build> | ||
| 134 | + | ||
| 135 | +</project> |
incubator/rpc/src/main/java/org/onosproject/incubator/rpc/impl/AbstractProviderRegistry.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.incubator.rpc.impl; | ||
| 17 | + | ||
| 18 | +import java.util.Map; | ||
| 19 | +import java.util.Set; | ||
| 20 | + | ||
| 21 | +import org.onosproject.incubator.rpc.RemoteServiceContextProvider; | ||
| 22 | +import org.onosproject.incubator.rpc.RemoteServiceContextProviderService; | ||
| 23 | +import org.onosproject.incubator.rpc.RemoteServiceProviderRegistry; | ||
| 24 | +import org.onosproject.net.provider.ProviderId; | ||
| 25 | + | ||
| 26 | +import com.google.common.annotations.Beta; | ||
| 27 | +import com.google.common.collect.ImmutableSet; | ||
| 28 | +import com.google.common.collect.Maps; | ||
| 29 | + | ||
| 30 | +// Probably should change name or add missing feature (provider from scheme) to | ||
| 31 | +// org.onosproject.net.provider.AbstractProviderRegistry<P, S> | ||
| 32 | +@Beta | ||
| 33 | +abstract class AbstractProviderRegistry | ||
| 34 | + implements RemoteServiceProviderRegistry { | ||
| 35 | + | ||
| 36 | + | ||
| 37 | + private final Map<ProviderId, RemoteServiceContextProvider> pidToProvider = Maps.newConcurrentMap(); | ||
| 38 | + private final Map<String, RemoteServiceContextProvider> schemeToProvider = Maps.newConcurrentMap(); | ||
| 39 | + | ||
| 40 | + public AbstractProviderRegistry() { | ||
| 41 | + super(); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + protected abstract RemoteServiceContextProviderService createProviderService(RemoteServiceContextProvider provider); | ||
| 45 | + | ||
| 46 | + @Override | ||
| 47 | + public synchronized RemoteServiceContextProviderService register(RemoteServiceContextProvider provider) { | ||
| 48 | + // TODO check if it already exists | ||
| 49 | + pidToProvider.put(provider.id(), provider); | ||
| 50 | + schemeToProvider.put(provider.id().scheme(), provider); | ||
| 51 | + return createProviderService(provider); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + @Override | ||
| 55 | + public synchronized void unregister(RemoteServiceContextProvider provider) { | ||
| 56 | + pidToProvider.remove(provider.id(), provider); | ||
| 57 | + schemeToProvider.remove(provider.id().scheme(), provider); | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + @Override | ||
| 61 | + public Set<ProviderId> getProviders() { | ||
| 62 | + return ImmutableSet.copyOf(pidToProvider.keySet()); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + protected RemoteServiceContextProvider getProvider(ProviderId pid) { | ||
| 66 | + return pidToProvider.get(pid); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + protected RemoteServiceContextProvider getProvider(String scheme) { | ||
| 70 | + return schemeToProvider.get(scheme); | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | +} |
incubator/rpc/src/main/java/org/onosproject/incubator/rpc/impl/LocalRemoteServiceProvider.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.incubator.rpc.impl; | ||
| 17 | + | ||
| 18 | +import static com.google.common.base.Preconditions.checkArgument; | ||
| 19 | + | ||
| 20 | +import java.net.URI; | ||
| 21 | +import java.util.Map; | ||
| 22 | +import java.util.Objects; | ||
| 23 | +import java.util.concurrent.ConcurrentHashMap; | ||
| 24 | + | ||
| 25 | +import org.apache.felix.scr.annotations.Activate; | ||
| 26 | +import org.apache.felix.scr.annotations.Component; | ||
| 27 | +import org.apache.felix.scr.annotations.Deactivate; | ||
| 28 | +import org.apache.felix.scr.annotations.Reference; | ||
| 29 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
| 30 | +import org.onlab.osgi.DefaultServiceDirectory; | ||
| 31 | +import org.onlab.osgi.ServiceDirectory; | ||
| 32 | +import org.onosproject.incubator.rpc.RemoteServiceContext; | ||
| 33 | +import org.onosproject.incubator.rpc.RemoteServiceContextProvider; | ||
| 34 | +import org.onosproject.incubator.rpc.RemoteServiceContextProviderService; | ||
| 35 | +import org.onosproject.incubator.rpc.RemoteServiceProviderRegistry; | ||
| 36 | +import org.onosproject.net.provider.ProviderId; | ||
| 37 | +import org.slf4j.Logger; | ||
| 38 | +import org.slf4j.LoggerFactory; | ||
| 39 | + | ||
| 40 | +import com.google.common.annotations.Beta; | ||
| 41 | + | ||
| 42 | +/** | ||
| 43 | + * Sample implementation of RemoteServiceContextProvider. | ||
| 44 | + * | ||
| 45 | + * Scheme: "local", calling corresponding local service on request. | ||
| 46 | + * Only expected for testing until real RPC implementation is ready. | ||
| 47 | + * | ||
| 48 | + * Note: This is expected to be removed or separated out as separate bundle | ||
| 49 | + * once other RPC implementaion became available. | ||
| 50 | + */ | ||
| 51 | +@Beta | ||
| 52 | +@Component(immediate = true) | ||
| 53 | +public class LocalRemoteServiceProvider implements RemoteServiceContextProvider { | ||
| 54 | + | ||
| 55 | + private final Logger log = LoggerFactory.getLogger(getClass()); | ||
| 56 | + | ||
| 57 | + private RemoteServiceContext theOne = new LocalServiceContext(); | ||
| 58 | + | ||
| 59 | + private static final ProviderId PID = new ProviderId("local", "org.onosproject.rpc.provider.local"); | ||
| 60 | + | ||
| 61 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
| 62 | + protected RemoteServiceProviderRegistry rpcRegistry; | ||
| 63 | + | ||
| 64 | + private final Map<Class<? extends Object>, Object> services = new ConcurrentHashMap<>(); | ||
| 65 | + | ||
| 66 | + private RemoteServiceContextProviderService providerService; | ||
| 67 | + | ||
| 68 | + @Activate | ||
| 69 | + protected void activate() { | ||
| 70 | + | ||
| 71 | + services.put(SomeOtherService.class, new SomeOtherServiceImpl()); | ||
| 72 | + | ||
| 73 | + providerService = rpcRegistry.register(this); | ||
| 74 | + log.info("Started"); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + @Deactivate | ||
| 78 | + protected void deactivate() { | ||
| 79 | + rpcRegistry.unregister(this); | ||
| 80 | + log.info("Stopped"); | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + @Override | ||
| 84 | + public ProviderId id() { | ||
| 85 | + return PID; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + @Override | ||
| 89 | + public RemoteServiceContext get(URI uri) { | ||
| 90 | + checkArgument(Objects.equals(uri.getScheme(), "local")); | ||
| 91 | + return theOne; | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + private final class LocalServiceContext implements RemoteServiceContext { | ||
| 95 | + | ||
| 96 | + private final ServiceDirectory directory = new DefaultServiceDirectory(); | ||
| 97 | + | ||
| 98 | + @Override | ||
| 99 | + public <T> T get(Class<T> serviceClass) { | ||
| 100 | + @SuppressWarnings("unchecked") | ||
| 101 | + T service = (T) services.get(serviceClass); | ||
| 102 | + if (service != null) { | ||
| 103 | + return service; | ||
| 104 | + } | ||
| 105 | + // look up OSGi services on this host. | ||
| 106 | + // provided to unblock development depending on RPC. | ||
| 107 | + return directory.get(serviceClass); | ||
| 108 | + } | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + // Service provided by RPC can be non-OSGi Service | ||
| 112 | + public static interface SomeOtherService { | ||
| 113 | + String hello(); | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + public static class SomeOtherServiceImpl implements SomeOtherService { | ||
| 117 | + | ||
| 118 | + @Override | ||
| 119 | + public String hello() { | ||
| 120 | + return "Goodbye"; | ||
| 121 | + } | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.incubator.rpc.impl; | ||
| 17 | + | ||
| 18 | +import java.net.URI; | ||
| 19 | + | ||
| 20 | +import org.apache.felix.scr.annotations.Activate; | ||
| 21 | +import org.apache.felix.scr.annotations.Component; | ||
| 22 | +import org.apache.felix.scr.annotations.Deactivate; | ||
| 23 | +import org.apache.felix.scr.annotations.Service; | ||
| 24 | +import org.onosproject.incubator.rpc.RemoteServiceContext; | ||
| 25 | +import org.onosproject.incubator.rpc.RemoteServiceDirectory; | ||
| 26 | +import org.onosproject.incubator.rpc.RemoteServiceContextProvider; | ||
| 27 | +import org.onosproject.incubator.rpc.RemoteServiceContextProviderService; | ||
| 28 | +import org.onosproject.incubator.rpc.RemoteServiceProviderRegistry; | ||
| 29 | +import org.onosproject.net.provider.AbstractProviderService; | ||
| 30 | +import org.slf4j.Logger; | ||
| 31 | +import org.slf4j.LoggerFactory; | ||
| 32 | + | ||
| 33 | +import com.google.common.annotations.Beta; | ||
| 34 | + | ||
| 35 | +/** | ||
| 36 | + * Provides RemoteService related APIs. | ||
| 37 | + */ | ||
| 38 | +@Beta | ||
| 39 | +@Component(immediate = true) | ||
| 40 | +@Service | ||
| 41 | +public class RemoteServiceManager extends AbstractProviderRegistry | ||
| 42 | + implements RemoteServiceDirectory, RemoteServiceProviderRegistry { | ||
| 43 | + | ||
| 44 | + private final Logger log = LoggerFactory.getLogger(getClass()); | ||
| 45 | + | ||
| 46 | + @Activate | ||
| 47 | + protected void activate() { | ||
| 48 | + log.info("Started"); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + @Deactivate | ||
| 52 | + protected void deactivate() { | ||
| 53 | + log.info("Stopped"); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + @Override | ||
| 57 | + public RemoteServiceContext get(URI uri) { | ||
| 58 | + RemoteServiceContextProvider factory = getProvider(uri.getScheme()); | ||
| 59 | + if (factory != null) { | ||
| 60 | + return factory.get(uri); | ||
| 61 | + } | ||
| 62 | + throw new UnsupportedOperationException(uri.getScheme() + " not supported"); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + private final class InternalRemoteServiceContextProviderService | ||
| 66 | + extends AbstractProviderService<RemoteServiceContextProvider> | ||
| 67 | + implements RemoteServiceContextProviderService { | ||
| 68 | + | ||
| 69 | + public InternalRemoteServiceContextProviderService(RemoteServiceContextProvider provider) { | ||
| 70 | + super(provider); | ||
| 71 | + } | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + // make this abstract method if slicing out | ||
| 75 | + @Override | ||
| 76 | + protected RemoteServiceContextProviderService createProviderService(RemoteServiceContextProvider provider) { | ||
| 77 | + return new InternalRemoteServiceContextProviderService(provider); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2015 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | + | ||
| 17 | +/** | ||
| 18 | + * Implementation of the inter-cluster RPC service. | ||
| 19 | + */ | ||
| 20 | +package org.onosproject.incubator.rpc.impl; |
incubator/rpc/src/test/java/org/onosproject/incubator/rpc/impl/RemoteServiceManagerTest.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2014 Open Networking Laboratory | ||
| 3 | + * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | + * you may not use this file except in compliance with the License. | ||
| 6 | + * You may obtain a copy of the License at | ||
| 7 | + * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | + * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | + * See the License for the specific language governing permissions and | ||
| 14 | + * limitations under the License. | ||
| 15 | + */ | ||
| 16 | +package org.onosproject.incubator.rpc.impl; | ||
| 17 | + | ||
| 18 | +import org.junit.After; | ||
| 19 | +import org.junit.Before; | ||
| 20 | +import org.junit.Test; | ||
| 21 | + | ||
| 22 | +/** | ||
| 23 | + * Set of tests of the ONOS application component. | ||
| 24 | + */ | ||
| 25 | +public class RemoteServiceManagerTest { | ||
| 26 | + | ||
| 27 | + private RemoteServiceManager component; | ||
| 28 | + | ||
| 29 | + @Before | ||
| 30 | + public void setUp() { | ||
| 31 | + component = new RemoteServiceManager(); | ||
| 32 | + component.activate(); | ||
| 33 | + | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + @After | ||
| 37 | + public void tearDown() { | ||
| 38 | + component.deactivate(); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + @Test | ||
| 42 | + public void basics() { | ||
| 43 | + | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | +} |
-
Please register or login to post a comment