List of usage examples for java.lang InterruptedException getMessage
public String getMessage()
From source file:ch.sbb.releasetrain.action.jenkins.JenkinsJobThread.java
private void sleep(int seconds) { try {//from ww w .j ava 2s. c o m Thread.sleep(seconds * 1000L); } catch (InterruptedException e) { log.error(e.getMessage(), e); } }
From source file:com.cm.beer.util.ContentManager.java
/** * // ww w . j av a2 s. com * @param urlString * @param imageView */ public void fetchContentOnThread(final String urlString, final Handler handler) { if (mContentCache.containsKey(urlString)) { SoftReference<String> softReference = mContentCache.get(urlString); if ((softReference == null) || (softReference.get() == null)) { mContentCache.remove(urlString); if (Logger.isLogEnabled()) Logger.log("fetchContentOnThread():Soft Reference has been Garbage Collected:" + urlString); } else { String jsonStr = softReference.get(); if (Logger.isLogEnabled()) Logger.log(urlString + "=>" + jsonStr); Message message = handler.obtainMessage(1, jsonStr); handler.sendMessage(message); return; } } Thread thread = new Thread() { @Override public void run() { while (mLockCache.containsKey(urlString)) { if (Logger.isLogEnabled()) Logger.log("URI download request in progress:" + urlString); try { Thread.sleep(1000L); } catch (InterruptedException e) { Log.e(this.getClass().getName(), e.getMessage()); } } String content = fetchContent(urlString); Message message = handler.obtainMessage(1, content); handler.sendMessage(message); } }; thread.start(); }
From source file:com.prasanna.android.stacknetwork.service.AbstractBaseServiceHelper.java
protected void sleep(long ms) { try {//w w w . j av a 2s . c o m Thread.sleep(ms); } catch (InterruptedException e) { LogWrapper.e(getLogTag(), e.getMessage()); } }
From source file:org.openbaton.autoscaling.core.detection.task.DetectionTask.java
@Override public void run() { if (!actionMonitor.requestAction(autoScalePolicy.getId(), Action.DETECT)) { return;//w w w. j a v a 2 s . co m } double alarmsWeightFired = 0; double alarmsWeightCount = 0; if (first_time == true) { log.debug("Starting DetectionTask the first time. So wait for the cooldown..."); first_time = false; try { int i = 0; while (i < autoScalePolicy.getCooldown()) { Thread.sleep(1000); i++; //terminate gracefully at this point in time if suggested from the outside if (actionMonitor.isTerminating(autoScalePolicy.getId())) { actionMonitor.finishedAction(autoScalePolicy.getId(), Action.TERMINATED); return; } } } catch (InterruptedException e) { log.error(e.getMessage(), e); } } log.info("[DETECTOR] CHECK_ALARM " + new Date().getTime()); log.debug("DetectionTask: Checking AutoScalingPolicy " + autoScalePolicy.getName() + " with id: " + autoScalePolicy.getId() + " VNFR with id: " + vnfr_id); VirtualNetworkFunctionRecord vnfr = null; try { vnfr = detectionEngine.getVNFR(nsr_id, vnfr_id); } catch (SDKException e) { log.error(e.getMessage()); } //terminate gracefully at this point in time if suggested from the outside if (actionMonitor.isTerminating(autoScalePolicy.getId())) { actionMonitor.finishedAction(autoScalePolicy.getId(), Action.TERMINATED); return; } if (vnfr != null) { for (ScalingAlarm alarm : autoScalePolicy.getAlarms()) { //terminate gracefully at this point in time if suggested from the outside if (actionMonitor.isTerminating(autoScalePolicy.getId())) { actionMonitor.finishedAction(autoScalePolicy.getId(), Action.TERMINATED); return; } alarmsWeightCount = +alarm.getWeight(); List<Item> measurementResults = null; try { log.info("[DETECTOR] REQUEST_MEASUREMENTS " + new Date().getTime()); measurementResults = detectionEngine.getRawMeasurementResults(vnfr, alarm.getMetric(), Integer.toString(autoScalePolicy.getPeriod())); log.info("[DETECTOR] GOT_MEASUREMENT_RESULTS " + new Date().getTime()); } catch (MonitoringException e) { log.error(e.getMessage(), e); } double finalAlarmResult = detectionEngine.calculateMeasurementResult(alarm, measurementResults); log.trace("DetectionTask: Measurement result on vnfr " + vnfr.getId() + " on metric " + alarm.getMetric() + " with statistic " + alarm.getStatistic() + " is " + finalAlarmResult + " " + measurementResults); if (detectionEngine.checkThreshold(alarm.getComparisonOperator(), alarm.getThreshold(), finalAlarmResult)) { alarmsWeightFired = +alarm.getWeight(); log.debug("DetectionTask: Alarm with id: " + alarm.getId() + " of AutoScalePolicy with id " + autoScalePolicy.getId() + " is fired"); } else { log.trace("DetectionTask: Alarm with id: " + alarm.getId() + " of AutoScalePolicy with id " + autoScalePolicy.getId() + " is not fired"); } } log.trace("Finished check of all Alarms of AutoScalePolicy with id " + autoScalePolicy.getId()); //Check if Alarm must be fired for this AutoScalingPolicy double finalResult = (100 * alarmsWeightFired) / alarmsWeightCount; log.trace("Checking if AutoScalingPolicy with id " + autoScalePolicy.getId() + " must be executed"); //terminate gracefully at this point in time if suggested from the outside if (actionMonitor.isTerminating(autoScalePolicy.getId())) { actionMonitor.finishedAction(autoScalePolicy.getId(), Action.TERMINATED); return; } if (detectionEngine.checkThreshold(autoScalePolicy.getComparisonOperator(), autoScalePolicy.getThreshold(), finalResult)) { //if (fired == false) { log.info("Threshold of AutoScalingPolicy with id " + autoScalePolicy.getId() + " is crossed -> " + autoScalePolicy.getThreshold() + autoScalePolicy.getComparisonOperator() + finalResult); fired = true; log.info("[DETECTOR] DETECTED_ALARM " + new Date().getTime()); detectionEngine.sendAlarm(nsr_id, vnfr_id, autoScalePolicy); } else { if (fired == false) { log.trace("Threshold of AutoScalingPolicy with id " + autoScalePolicy.getId() + " is not crossed -> " + finalResult + autoScalePolicy.getComparisonOperator() + autoScalePolicy.getThreshold()); } else { log.info("Threshold of AutoScalingPolicy with id " + autoScalePolicy.getId() + " is not crossed anymore. This means that the Alarm is cleared -> " + autoScalePolicy.getThreshold() + autoScalePolicy.getComparisonOperator() + finalResult); fired = false; //ToDo throw event CLEARED } } } else { log.error("DetectionTask: Not found VNFR with id: " + vnfr_id + " of NSR with id: " + nsr_id); } log.trace("DetectionTask: Starting sleeping period (" + autoScalePolicy.getPeriod() + "s) for AutoScalePolicy with id: " + autoScalePolicy.getId()); actionMonitor.finishedAction(autoScalePolicy.getId()); }
From source file:br.com.i9torpedos.model.service.sms.DServiceModem1.java
@Override public void run() { try {/* ww w. j ava 2s . c o m*/ while (!filaSMS.isEmpty()) { SendSMSMessage smsMessage = getFilaSMS().peek(); OutboundMessage msg = new OutboundMessage(smsMessage.getNumero(), smsMessage.getMensagem()); msg.setEncoding(Message.MessageEncodings.ENCUCS2); Thread.sleep(TEMPO); Service.getInstance().sendMessage(msg); log.warn(msg); getPonte().set(smsMessage); new Thread(new ConsumerModem1Info(getPonte(), msg)).start(); log.info("SMS para o numero: " + smsMessage.getNumero() + " Enviado com sucesso"); SendSMSMessage poll = getFilaSMS().poll(); boolean contains = getFilaSMS().contains(poll); if (contains) { getFilaSMS().remove(poll); } } } catch (InterruptedException ex) { log.fatal("Falha ao Inciiar ou Parar Servio SMS DServiceModem1 " + ex.getMessage()); } catch (TimeoutException | GatewayException | IOException ex) { Logger.getLogger(DServiceModem1.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.boulmier.machinelearning.jobexecutor.job.Job.java
public void start() throws IOException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); final DefaultExecutor exec = new DefaultExecutor(); final ExecuteWatchdog wd = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT); final PumpStreamHandler output = new PumpStreamHandler(out); final DefaultExecuteResultHandler handler = new DefaultExecuteResultHandler(); exec.setWatchdog(wd);//ww w . j a v a2 s .c om exec.setStreamHandler(output); exec.execute(cl, handler); JobExecutor.logger.info("Running job " + jobid); new Thread(new Runnable() { @Override public void run() { try { handler.waitFor(); Computer.ComputeProperties properties = Computer.ComputeProperties.buildFromRequest(req); new SenderComputer(new StorageComputer(out.toString(), properties)).compute(); JobExecutor.logger.info("Job complete " + jobid); } catch (InterruptedException ex) { exec.getWatchdog().destroyProcess(); JobExecutor.logger.error( "Job (" + jobid + ") has been destroyed due to internal error " + ex.getMessage()); } } }).start(); }
From source file:com.magnet.mmx.server.plugin.mmxmgmt.apns.APNSConnectionPoolImplTest.java
@Test public void testPoolWithMultipleThreads() { String testAppId = "multithreadTestApp"; /**//from ww w . j av a 2 s. co m * create 5 threads each sending to 100 devices */ int deviceCount = 100; int threadCount = 5; Map<String, String> payload = new LinkedHashMap<String, String>(100); for (int i = 0; i < deviceCount; i++) { payload.put("device:" + (i + 1), "JSON Payload{}:" + (i + 1)); } objectFactory.clearCounter(); APNSConnectionPoolImpl pool = APNSConnectionPoolImpl.getInstance(); //initialize the pool with connections for all apps // for (int i = 0; i < appIds.length; i++) { // APNSConnection conn = pool.getConnection(appIds[i], true); // pool.returnConnection(conn); // } CountDownLatch countDownLatch = new CountDownLatch(threadCount); Executor executor = Executors.newFixedThreadPool(threadCount, new ThreadFactory() { private AtomicInteger counter = new AtomicInteger(1); @Override public Thread newThread(Runnable r) { Thread t = new Thread(r); t.setName("TestThread:" + counter.getAndIncrement()); return t; } }); for (int i = 0; i < threadCount; i++) { executor.execute(new SimpleAPNSSenderThread(testAppId, true, payload, countDownLatch)); } //wait for the threads to finish try { countDownLatch.await(); } catch (InterruptedException e) { e.printStackTrace(); fail(e.getMessage()); } int count = objectFactory.getCreatedCount(new APNSConnectionPoolImpl.APNSConnectionKey(testAppId, true)); assertEquals("Object got created too many times", MAX_OBJECTS_PER_KEY, count); }
From source file:edu.vt.middleware.gator.log4j.LoggingEventHandlerExecutor.java
/** * Attempts to perform a clean shutdown of all running {@link * LoggingEventHandler} tasks./*from w w w . ja v a 2 s . c o m*/ */ public void shutdown() { for (LoggingEventHandlerThread runner : runningThreads) { runner.getLoggingEventHandler().shutdown(); try { runner.join(STOP_TIMEOUT); } catch (InterruptedException e) { logger.warn("Timed out waiting for LoggingEventHandler shutdown"); } catch (Exception e) { logger.warn("Error on logging event handler shutdown: " + e.getMessage()); } } }
From source file:com.metamx.druid.loading.S3DataSegmentPuller.java
@Override public long getLastModified(DataSegment segment) throws SegmentLoadingException { final S3Coords coords = new S3Coords(segment); try {//from www. j av a2 s .c om final StorageObject objDetails = S3Utils.retryS3Operation(new Callable<StorageObject>() { @Override public StorageObject call() throws Exception { return s3Client.getObjectDetails(coords.bucket, coords.path); } }); return objDetails.getLastModifiedDate().getTime(); } catch (InterruptedException e) { throw Throwables.propagate(e); } catch (IOException e) { throw new SegmentLoadingException(e, e.getMessage()); } catch (ServiceException e) { throw new SegmentLoadingException(e, e.getMessage()); } }
From source file:at.grahsl.kafka.connect.mongodb.MongoDbSinkTask.java
@Override public void put(Collection<SinkRecord> records) { if (records.isEmpty()) { LOGGER.debug("no sink records to process for current poll operation"); return;//from w w w .j av a 2 s . c o m } Map<String, MongoDbSinkRecordBatches> batchMapping = createSinkRecordBatchesPerTopic(records); batchMapping.forEach((namespace, batches) -> { String collection = StringUtils.substringAfter(namespace, MongoDbSinkConnectorConfig.MONGODB_NAMESPACE_SEPARATOR); batches.getBufferedBatches().forEach(batch -> { processSinkRecords(cachedCollections.get(namespace), batch); MongoDbSinkConnectorConfig.RateLimitSettings rls = rateLimitSettings.getOrDefault(collection, rateLimitSettings.get(MongoDbSinkConnectorConfig.TOPIC_AGNOSTIC_KEY_NAME)); if (rls.isTriggered()) { LOGGER.debug( "rate limit settings triggering {}ms defer timeout" + " after processing {} further batches for collection {}", rls.getTimeoutMs(), rls.getEveryN(), collection); try { Thread.sleep(rls.getTimeoutMs()); } catch (InterruptedException e) { LOGGER.error(e.getMessage()); } } }); }); }