List of usage examples for java.lang Exception getCause
public synchronized Throwable getCause()
From source file:com.ikanow.aleph2.distributed_services.services.TestCoreDistributedServices.java
@Test public void testCoreDistributedServices() throws KeeperException, InterruptedException, Exception { final CuratorFramework curator = _core_distributed_services.getCuratorFramework(); String path = curator.getZookeeperClient().getZooKeeper().create("/test", new byte[] { 1, 2, 3 }, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); assertEquals(path, "/test"); // Test serialization is hooked up: Serialization tester = SerializationExtension.get(_core_distributed_services.getAkkaSystem()); TestBean test = BeanTemplateUtils.build(TestBean.class).with("test1", "val1") .with("embedded", BeanTemplateUtils.build(EmbeddedTestBean.class).with("test2", "val2").done().get()) .done().get();/*from w w w . j ava 2 s . c om*/ Serializer serializer = tester.findSerializerFor(test); byte[] test_bytes2 = serializer.toBinary(test); TestBean test2 = (TestBean) serializer.fromBinary(test_bytes2, TestBean.class); assertEquals(test.test1(), test2.test1()); assertEquals(test.embedded().test2(), test2.embedded().test2()); assertEquals(Optional.empty(), _core_distributed_services.getApplicationName()); _completed1.get(20, TimeUnit.SECONDS); assertEquals(true, _test1.get()); try { _completed2.get(20, TimeUnit.SECONDS); } catch (Exception e) { assertEquals(e.getCause().getMessage(), "test2"); } _completed3 = _core_distributed_services.runOnAkkaJoin(() -> { _test3.set(false); }); _completed3.get(20, TimeUnit.SECONDS); assertEquals(false, _test3.get()); }
From source file:com.openteach.diamond.network.waverider.slave.DefaultSlaveNode.java
@Override public boolean start() { while (true) { try {/* ww w. ja v a 2 s.c o m*/ netWorkClient.start(); break; } catch (Exception e) { logger.error(e); if (e.getCause() instanceof IOException || e.getCause() instanceof ConnectException) { try { logger.error("Can not connect to master , sleep 60s, then try again"); Thread.sleep(60 * 1000); } catch (InterruptedException ex) { logger.error("OOPSException", ex); Thread.currentThread().interrupt(); } continue; } } } masterFailureMonitor.start(); commandDispatchThread.start(); heartbeatScheduler.scheduleAtFixedRate(new HeartbeatTask(), WaveriderConfig.WAVERIDER_DEFAULT_HEART_BEAT_INTERVAL, WaveriderConfig.WAVERIDER_DEFAULT_HEART_BEAT_INTERVAL, TimeUnit.SECONDS); return true; }
From source file:io.hops.tensorflow.TimelineHandler.java
public void publishContainerStartEvent(Container container) { final TimelineEntity entity = new TimelineEntity(); entity.setEntityId(container.getId().toString()); entity.setEntityType(ApplicationMaster.YarntfEntity.YARNTF_CONTAINER.toString()); entity.setDomainId(domainId);/*from w w w. j a v a 2 s . c om*/ entity.addPrimaryFilter("user", ugi.getShortUserName()); TimelineEvent event = new TimelineEvent(); event.setTimestamp(System.currentTimeMillis()); event.setEventType(ApplicationMaster.YarntfEvent.YARNTF_CONTAINER_START.toString()); event.addEventInfo("Node", container.getNodeId().toString()); event.addEventInfo("Resources", container.getResource().toString()); entity.addEvent(event); try { ugi.doAs(new PrivilegedExceptionAction<TimelinePutResponse>() { @Override public TimelinePutResponse run() throws Exception { return timelineClient.putEntities(entity); } }); } catch (Exception e) { LOG.error("Container start event could not be published for " + container.getId().toString(), e instanceof UndeclaredThrowableException ? e.getCause() : e); } }
From source file:gov.nih.nci.caarray.application.project.FileUploadUtils.java
/** * Uploads a file chunk to a project.// ww w. j a v a 2 s.c om * @param project the project the file is being uploaded in to. * @param wrapper FileWrapper for the chunk being uploaded. */ private void addFileChunk(Project project, FileWrapper wrapper) throws InvalidFileException { File file = wrapper.getFile(); String fileName = wrapper.getFileName(); try { if (!checkDuplicateFilename(project, fileName)) { CaArrayFile caArrayFile = getProjectManagementService().addFileChunk(project, file, fileName, wrapper.getTotalFileSize()); if (caArrayFile.getFileStatus().equals(FileStatus.UPLOADED)) { handleLastChunk(project, caArrayFile, fileName, wrapper.isCompressed()); } else { result.setPartialUpload(true); } } } catch (final Exception e) { if (e.getCause() instanceof InvalidStateException) { result.addConflictingFile(fileName); } else { throw new InvalidFileException(fileName, "errors.addingFile", result, "Unable to add file tp persistent store", e); } } }
From source file:org.openmrs.module.sync.api.SyncIngestServiceTest.java
/** * @see {@link SyncIngestService#processSyncRecord(SyncRecord,RemoteServer)} *///w w w .j ava 2 s .c o m @Test @Verifies(value = "should log the full stacktrace when it fails", method = "processSyncRecord(SyncRecord,RemoteServer)") public void processSyncRecord_shouldLogTheFullStacktraceWhenItFails() throws Exception { final String recordUuid = "someRandomUuid"; Throwable t = null; try { SyncIngestService sis = Context.getService(SyncIngestService.class); SyncRecord record = new SyncRecord(); record.setOriginalUuid(recordUuid); //This should force a NPE since server is null sis.processSyncRecord(record, null); } catch (Exception e) { //since sync re throws the exception as a SyncIngestException, //get the actual NPE exception that was thrown t = e.getCause(); } Assert.assertNotNull(t); Assert.assertTrue(StringUtils.isBlank(t.getMessage())); Assert.assertTrue(t instanceof NullPointerException); SyncImportRecord importRecord = Context.getService(SyncService.class).getSyncImportRecord(recordUuid); Assert.assertNotNull(importRecord); Assert.assertFalse(StringUtils.isBlank(importRecord.getErrorMessage())); }
From source file:be.error.rpi.config.RunConfig.java
public synchronized void doWithLucidControl(Integer device, Consumer<LucidControlAO4> consumer) { LucidControlAO4 lucidControlAO4 = lucidControlMap.get(device); synchronized (lucidControlAO4) { try {/*w ww .j a va 2s . c o m*/ consumer.accept(lucidControlAO4); } catch (Exception exception) { logger.error("Lucid control had IO error, trying to recover", exception.getCause()); reInitLucidControl(lucidControlAO4); doWithLucidControl(device, consumer); } } }
From source file:com.developmentsprint.spring.breaker.hystrix.HystrixCircuitManager.java
@Override public Object execute(final Invoker invoker) { CircuitBreakerAttribute attr = invoker.getCircuitBreakerAttribute(); String circuitBreakerName = determineCommandName(attr); String circuitBreakerGroup = determineGroupName(attr); String threadPoolName = determineThreadPoolName(attr); if (!CONFIGURED_BREAKERS.containsKey(circuitBreakerName)) { synchronized (circuitBreakerName) { if (!CONFIGURED_BREAKERS.containsKey(circuitBreakerName)) { for (Map.Entry<String, String> entry : attr.getProperties().entrySet()) { String commandKey = String.format(INSTANCE_COMMAND_PROP_KEY_FORMAT, circuitBreakerName, entry.getKey()); configuration.setProperty(commandKey, entry.getValue()); String threadPoolKey = String.format(INSTANCE_THREADPOOL_PROP_KEY_FORMAT, threadPoolName, entry.getKey()); configuration.setProperty(threadPoolKey, entry.getValue()); String collapserKey = String.format(INSTANCE_COLLAPSER_PROP_KEY_FORMAT, threadPoolName, entry.getKey()); configuration.setProperty(collapserKey, entry.getValue()); }/*from w w w.jav a 2s . c o m*/ CONFIGURED_BREAKERS.put(circuitBreakerName, Boolean.TRUE); } } } if (log.isDebugEnabled()) { StringBuilder builder = new StringBuilder(); Iterator<String> keyIterator = configuration.getKeys(); while (keyIterator.hasNext()) { String key = keyIterator.next(); builder.append(System.getProperty("line.separator")).append("\t").append(key).append(" : ") .append(configuration.getString(key)); } log.debug("Configured Hystrix Properties: {}", builder); } final HystrixFallback<?> fallback = determineFallback(attr); log.debug("Creating circuit breaker command '{}' around {}", circuitBreakerName, new Object() { public String toString() { return invoker.getMethod().toString(); } }); HystrixCommand.Setter setter = HystrixCommand.Setter .withGroupKey(HystrixCommandGroupKey.Factory.asKey(circuitBreakerGroup)) .andCommandKey(HystrixCommandKey.Factory.asKey(circuitBreakerName)) .andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey(threadPoolName)); HystrixCommand<Object> command = new HystrixCommand<Object>(setter) { @Override protected Object run() throws Exception { try { return invoker.invoke(); } catch (Exception e) { if (e.getCause() != null && e.getCause() instanceof Exception) { e = ((Exception) e.getCause()); } throw e; } } @Override protected Object getFallback() { if (fallback == null || fallback instanceof FailFastFallback) { return super.getFallback(); } else if (fallback instanceof FailSilentFallback) { return null; } else { return fallback.fallback(); } } }; try { return command.execute(); } catch (HystrixRuntimeException e) { Throwable t = e.getCause(); if (t instanceof CircuitBreakerException) { throw (CircuitBreakerException) t.getCause(); } else if (t instanceof TimeoutException) { throw new CircuitTimeoutException(t.getMessage(), t); } else if (t instanceof RejectedExecutionException) { throw new CircuitOverloadException(t.getMessage(), t); } throw new CircuitBreakerException(t); } }
From source file:com.paxxis.cornerstone.messaging.service.shell.ServiceShell.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private void doUnbind(String[] vals) throws NamingException { String url = "rmi://localhost:" + vals[1]; String serviceName = vals[0]; System.out.println("Unbinding " + url + "/" + serviceName); Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.rmi.registry.RegistryContextFactory"); env.put(Context.PROVIDER_URL, url); Context ictx = new InitialContext(env); try {//w ww.j a v a2s.c o m ictx.unbind(serviceName); System.out.println("Done"); } catch (Exception ex) { System.err.println(ex.getMessage() + ex.getCause().getMessage()); } }
From source file:csiro.pidsvc.mappingstore.action.ActionProxy.java
@Override public void run() { HttpClient httpClient = new DefaultHttpClient(); try {//w w w . j av a2 s . co m HttpServletRequest originalHttpRequest = _controller.getRequest(); HttpServletResponse originalHttpResponse = _controller.getResponse(); HttpGet httpGet = new HttpGet(getExpandedActionValue()); if (isTraceMode()) trace(httpGet.getRequestLine().toString()); // Pass-through HTTP headers. HashMap<String, String> hmHeaders = _controller.getHttpHeaders(); for (String header : hmHeaders.keySet()) { httpGet.addHeader(header, hmHeaders.get(header)); if (isTraceMode()) trace("\t" + header + ": " + hmHeaders.get(header)); } // Handle X-Original-URI HTTP header. if (!hmHeaders.containsKey("X-Original-URI")) { String originalUri = originalHttpRequest.getScheme() + "://" + originalHttpRequest.getServerName(); if (originalHttpRequest.getServerPort() != 80) originalUri += ":" + originalHttpRequest.getServerPort(); originalUri += _controller.getUri().getOriginalUriAsString(); httpGet.addHeader("X-Original-URI", originalUri); if (isTraceMode()) trace("\tX-Original-URI: " + originalUri); } // Get the data. HttpResponse response = httpClient.execute(httpGet); HttpEntity entity = response.getEntity(); if (isTraceMode()) trace(response.getStatusLine().toString()); // Pass HTTP headers through. if (!isTraceMode()) originalHttpResponse.setStatus(response.getStatusLine().getStatusCode()); if (entity.getContentType() != null) { if (isTraceMode()) { trace("\tContent-Type: " + entity.getContentType().getValue()); trace("\tContent-Length: " + EntityUtils.toString(entity).getBytes().length); } else originalHttpResponse.setContentType(entity.getContentType().getValue()); } String headerName; for (Header header : response.getAllHeaders()) { headerName = header.getName(); if (headerName.equalsIgnoreCase("Expires") || headerName.equalsIgnoreCase("Cache-Control") || headerName.equalsIgnoreCase("Content-Type") || headerName.equalsIgnoreCase("Set-Cookie") || headerName.equalsIgnoreCase("Transfer-Encoding")) continue; if (isTraceMode()) trace("\t" + header.getName() + ": " + header.getValue()); else originalHttpResponse.addHeader(header.getName(), header.getValue()); } // Pass content through. if (!isTraceMode()) originalHttpResponse.getWriter().write(EntityUtils.toString(entity)); } catch (Exception e) { _logger.trace("Exception occurred while proxying HTTP request.", e); if (isTraceMode()) { Throwable cause = e.getCause(); trace("Set response status: 500; exception: " + (cause == null ? e.getMessage() : cause.getMessage())); } else Http.returnErrorCode(_controller.getResponse(), 500, e); } finally { httpClient.getConnectionManager().shutdown(); } }