a619261a1ab4f8448bf6811c0d10f6b8ce1d7bbb
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / rpc / RpcManagerImpl.java
1 /**
2  * Copyright (c) 2015 Cisco Systems, Inc. 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 org.opendaylight.openflowplugin.impl.rpc;
9
10 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
11 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
12 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceInitializationPhaseHandler;
13 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
14 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcManager;
15 import org.opendaylight.openflowplugin.impl.util.MdSalRegistratorUtils;
16
17 public class RpcManagerImpl implements RpcManager {
18
19     private final RpcProviderRegistry rpcProviderRegistry;
20     private DeviceInitializationPhaseHandler deviceInitPhaseHandler;
21     private final Long maxRequestsQuota;
22
23     public RpcManagerImpl(final RpcProviderRegistry rpcProviderRegistry,
24                           final Long quotaValue) {
25         this.rpcProviderRegistry = rpcProviderRegistry;
26         maxRequestsQuota = quotaValue;
27     }
28
29     @Override
30     public void setDeviceInitializationPhaseHandler(final DeviceInitializationPhaseHandler handler) {
31         deviceInitPhaseHandler = handler;
32     }
33
34     @Override
35     public void onDeviceContextLevelUp(final DeviceContext deviceContext) {
36         final RpcContext rpcContext = new RpcContextImpl(deviceContext.getMessageSpy(), rpcProviderRegistry, deviceContext.getDeviceState().getNodeInstanceIdentifier(), maxRequestsQuota.intValue());
37         deviceContext.setDeviceDisconnectedHandler(rpcContext);
38         MdSalRegistratorUtils.registerServices(rpcContext, deviceContext);
39         // finish device initialization cycle back to DeviceManager
40         deviceInitPhaseHandler.onDeviceContextLevelUp(deviceContext);
41     }
42 }