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
9 package org.opendaylight.openflowplugin.impl.services;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import com.google.common.util.concurrent.SettableFuture;
13 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
14 import org.opendaylight.yangtools.yang.binding.DataObject;
15 import org.opendaylight.yangtools.yang.common.RpcError;
16 import org.opendaylight.yangtools.yang.common.RpcResult;
17 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
18 import java.util.concurrent.ExecutionException;
19 import java.util.concurrent.Future;
20 import java.util.concurrent.TimeUnit;
21 import java.util.concurrent.TimeoutException;
24 * Created by Martin Bobak <mbobak@cisco.com> on 26.3.2015.
26 public class RpcResultConvertor<T extends DataObject> {
28 private final RequestContext requestContext;
30 public RpcResultConvertor(RequestContext requestContext) {
31 this.requestContext = requestContext;
34 public void processResultFromOfJava(final Future<RpcResult<Void>> futureResultFromOfLib,
35 final long waitTime) {
37 final RpcResult<Void> rpcResult = futureResultFromOfLib.get(waitTime, TimeUnit.MILLISECONDS);
38 if (!rpcResult.isSuccessful()) {
39 requestContext.getFuture().set(RpcResultBuilder.<T>failed().withRpcErrors(rpcResult.getErrors()).build());
40 requestContext.close();
42 } catch (InterruptedException | ExecutionException | TimeoutException e) {
43 requestContext.getFuture().set(RpcResultBuilder
45 .withError(RpcError.ErrorType.APPLICATION, "",
46 "Flow modification on device wasn't successfull.").build());
47 requestContext.close();
48 } catch (final Exception e) {
49 requestContext.getFuture().set(RpcResultBuilder.<T>failed()
50 .withError(RpcError.ErrorType.APPLICATION, "", "Flow translation to OF JAVA failed.").build());
51 requestContext.close();