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.wso2.carbon.governance.custom.lifecycles.checklist.ui.clients.LifecycleManagementServiceClient.java
/** * This method is used to format a timestamp to 'dd:hh:mm:ss'. * * @param duration timestamp duration./*from w w w. j a v a 2s . co m*/ * @return formatted time duration to 'dd:hh:mm:ss'. */ private String formatTimeDuration(long duration) { String timeDuration; 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)); // Setting the duration to a readable format. if (days == 0 && hours == 0 && minutes == 0) { timeDuration = String.format(durationSecondsFormat, seconds); } else if (days == 0 && hours == 0) { timeDuration = String.format(durationMinutesSecondsFormat, minutes, seconds); } else if (days == 0) { timeDuration = String.format(durationHoursMinutesSecondsFormat, hours, minutes, seconds); } else { timeDuration = String.format(durationDaysHoursMinutesSecondsFormat, days, hours, minutes, seconds); } return timeDuration; }
From source file:org.lilyproject.repository.impl.AbstractSchemaCache.java
public void start() throws InterruptedException, KeeperException, RepositoryException { cacheRefresher.start();/*from w w w .j a va 2 s.c o m*/ ZkUtil.createPath(zooKeeper, CACHE_INVALIDATION_PATH); final ExecutorService threadPool = Executors.newFixedThreadPool(50); final List<Future> futures = new ArrayList<Future>(); for (int i = 0; i < 16; i++) { final int index = i; futures.add(threadPool.submit(new Callable<Void>() { @Override public Void call() throws InterruptedException, KeeperException, RepositoryException { for (int j = 0; j < 16; j++) { String bucket = "" + DIGITS_LOWER[index] + DIGITS_LOWER[j]; ZkUtil.createPath(zooKeeper, bucketPath(bucket)); cacheWatchers.add(new CacheWatcher(bucket)); } return null; } })); } for (Future future : futures) { try { future.get(); } catch (ExecutionException e) { throw new RuntimeException("failed to start cache", e); } } threadPool.shutdown(); threadPool.awaitTermination(1, TimeUnit.HOURS); ZkUtil.createPath(zooKeeper, CACHE_REFRESHENABLED_PATH); connectionWatcher = new ConnectionWatcher(); zooKeeper.addDefaultWatcher(connectionWatcher); readRefreshingEnabledState(); refreshAll(); }
From source file:org.apache.metron.profiler.hbase.SaltyRowKeyBuilderTest.java
/** * `rowKeys` should return all of the row keys needed to retrieve the profile values over a given time horizon. *//* w ww. j a v a 2 s . com*/ @Test public void testRowKeys() throws Exception { int hoursAgo = 1; // setup List<Object> groups = Collections.emptyList(); rowKeyBuilder = new SaltyRowKeyBuilder(saltDivisor, periodDuration, periodUnits); // a dummy profile measurement long now = System.currentTimeMillis(); long oldest = now - TimeUnit.HOURS.toMillis(hoursAgo); ProfileMeasurement m = new ProfileMeasurement().withProfileName("profile").withEntity("entity") .withPeriod(oldest, periodDuration, periodUnits).withProfileValue(22); // generate a list of expected keys List<byte[]> expectedKeys = new ArrayList<>(); for (int i = 0; i < (hoursAgo * 4) + 1; i++) { // generate the expected key byte[] rk = rowKeyBuilder.rowKey(m); expectedKeys.add(rk); // advance to the next period ProfilePeriod next = m.getPeriod().next(); m = new ProfileMeasurement().withProfileName("profile").withEntity("entity") .withPeriod(next.getStartTimeMillis(), periodDuration, periodUnits); } // execute List<byte[]> actualKeys = rowKeyBuilder.rowKeys(measurement.getProfileName(), measurement.getEntity(), groups, oldest, now); // validate - expectedKeys == actualKeys for (int i = 0; i < actualKeys.size(); i++) { byte[] actual = actualKeys.get(i); byte[] expected = expectedKeys.get(i); assertThat(actual, equalTo(expected)); } }
From source file:org.dcache.util.histograms.TimeseriesHistogramTest.java
@Test public void updateOnTimeseriesHistogramShouldRotateBuffer() throws Exception { givenTimeseriesHistogram();/*from ww w . j a v a 2 s. c o m*/ givenQueueCountValuesFor(48); givenBinUnitOf((double) TimeUnit.HOURS.toMillis(1)); givenBinCountOf(48); givenBinLabelOf(TimeUnit.HOURS.name()); givenDataLabelOf("COUNT"); givenHistogramTypeOf("Queued Movers"); givenHighestBinOf(getHoursInThePastFromNow(3)); whenConfigureIsCalled(); assertThatUpdateRotatesBuffer(3); }
From source file:werecloud.api.bean.VMWareMacCache.java
private void initializeMACCache() throws RemoteException, InterruptedException { long start = System.currentTimeMillis(); ManagedEntity[] mes = new InventoryNavigator(rootFolder).searchManagedEntities("VirtualMachine"); ExecutorService exec = Executors.newFixedThreadPool(loadThreads); try {//from w w w . j av a 2s.c o m for (final ManagedEntity me : mes) { exec.submit(new Runnable() { @Override public void run() { VirtualMachine vm = (VirtualMachine) me; addVirtualMachine(vm); } }); } } finally { exec.shutdown(); } exec.awaitTermination(1, TimeUnit.HOURS); logger.info("{} MAC addresses added and took {} milliseconds.", macAddresses.size(), System.currentTimeMillis() - start); }
From source file:co.marcin.novaguilds.command.guild.CommandGuildInfo.java
@Override public void execute(CommandSender sender, String[] args) throws Exception { String guildName;/*from w w w . j a v a 2 s. c o m*/ NovaPlayer nPlayer = PlayerManager.getPlayer(sender); if (args.length > 0) { guildName = args[0]; } else { if (!(sender instanceof Player)) { Message.CHAT_CMDFROMCONSOLE.send(sender); return; } if (nPlayer.hasGuild()) { guildName = nPlayer.getGuild().getName(); } else { Message.CHAT_GUILD_NOTINGUILD.send(sender); return; } } //searching by name NovaGuild guild = GuildManager.getGuildFind(guildName); if (guild == null) { Message.CHAT_GUILD_NAMENOTEXIST.send(sender); return; } Map<VarKey, String> vars = new HashMap<>(); List<String> guildInfoMessages; String separator = Message.CHAT_GUILDINFO_PLAYERSEPARATOR.get(); if ((sender instanceof Player && nPlayer.hasGuild() && guild.isMember(nPlayer)) || Permission.NOVAGUILDS_ADMIN_GUILD_FULLINFO.has(sender)) { guildInfoMessages = Message.CHAT_GUILDINFO_FULLINFO.getList(); } else { guildInfoMessages = Message.CHAT_GUILDINFO_INFO.getList(); } MessageManager.sendPrefixMessage(sender, guildInfoMessages.get(0)); int i; List<NovaPlayer> playerList = guild.getPlayers(); String leader = guild.getLeader().getName(); String players = ""; String playerColor; String leaderPrefixString; //String to insert to playername (leader prefix) String leaderPrefixFormat = Message.CHAT_GUILDINFO_LEADERPREFIX.get(); //players list if (!playerList.isEmpty()) { for (NovaPlayer nPlayerList : guild.getPlayers()) { if (nPlayerList.isOnline()) { playerColor = Message.CHAT_GUILDINFO_PLAYERCOLOR_ONLINE.get(); } else { playerColor = Message.CHAT_GUILDINFO_PLAYERCOLOR_OFFLINE.get(); } leaderPrefixString = ""; if (nPlayerList.getName().equalsIgnoreCase(leader)) { leaderPrefixString = leaderPrefixFormat; } players += playerColor + leaderPrefixString + nPlayerList.getName(); if (!nPlayerList.equals(playerList.get(playerList.size() - 1))) { players += separator; } } } //allies String allies = ""; if (!guild.getAllies().isEmpty()) { String allyFormat = Message.CHAT_GUILDINFO_ALLY.get(); for (NovaGuild allyGuild : guild.getAllies()) { String allyName = org.apache.commons.lang.StringUtils.replace(allyFormat, "{GUILDNAME}", allyGuild.getName()); allies = allies + allyName + separator; } allies = allies.substring(0, allies.length() - separator.length()); } //wars String wars = ""; if (!guild.getWars().isEmpty()) { String warFormat = Message.CHAT_GUILDINFO_WAR.get(); for (NovaGuild war : guild.getWars()) { String warName = org.apache.commons.lang.StringUtils.replace(warFormat, "{GUILDNAME}", war.getName()); wars = wars + warName + separator; } wars = wars.substring(0, wars.length() - separator.length()); } vars.put(VarKey.RANK, ""); vars.put(VarKey.GUILDNAME, guild.getName()); vars.put(VarKey.LEADER, guild.getLeader().getName()); vars.put(VarKey.TAG, guild.getTag()); vars.put(VarKey.MONEY, String.valueOf(guild.getMoney())); vars.put(VarKey.PLAYERS, players); vars.put(VarKey.PLAYERSCOUNT, String.valueOf(guild.getPlayers().size())); vars.put(VarKey.SLOTS, String.valueOf(guild.getSlots())); vars.put(VarKey.POINTS, String.valueOf(guild.getPoints())); vars.put(VarKey.LIVES, String.valueOf(guild.getLives())); vars.put(VarKey.OPENINV, Message.getOnOff(guild.isOpenInvitation())); //live regeneration time long liveRegenerationTime = Config.LIVEREGENERATION_REGENTIME.getSeconds() - (NumberUtils.systemSeconds() - guild.getLostLiveTime()); String liveRegenerationString = StringUtils.secondsToString(liveRegenerationTime); long timeWait = (guild.getTimeRest() + Config.RAID_TIMEREST.getSeconds()) - NumberUtils.systemSeconds(); vars.put(VarKey.LIVEREGENERATIONTIME, liveRegenerationString); vars.put(VarKey.TIMEREST, StringUtils.secondsToString(timeWait)); //time created and protection long createdAgo = NumberUtils.systemSeconds() - guild.getTimeCreated(); long protectionLeft = Config.GUILD_CREATEPROTECTION.getSeconds() - createdAgo; vars.put(VarKey.CREATEDAGO, StringUtils.secondsToString(createdAgo, TimeUnit.HOURS)); vars.put(VarKey.PROTLEFT, StringUtils.secondsToString(protectionLeft, TimeUnit.HOURS)); //home location coordinates Location sp = guild.getHome(); if (sp != null) { vars.put(VarKey.SP_X, String.valueOf(sp.getBlockX())); vars.put(VarKey.SP_Y, String.valueOf(sp.getBlockY())); vars.put(VarKey.SP_Z, String.valueOf(sp.getBlockZ())); } //put wars and allies into vars vars.put(VarKey.ALLIES, allies); vars.put(VarKey.WARS, wars); for (i = 1; i < guildInfoMessages.size(); i++) { boolean skip = false; String guildInfoMessage = guildInfoMessages.get(i); //lost live if (liveRegenerationTime <= 0 && guildInfoMessage.contains("{LIVEREGENERATIONTIME}")) { skip = true; } //Time rest if (timeWait <= 0 && guildInfoMessage.contains("{TIMEREST}")) { skip = true; } //home location if ((guildInfoMessage.contains("{SP_X}") || guildInfoMessage.contains("{SP_Y}") || guildInfoMessage.contains("{SP_Z}")) && guild.getHome() == null) { skip = true; } //allies if (guildInfoMessage.contains("{ALLIES}") && allies.isEmpty()) { skip = true; } //displaying wars if (guildInfoMessage.contains("{WARS}") && wars.isEmpty()) { skip = true; } if (guildInfoMessage.contains("{PROTLEFT}") && protectionLeft <= 0) { skip = true; } if (guildInfoMessage.contains("{CREATEDAGO}") && protectionLeft > 0) { skip = true; } if (!skip) { guildInfoMessage = MessageManager.replaceVarKeyMap(guildInfoMessage, vars); MessageManager.sendMessage(sender, guildInfoMessage); } } }
From source file:co.marcin.novaguilds.util.StringUtils.java
public static String secondsToString(long seconds, TimeUnit unit) { if (seconds <= 0) { seconds = 0;//from w w w.ja v a 2 s. c o m } int minute = 60; int hour = 60 * minute; int day = hour * 24; int week = day * 7; int month = day * 31; int year = 31536000; long years = seconds / year; seconds = seconds % year; long months = seconds / month; seconds = seconds % month; long weeks = seconds / week; seconds = seconds % week; long days = seconds / day; seconds = seconds % day; long hours = seconds / hour; seconds = seconds % hour; long minutes = seconds / minute; seconds = seconds % minute; String stringYears = "", stringMonths = "", stringWeeks = "", stringDays = "", stringHours = "", stringSeconds = "", stringMinutes = ""; if (years > 0) { Message form = years > 1 ? Message.TIMEUNIT_YEAR_PLURAL : Message.TIMEUNIT_YEAR_SINGULAR; stringYears = years + " " + form.get() + " "; } if (months > 0) { Message form = months > 1 ? Message.TIMEUNIT_MONTH_PLURAL : Message.TIMEUNIT_MONTH_SINGULAR; stringMonths = months + " " + form.get() + " "; } if (weeks > 0) { Message form = weeks > 1 ? Message.TIMEUNIT_WEEK_PLURAL : Message.TIMEUNIT_WEEK_SINGULAR; stringWeeks = weeks + " " + form.get() + " "; } if (days > 0) { Message form = days > 1 ? Message.TIMEUNIT_DAY_PLURAL : Message.TIMEUNIT_DAY_SINGULAR; stringDays = days + " " + form.get() + " "; } if (hours > 0) { Message form = hours > 1 ? Message.TIMEUNIT_HOUR_PLURAL : Message.TIMEUNIT_HOUR_SINGULAR; stringHours = hours + " " + form.get() + " "; } if (minutes > 0) { Message form = minutes > 1 ? Message.TIMEUNIT_MINUTE_PLURAL : Message.TIMEUNIT_MINUTE_SINGULAR; stringMinutes = minutes + " " + form.get() + " "; } if (seconds > 0 || (seconds == 0 && minutes == 0 && hours == 0 && days == 0 && weeks == 0 && months == 0 && years == 0)) { Message form = seconds == 1 ? Message.TIMEUNIT_SECOND_SINGULAR : Message.TIMEUNIT_SECOND_PLURAL; stringSeconds = seconds + " " + form.get() + " "; } if (unit == TimeUnit.DAYS && days > 0) { stringHours = ""; stringMinutes = ""; stringSeconds = ""; } else if (unit == TimeUnit.HOURS && hours > 0) { stringMinutes = ""; stringSeconds = ""; } else if (unit == TimeUnit.MINUTES && minutes > 0) { stringSeconds = ""; } String r = stringYears + stringMonths + stringWeeks + stringDays + stringHours + stringMinutes + stringSeconds; r = r.substring(0, r.length() - 1); return r; }
From source file:org.apache.accumulo.server.util.VerifyTabletAssignments.java
private static void checkTable(final String user, final String pass, String table, HashSet<KeyExtent> check, boolean verbose) throws AccumuloException, AccumuloSecurityException, TableNotFoundException, InterruptedException { if (check == null) System.out.println("Checking table " + table); else/*from www. java 2 s . com*/ System.out.println("Checking table " + table + " again, failures " + check.size()); Map<KeyExtent, String> locations = new TreeMap<KeyExtent, String>(); SortedSet<KeyExtent> tablets = new TreeSet<KeyExtent>(); MetadataTable.getEntries(HdfsZooInstance.getInstance(), new AuthInfo(user, ByteBuffer.wrap(pass.getBytes()), HdfsZooInstance.getInstance().getInstanceID()), table, false, locations, tablets); final HashSet<KeyExtent> failures = new HashSet<KeyExtent>(); for (KeyExtent keyExtent : tablets) if (!locations.containsKey(keyExtent)) System.out.println(" Tablet " + keyExtent + " has no location"); else if (verbose) System.out.println(" Tablet " + keyExtent + " is located at " + locations.get(keyExtent)); Map<String, List<KeyExtent>> extentsPerServer = new TreeMap<String, List<KeyExtent>>(); for (Entry<KeyExtent, String> entry : locations.entrySet()) { List<KeyExtent> extentList = extentsPerServer.get(entry.getValue()); if (extentList == null) { extentList = new ArrayList<KeyExtent>(); extentsPerServer.put(entry.getValue(), extentList); } if (check == null || check.contains(entry.getKey())) extentList.add(entry.getKey()); } ExecutorService tp = Executors.newFixedThreadPool(20); for (final Entry<String, List<KeyExtent>> entry : extentsPerServer.entrySet()) { Runnable r = new Runnable() { @Override public void run() { try { checkTabletServer(user, ByteBuffer.wrap(pass.getBytes()), entry, failures); } catch (Exception e) { System.err.println("Failure on ts " + entry.getKey() + " " + e.getMessage()); e.printStackTrace(); failures.addAll(entry.getValue()); } } }; tp.execute(r); } tp.shutdown(); while (!tp.awaitTermination(1, TimeUnit.HOURS)) { } if (failures.size() > 0) checkTable(user, pass, table, failures, verbose); }
From source file:com.karthikb351.vitinfo2.fragment.today.TodayListAdapter.java
private String getTimeDifferenceString(long diff, boolean ended) { int hours;/*from ww w .j a v a 2 s .com*/ int minutes; if (diff < 0 && ended) { return context.getString(R.string.today_course_timing_done); } else if (diff > Constants.MILLISECONDS_IN_MINUTE) { hours = (int) TimeUnit.MILLISECONDS.toHours(diff); minutes = (int) (TimeUnit.MILLISECONDS.toMinutes(diff) - TimeUnit.HOURS.toMinutes(hours)); if (hours == 0) { return context.getResources().getQuantityString(R.plurals.today_course_timing_minutes_later, minutes, minutes); } else if (minutes == 0) { return context.getResources().getQuantityString(R.plurals.today_course_timing_hours_later, hours, hours); } else { return context.getString(R.string.today_course_timing_hours_minutes_later, context.getResources().getQuantityString(R.plurals.today_course_timing_hours, hours, hours), context.getResources().getQuantityString(R.plurals.today_course_timing_minutes_later, minutes, minutes)); } } else { return context.getString(R.string.today_course_timing_right_now); } }
From source file:org.apache.falcon.expression.ExpressionHelper.java
public static long hours(int val) { return TimeUnit.HOURS.toMillis(val); }