blob: b6afe06a8f8ab89a56f2e118017bed81db97cb76 [file] [log] [blame]
HIGUCHI Yuta279b8d12015-11-04 10:58:06 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
HIGUCHI Yuta279b8d12015-11-04 10:58:06 -08003 *
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 */
16package org.onosproject.incubator.rpc.impl;
17
Ray Milkeyd84f89b2018-08-17 14:54:17 -070018import com.google.common.annotations.Beta;
HIGUCHI Yuta279b8d12015-11-04 10:58:06 -080019import org.onosproject.incubator.rpc.RemoteServiceContext;
HIGUCHI Yuta279b8d12015-11-04 10:58:06 -080020import org.onosproject.incubator.rpc.RemoteServiceContextProvider;
21import org.onosproject.incubator.rpc.RemoteServiceContextProviderService;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070022import org.onosproject.incubator.rpc.RemoteServiceDirectory;
HIGUCHI Yuta279b8d12015-11-04 10:58:06 -080023import org.onosproject.incubator.rpc.RemoteServiceProviderRegistry;
24import org.onosproject.net.provider.AbstractProviderService;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070025import org.osgi.service.component.annotations.Activate;
26import org.osgi.service.component.annotations.Component;
27import org.osgi.service.component.annotations.Deactivate;
HIGUCHI Yuta279b8d12015-11-04 10:58:06 -080028import org.slf4j.Logger;
29import org.slf4j.LoggerFactory;
30
Ray Milkeyd84f89b2018-08-17 14:54:17 -070031import java.net.URI;
HIGUCHI Yuta279b8d12015-11-04 10:58:06 -080032
33/**
34 * Provides RemoteService related APIs.
35 */
36@Beta
Ray Milkeyd84f89b2018-08-17 14:54:17 -070037@Component(immediate = true, service = { RemoteServiceDirectory.class, RemoteServiceProviderRegistry.class })
HIGUCHI Yuta279b8d12015-11-04 10:58:06 -080038public class RemoteServiceManager extends AbstractProviderRegistry
39 implements RemoteServiceDirectory, RemoteServiceProviderRegistry {
40
41 private final Logger log = LoggerFactory.getLogger(getClass());
42
43 @Activate
44 protected void activate() {
45 log.info("Started");
46 }
47
48 @Deactivate
49 protected void deactivate() {
50 log.info("Stopped");
51 }
52
53 @Override
54 public RemoteServiceContext get(URI uri) {
55 RemoteServiceContextProvider factory = getProvider(uri.getScheme());
56 if (factory != null) {
57 return factory.get(uri);
58 }
59 throw new UnsupportedOperationException(uri.getScheme() + " not supported");
60 }
61
62 private final class InternalRemoteServiceContextProviderService
63 extends AbstractProviderService<RemoteServiceContextProvider>
64 implements RemoteServiceContextProviderService {
65
66 public InternalRemoteServiceContextProviderService(RemoteServiceContextProvider provider) {
67 super(provider);
68 }
69 }
70
71 // make this abstract method if slicing out
72 @Override
73 protected RemoteServiceContextProviderService createProviderService(RemoteServiceContextProvider provider) {
74 return new InternalRemoteServiceContextProviderService(provider);
75 }
76
77}