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 com.google.common.util.concurrent.ListenableFuture;
11 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
12 import org.opendaylight.yangtools.yang.common.RpcError;
13 import org.opendaylight.yangtools.yang.common.RpcResult;
14 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
15 import org.slf4j.Logger;
17 public final class RequestContextUtil {
19 private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(RequestContextUtil.class);
21 private RequestContextUtil() {
22 throw new UnsupportedOperationException();
26 public static <T> ListenableFuture<RpcResult<T>> closeRequestContextWithRpcError(final RequestContext<T> requestContext, final String errorMessage) {
27 RpcResultBuilder<T> rpcResultBuilder = RpcResultBuilder.<T>failed().withRpcError(RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, "", errorMessage));
28 requestContext.setResult(rpcResultBuilder.build());
29 closeRequestContext(requestContext);
30 return requestContext.getFuture();
33 public static void closeRequestContext(final RequestContext<?> requestContext) {
35 requestContext.close();
36 } catch (Exception e) {
37 LOG.error("Request context failed to close", e);