List of usage examples for java.util.concurrent TimeUnit HOURS
TimeUnit HOURS
To view the source code for java.util.concurrent TimeUnit HOURS.
Click Source Link
From source file:org.codice.ddf.commands.catalog.CqlCommands.java
protected long getFilterStartTime() { if (lastSeconds > 0) { return filterCurrentTime - TimeUnit.SECONDS.toMillis(lastSeconds); } else if (lastMinutes > 0) { return filterCurrentTime - TimeUnit.MINUTES.toMillis(lastMinutes); } else if (lastHours > 0) { return filterCurrentTime - TimeUnit.HOURS.toMillis(lastHours); } else if (lastDays > 0) { return filterCurrentTime - TimeUnit.DAYS.toMillis(lastDays); } else if (lastWeeks > 0) { Calendar weeks = GregorianCalendar.getInstance(); weeks.setTimeInMillis(filterCurrentTime); weeks.add(Calendar.WEEK_OF_YEAR, -1 * lastWeeks); return weeks.getTimeInMillis(); } else if (lastMonths > 0) { Calendar months = GregorianCalendar.getInstance(); months.setTimeInMillis(filterCurrentTime); months.add(Calendar.MONTH, -1 * lastMonths); return months.getTimeInMillis(); } else {//from www . j av a 2 s .c om return 0; } }
From source file:com.epam.ta.reportportal.core.jasper.GetJasperReportHandler.java
/** * Format launch duration from long to human readable format. * * @param duration//from w ww.j av a 2 s .c o m * - input duration as long value * @return String - formatted output */ private static String millisToShortDHMS(long duration) { String res; long days = TimeUnit.MILLISECONDS.toDays(duration); long hours = TimeUnit.MILLISECONDS.toHours(duration) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(duration)); long minutes = TimeUnit.MILLISECONDS.toMinutes(duration) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(duration)); long seconds = TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration)); if (days == 0) { res = String.format("%02d:%02d:%02d", hours, minutes, seconds); } else { res = String.format("%dd%02d:%02d:%02d", days, hours, minutes, seconds); } return res; }
From source file:com.linkedin.drelephant.util.Utils.java
/** * Convert a millisecond duration to a string format * * @param millis A duration to convert to a string form * @return A string of the form "X:Y:Z Hours". *///from w w w . j a v a 2 s . c om public static String getDurationBreakdown(long millis) { long hours = TimeUnit.MILLISECONDS.toHours(millis); millis -= TimeUnit.HOURS.toMillis(hours); long minutes = TimeUnit.MILLISECONDS.toMinutes(millis); millis -= TimeUnit.MINUTES.toMillis(minutes); long seconds = TimeUnit.MILLISECONDS.toSeconds(millis); return String.format("%d:%02d:%02d", hours, minutes, seconds); }
From source file:cloudeventbus.cli.Certs.java
private static String formatTime(long seconds) { final long days = seconds / TimeUnit.DAYS.toSeconds(1); seconds -= TimeUnit.DAYS.toSeconds(days); final long hours = seconds / TimeUnit.HOURS.toSeconds(1); seconds -= TimeUnit.HOURS.toSeconds(hours); final long minutes = seconds / TimeUnit.MINUTES.toSeconds(1); seconds -= TimeUnit.MINUTES.toSeconds(minutes); return String.format("%dd:%dh:%dm:%ds", days, hours, minutes, seconds); }
From source file:org.dcache.util.histograms.TimeseriesHistogramTest.java
@Test public void updateOnTimeseriesHistogramShouldSumLastValue() throws Exception { givenTimeseriesHistogram();//from w w w .j av a 2 s. com givenQueueCountValuesFor(48); givenBinUnitOf((double) TimeUnit.HOURS.toMillis(1)); givenBinCountOf(48); givenBinLabelOf(TimeUnit.HOURS.name()); givenDataLabelOf("COUNT"); givenHistogramTypeOf("Queued Movers"); givenHighestBinOf(getHoursInThePastFromNow(0)); whenConfigureIsCalled(); assertThatUpdateSumsLastValue(); }
From source file:com.amazon.alexa.avs.AVSController.java
public AVSController(ExpectSpeechListener listenHandler, AVSAudioPlayerFactory audioFactory, AlertManagerFactory alarmFactory, AVSClientFactory avsClientFactory, DialogRequestIdAuthority dialogRequestIdAuthority, boolean wakeWordAgentEnabled, WakeWordIPCFactory wakewordIPCFactory, WakeWordDetectedHandler wakeWakeDetectedHandler) throws Exception { this.wakeWordAgentEnabled = wakeWordAgentEnabled; this.wakeWordDetectedHandler = wakeWakeDetectedHandler; if (this.wakeWordAgentEnabled) { try {//from w w w . j av a 2 s .c o m log.info("Creating Wake Word IPC | port number: " + WAKE_WORD_AGENT_PORT_NUMBER); this.wakeWordIPC = wakewordIPCFactory.createWakeWordIPC(this, WAKE_WORD_AGENT_PORT_NUMBER); this.wakeWordIPC.init(); Thread.sleep(1000); log.info("Created Wake Word IPC ok."); } catch (IOException e) { log.error("Error creating Wake Word IPC ok.", e); } } initializeMicrophone(); this.player = audioFactory.getAudioPlayer(this); this.player.registerAlexaSpeechListener(this); this.dialogRequestIdAuthority = dialogRequestIdAuthority; speechRequestAudioPlayerPauseController = new SpeechRequestAudioPlayerPauseController(player); expectSpeechListeners = new HashSet<ExpectSpeechListener>( Arrays.asList(listenHandler, speechRequestAudioPlayerPauseController)); dependentQueue = new LinkedBlockingDeque<>(); independentQueue = new LinkedBlockingDeque<>(); DirectiveEnqueuer directiveEnqueuer = new DirectiveEnqueuer(dialogRequestIdAuthority, dependentQueue, independentQueue); avsClient = avsClientFactory.getAVSClient(directiveEnqueuer, this); alertManager = alarmFactory.getAlertManager(this, this, AlertsFileDataStore.getInstance()); // Ensure that we have attempted to finish loading all alarms from file before sending // synchronize state alertManager.loadFromDisk(new ResultListener() { @Override public void onSuccess() { sendSynchronizeStateEvent(); } @Override public void onFailure() { sendSynchronizeStateEvent(); } }); // ensure we notify AVS of playbackStopped on app exit Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { player.stop(); avsClient.shutdown(); } }); dependentDirectiveThread = new BlockableDirectiveThread(dependentQueue, this, "DependentDirectiveThread"); independentDirectiveThread = new BlockableDirectiveThread(independentQueue, this, "IndependentDirectiveThread"); lastUserInteractionTimestampSeconds = new AtomicLong(System.currentTimeMillis() / MILLISECONDS_PER_SECOND); scheduledExecutor.scheduleAtFixedRate(new UserInactivityReport(), USER_INACTIVITY_REPORT_PERIOD_HOURS, USER_INACTIVITY_REPORT_PERIOD_HOURS, TimeUnit.HOURS); }
From source file:gov.llnl.lc.smt.command.record.SmtRecord.java
/** * Describe the method here//from w ww .ja v a2 s . co m * * @see gov.llnl.lc.smt.command.SmtCommand#doCommand(gov.llnl.lc.smt.command.config.SmtConfig) * * @param config * @return * @throws Exception ***********************************************************/ @Override public boolean doCommand(SmtConfig config) throws Exception { // this is the record command // support obtaining the fabric on-line, or from an OMS or Fabric // file. Only one at a time.... // which is all done by default within the execute() command of the // parent superclass smt-command // only one way of obtaining fabric data should be specified, but IF more // than one is, prefer; // // on-line (if host or port is specified) // OMS file // Fabric file // on-line using localhost and port 10011 Map<String, String> map = smtConfig.getConfigMap(); String hostNam = map.get(SmtProperty.SMT_HOST.getName()); String portNum = map.get(SmtProperty.SMT_PORT.getName()); // String file = convertSpecialFileName(map.get(SmtProperty.SMT_WRITE_OMS.getName())); // if(file != null) // { // try // { // OpenSmMonitorService.writeOMS(file, OMService); // map.put(SmtProperty.SMT_OMS_FILE.getName(), file); // System.out.println(OMService.toInfo()); // } // catch (IOException e) // { // logger.severe("Unable to save OMS file: (" + e.getMessage() + ")"); // } // } // // file = convertSpecialFileName(map.get(SmtProperty.SMT_WRITE_FABRIC.getName())); // if(file != null) // { // try // { // OSM_Fabric.writeFabric(file, OMService.getFabric()); // map.put(SmtProperty.SMT_FABRIC_FILE.getName(), file); // System.out.println(OMService.getFabric().toInfo()); // } // catch (IOException e) // { // logger.severe("Unable to save Fabric file: (" + e.getMessage() + ")"); // } // } // // file = convertSpecialFileName(map.get(SmtProperty.SMT_WRITE_DELTA.getName())); // if(file != null) // { // try // { // OSM_FabricDelta fd = getOSM_FabricDeltaOld(false); // OSM_FabricDelta.writeFabricDelta(file, fd); // map.put(SmtProperty.SMT_FABRIC_DELTA_FILE.getName(), file); // System.out.println(fd.toInfo()); // } // catch (IOException e) // { // logger.severe("Unable to save FabricDelta file: (" + e.getMessage() + ")"); // } // } // // file = convertSpecialFileName(map.get(SmtProperty.SMT_WRITE_DELTA_HISTORY.getName())); // if(file != null) // { // // this is the flight recorder, I need to know how long // String argType = map.get(SmtProperty.SMT_SUBCOMMAND_ARG.getName()); // if(argType != null) // { // int duration = Integer.parseInt(map.get(argType)); // TimeUnit tUnit = null; // if(argType.equals(SmtProperty.SMT_HISTORY_MINUTES.getName())) // tUnit = TimeUnit.MINUTES; // if(argType.equals(SmtProperty.SMT_HISTORY_HOURS.getName())) // tUnit = TimeUnit.HOURS; // // // always save the OSM_FabricDeltaCollection // OSM_FabricDeltaCollection.recordHistory(hostNam, portNum, duration, tUnit, file, true); // } // else // { // System.err.println("You must supply a duration (-nr | -nh | -nm) in order to record a History"); // } // } String file = convertSpecialFileName(map.get(SmtProperty.SMT_WRITE_OMS_HISTORY.getName())); if (file != null) { // this is the flight recorder, I need to know how long String argType = map.get(SmtProperty.SMT_SUBCOMMAND_ARG.getName()); if (argType != null) { int duration = Integer.parseInt(map.get(argType)); TimeUnit tUnit = null; if (argType.equals(SmtProperty.SMT_HISTORY_MINUTES.getName())) tUnit = TimeUnit.MINUTES; if (argType.equals(SmtProperty.SMT_HISTORY_HOURS.getName())) tUnit = TimeUnit.HOURS; // always save the OSM_Collection OMS_Collection.recordHistory(hostNam, portNum, duration, tUnit, file, true); } else { System.err.println("You must supply a duration (-nr | -nh | -nm) in order to record a History"); } } file = convertSpecialFileName(map.get(SmtProperty.SMT_WRITE_CONFIG.getName())); if (file != null) { // this is for the Fabric Configuration file if (OMService != null) { OSM_Configuration cfg = getOsmConfig(true); if ((cfg != null) && (cfg.getFabricConfig() != null)) { // save this configuration (cache it as well) OSM_Configuration.writeConfig(file, cfg); OSM_Configuration.cacheOSM_Configuration(OMService.getFabricName(), cfg); } } else System.err.println( "You must supply connection information to obtain and save the Fabric Configuration."); } return true; }
From source file:com.fluidops.iwb.provider.CkanProvider.java
@Override public void gather(List<Statement> res) throws Exception { // Read CKAN location and establish connection URL registryUrl = new URL(config.location); HttpURLConnection registryConnection = (HttpURLConnection) registryUrl.openConnection(); registryConnection.setRequestMethod("GET"); // Check if connection to CKAN could be established if (registryConnection.getResponseCode() != HttpURLConnection.HTTP_OK) { String msg = String.format("Connection to the CKAN registry could not be established. (%s, %s)", registryConnection.getResponseCode(), registryConnection.getResponseMessage()); logger.info(msg);/* ww w .j a va2s. c o m*/ throw new IllegalStateException(msg); } logger.trace("Connection to CKAN established successfully."); String siteContent = GenUtil.readUrl(registryConnection.getInputStream()); JSONObject groupAsJson = null; JSONArray packageListJsonArray = null; try { groupAsJson = new JSONObject(new JSONTokener(siteContent)); packageListJsonArray = groupAsJson.getJSONArray("packages"); } catch (JSONException e) { String msg = String.format("Returned content %s is not valid JSON. Check if the registry URL is valid.", siteContent); logger.debug(msg); throw new IllegalStateException(msg); } logger.trace("Extracted JSON from CKAN successfully"); // Create metadata about LOD catalog res.add(ProviderUtils.createStatement(CKAN.CKAN_CATALOG, RDF.TYPE, Vocabulary.DCAT.CATALOG)); res.add(ProviderUtils.createStatement(CKAN.CKAN_CATALOG, RDFS.LABEL, CKAN.CKAN_CATALOG_LABEL)); // Extract metadata for individual data sets listed in CKAN MultiThreadedHttpConnectionManager connectionManager = null; ExecutorService pool = null; try { pool = Executors.newFixedThreadPool(10); connectionManager = new MultiThreadedHttpConnectionManager(); HttpClient client = new HttpClient(connectionManager); List<Statement> synchedList = Collections.synchronizedList(res); for (int i = 0; i < packageListJsonArray.length(); i++) { String host = "http://www.ckan.net/package/" + packageListJsonArray.get(i).toString(); String baseUri = findBaseUri( "http://www.ckan.net/api/rest/package/" + packageListJsonArray.get(i).toString()); baseUri = (baseUri == null) ? host : baseUri; pool.execute(new MetadataReader(client, host, baseUri, CKAN.CKAN_CATALOG, synchedList)); } } finally { if (pool != null) { pool.shutdown(); pool.awaitTermination(4, TimeUnit.HOURS); } if (connectionManager != null) connectionManager.shutdown(); } }
From source file:org.shaf.core.process.config.ProcessConfiguration.java
/** * Sets the default properties in constructors. */// www .j av a 2s . co m private final void setDefaultProperties() { // Sets the "force emulation mode" property flag if it is not found. if (!this.isPropertyDefined(FORCE_EMULATION_MODE)) { LOG.warn("The '" + FORCE_EMULATION_MODE + "' property is not defined."); setForceEmulatorMode(false); } // Sets the "force delete output" property flag if it is not found. if (!this.isPropertyDefined(FORCE_DELETE_OUTPUT)) { LOG.warn("The '" + FORCE_DELETE_OUTPUT + "' property is not defined."); setForceDeleteOutput(true); } // Sets the process base if it is not found. if (!this.isPropertyDefined(PROCESS_BASE)) { LOG.warn("The '" + PROCESS_BASE + "' property is not defined."); this.setBase(System.getProperty("java.io.tmpdir")); } // Sets the max duration for process execution if it is not found. if (!this.isPropertyDefined(PROCESS_EXECUTION_TIMEOUT) || !this.isPropertyDefined(PROCESS_EXECUTION_TIMEOUT_UNIT)) { LOG.warn("The '" + PROCESS_EXECUTION_TIMEOUT + "' or '" + PROCESS_EXECUTION_TIMEOUT_UNIT + "'property is not defined."); this.setTimeout(1, TimeUnit.HOURS); } // Sets the default maximum buffer length for the generic I/O if it is // not found. if (!this.isPropertyDefined(IO_MAX_BUFFER_LENGTH)) { LOG.warn("The '" + IO_MAX_BUFFER_LENGTH + "' property is not defined."); this.setIOMaxBufferLength(10240L); } }
From source file:org.artifactory.bintray.BintrayServiceImpl.java
public BintrayServiceImpl() { bintrayPackageCache = initCache(500, TimeUnit.HOURS.toSeconds(1), false); }