本文整理汇总了Java中com.google.common.base.Throwables.getRootCause方法的典型用法代码示例。如果您正苦于以下问题:Java Throwables.getRootCause方法的具体用法?Java Throwables.getRootCause怎么用?Java Throwables.getRootCause使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.base.Throwables
的用法示例。
在下文中一共展示了Throwables.getRootCause方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doHandle
import com.google.common.base.Throwables; //导入方法依赖的package包/类
@Override
protected int doHandle(final String body, final String pathInfo) throws ServletException {
final Matcher matcher = SESSION_ID_PATTERN.matcher(pathInfo);
String sessionId = null;
if (matcher.find()) {
sessionId = matcher.group();
}
if (sessionExists(sessionId)) {
try {
bus.post(createEvent(sessionId, body));
} catch (final Exception e) {
final Throwable rootCause = Throwables.getRootCause(e);
if (rootCause instanceof ClientResourceException) {
throw (ClientResourceException) rootCause;
}
LOGGER.error("Error while creating event for test session. [Session ID: " + sessionId + "]", e);
throw new ServletException(e);
}
return SC_OK;
}
return SC_NOT_FOUND;
}
示例2: doHandle
import com.google.common.base.Throwables; //导入方法依赖的package包/类
@Override
protected int doHandle(final String body, final String pathInfo) throws ServletException {
TestResourceParameters parameters = this.getParametersFromPathInfo(pathInfo);
if (null != parameters && sessionExists(parameters.sessionId)) {
try {
bus.post(createEvent(parameters.sessionId, parameters.testId, body));
} catch (final Exception e) {
final Throwable rootCause = Throwables.getRootCause(e);
if (rootCause instanceof ClientResourceException) {
throw (ClientResourceException) rootCause;
}
LOGGER.error("Error while creating event for test session. [Session ID: " + parameters.sessionId + "]",
e);
throw new ServletException(e);
}
return SC_OK;
}
return SC_NOT_FOUND;
}
示例3: testPersisterConflictingVersionException
import com.google.common.base.Throwables; //导入方法依赖的package包/类
@Test
public void testPersisterConflictingVersionException() throws Exception {
doReturn(new TreeSet<>(Lists.newArrayList("namespace?module=module&revision=2012-12-12"))).when(mockedConfigSnapshot).getCapabilities();
final Capability cap = mock(Capability.class);
doReturn("namespace?module=module&revision=2012-12-12").when(cap).getCapabilityUri();
doReturn(Sets.newHashSet(cap)).when(facadeFactory).getCurrentCapabilities();
final ConfigExecution cfgExec = mock(ConfigExecution.class);
doReturn("cfg exec").when(cfgExec).toString();
doReturn(cfgExec).when(facade).getConfigExecution(any(Config.class), any(Element.class));
doNothing().when(facade).executeConfigExecution(any(ConfigExecution.class));
doThrow(ConflictingVersionException.class).when(facade).commitSilentTransaction();
doReturn(Sets.newHashSet(module)).when(yangStoreService).getModules();
final ConfigPusherImpl configPusher = new ConfigPusherImpl(facadeFactory, 0, 0);
configPusher.pushConfigs(Collections.singletonList(mockedConfigSnapshot));
try {
configPusher.processSingle(Lists.<AutoCloseable>newArrayList(), mBeanServer, mockedAggregator, true);
} catch (final IllegalStateException e) {
Throwable cause = Throwables.getRootCause(e);
assertTrue(cause instanceof ConflictingVersionException);
return;
}
fail();
}
示例4: handle
import com.google.common.base.Throwables; //导入方法依赖的package包/类
@SuppressWarnings("nls")
@Override
public void handle(Throwable exception, SectionInfo info, SectionsController controller, SectionEvent<?> event)
{
LOGGER.error("Error during ajax request", exception);
info.setRendered();
final HttpServletResponse response = info.getResponse();
if( !response.isCommitted() )
{
response.reset();
response.setStatus(500);
response.setHeader("Content-Type", "application/json");
try
{
final Map<String, Object> message = new HashMap<String, Object>();
final Throwable rootCause = Throwables.getRootCause(exception);
final String errorMessage = Utils.coalesce(rootCause.getMessage(), rootCause.getClass()
.getCanonicalName());
message.put("message", errorMessage);
mapper.writeValue(response.getWriter(), message);
}
catch( IOException e )
{
throw new SectionsRuntimeException(e);
}
}
}
示例5: checkErrors
import com.google.common.base.Throwables; //导入方法依赖的package包/类
private boolean checkErrors(SectionInfo info)
{
final FindUsesModel model = getModel(info);
try
{
getUsage(info);
}
catch( Exception e )
{
final Throwable t = Throwables.getRootCause(e);
LOGGER.error("Error loading usages", t);
if( t instanceof LmsUserNotFoundException )
{
model.setError(CurrentLocale.get(KEY_NO_USER, ((LmsUserNotFoundException) t).getUsername()));
}
else
{
model.setError(e.getLocalizedMessage());
}
}
return !Check.isEmpty(model.getError());
}
示例6: testConnection
import com.google.common.base.Throwables; //导入方法依赖的package包/类
@Override
public void testConnection(String driverClass, String jdbcUrl, String username, String password)
{
try
{
HikariDataSource source = new HikariDataSource();
source.setDriverClassName(driverClass);
source.setJdbcUrl(jdbcUrl);
source.setUsername(username);
source.setPassword(password);
source.setMaximumPoolSize(1);
String testQuery = "SELECT COUNT(*) FROM "
+ (jdbcUrl.startsWith("jdbc:oracle") ? "ALL_TABLES" : "information_schema.tables");
new JdbcTemplate(source).query(testQuery, IGNORE_ROWS);
source.close();
}
catch( Exception ex )
{
LOGGER.warn("Test connection failure", ex);
Throwable rootCause = Throwables.getRootCause(ex);
throw new RuntimeException("Error attempting to connect or while executing test query: "
+ rootCause.getMessage());
}
}
示例7: deliverEventToDelegate
import com.google.common.base.Throwables; //导入方法依赖的package包/类
protected void deliverEventToDelegate(FileWatcher watcher, FileWatcherEvent event) {
if(!Thread.currentThread().isInterrupted()) {
try {
delegate.onChange(watcher, event);
} catch (RuntimeException e) {
if (Throwables.getRootCause(e) instanceof InterruptedException) {
// delivery was interrupted, return silently
return;
}
throw e;
}
} else {
LOG.debug("Skipping event delivery since current thread is interrupted.");
}
}
示例8: switchToParentFrame
import com.google.common.base.Throwables; //导入方法依赖的package包/类
/**
* Switch driver focus to the parent of the specified frame context element.
* <p>
* <b>NOTE</b> This method initially invokes {@code driver.switchTo().parentFrame()}. If that fails with
* {@link UnsupportedCommandException}, it invokes {@code element.switchTo()} as a fallback.
*
* @param element frame context element
* @return parent search context
*/
public static SearchContext switchToParentFrame(RobustWebElement element) {
if (canSwitchToParentFrame) {
try {
return element.getWrappedDriver().switchTo().parentFrame();
} catch (WebDriverException e) {
if (Throwables.getRootCause(e) instanceof UnsupportedCommandException) {
canSwitchToParentFrame = false;
} else {
throw e;
}
}
}
return element.switchTo();
}
示例9: handleWatchFailure
import com.google.common.base.Throwables; //导入方法依赖的package包/类
private Object handleWatchFailure(Throwable thrown) {
if (Throwables.getRootCause(thrown) instanceof CancellationException &&
!watchService.isServerStopping()) {
// timeout happens
return HttpResponse.of(HttpStatus.NOT_MODIFIED);
}
return Exceptions.throwUnsafely(thrown);
}
示例10: creationTimeMillis
import com.google.common.base.Throwables; //导入方法依赖的package包/类
/**
* Returns the creation time of this {@link Repository}.
*/
default long creationTimeMillis() {
try {
final List<Commit> history = history(Revision.INIT, Revision.INIT, ALL_PATH, 1).join();
return history.get(0).when();
} catch (CompletionException e) {
final Throwable cause = Throwables.getRootCause(e);
Throwables.throwIfUnchecked(cause);
throw new StorageException("failed to retrieve the initial commit", cause);
}
}
示例11: author
import com.google.common.base.Throwables; //导入方法依赖的package包/类
/**
* Returns the author who created this {@link Repository}.
*/
default Author author() {
try {
final List<Commit> history = history(Revision.INIT, Revision.INIT, ALL_PATH, 1).join();
return history.get(0).author();
} catch (CompletionException e) {
final Throwable cause = Throwables.getRootCause(e);
Throwables.throwIfUnchecked(cause);
throw new StorageException("failed to retrieve the initial commit", cause);
}
}
示例12: CachingRepository
import com.google.common.base.Throwables; //导入方法依赖的package包/类
CachingRepository(Repository repo, RepositoryCache cache) {
this.repo = requireNonNull(repo, "repo");
this.cache = requireNonNull(cache, "cache").cache;
try {
final List<Commit> history = repo.history(Revision.INIT, Revision.INIT, ALL_PATH, 1).join();
firstCommit = history.get(0);
} catch (CompletionException e) {
final Throwable cause = Throwables.getRootCause(e);
Throwables.throwIfUnchecked(cause);
throw new StorageException("failed to retrieve the initial commit", cause);
}
}
示例13: handleKey
import com.google.common.base.Throwables; //导入方法依赖的package包/类
public static void handleKey(SelectionKey key) {
ConnectionHandler handler = ((ConnectionHandler)key.attachment());
try {
if (handler == null)
return;
if (!key.isValid()) {
handler.closeConnection(); // Key has been cancelled, make sure the socket gets closed
return;
}
if (key.isReadable()) {
// Do a socket read and invoke the connection's receiveBytes message
int read = handler.channel.read(handler.readBuff);
if (read == 0)
return; // Was probably waiting on a write
else if (read == -1) { // Socket was closed
key.cancel();
handler.closeConnection();
return;
}
// "flip" the buffer - setting the limit to the current position and setting position to 0
handler.readBuff.flip();
// Use connection.receiveBytes's return value as a check that it stopped reading at the right location
int bytesConsumed = checkNotNull(handler.connection).receiveBytes(handler.readBuff);
checkState(handler.readBuff.position() == bytesConsumed);
// Now drop the bytes which were read by compacting readBuff (resetting limit and keeping relative
// position)
handler.readBuff.compact();
}
if (key.isWritable())
handler.tryWriteBytes();
} catch (Exception e) {
// This can happen eg if the channel closes while the thread is about to get killed
// (ClosedByInterruptException), or if handler.connection.receiveBytes throws something
Throwable t = Throwables.getRootCause(e);
log.warn("Error handling SelectionKey: {} {}", t.getClass().getName(), t.getMessage() != null ? t.getMessage() : "", e);
handler.closeConnection();
}
}
示例14: handleKey
import com.google.common.base.Throwables; //导入方法依赖的package包/类
private void handleKey(SelectionKey key) throws IOException {
// We could have a !isValid() key here if the connection is already closed at this point
if (key.isValid() && key.isConnectable()) { // ie a client connection which has finished the initial connect process
// Create a ConnectionHandler and hook everything together
PendingConnect data = (PendingConnect) key.attachment();
StreamConnection connection = data.connection;
SocketChannel sc = (SocketChannel) key.channel();
ConnectionHandler handler = new ConnectionHandler(connection, key, connectedHandlers);
try {
if (sc.finishConnect()) {
log.info("Connected to {}", sc.socket().getRemoteSocketAddress());
key.interestOps((key.interestOps() | SelectionKey.OP_READ) & ~SelectionKey.OP_CONNECT).attach(handler);
connection.connectionOpened();
data.future.set(data.address);
} else {
log.warn("Failed to connect to {}", sc.socket().getRemoteSocketAddress());
handler.closeConnection(); // Failed to connect for some reason
data.future.setException(new ConnectException("Unknown reason"));
data.future = null;
}
} catch (Exception e) {
// If e is a CancelledKeyException, there is a race to get to interestOps after finishConnect() which
// may cause this. Otherwise it may be any arbitrary kind of connection failure.
// Calling sc.socket().getRemoteSocketAddress() here throws an exception, so we can only log the error itself
Throwable cause = Throwables.getRootCause(e);
log.warn("Failed to connect with exception: {}: {}", cause.getClass().getName(), cause.getMessage(), e);
handler.closeConnection();
data.future.setException(cause);
data.future = null;
}
} else // Process bytes read
ConnectionHandler.handleKey(key);
}
示例15: crashAlert
import com.google.common.base.Throwables; //导入方法依赖的package包/类
public static void crashAlert(Throwable t) {
t.printStackTrace();
Throwable rootCause = Throwables.getRootCause(t);
Runnable r = () -> {
runAlert((stage, controller) -> controller.crashAlert(stage, rootCause.toString()));
Platform.exit();
};
if (Platform.isFxApplicationThread())
r.run();
else
Platform.runLater(r);
}