Exemplo n.º 1
0
  private void call(final int functionId, final XdrAble parameter, final XdrAble result)
      throws NFS2Exception, IOException {
    OncRpcClient client = null;
    int countCall = 0;
    while (true) {
      try {
        countCall++;
        client = getRpcClient();
        if (result == XdrVoid.XDR_VOID) {
          client.call(functionId, parameter, result);
        } else {
          ResultWithCode nfsResult = new ResultWithCode(result);
          client.call(functionId, parameter, nfsResult);
          if (nfsResult.getResultCode() != ResultCode.NFS_OK) {
            throw new NFS2Exception(nfsResult.getResultCode());
          }
        }
        break;
      } catch (Exception e) {
        if (client != null) {
          try {
            client.close();
          } catch (OncRpcException e1) {
            // Ignore this
          }
          client = null;
        }
        if (e instanceof RuntimeException) {
          throw (RuntimeException) e;
        }
        if (e instanceof OncRpcException) {
          if (countCall > 5) {
            throw new NFS2Exception(e.getMessage(), e);
          } else {
            LOGGER.warn(
                "An error occurs when nfs file system try to call the rpc method. Reason: "
                    + e.getMessage()
                    + " . It will try again");
            continue;
          }
        } else {
          throw new NFS2Exception(e.getMessage(), e);
        }
      } finally {

        if (client != null) {
          try {
            releaseRpcClient(client);
          } catch (IOException e) {
            // ignore
          }
        }
      }
    }
  }
Exemplo n.º 2
0
 public synchronized void close() throws IOException {
   closed = true;
   List<OncRpcException> exceptionList = new ArrayList<OncRpcException>();
   for (OncRpcClient client : rpcClientPool) {
     try {
       client.close();
     } catch (OncRpcException e) {
       exceptionList.add(e);
     }
   }
   if (exceptionList.size() != 0) {
     StringBuilder builder = new StringBuilder();
     builder.append("An error occurs when the mount client close connections. Reason:");
     for (OncRpcException anExceptionList : exceptionList) {
       builder.append(anExceptionList.getMessage());
       builder.append('.');
     }
     throw new IOException(builder.toString());
   }
 }