2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 package org.opendaylight.controller.sal.core.impl;
\r
10 import java.util.Collection;
\r
11 import java.util.HashMap;
\r
12 import java.util.Map;
\r
13 import java.util.concurrent.Future;
\r
15 import org.opendaylight.controller.sal.core.api.BrokerService;
\r
16 import org.opendaylight.controller.sal.core.api.Consumer;
\r
17 import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession;
\r
18 import org.opendaylight.controller.yang.common.QName;
\r
19 import org.opendaylight.controller.yang.common.RpcResult;
\r
20 import org.opendaylight.controller.yang.data.api.CompositeNode;
\r
23 public class ConsumerSessionImpl implements ConsumerSession {
\r
25 private final BrokerImpl broker;
\r
26 private final Consumer consumer;
\r
28 private Map<Class<? extends BrokerService>, BrokerService> instantiatedServices = new HashMap<Class<? extends BrokerService>, BrokerService>();
\r
29 private boolean closed = false;
\r
31 public Consumer getConsumer() {
\r
35 public ConsumerSessionImpl(BrokerImpl broker, Consumer consumer) {
\r
36 this.broker = broker;
\r
37 this.consumer = consumer;
\r
41 public Future<RpcResult<CompositeNode>> rpc(QName rpc, CompositeNode input) {
\r
42 return broker.invokeRpc(rpc, input);
\r
46 public <T extends BrokerService> T getService(Class<T> service) {
\r
47 BrokerService potential = instantiatedServices.get(service);
\r
48 if (potential != null) {
\r
49 @SuppressWarnings("unchecked")
\r
50 T ret = (T) potential;
\r
53 T ret = this.broker.serviceFor(service, this);
\r
55 instantiatedServices.put(service, ret);
\r
61 public void close() {
\r
62 Collection<BrokerService> toStop = instantiatedServices.values();
\r
64 for (BrokerService brokerService : toStop) {
\r
65 brokerService.closeSession();
\r
67 broker.consumerSessionClosed(this);
\r
71 public boolean isClosed() {
\r