Java Code Examples for com.google.common.util.concurrent.UncheckedExecutionException#getCause()
The following examples show how to use
com.google.common.util.concurrent.UncheckedExecutionException#getCause() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PartitionedDatasetWriter.java From kite with Apache License 2.0 | 6 votes |
@Override public void write(E entity) { Preconditions.checkState(state.equals(ReaderWriterState.OPEN), "Attempt to write to a writer in state:%s", state); accessor.keyFor(entity, provided, reusedKey); DatasetWriter<E> writer = cachedWriters.getIfPresent(reusedKey); if (writer == null) { // avoid checking in every whether the entity belongs in the view by only // checking when a new writer is created Preconditions.checkArgument(view.includes(entity), "View %s does not include entity %s", view, entity); // get a new key because it is stored in the cache StorageKey key = StorageKey.copy(reusedKey); try { writer = cachedWriters.getUnchecked(key); } catch (UncheckedExecutionException ex) { throw new IllegalArgumentException( "Problem creating view for entity: " + entity, ex.getCause()); } } writer.write(entity); }
Example 2
Source File: SequenceGeneratorFactoryBean.java From cloud-config with MIT License | 6 votes |
@Override public String next(String seqName) throws Exception { String routingKey = resolver.get().orNull(); if( routingKey!=null ) { logger.debug("Routing sequence generator lookup key is '{}'", routingKey); } else { logger.warn("Routing sequence generator lookup key cannot be found in current context!"); routingKey = "__absent_tenant__"; } try { return localResourceStore.getUnchecked(routingKey).next(seqName); } catch (UncheckedExecutionException e) { Throwable cause = e.getCause(); throw new IllegalStateException("Cannot determine target DataSource for lookup key [" + routingKey + "]", cause); } }
Example 3
Source File: MessagingTest.java From rapid with Apache License 2.0 | 6 votes |
/** * Tests all GrpcClient request types to an endpoint that exists, but after shutdown is invoked. */ @Test public void rpcClientErrorHandlingAfterShutdown() throws InterruptedException { final int basePort = 1234; final Endpoint clientAddr = Utils.hostFromParts(LOCALHOST_IP, basePort); final Endpoint dst = Utils.hostFromParts(LOCALHOST_IP, 4321); final SharedResources resources = new SharedResources(clientAddr); final Settings settings = new Settings(); final IMessagingClient client = new GrpcClient(clientAddr, resources, settings); client.shutdown(); resources.shutdown(); try { client.sendMessage(dst, Utils.toRapidRequest(ProbeMessage.getDefaultInstance())).get(); fail("sendProbeMessage did not throw an exception"); } catch (final ExecutionException | GrpcClient.ShuttingDownException ignored) { } catch (final UncheckedExecutionException e) { if (!(e.getCause() instanceof GrpcClient.ShuttingDownException)) { throw e; } } }
Example 4
Source File: LocalizedLazyThreadSafeProducer.java From arctic-sea with Apache License 2.0 | 6 votes |
@Override public T get(Locale language) throws ConfigurationError { if (language == null) { return get(); } else { try { return this.cache.getUnchecked(language); } catch (UncheckedExecutionException ex) { if (ex.getCause() instanceof ConfigurationError) { throw (ConfigurationError) ex.getCause(); } else { throw ex; } } } }
Example 5
Source File: InMemoryTopology.java From incubator-gobblin with Apache License 2.0 | 6 votes |
public Collection<ConfigKeyPath> getImportedBy(ConfigKeyPath configKey, Optional<Config> runtimeConfig) { if (this.fullImportedByMap != null) { return this.fullImportedByMap.get(configKey); } try { return this.ownImportedByMap.get(configKey, () -> this.fallback.getImportedBy(configKey, runtimeConfig)); } catch (UncheckedExecutionException exc) { if (exc.getCause() instanceof UnsupportedOperationException) { computeImportedByMap(runtimeConfig); return getImportedBy(configKey, runtimeConfig); } else { throw new RuntimeException(exc); } } catch (ExecutionException ee) { throw new RuntimeException(ee); } }
Example 6
Source File: CompositeService.java From twill with Apache License 2.0 | 6 votes |
@Override protected void startUp() throws Exception { Throwable failureCause = null; for (Service service : services) { try { service.startAndWait(); } catch (UncheckedExecutionException e) { failureCause = e.getCause(); break; } } if (failureCause != null) { // Stop all running services and then throw the failure exception try { stopAll(); } catch (Throwable t) { // Ignore the stop error. Just log. LOG.warn("Failed when stopping all services on start failure", t); } Throwables.propagateIfPossible(failureCause, Exception.class); throw new RuntimeException(failureCause); } }
Example 7
Source File: PathTypeCoercer.java From buck with Apache License 2.0 | 5 votes |
@Override public Path coerceToUnconfigured( CellNameResolver cellRoots, ProjectFilesystem filesystem, ForwardRelativePath pathRelativeToProjectRoot, Object object) throws CoerceFailedException { if (object instanceof String) { String pathString = (String) object; if (pathString.isEmpty()) { throw new CoerceFailedException("invalid path"); } try { Path fsPath = pathRelativeToProjectRoot.toPath(filesystem.getFileSystem()); Path resultPath = pathCache.getUnchecked(fsPath).getUnchecked(pathString); if (resultPath.isAbsolute()) { throw CoerceFailedException.simple( object, getOutputType(), "Path cannot contain an absolute path"); } if (resultPath.startsWith("..")) { throw CoerceFailedException.simple( object, getOutputType(), "Path cannot point to above repository root"); } return resultPath; } catch (UncheckedExecutionException e) { throw new CoerceFailedException( String.format("Could not convert '%s' to a Path", pathString), e.getCause()); } } else { throw CoerceFailedException.simple(object, getOutputType()); } }
Example 8
Source File: AbstractRoutingResourceFactoryBean.java From cloud-config with MIT License | 5 votes |
protected T getLocalResource(String routingKey) { try { return localResourceStore.getUnchecked(routingKey); } catch (UncheckedExecutionException e) { Throwable cause = e.getCause(); if(cause instanceof NoSuchBeanDefinitionException && fallbackResource!=null) { logger.warn("Cannot find proper data source for '{}'. Use fallback data source instead.", routingKey); return fallbackResource; } throw new IllegalStateException("Cannot determine target DataSource for lookup key [" + routingKey + "]", cause); } }
Example 9
Source File: UserCacheImpl.java From flowable-engine with Apache License 2.0 | 5 votes |
public CachedUser getUser(String userId, boolean throwExceptionOnNotFound, boolean throwExceptionOnInactive, boolean checkValidity) { try { // The cache is a LoadingCache and will fetch the value itself CachedUser cachedUser = userCache.get(userId); return cachedUser; } catch (ExecutionException e) { return null; } catch (UncheckedExecutionException uee) { // Some magic with the exceptions is needed: // the exceptions like UserNameNotFound and Locked cannot // bubble up, since Spring security will react on them otherwise if (uee.getCause() instanceof RuntimeException) { RuntimeException runtimeException = (RuntimeException) uee.getCause(); if (runtimeException instanceof UsernameNotFoundException) { if (throwExceptionOnNotFound) { throw runtimeException; } else { return null; } } if (runtimeException instanceof LockedException) { if (throwExceptionOnNotFound) { throw runtimeException; } else { return null; } } } throw uee; } }
Example 10
Source File: UserCacheImpl.java From flowable-engine with Apache License 2.0 | 5 votes |
public CachedUser getUser(String userId, boolean throwExceptionOnNotFound, boolean throwExceptionOnInactive, boolean checkValidity) { try { // The cache is a LoadingCache and will fetch the value itself CachedUser cachedUser = userCache.get(userId); return cachedUser; } catch (ExecutionException e) { return null; } catch (UncheckedExecutionException uee) { // Some magic with the exceptions is needed: // the exceptions like UserNameNotFound and Locked cannot // bubble up, since Spring security will react on them otherwise if (uee.getCause() instanceof RuntimeException) { RuntimeException runtimeException = (RuntimeException) uee.getCause(); if (runtimeException instanceof UsernameNotFoundException) { if (throwExceptionOnNotFound) { throw runtimeException; } else { return null; } } if (runtimeException instanceof LockedException) { if (throwExceptionOnNotFound) { throw runtimeException; } else { return null; } } } throw uee; } }
Example 11
Source File: GroupName.java From monsoon with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static GroupName valueOf(SimpleGroupPath path, Tags tags) { try { return CACHE.apply(new GroupNameArgs(path, tags)); } catch (UncheckedExecutionException e) { if (e.getCause() instanceof RuntimeException) throw (RuntimeException)e.getCause(); throw e; } }
Example 12
Source File: CompositeService.java From twill with Apache License 2.0 | 5 votes |
private void stopAll() throws Exception { Throwable failureCause = null; // Stop services in reverse order. Iterator<Service> itor = services.descendingIterator(); while (itor.hasNext()) { Service service = itor.next(); try { if (service.isRunning() || service.state() == State.STARTING) { service.stopAndWait(); } } catch (UncheckedExecutionException e) { // Just catch as we want all services stopped if (failureCause == null) { failureCause = e.getCause(); } else { // Log for sub-sequence service shutdown error, as only the first failure cause will be thrown. LOG.warn("Failed to stop service {}", service, e); } } } if (failureCause != null) { Throwables.propagateIfPossible(failureCause, Exception.class); throw new RuntimeException(failureCause); } }
Example 13
Source File: PermissionCheckCache.java From dremio-oss with Apache License 2.0 | 5 votes |
private Value getFromPermissionsCache(Key key, Callable<Value> loader) throws ExecutionException { Value value; try { value = permissionsCache.get(key, loader); } catch (UncheckedExecutionException e) { if (e.getCause() != NoAccessException.INSTANCE) { throw e; } value = new Value(false, System.currentTimeMillis()); } return value; }
Example 14
Source File: CachedDataSourceRegistryWrapper.java From metamodel-membrane with Apache License 2.0 | 5 votes |
@Override public DataContext openDataContext(final String dataSourceName) throws NoSuchDataSourceException { try { return loadingCache.getUnchecked(dataSourceName); } catch (UncheckedExecutionException e) { final Throwable cause = e.getCause(); if (cause instanceof RuntimeException) { throw (RuntimeException) cause; } throw new MetaModelException( "Unexpected error happened while getting DataContext '" + dataSourceName + "' from cache", e); } }
Example 15
Source File: UserCacheImpl.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public CachedUser getUser(String userId, boolean throwExceptionOnNotFound, boolean throwExceptionOnInactive, boolean checkValidity) { try { // The cache is a LoadingCache and will fetch the value itself CachedUser cachedUser = userCache.get(userId); return cachedUser; } catch (ExecutionException e) { return null; } catch (UncheckedExecutionException uee) { // Some magic with the exceptions is needed: // the exceptions like UserNameNotFound and Locked cannot // bubble up, since Spring security will react on them otherwise if (uee.getCause() instanceof RuntimeException) { RuntimeException runtimeException = (RuntimeException) uee.getCause(); if (runtimeException instanceof UsernameNotFoundException) { if (throwExceptionOnNotFound) { throw runtimeException; } else { return null; } } if (runtimeException instanceof LockedException) { if (throwExceptionOnNotFound) { throw runtimeException; } else { return null; } } } throw uee; } }
Example 16
Source File: EventServiceImpl.java From ic with MIT License | 5 votes |
@Override public Event queryById(Long id) { //使用getUnchecked要求CacheLoader.load方法必须不能抛出任何checked的异常 try { return caches.getUnchecked(id); } catch (UncheckedExecutionException e) { //如果load方法出现异常,取出原始的ICException异常对象 if (e.getCause() instanceof ICException) { throw (ICException) e.getCause(); } throw e; } }
Example 17
Source File: LumongoSegment.java From lumongo with Apache License 2.0 | 4 votes |
private void searchWithFacets(FacetRequest facetRequest, Query q, IndexSearcher indexSearcher, TopDocsCollector<?> collector, SegmentResponse.Builder segmentReponseBuilder) throws Exception { FacetsCollector facetsCollector = new FacetsCollector(); indexSearcher.search(q, MultiCollector.wrap(collector, facetsCollector)); Facets facets = new FastTaxonomyFacetCounts(taxoReader, facetsConfig, facetsCollector); for (CountRequest countRequest : facetRequest.getCountRequestList()) { String label = countRequest.getFacetField().getLabel(); if (!indexConfig.existingFacet(label)) { throw new Exception(label + " is not defined as a facetable field"); } if (countRequest.hasSegmentFacets()) { if (indexConfig.getNumberOfSegments() == 1) { log.info("Segment facets is ignored with segments of 1 for facet <" + label + "> on index <" + indexName + ">"); } if (countRequest.getSegmentFacets() < countRequest.getMaxFacets()) { throw new IllegalArgumentException("Segment facets must be greater than or equal to max facets"); } } int numOfFacets; if (indexConfig.getNumberOfSegments() > 1) { if (countRequest.getSegmentFacets() != 0) { numOfFacets = countRequest.getSegmentFacets(); } else { numOfFacets = countRequest.getMaxFacets() * 8; } } else { numOfFacets = countRequest.getMaxFacets(); } FacetResult facetResult = null; try { if (indexConfig.getNumberOfSegments() > 1) { if (countRequest.hasSegmentFacets() && countRequest.getSegmentFacets() == 0) { //TODO: this not ideal numOfFacets = taxoReader.getSize(); } } facetResult = facets.getTopChildren(numOfFacets, label); } catch (UncheckedExecutionException e) { Throwable cause = e.getCause(); if (cause.getMessage().contains(" was not indexed with SortedSetDocValues")) { //this is when no data has been indexing into a facet or facet does not exist } else { throw e; } } FacetGroup.Builder fg = FacetGroup.newBuilder(); fg.setCountRequest(countRequest); if (facetResult != null) { for (LabelAndValue subResult : facetResult.labelValues) { FacetCount.Builder facetCountBuilder = FacetCount.newBuilder(); facetCountBuilder.setCount(subResult.value.longValue()); facetCountBuilder.setFacet(subResult.label); fg.addFacetCount(facetCountBuilder); } } segmentReponseBuilder.addFacetGroup(fg); } }
Example 18
Source File: GeSuiteImporter.java From BungeeAdminTools with GNU General Public License v3.0 | 4 votes |
@Override protected void importData(final ProgressCallback<ImportStatus> progressionCallback, String... additionalsArgs) throws Exception { ResultSet res = null; try (Connection conn = BAT.getConnection()) { // Check if the bungee suite tables are here final DatabaseMetaData dbm = conn.getMetaData(); for(final String table : Arrays.asList("bans", "players")){ final ResultSet tables = dbm.getTables(null, null, table, null); if (!tables.next()) { throw new IllegalArgumentException("The table " + table + " wasn't found. Import aborted ..."); } } // Count the number of entries (use to show the progression) final ResultSet resCount = conn.prepareStatement("SELECT COUNT(*) FROM bans;").executeQuery(); if(resCount.next()){ status = new ImportStatus(resCount.getInt("COUNT(*)")); } final PreparedStatement insertBans = conn.prepareStatement("INSERT INTO `" + SQLQueries.Ban.table + "`(UUID, ban_ip, ban_staff, ban_server, ban_begin, ban_end, ban_reason) VALUES (?, ?, ?, ?, ?, ?, ?);"); final PreparedStatement getIP = conn.prepareStatement("SELECT ipaddress FROM players WHERE playername = ?;"); res = conn.createStatement().executeQuery("SELECT * FROM bans;"); int uncomittedEntries = 0; conn.setAutoCommit(false); while (res.next()) { final boolean ipBan = "ipban".equals(res.getString("type")); final String pName = res.getString("banned_playername"); final String server = IModule.GLOBAL_SERVER; final String staff = res.getString("banned_by"); final String reason = res.getString("reason"); final Timestamp ban_begin = res.getTimestamp("banned_on"); final Timestamp ban_end = res.getTimestamp("banned_until"); String UUID = res.getString("banned_uuid"); if(UUID == null){ try{ UUID = uuidCache.get(pName); }catch (final UncheckedExecutionException e) { if(e.getCause() instanceof UUIDNotFoundException){ continue; }else{ throw e; } } } // Get the ip String ip = null; getIP.setString(1, pName); final ResultSet resIP = getIP.executeQuery(); if(resIP.next()){ ip = resIP.getString("ipaddress"); } resIP.close(); if(ipBan && ip == null){ continue; } // Insert the ban insertBans.setString(1, (ipBan) ? null : UUID); insertBans.setString(2, (ipBan) ? ip : null); insertBans.setString(3, staff); insertBans.setString(4, server); insertBans.setTimestamp(5, ban_begin); insertBans.setTimestamp(6, ban_end); insertBans.setString(7, reason); insertBans.execute(); insertBans.clearParameters(); getIP.clearParameters(); uncomittedEntries++; if(!ipBan){ initPlayerRowInBatPlayer(conn, pName, UUID); } if(uncomittedEntries % 100 == 0){ conn.commit(); status.incrementConvertedEntries(uncomittedEntries); uncomittedEntries = 0; progressionCallback.onProgress(status); } } conn.commit(); status.incrementConvertedEntries(uncomittedEntries); progressionCallback.done(status, null); }finally{ if(res != null){ DataSourceHandler.close(res); } } }
Example 19
Source File: BungeeSuiteImporter.java From BungeeAdminTools with GNU General Public License v3.0 | 4 votes |
@Override protected void importData(final ProgressCallback<ImportStatus> progressionCallback, String... additionalsArgs) throws Exception{ ResultSet res = null; try (Connection conn = BAT.getConnection()) { // Check if the bungee suite tables are here final DatabaseMetaData dbm = conn.getMetaData(); for(final String table : Arrays.asList("BungeeBans", "BungeePlayers")){ final ResultSet tables = dbm.getTables(null, null, table, null); if (!tables.next()) { throw new IllegalArgumentException("The table " + table + " wasn't found. Import aborted ..."); } } // Count the number of entries (use to show the progression) final ResultSet resCount = conn.prepareStatement("SELECT COUNT(*) FROM BungeeBans;").executeQuery(); if(resCount.next()){ status = new ImportStatus(resCount.getInt("COUNT(*)")); } final PreparedStatement insertBans = conn.prepareStatement("INSERT INTO `" + SQLQueries.Ban.table + "`(UUID, ban_ip, ban_staff, ban_server, ban_begin, ban_end, ban_reason) VALUES (?, ?, ?, ?, ?, ?, ?);"); final PreparedStatement getIP = conn.prepareStatement("SELECT ipaddress FROM BungeePlayers WHERE playername = ?;"); res = conn.createStatement().executeQuery("SELECT * FROM BungeeBans;"); int uncomittedEntries = 0; conn.setAutoCommit(false); while (res.next()) { final boolean ipBan = "ipban".equals(res.getString("type")); final String pName = res.getString("player"); final String server = IModule.GLOBAL_SERVER; final String staff = res.getString("banned_by"); final String reason = res.getString("reason"); final Timestamp ban_begin = res.getTimestamp("banned_on"); Timestamp ban_end = res.getTimestamp("banned_until"); /* For unknown reason BungeeBans table contained (hardly ever but it did) date with a year > 3000, * not sure if that was some kind of joke from a staff member ... Anyways this code convert long-duration tempban to definitive ban */ if(ban_end == null || ban_end.getTime() > System.currentTimeMillis() + 10 * (365 * (24 * 3600))){ ban_end = null; } // Get the ip String ip = null; getIP.setString(1, pName); final ResultSet resIP = getIP.executeQuery(); if(resIP.next()){ ip = resIP.getString("ipaddress"); } resIP.close(); if(ipBan && ip == null){ continue; } // Get UUID String UUID = null; try{ UUID = uuidCache.get(pName); } catch (UncheckedExecutionException e) { if(e.getCause() instanceof UUIDNotFoundException){ continue; }else{ throw e; } } // Insert the ban insertBans.setString(1, (ipBan) ? null : UUID); insertBans.setString(2, (ipBan) ? ip : null); insertBans.setString(3, staff); insertBans.setString(4, server); insertBans.setTimestamp(5, ban_begin); insertBans.setTimestamp(6, ban_end); insertBans.setString(7, reason); insertBans.execute(); insertBans.clearParameters(); getIP.clearParameters(); uncomittedEntries++; initPlayerRowInBatPlayer(conn, pName, UUID); if(uncomittedEntries % 100 == 0){ conn.commit(); status.incrementConvertedEntries(uncomittedEntries); uncomittedEntries = 0; progressionCallback.onProgress(status); } } conn.commit(); status.incrementConvertedEntries(uncomittedEntries); progressionCallback.done(status, null); }finally{ if(res != null){ DataSourceHandler.close(res); } } }
Example 20
Source File: DElementStore.java From org.openntf.domino with Apache License 2.0 | 4 votes |
@Override public Element getElement(final Object id) throws IllegalStateException { try { // if (isProxied()) { // System.out.println("Getting a proxied element for id: " + String.valueOf(id)); // } NoteCoordinate nc = normalizeId((Serializable) id); Element result = null; // if (nc.getReplicaId().equalsIgnoreCase("852582F7007073B5")) { // System.out.println("Getting a demo document " + nc + " from the element cache"); // result = getElementCache().get(nc); // if (result != null) { // System.out.println( // "Result was loaded from cache with id " + nc + " and cache now has " + getElementCache().size() + " elements"); // // } // } else { result = getElementCache().get(nc); // } // if (isProxied()) { // if (result instanceof DProxyVertex) { // NoteCoordinate proxyid = ((DProxyVertex) result).getProxiedId(); // getElementCache().put(proxyid, result); // } // } // System.out.println("TEMP DEBUG requesting element for id " + id.getClass().getSimpleName() + ": " + String.valueOf(id) // + " from element store " + System.identityHashCode(this) + " using element cache " // + System.identityHashCode(getElementCache()) + " resulting in a " + result.getClass().getSimpleName() + ": " // + System.identityHashCode(result)); return result; } catch (InvalidCacheLoadException icle) { // System.out.println( // "TEMP DEBUG invalidCacheLoad for id " + String.valueOf(id) + " from element store " + System.identityHashCode(this)); return null; } catch (UncheckedExecutionException uee) { Throwable cause = uee.getCause(); if (cause != null && cause instanceof UserAccessException) { throw new UserAccessException(cause.getMessage(), cause); } else { throw uee; } } catch (UserAccessException uae) { throw uae; } catch (Throwable t) { throw new IllegalStateException("Unable to retrieve id " + String.valueOf(id), t); } }