X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Frpc%2Fimpl%2FAbstractRpcExecutor.java;h=4c5e3ab5301e0dc1fa4f27507030bc479f49a012;hp=417cca653365bf96e925925226ee313513a79417;hb=refs%2Fchanges%2F27%2F8927%2F3;hpb=cb210bea2ab44aa2922ed86232c9db9a10452fc0 diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/rpc/impl/AbstractRpcExecutor.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/rpc/impl/AbstractRpcExecutor.java index 417cca6533..4c5e3ab530 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/rpc/impl/AbstractRpcExecutor.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/rpc/impl/AbstractRpcExecutor.java @@ -1,16 +1,15 @@ /* -* Copyright (c) 2014 Brocade Communications Systems, Inc. and others. All rights reserved. -* -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0 which accompanies this distribution, -* and is available at http://www.eclipse.org/legal/epl-v10.html -*/ + * Copyright (c) 2014 Brocade Communications Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ package org.opendaylight.controller.sal.restconf.rpc.impl; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; - import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException; import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorTag; import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType; @@ -21,7 +20,7 @@ import org.opendaylight.yangtools.yang.model.api.RpcDefinition; public abstract class AbstractRpcExecutor implements RpcExecutor { private final RpcDefinition rpcDef; - public AbstractRpcExecutor( RpcDefinition rpcDef ){ + public AbstractRpcExecutor(RpcDefinition rpcDef) { this.rpcDef = rpcDef; } @@ -31,60 +30,47 @@ public abstract class AbstractRpcExecutor implements RpcExecutor { } @Override - public RpcResult invokeRpc( CompositeNode rpcRequest ) - throws RestconfDocumentedException { + public RpcResult invokeRpc(CompositeNode rpcRequest) throws RestconfDocumentedException { try { - return getRpcResult( invokeRpcUnchecked( rpcRequest ) ); - } - catch( IllegalArgumentException e ) { - throw new RestconfDocumentedException( - e.getMessage(), ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE ); - } - catch( UnsupportedOperationException e ) { - throw new RestconfDocumentedException( - e.getMessage(), ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED ); - } - catch( Exception e ) { - throw new RestconfDocumentedException( - "The operation encountered an unexpected error while executing.", e ); + return getRpcResult(invokeRpcUnchecked(rpcRequest)); + } catch (IllegalArgumentException e) { + throw new RestconfDocumentedException(e.getMessage(), ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE); + } catch (UnsupportedOperationException e) { + throw new RestconfDocumentedException(e.getMessage(), ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED); + } catch (Exception e) { + throw new RestconfDocumentedException("The operation encountered an unexpected error while executing.", e); } } - protected abstract Future> invokeRpcUnchecked( CompositeNode rpcRequest ); + protected abstract Future> invokeRpcUnchecked(CompositeNode rpcRequest); - protected RpcResult getRpcResult( - Future> fromFuture ) { + protected RpcResult getRpcResult(Future> fromFuture) { try { return fromFuture.get(); - } - catch( InterruptedException e ) { + } catch (InterruptedException e) { throw new RestconfDocumentedException( - "The operation was interrupted while executing and did not complete.", - ErrorType.RPC, ErrorTag.PARTIAL_OPERATION ); - } - catch( ExecutionException e ) { + "The operation was interrupted while executing and did not complete.", ErrorType.RPC, + ErrorTag.PARTIAL_OPERATION); + } catch (ExecutionException e) { Throwable cause = e.getCause(); - if( cause instanceof CancellationException ) { - throw new RestconfDocumentedException( - "The operation was cancelled while executing.", - ErrorType.RPC, ErrorTag.PARTIAL_OPERATION ); - } - else if( cause != null ){ - while( cause.getCause() != null ) { + if (cause instanceof CancellationException) { + throw new RestconfDocumentedException("The operation was cancelled while executing.", ErrorType.RPC, + ErrorTag.PARTIAL_OPERATION); + } else if (cause != null) { + while (cause.getCause() != null) { cause = cause.getCause(); } - if( cause instanceof IllegalArgumentException ) { - throw new RestconfDocumentedException( - cause.getMessage(), ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE ); + if (cause instanceof IllegalArgumentException) { + throw new RestconfDocumentedException(cause.getMessage(), ErrorType.PROTOCOL, + ErrorTag.INVALID_VALUE); } - throw new RestconfDocumentedException( - "The operation encountered an unexpected error while executing.", cause ); - } - else { - throw new RestconfDocumentedException( - "The operation encountered an unexpected error while executing.", e ); + throw new RestconfDocumentedException("The operation encountered an unexpected error while executing.", + cause); + } else { + throw new RestconfDocumentedException("The operation encountered an unexpected error while executing.", + e); } } }