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.apache.pulsar.client.impl.auth.AuthenticationAthenz.java
private boolean cachedRoleTokenIsValid() { if (roleToken == null) { return false; }//w ww . java 2 s. c o m // Ensure we refresh the Athenz role token every hour to avoid using an expired // role token return (System.nanoTime() - cachedRoleTokenTimestamp) < TimeUnit.HOURS.toNanos(cacheDurationInHour); }
From source file:net.pterodactylus.sone.web.ajax.GetTimesAjaxPage.java
/** * Returns the formatted relative time for a given time. * * @param webInterface/* www . j a v a 2 s. co m*/ * The Sone web interface (for l10n access) * @param time * The time to format the difference from (in milliseconds) * @return The formatted age */ public static Time getTime(WebInterface webInterface, long time) { if (time == 0) { return new Time(webInterface.getL10n().getString("View.Sone.Text.UnknownDate"), TimeUnit.HOURS.toMillis(12)); } long age = System.currentTimeMillis() - time; String text; long refresh; if (age < 0) { text = webInterface.getL10n().getDefaultString("View.Time.InTheFuture"); refresh = TimeUnit.MINUTES.toMillis(5); } else if (age < TimeUnit.SECONDS.toMillis(20)) { text = webInterface.getL10n().getDefaultString("View.Time.AFewSecondsAgo"); refresh = TimeUnit.SECONDS.toMillis(10); } else if (age < TimeUnit.SECONDS.toMillis(45)) { text = webInterface.getL10n().getString("View.Time.HalfAMinuteAgo"); refresh = TimeUnit.SECONDS.toMillis(20); } else if (age < TimeUnit.SECONDS.toMillis(90)) { text = webInterface.getL10n().getString("View.Time.AMinuteAgo"); refresh = TimeUnit.MINUTES.toMillis(1); } else if (age < TimeUnit.MINUTES.toMillis(30)) { text = webInterface.getL10n().getString("View.Time.XMinutesAgo", "min", String.valueOf(TimeUnit.MILLISECONDS.toMinutes(age + TimeUnit.SECONDS.toMillis(30)))); refresh = TimeUnit.MINUTES.toMillis(1); } else if (age < TimeUnit.MINUTES.toMillis(45)) { text = webInterface.getL10n().getString("View.Time.HalfAnHourAgo"); refresh = TimeUnit.MINUTES.toMillis(10); } else if (age < TimeUnit.MINUTES.toMillis(90)) { text = webInterface.getL10n().getString("View.Time.AnHourAgo"); refresh = TimeUnit.HOURS.toMillis(1); } else if (age < TimeUnit.HOURS.toMillis(21)) { text = webInterface.getL10n().getString("View.Time.XHoursAgo", "hour", String.valueOf(TimeUnit.MILLISECONDS.toHours(age + TimeUnit.MINUTES.toMillis(30)))); refresh = TimeUnit.HOURS.toMillis(1); } else if (age < TimeUnit.HOURS.toMillis(42)) { text = webInterface.getL10n().getString("View.Time.ADayAgo"); refresh = TimeUnit.DAYS.toMillis(1); } else if (age < TimeUnit.DAYS.toMillis(6)) { text = webInterface.getL10n().getString("View.Time.XDaysAgo", "day", String.valueOf(TimeUnit.MILLISECONDS.toDays(age + TimeUnit.HOURS.toMillis(12)))); refresh = TimeUnit.DAYS.toMillis(1); } else if (age < TimeUnit.DAYS.toMillis(11)) { text = webInterface.getL10n().getString("View.Time.AWeekAgo"); refresh = TimeUnit.DAYS.toMillis(1); } else if (age < TimeUnit.DAYS.toMillis(28)) { text = webInterface.getL10n().getString("View.Time.XWeeksAgo", "week", String.valueOf((TimeUnit.MILLISECONDS.toHours(age) + 84) / (7 * 24))); refresh = TimeUnit.DAYS.toMillis(1); } else if (age < TimeUnit.DAYS.toMillis(42)) { text = webInterface.getL10n().getString("View.Time.AMonthAgo"); refresh = TimeUnit.DAYS.toMillis(1); } else if (age < TimeUnit.DAYS.toMillis(330)) { text = webInterface.getL10n().getString("View.Time.XMonthsAgo", "month", String.valueOf((TimeUnit.MILLISECONDS.toDays(age) + 15) / 30)); refresh = TimeUnit.DAYS.toMillis(1); } else if (age < TimeUnit.DAYS.toMillis(540)) { text = webInterface.getL10n().getString("View.Time.AYearAgo"); refresh = TimeUnit.DAYS.toMillis(7); } else { text = webInterface.getL10n().getString("View.Time.XYearsAgo", "year", String.valueOf((long) ((TimeUnit.MILLISECONDS.toDays(age) + 182.64) / 365.28))); refresh = TimeUnit.DAYS.toMillis(7); } return new Time(text, refresh); }
From source file:ch.cyberduck.core.openstack.SwiftUrlProvider.java
@Override public DescriptiveUrlBag toUrl(final Path file) { final DescriptiveUrlBag list = new DescriptiveUrlBag(); if (file.isFile()) { Region region = null;//from w w w.j a v a 2s.c o m try { region = regionService.lookup(file); } catch (BackgroundException e) { log.warn(String.format("Failure looking up region for %s %s", file, e.getMessage())); } if (null == region) { list.addAll(new DefaultUrlProvider(session.getHost()).toUrl(file)); } else { if (!session.getHost().isDefaultWebURL()) { list.addAll(new WebUrlProvider(session.getHost()).toUrl(file)); } list.add(new DescriptiveUrl( URI.create(region.getStorageUrl(containerService.getContainer(file).getName(), containerService.getKey(file)).toString()), DescriptiveUrl.Type.provider, MessageFormat.format(LocaleFactory.localizedString("{0} URL"), session.getHost().getProtocol().getScheme().name().toUpperCase(Locale.ROOT)))); // In one hour list.addAll(this.sign(region, file, this.getExpiry((int) TimeUnit.HOURS.toSeconds(1)))); // Default signed URL expiring in 24 hours. list.addAll(this.sign(region, file, this.getExpiry((int) TimeUnit.SECONDS .toSeconds(PreferencesFactory.get().getInteger("s3.url.expire.seconds"))))); // 1 Week list.addAll(this.sign(region, file, this.getExpiry((int) TimeUnit.DAYS.toSeconds(7)))); // 1 Month list.addAll(this.sign(region, file, this.getExpiry((int) TimeUnit.DAYS.toSeconds(30)))); // 1 Year list.addAll(this.sign(region, file, this.getExpiry((int) TimeUnit.DAYS.toSeconds(365)))); } } return list; }
From source file:com.linkedin.pinot.core.data.readers.PinotSegmentRecordReaderTest.java
private Schema createPinotSchema() { Schema testSchema = new Schema(); testSchema.setSchemaName("schema"); FieldSpec spec;// ww w . j av a2 s .c o m spec = new DimensionFieldSpec(D_SV_1, DataType.STRING, true); testSchema.addField(spec); spec = new DimensionFieldSpec(D_MV_1, DataType.STRING, false); testSchema.addField(spec); spec = new MetricFieldSpec(M1, DataType.INT); testSchema.addField(spec); spec = new MetricFieldSpec(M2, DataType.FLOAT); testSchema.addField(spec); spec = new TimeFieldSpec(new TimeGranularitySpec(DataType.LONG, TimeUnit.HOURS, TIME)); testSchema.addField(spec); return testSchema; }
From source file:com.room5.server.spring_boot.jmx.JMXServerStatistics.java
/** * Current uptime: http://localhost:9191/jolokia/read/com.room5.jmx:name=JMXServerStatistics/Uptime *///w ww. jav a2 s . co m @ManagedMetric(description = "Current system uptime.", displayName = "Current system uptime.", metricType = MetricType.COUNTER, currencyTimeLimit = 10) public String getUptime() { long upTime = System.currentTimeMillis() - startTime; long days = TimeUnit.MILLISECONDS.toDays(upTime); long hoursRaw = TimeUnit.MILLISECONDS.toHours(upTime); long minutesRaw = TimeUnit.MILLISECONDS.toMinutes(upTime); //convert to string return String.format("%d days, %d hrs, %d min, %d sec", days, hoursRaw - TimeUnit.DAYS.toHours(days), minutesRaw - TimeUnit.HOURS.toMinutes(hoursRaw), TimeUnit.MILLISECONDS.toSeconds(upTime) - TimeUnit.MINUTES.toSeconds(minutesRaw)); }
From source file:org.dcache.util.histograms.TimeseriesHistogramTest.java
@Test public void buildShouldSucceedForTimeseriesHistogramWithoutData() throws Exception { givenTimeseriesHistogram();//ww w.j a v a 2 s . com givenBinUnitOf((double) TimeUnit.HOURS.toMillis(1)); givenBinCountOf(48); givenBinLabelOf(TimeUnit.HOURS.name()); givenDataLabelOf("COUNT"); givenHistogramTypeOf("Queued Movers"); givenHighestBinOf(getHoursInThePastFromNow(0)); whenConfigureIsCalled(); assertThatBuildSucceeded(); }
From source file:org.craftercms.profile.interceptors.AccessTokenCheckingInterceptorTest.java
private AccessToken getNormalToken() { TenantPermission permission = new TenantPermission(); permission.allow("*"); AccessToken token = new AccessToken(); token.setId(NORMAL_TOKEN_ID);/*from w ww .j av a2s. co m*/ token.setApplication(APPLICATION); token.setTenantPermissions(Arrays.asList(permission)); token.setExpiresOn(new Date(System.currentTimeMillis() + TimeUnit.HOURS.toMillis(24))); return token; }
From source file:org.codelibs.fess.helper.SystemHelper.java
@PostConstruct public void init() { final FessConfig fessConfig = ComponentUtil.getFessConfig(); filterPathEncoding = fessConfig.getPathEncoding(); supportedLanguages = fessConfig.getSupportedLanguagesAsArray(); langItemsCache = CacheBuilder.newBuilder().maximumSize(20).expireAfterAccess(1, TimeUnit.HOURS) .build(new CacheLoader<String, List<Map<String, String>>>() { @Override/* w w w . ja va 2 s . c om*/ public List<Map<String, String>> load(final String key) throws Exception { final ULocale uLocale = new ULocale(key); final Locale displayLocale = uLocale.toLocale(); final List<Map<String, String>> langItems = new ArrayList<>(supportedLanguages.length); final String msg = ComponentUtil.getMessageManager().getMessage(displayLocale, "labels.allLanguages"); final Map<String, String> defaultMap = new HashMap<>(2); defaultMap.put(Constants.ITEM_LABEL, msg); defaultMap.put(Constants.ITEM_VALUE, "all"); langItems.add(defaultMap); for (final String lang : supportedLanguages) { final Locale locale = LocaleUtils.toLocale(lang); final String label = locale.getDisplayName(displayLocale); final Map<String, String> map = new HashMap<>(2); map.put(Constants.ITEM_LABEL, label); map.put(Constants.ITEM_VALUE, lang); langItems.add(map); } return langItems; } }); ComponentUtil.doInitProcesses(p -> p.run()); parseProjectProperties(); }
From source file:io.gromit.uaparser.Parser.java
/** * Start schedule./* w w w .j av a 2 s . c om*/ * * @return the parser */ public Parser startSchedule() { scheduledExecutorService = Executors.newScheduledThreadPool(1); scheduledExecutorService.scheduleAtFixedRate(new Runnable() { @Override public void run() { initialize(uaRegexYaml); } }, 0, 1, TimeUnit.HOURS); return this; }
From source file:org.onebusaway.admin.service.server.impl.RssServiceAlertsSerivceImpl.java
@PostConstruct public void start() throws Exception { if (_locale == null) _locale = Locale.getDefault(); _executor = Executors.newSingleThreadScheduledExecutor(); // re-build internal route cache _executor.scheduleAtFixedRate(new RefreshDataTask(), 0, 1, TimeUnit.HOURS); // poll feed after cache is built above _executor.scheduleAtFixedRate(new PollRssTask(), 1, 5, TimeUnit.MINUTES); }