org.apache.hadoop.ipc.RemoteException.unwrapRemoteException()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(135)

本文整理了Java中org.apache.hadoop.ipc.RemoteException.unwrapRemoteException方法的一些代码示例,展示了RemoteException.unwrapRemoteException的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RemoteException.unwrapRemoteException方法的具体详情如下:
包路径:org.apache.hadoop.ipc.RemoteException
类名称:RemoteException
方法名:unwrapRemoteException

RemoteException.unwrapRemoteException介绍

[英]Instantiate and return the exception wrapped up by this remote exception.

This unwraps any Throwable that has a constructor taking a String as a parameter. Otherwise it returns this.
[中]实例化并返回由该远程异常包装的异常。
这将展开任何Throwable的构造函数,该构造函数将String作为参数。否则它会返回这个。

代码示例

代码示例来源:origin: apache/hbase

protected IOException unwrapException(IOException e) {
  if (e instanceof RemoteException) {
   e = ((RemoteException)e).unwrapRemoteException();
  }
  return e;
 }
}

代码示例来源:origin: apache/hbase

private static IOException unwrapException(IOException e) {
 if (e instanceof RemoteException) {
  return ((RemoteException)e).unwrapRemoteException();
 }
 return e;
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

private boolean isHealthCheckFailedException(Throwable t) {
 return ((t instanceof HealthCheckFailedException) ||
   (t instanceof RemoteException &&
   ((RemoteException)t).unwrapRemoteException(
     HealthCheckFailedException.class) instanceof
     HealthCheckFailedException));
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

private static boolean isWrappedStandbyException(Exception e) {
 if (!(e instanceof RemoteException)) {
  return false;
 }
 Exception unwrapped = ((RemoteException)e).unwrapRemoteException(
   StandbyException.class);
 return unwrapped instanceof StandbyException;
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

static RetriableException getWrappedRetriableException(Exception e) {
  if (!(e instanceof RemoteException)) {
   return null;
  }
  Exception unwrapped = ((RemoteException)e).unwrapRemoteException(
    RetriableException.class);
  return unwrapped instanceof RetriableException ? 
    (RetriableException) unwrapped : null;
 }
}

代码示例来源:origin: apache/storm

/**
 * Returns null if file already exists. throws if there was unexpected problem
 */
public static FSDataOutputStream tryCreateFile(FileSystem fs, Path file) throws IOException {
  try {
    FSDataOutputStream os = fs.create(file, false);
    return os;
  } catch (FileAlreadyExistsException e) {
    return null;
  } catch (RemoteException e) {
    if (e.unwrapRemoteException() instanceof AlreadyBeingCreatedException) {
      return null;
    } else { // unexpected error
      throw e;
    }
  }
}

代码示例来源:origin: apache/hbase

public Exception unwrapRemoteException() {
 final Throwable cause = getCause();
 if (cause instanceof RemoteException) {
  return ((RemoteException)cause).unwrapRemoteException();
 }
 if (cause instanceof Exception) {
  return (Exception)cause;
 }
 return new Exception(cause);
}

代码示例来源:origin: apache/hbase

static Throwable translateException(Throwable t) {
 if (t instanceof UndeclaredThrowableException && t.getCause() != null) {
  t = t.getCause();
 }
 if (t instanceof RemoteException) {
  t = ((RemoteException) t).unwrapRemoteException();
 }
 if (t instanceof ServiceException && t.getCause() != null) {
  t = translateException(t.getCause());
 }
 return t;
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

public static void monitorHealth(HAServiceProtocol svc,
  StateChangeRequestInfo reqInfo)
  throws IOException {
 try {
  svc.monitorHealth();
 } catch (RemoteException e) {
  throw e.unwrapRemoteException(HealthCheckFailedException.class);
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

public static void transitionToActive(HAServiceProtocol svc,
  StateChangeRequestInfo reqInfo)
  throws IOException {
 try {
  svc.transitionToActive(reqInfo);
 } catch (RemoteException e) {
  throw e.unwrapRemoteException(ServiceFailedException.class);
 }
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

public static void transitionToStandby(HAServiceProtocol svc,
   StateChangeRequestInfo reqInfo)
   throws IOException {
  try {
   svc.transitionToStandby(reqInfo);
  } catch (RemoteException e) {
   throw e.unwrapRemoteException(ServiceFailedException.class);
  }
 }
}

代码示例来源:origin: apache/hbase

private void shutdownWAL(final boolean close) {
 if (this.walFactory != null) {
  try {
   if (close) {
    walFactory.close();
   } else {
    walFactory.shutdown();
   }
  } catch (Throwable e) {
   e = e instanceof RemoteException ? ((RemoteException) e).unwrapRemoteException() : e;
   LOG.error("Shutdown / close of WAL failed: " + e);
   LOG.debug("Shutdown / close exception details:", e);
  }
 }
}

代码示例来源:origin: apache/hbase

private Throwable cleanup(final Throwable t, final String msg) {
 // Don't log as error if NSRE; NSRE is 'normal' operation.
 if (t instanceof NotServingRegionException) {
  LOG.debug("NotServingRegionException; " + t.getMessage());
  return t;
 }
 Throwable e = t instanceof RemoteException ? ((RemoteException) t).unwrapRemoteException() : t;
 if (msg == null) {
  LOG.error("", e);
 } else {
  LOG.error(msg, e);
 }
 if (!rpcServices.checkOOME(t)) {
  checkFileSystem();
 }
 return t;
}

代码示例来源:origin: apache/hbase

private static IOException makeIOExceptionOfException(Exception e) {
 Throwable t = e;
 if (e instanceof ServiceException) {
  t = e.getCause();
 }
 if (ExceptionUtil.isInterrupt(t)) {
  return ExceptionUtil.asInterrupt(t);
 }
 if (t instanceof RemoteException) {
  t = ((RemoteException)t).unwrapRemoteException();
 }
 return t instanceof IOException? (IOException)t: new HBaseIOException(t);
}

代码示例来源:origin: apache/hbase

private static IOException makeIOExceptionOfException(Exception e) {
 Throwable t = e;
 if (e instanceof ServiceException ||
   e instanceof org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) {
  t = e.getCause();
 }
 if (ExceptionUtil.isInterrupt(t)) {
  return ExceptionUtil.asInterrupt(t);
 }
 if (t instanceof RemoteException) {
  t = ((RemoteException)t).unwrapRemoteException();
 }
 return t instanceof IOException? (IOException)t: new HBaseIOException(t);
}

代码示例来源:origin: apache/hbase

@Override
public List<SecurityCapability> getSecurityCapabilities() throws IOException {
 try {
  return executeCallable(new MasterCallable<List<SecurityCapability>>(getConnection(),
    getRpcControllerFactory()) {
   @Override
   protected List<SecurityCapability> rpcCall() throws Exception {
    SecurityCapabilitiesRequest req = SecurityCapabilitiesRequest.newBuilder().build();
    return ProtobufUtil.toSecurityCapabilityList(
     master.getSecurityCapabilities(getRpcController(), req).getCapabilitiesList());
   }
  });
 } catch (IOException e) {
  if (e instanceof RemoteException) {
   e = ((RemoteException)e).unwrapRemoteException();
  }
  throw e;
 }
}

代码示例来源:origin: apache/hbase

@Test
public void testNotOverwrite() throws IOException {
 Path file = new Path("/" + name.getMethodName());
 try (FSDataOutputStream out1 = FS.create(file)) {
  try {
   FS.create(file, false);
   fail("Should fail as there is a file with the same name which is being written");
  } catch (RemoteException e) {
   // expected
   assertThat(e.unwrapRemoteException(), instanceOf(AlreadyBeingCreatedException.class));
  }
 }
}

代码示例来源:origin: apache/storm

@Test
public void testDoubleCreateSemantics() throws Exception {
  //1 create an already existing open file w/o override flag
  Path file1 = new Path(dir.toString() + Path.SEPARATOR_CHAR + "file1");
  try (FSDataOutputStream os1 = fs.create(file1, false)) {
    fs.create(file1, false); // should fail
    fail("Create did not throw an exception");
  } catch (RemoteException e) {
    Assert.assertEquals(AlreadyBeingCreatedException.class, e.unwrapRemoteException().getClass());
  }
  //2 close file and retry creation
  try {
    fs.create(file1, false);  // should still fail
    fail("Create did not throw an exception");
  } catch (FileAlreadyExistsException e) {
    // expecting this exception
  }
  //3 delete file and retry creation
  fs.delete(file1, false);
  try (FSDataOutputStream os2 = fs.create(file1, false)) {
    Assert.assertNotNull(os2);
  }
}

代码示例来源:origin: apache/storm

@Test
public void testAppendSemantics() throws Exception {
  //1 try to append to an open file
  Path file1 = new Path(dir.toString() + Path.SEPARATOR_CHAR + "file1");
  try (FSDataOutputStream os1 = fs.create(file1, false)) {
    fs.append(file1); // should fail
    fail("Append did not throw an exception");
  } catch (RemoteException e) {
    // expecting AlreadyBeingCreatedException inside RemoteException
    Assert.assertEquals(AlreadyBeingCreatedException.class, e.unwrapRemoteException().getClass());
  }
  //2 try to append to a closed file
  try (FSDataOutputStream os2 = fs.append(file1)) {
    assertThat(os2, notNull());
  }
}

代码示例来源:origin: apache/hbase

/**
 * This is important for fencing when recover from RS crash.
 */
@Test
public void testCreateParentFailed() throws IOException {
 Path f = new Path("/" + name.getMethodName() + "/test");
 EventLoop eventLoop = EVENT_LOOP_GROUP.next();
 try {
  FanOutOneBlockAsyncDFSOutputHelper.createOutput(FS, f, true, false, (short) 3,
   FS.getDefaultBlockSize(), eventLoop, CHANNEL_CLASS);
  fail("should fail with parent does not exist");
 } catch (RemoteException e) {
  LOG.info("expected exception caught", e);
  assertThat(e.unwrapRemoteException(), instanceOf(FileNotFoundException.class));
 }
}

相关文章