Search in sources :

Example 1 with AsyncGet

use of org.apache.hadoop.util.concurrent.AsyncGet in project hadoop by apache.

the class ClientNamenodeProtocolTranslatorPB method getAclStatus.

@Override
public AclStatus getAclStatus(String src) throws IOException {
    GetAclStatusRequestProto req = GetAclStatusRequestProto.newBuilder().setSrc(src).build();
    try {
        if (Client.isAsynchronousMode()) {
            rpcProxy.getAclStatus(null, req);
            final AsyncGet<Message, Exception> asyncReturnMessage = ProtobufRpcEngine.getAsyncReturnMessage();
            final AsyncGet<AclStatus, Exception> asyncGet = new AsyncGet<AclStatus, Exception>() {

                @Override
                public AclStatus get(long timeout, TimeUnit unit) throws Exception {
                    return PBHelperClient.convert((GetAclStatusResponseProto) asyncReturnMessage.get(timeout, unit));
                }

                @Override
                public boolean isDone() {
                    return asyncReturnMessage.isDone();
                }
            };
            AsyncCallHandler.setLowerLayerAsyncReturn(asyncGet);
            return null;
        } else {
            return PBHelperClient.convert(rpcProxy.getAclStatus(null, req));
        }
    } catch (ServiceException e) {
        throw ProtobufHelper.getRemoteException(e);
    }
}
Also used : Message(com.google.protobuf.Message) AclStatus(org.apache.hadoop.fs.permission.AclStatus) ServiceException(com.google.protobuf.ServiceException) GetAclStatusRequestProto(org.apache.hadoop.hdfs.protocol.proto.AclProtos.GetAclStatusRequestProto) AsyncGet(org.apache.hadoop.util.concurrent.AsyncGet) TimeUnit(java.util.concurrent.TimeUnit) IOException(java.io.IOException) ServiceException(com.google.protobuf.ServiceException)

Example 2 with AsyncGet

use of org.apache.hadoop.util.concurrent.AsyncGet in project hadoop by apache.

the class Client method call.

/**
   * Make a call, passing <code>rpcRequest</code>, to the IPC server defined by
   * <code>remoteId</code>, returning the rpc response.
   *
   * @param rpcKind
   * @param rpcRequest -  contains serialized method and method parameters
   * @param remoteId - the target rpc server
   * @param serviceClass - service class for RPC
   * @param fallbackToSimpleAuth - set to true or false during this method to
   *   indicate if a secure client falls back to simple auth
   * @returns the rpc response
   * Throws exceptions if there are network problems or if the remote code
   * threw an exception.
   */
Writable call(RPC.RpcKind rpcKind, Writable rpcRequest, ConnectionId remoteId, int serviceClass, AtomicBoolean fallbackToSimpleAuth) throws IOException {
    final Call call = createCall(rpcKind, rpcRequest);
    final Connection connection = getConnection(remoteId, call, serviceClass, fallbackToSimpleAuth);
    try {
        checkAsyncCall();
        try {
            // send the rpc request
            connection.sendRpcRequest(call);
        } catch (RejectedExecutionException e) {
            throw new IOException("connection has been closed", e);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            LOG.warn("interrupted waiting to send rpc request to server", e);
            throw new IOException(e);
        }
    } catch (Exception e) {
        if (isAsynchronousMode()) {
            releaseAsyncCall();
        }
        throw e;
    }
    if (isAsynchronousMode()) {
        final AsyncGet<Writable, IOException> asyncGet = new AsyncGet<Writable, IOException>() {

            @Override
            public Writable get(long timeout, TimeUnit unit) throws IOException, TimeoutException {
                boolean done = true;
                try {
                    final Writable w = getRpcResponse(call, connection, timeout, unit);
                    if (w == null) {
                        done = false;
                        throw new TimeoutException(call + " timed out " + timeout + " " + unit);
                    }
                    return w;
                } finally {
                    if (done) {
                        releaseAsyncCall();
                    }
                }
            }

            @Override
            public boolean isDone() {
                synchronized (call) {
                    return call.done;
                }
            }
        };
        ASYNC_RPC_RESPONSE.set(asyncGet);
        return null;
    } else {
        return getRpcResponse(call, connection, -1, null);
    }
}
Also used : AsyncGet(org.apache.hadoop.util.concurrent.AsyncGet) Writable(org.apache.hadoop.io.Writable) ConnectTimeoutException(org.apache.hadoop.net.ConnectTimeoutException) ConnectTimeoutException(org.apache.hadoop.net.ConnectTimeoutException)

Aggregations

AsyncGet (org.apache.hadoop.util.concurrent.AsyncGet)2 Message (com.google.protobuf.Message)1 ServiceException (com.google.protobuf.ServiceException)1 IOException (java.io.IOException)1 TimeUnit (java.util.concurrent.TimeUnit)1 AclStatus (org.apache.hadoop.fs.permission.AclStatus)1 GetAclStatusRequestProto (org.apache.hadoop.hdfs.protocol.proto.AclProtos.GetAclStatusRequestProto)1 Writable (org.apache.hadoop.io.Writable)1 ConnectTimeoutException (org.apache.hadoop.net.ConnectTimeoutException)1