List of usage examples for java.util.concurrent TimeUnit MILLISECONDS
TimeUnit MILLISECONDS
To view the source code for java.util.concurrent TimeUnit MILLISECONDS.
Click Source Link
From source file:com.amazonaws.eclipse.core.accounts.profiles.SdkCredentialsFileContentMonitorTest.java
@Test public void testMonitorInStoppedStatus() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); SdkCredentialsFileContentMonitor monitor = new SdkCredentialsFileContentMonitor(targetFile, MONITOR_POLLING_INTERVAL_MILLIS, new FileAlterationListenerAdaptor() { @Override// w ww . ja v a2s . c o m public void onFileChange(final File changedFile) { System.err.println("stopped"); latch.countDown(); } }); monitor.setDebugMode(true); monitor.start(); monitor.stop(); touch(targetFile); long waitTime = MONITOR_POLLING_INTERVAL_MILLIS * 2; Assert.assertFalse("Who counted it down to zero???", latch.await(waitTime, TimeUnit.MILLISECONDS)); }
From source file:models.NotificationMail.java
/** * Sets up a schedule to send notification mails. * * Since the application started and then * {@code application.notification.bymail.initdelay} of time passed, send * notification mails every {@code application.notification.bymail.interval} * of time.//from ww w . ja v a 2s . c om */ public static void startSchedule() { final Long MAIL_NOTIFICATION_INITDELAY_IN_MILLIS = Configuration.root() .getMilliseconds("application.notification.bymail.initdelay", 5 * 1000L); final Long MAIL_NOTIFICATION_INTERVAL_IN_MILLIS = Configuration.root() .getMilliseconds("application.notification.bymail.interval", 60 * 1000L); final int MAIL_NOTIFICATION_DELAY_IN_MILLIS = Configuration.root() .getMilliseconds("application.notification.bymail.delay", 180 * 1000L).intValue(); Akka.system().scheduler().schedule( Duration.create(MAIL_NOTIFICATION_INITDELAY_IN_MILLIS, TimeUnit.MILLISECONDS), Duration.create(MAIL_NOTIFICATION_INTERVAL_IN_MILLIS, TimeUnit.MILLISECONDS), new Runnable() { public void run() { try { sendMail(); } catch (Exception e) { play.Logger.warn("Failed to send notification mail", e); } } /** * Sends notification mails. * * Get and send notification mails for the events which satisfy * all of following conditions: * - {@code application.notification.bymail.delay} of time * passed since the event is created. * - The base resource still exists. In the case of an event * for new comment, the comment still exists. * * Every mail will be deleted regardless of whether it is sent * or not. */ private void sendMail() { Date sinceDate = DateTime.now().minusMillis(MAIL_NOTIFICATION_DELAY_IN_MILLIS).toDate(); List<NotificationMail> mails = find.where().lt("notificationEvent.created", sinceDate) .orderBy("notificationEvent.created ASC").findList(); for (NotificationMail mail : mails) { if (mail.notificationEvent.resourceExists()) { sendNotification(mail.notificationEvent); } mail.delete(); } } }, Akka.system().dispatcher()); }
From source file:com.android.volley.toolbox.RequestFuture.java
@Override public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { return doGet(TimeUnit.MILLISECONDS.convert(timeout, unit)); }
From source file:io.horizondb.model.core.fields.TimestampField.java
/** * {@inheritDoc}//from ww w. j a v a 2s .c o m */ @Override public FieldType getType() { if (this.sourceUnit.equals(TimeUnit.NANOSECONDS)) { return FieldType.NANOSECONDS_TIMESTAMP; } if (this.sourceUnit.equals(TimeUnit.MICROSECONDS)) { return FieldType.MICROSECONDS_TIMESTAMP; } if (this.sourceUnit.equals(TimeUnit.MILLISECONDS)) { return FieldType.MILLISECONDS_TIMESTAMP; } return FieldType.SECONDS_TIMESTAMP; }
From source file:com.sm.store.AppClientHandler.java
public Response sendRequest(Request request, Channel channel) { AsynReq asynReq = new AsynReq(request); try {//from w w w . j ava 2 s.c o m AsynReq tmp = map.putIfAbsent(request.getHeader().getVersion(), asynReq); if (tmp != null) throw new ConnectionException(request.getHeader().toString() + " was submitted twice"); channel.write(request); boolean flag = false; asynReq.getLock().lock(); try { flag = asynReq.getReady().await(timeout, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { //nameMap.remove( request.getHeader().getVersion() ); //swallow exception return new Response("InterruptedException", true); } finally { asynReq.getLock().unlock(); } if (flag == false) return new Response("time out ms" + timeout, true); else return new Response(asynReq.getRequest().getHeader().toString() + " Successful"); } finally { if (asynReq != null) { map.remove(asynReq.getRequest().getHeader().getVersion()); } } }
From source file:com.bt.aloha.testing.mockphones.NoAnswerDialogBean.java
@Override public void processInitialInvite(final Request request, final ServerTransaction serverTransaction, final String dialogId) { DialogInfo dialogInfo = getDialogCollection().get(dialogId); try {/* ww w .ja v a2 s . c o m*/ Thread.sleep(SLEEP_INTERVAL); } catch (InterruptedException e) { log.info("Unable to sleep full interval", e); } log.info("sending RINGING..."); getDialogBeanHelper().sendResponse(request, serverTransaction, Response.RINGING); int maxCallDuration = dialogInfo.getIntProperty(MAX_CALL_DURATION_PROPERTY_KEY, MAX_CALL_DURATION); log.debug(String.format("Sending Temporarily Unavailable in %s milliseconds", maxCallDuration)); getScheduledExecutorService().schedule(new Runnable() { public void run() { try { log.info("sending TEMPORARILY_UNAVAILABLE..."); getDialogBeanHelper().sendResponse(request, serverTransaction, Response.TEMPORARILY_UNAVAILABLE); } catch (Exception e) { log.info("Exception occured in NoAnswerPhone " + e.getMessage()); } } }, maxCallDuration, TimeUnit.MILLISECONDS); }
From source file:puma.application.evaluation.metrics.MetricsController.java
@RequestMapping(value = "/metrics/clear", method = RequestMethod.GET) public @ResponseBody void clear() { TimerFactory.getInstance().resetAllTimers(); // connect metrics to the Graphite server if (reporter != null) { reporter.stop();//ww w . j a v a 2 s . c om } final Graphite graphite = new Graphite(new InetSocketAddress("172.16.4.2", 2003)); reporter = GraphiteReporter.forRegistry(TimerFactory.getInstance().getMetricRegistry()) .prefixedWith("puma-application").convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL).build(graphite); reporter.start(10, TimeUnit.SECONDS); }
From source file:org.sample.asyncserver.MyResource.java
@GET public void getList(@Suspended final AsyncResponse ar) { ar.setTimeoutHandler(new TimeoutHandler() { @Override/* w w w . j a va 2 s . c o m*/ public void handleTimeout(AsyncResponse ar) { ar.resume("Operation timed out"); } }); ar.setTimeout(4000, TimeUnit.MILLISECONDS); ar.register(new MyCompletionCallback()); ar.register(new MyConnectionCallback()); Executors.newSingleThreadExecutor().submit(new Runnable() { @Override public void run() { try { Thread.sleep(3000); ar.resume(response[0]); } catch (InterruptedException ex) { } } }); }
From source file:com.agileEAP.module.cache.memcached.SpyMemcachedClient.java
/** * Delete, ??updateTimeout, ?false??.//from w w w .j a v a2 s.c o m */ public boolean safeDelete(String key) { Future<Boolean> future = memcachedClient.delete(key); try { return future.get(updateTimeout, TimeUnit.MILLISECONDS); } catch (Exception e) { future.cancel(false); } return false; }
From source file:ms1quant.MS1TargetQuantThread.java
@Override public void run() { try {//from w w w .java 2 s . c om Logger.getRootLogger().info("Processing file " + mzxmlfile.getAbsolutePath() + "...."); long time = System.currentTimeMillis(); LCMSPeakMS1 LCMS1 = new LCMSPeakMS1(mzxmlfile.getAbsolutePath(), NoCPUs); LCMS1.SetParameter(param); LCMS1.Resume = false; if (!param.TargetIDOnly) { LCMS1.CreatePeakFolder(); } LCMS1.ExportPeakClusterTable = false; if (id.PSMList.isEmpty()) { Logger.getRootLogger() .warn("There is no PSM mapped to the file:" + mzxmlfile.getName() + ", skipping the file."); return; } LCMS1.IDsummary = id; LCMS1.IDsummary.mzXMLFileName = mzxmlfile.getAbsolutePath(); if (param.TargetIDOnly) { LCMS1.SaveSerializationFile = false; } if (param.TargetIDOnly || !LCMS1.ReadPeakCluster()) { LCMS1.PeakClusterDetection(); } LCMS1.AssignQuant(false); LCMS1.IDsummary.ExportPepID(outputfolder); time = System.currentTimeMillis() - time; //logger.info(LCMS1.ParentmzXMLName + " processed time:" + String.format("%d hour, %d min, %d sec", TimeUnit.MILLISECONDS.toHours(time), TimeUnit.MILLISECONDS.toMinutes(time) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time)), TimeUnit.MILLISECONDS.toSeconds(time) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time)))); Logger.getRootLogger() .info(LCMS1.ParentmzXMLName + " processed time:" + String.format("%d hour, %d min, %d sec", TimeUnit.MILLISECONDS.toHours(time), TimeUnit.MILLISECONDS.toMinutes(time) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time)), TimeUnit.MILLISECONDS.toSeconds(time) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time)))); LCMS1.BaseClearAllPeaks(); LCMS1.SetSpectrumParser(null); LCMS1.IDsummary = null; LCMS1 = null; id.ReleaseIDs(); id = null; System.gc(); } catch (Exception ex) { Logger.getRootLogger().error(ExceptionUtils.getStackTrace(ex)); } }