HIGUCHI Yuta | 279b8d1 | 2015-11-04 10:58:06 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
HIGUCHI Yuta | 279b8d1 | 2015-11-04 10:58:06 -0800 | [diff] [blame] | 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 | } |