2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.openflowplugin.impl.services;
10 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
12 import com.google.common.base.Function;
13 import com.google.common.util.concurrent.SettableFuture;
14 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
15 import org.opendaylight.openflowplugin.api.openflow.rpc.RpcContext;
16 import org.opendaylight.yangtools.yang.binding.DataObject;
17 import org.opendaylight.yangtools.yang.common.RpcResult;
18 import org.slf4j.Logger;
19 import java.math.BigInteger;
20 import java.util.concurrent.Future;
26 public class ServiceCallProcessingUtil {
28 private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(ServiceCallProcessingUtil.class);
30 static <T extends DataObject, F> Future<RpcResult<T>> handleServiceCall(final RpcContext rpcContext,
31 final BigInteger connectionID, final DeviceContext deviceContext, final Function<BigInteger,Future<RpcResult<F>>> function) {
32 LOG.debug("Calling the FlowMod RPC method on MessageDispatchService");
33 // use primary connection
35 final RequestContext<T> requestContext = rpcContext.createRequestContext();
36 final SettableFuture<RpcResult<T>> result = rpcContext.storeOrFail(requestContext);
38 if (!result.isDone()) {
39 final Future<RpcResult<F>> resultFromOFLib = function.apply(connectionID);
41 final RpcResultConvertor<T> rpcResultConvertor = new RpcResultConvertor<>(requestContext, deviceContext);
42 rpcResultConvertor.processResultFromOfJava(resultFromOFLib);
45 RequestContextUtil.closeRequstContext(requestContext);