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.RequestContext;
11 import org.opendaylight.yangtools.yang.common.RpcError;
12 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
13 import org.slf4j.Logger;
15 public final class RequestContextUtil {
17 private static final Logger LOG = org.slf4j.LoggerFactory.getLogger(RequestContextUtil.class);
19 private RequestContextUtil() {
20 throw new UnsupportedOperationException();
24 public static void closeRequestContextWithRpcError(final RequestContext<?> requestContext, String errorMessage) {
26 RpcResultBuilder rpcResultBuilder = RpcResultBuilder.failed().withRpcError(RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, "", errorMessage));
27 requestContext.getFuture().set(rpcResultBuilder.build());
28 closeRequstContext(requestContext);
31 public static void closeRequstContext(final RequestContext<?> requestContext) {
33 requestContext.close();
34 } catch (Exception e) {
35 LOG.debug("Request context wasn't closed. Exception message: {}", e.getMessage());