bac7a659a2ab72ba2a7745496393b29a44280ca5
[controller.git] / benchmark / rpcbenchmark / src / main / java / rpcbenchmark / impl / GlobalBindingRTCServer.java
1 /*
2  * Copyright (c) 2015 Cisco Systems and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package rpcbenchmark.impl;
9
10 import com.google.common.collect.ImmutableClassToInstanceMap;
11 import org.opendaylight.mdsal.binding.api.RpcProviderService;
12 import org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.GlobalRpcBench;
13 import org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.RoutedRpcBench;
14 import org.opendaylight.yangtools.concepts.Registration;
15 import org.opendaylight.yangtools.yang.binding.Rpc;
16 import org.osgi.service.component.annotations.Reference;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 final class GlobalBindingRTCServer extends AbstractRpcbenchPayloadService implements AutoCloseable {
21     private static final Logger LOG = LoggerFactory.getLogger(GlobalBindingRTCServer.class);
22
23     private final Registration reg;
24
25     GlobalBindingRTCServer(@Reference final RpcProviderService rpcProvider) {
26         reg = rpcProvider.registerRpcImplementations(ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
27             .put(GlobalRpcBench.class, this::globalRpcBench)
28             .put(RoutedRpcBench.class, this::routedRpcBench)
29             .build());
30         LOG.debug("GlobalBindingRTCServer started");
31     }
32
33     @Override
34     public void close() {
35         reg.close();
36         LOG.debug("GlobalBindingRTCServer stopped");
37     }
38 }