blob: 2ce7bc83c815607376ff478b9917360f6b14adf9 [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
18import java.net.URI;
19
20import org.apache.felix.scr.annotations.Activate;
21import org.apache.felix.scr.annotations.Component;
22import org.apache.felix.scr.annotations.Deactivate;
23import org.apache.felix.scr.annotations.Service;
24import org.onosproject.incubator.rpc.RemoteServiceContext;
25import org.onosproject.incubator.rpc.RemoteServiceDirectory;
26import org.onosproject.incubator.rpc.RemoteServiceContextProvider;
27import org.onosproject.incubator.rpc.RemoteServiceContextProviderService;
28import org.onosproject.incubator.rpc.RemoteServiceProviderRegistry;
29import org.onosproject.net.provider.AbstractProviderService;
30import org.slf4j.Logger;
31import org.slf4j.LoggerFactory;
32
33import com.google.common.annotations.Beta;
34
35/**
36 * Provides RemoteService related APIs.
37 */
38@Beta
39@Component(immediate = true)
40@Service
41public 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}