List of usage examples for org.apache.commons.lang.time DateUtils MILLIS_PER_MINUTE
long MILLIS_PER_MINUTE
To view the source code for org.apache.commons.lang.time DateUtils MILLIS_PER_MINUTE.
Click Source Link
From source file:eagle.jobrunning.crawler.RunningJobCrawlerImpl.java
public void startCompleteStatusCheckerThread() { while (true) { List<Object> list; try {/*from w w w . j a v a2s . c om*/ list = fetcher.getResource(ResourceType.JOB_LIST, JobState.COMPLETED.name()); if (list == null) { LOG.warn("Current Completed Job List is Empty"); continue; } @SuppressWarnings("unchecked") List<AppInfo> apps = (List<AppInfo>) list.get(0); Set<String> completedJobSet = new HashSet<String>(); for (AppInfo app : apps) { //Only fetch MapReduce job if (!YarnApplicationType.MAPREDUCE.name().equals(app.getApplicationType()) || !jobFilter.accept(app.getUser())) { continue; } if (System.currentTimeMillis() - app.getFinishedTime() < controlConfig.completedJobOutofDateTimeInMin * DateUtils.MILLIS_PER_MINUTE) { completedJobSet.add(JobUtils.getJobIDByAppID(app.getId())); } } if (controlConfig.jobConfigEnabled) { addIntoProcessingQueueAndList(completedJobSet, queueOfConfig, ResourceType.JOB_CONFIGURATION); } if (controlConfig.jobInfoEnabled) { addIntoProcessingQueueAndList(completedJobSet, queueOfCompleteJobInfo, ResourceType.JOB_COMPLETE_INFO); } Thread.sleep(20 * 1000); } catch (Throwable t) { LOG.error("Got a throwable in fetching job completed list :", t); } } }
From source file:com.example.app.support.address.CommonUtils.java
/** * Calculate the elapsed time in specified {@link TimeUnit} * * @param startInMilli start time./*from w w w . j av a 2 s.c o m*/ * @param unit unit. * * @return the elapsed time. */ public static double getElapsed(long startInMilli, TimeUnit unit) { double elapsed = System.currentTimeMillis() - startInMilli; if (unit == MILLISECONDS) { return elapsed; } else if (unit == DAYS) { return elapsed / DateUtils.MILLIS_PER_DAY; } else if (unit == HOURS) { return elapsed / DateUtils.MILLIS_PER_HOUR; } else if (unit == MINUTES) { return elapsed / DateUtils.MILLIS_PER_MINUTE; } else if (unit == SECONDS) { return elapsed / DateUtils.MILLIS_PER_SECOND; } else { throw new UnsupportedOperationException(unit + " conversion is not supported"); } }
From source file:de.tor.tribes.ui.algo.TimeFrameVisualizer.java
private void renderDayMarkers(long pStart, long pEnd, Graphics2D pG2D) { Date d = new Date(pStart); d = DateUtils.setHours(d, 0);//from w w w . j ava2s . c o m d = DateUtils.setMinutes(d, 0); d = DateUtils.setSeconds(d, 0); d = DateUtils.setMilliseconds(d, 0); for (long mark = d.getTime(); mark <= pEnd; mark += DateUtils.MILLIS_PER_HOUR) { int markerPos = Math.round((mark - pStart) / DateUtils.MILLIS_PER_MINUTE); pG2D.setColor(Color.YELLOW); pG2D.fillRect(markerPos, 20, 2, 10); pG2D.setColor(Color.WHITE); pG2D.setFont(pG2D.getFont().deriveFont(Font.BOLD, 10.0f)); pG2D.fillRect(markerPos - 5, 15, 12, 10); pG2D.setColor(Color.BLACK); Calendar cal = Calendar.getInstance(); cal.setTime(new Date(mark)); NumberFormat f = NumberFormat.getNumberInstance(); f.setMinimumIntegerDigits(2); f.setMaximumFractionDigits(2); pG2D.drawString(f.format(cal.get(Calendar.HOUR_OF_DAY)), markerPos - 5, 23); } long currentDay = d.getTime(); while (currentDay < pEnd) { currentDay += DateUtils.MILLIS_PER_DAY; int markerPos = Math.round((currentDay - pStart) / DateUtils.MILLIS_PER_MINUTE); pG2D.setColor(new Color(123, 123, 123)); pG2D.fillRect(markerPos, 15, 3, 30); SimpleDateFormat f = new SimpleDateFormat("dd.MM.yy"); String dayLabel = f.format(currentDay); Rectangle2D labelBounds = pG2D.getFontMetrics().getStringBounds(dayLabel, pG2D); pG2D.setColor(Color.YELLOW); int labelWidth = (int) labelBounds.getWidth() + 5; pG2D.fillRect(markerPos - (int) Math.rint(labelWidth / 2), 15, labelWidth, 10); pG2D.setColor(Color.BLACK); pG2D.setFont(pG2D.getFont().deriveFont(Font.BOLD, 10.0f)); pG2D.drawString(dayLabel, markerPos - (int) Math.rint(labelWidth / 2) + 2, 23); } }
From source file:de.tor.tribes.ui.algo.TimeFrameVisualizer.java
private void updateSize() { LongRange startRange = mTimeFrame.getStartRange(); LongRange arriveRange = mTimeFrame.getArriveRange(); long minValue = startRange.getMinimumLong(); long maxValue = arriveRange.getMaximumLong(); Dimension size = new Dimension(Math.round( (maxValue - minValue + 240 * (int) DateUtils.MILLIS_PER_MINUTE) / DateUtils.MILLIS_PER_MINUTE), getHeight());//from ww w .jav a 2 s.c om if (size.getWidth() < mParent.getWidth()) { size = mParent.getSize(); } setMinimumSize(size); setMaximumSize(size); setPreferredSize(size); mParent.getViewport().setViewSize(size); }
From source file:edu.kit.dama.transfer.client.impl.AbstractTransferClient.java
/** * Performs all transfer tasks defined for this client. If the transfer fails, * there are MAX_TRIES retries. After this amount, FALSE is returned, the last * file is put back to the transfer map and no more files will be transfered. * * @return TRUE if the transfer was finished successfully. *//*from w ww . j a v a 2 s . c om*/ private boolean transferFiles() { createCheckpoint(); runningTasks.clear(); finishedTasks.clear(); failedTasks.clear(); int maxProtocolnstances = AdalapiSettings.getSingleton().getMaxProtocolInstances(); LOGGER.debug("Staging transfer of files using {} ADALAPI protocol instances by {} parallel tasks.", maxProtocolnstances, MAX_PARALLEL_TRANSFERS); long nextAliveAt = System.currentTimeMillis() + DateUtils.MILLIS_PER_MINUTE * 10; for (TransferTask transferTask : getTransferTasks().toArray(new TransferTask[getTransferTasks().size()])) { LOGGER.debug("Try to schedule transfer task {}", transferTask); while (getRunningTaskCount() >= MAX_PARALLEL_TRANSFERS) { try { Thread.sleep(CHECK_DELAY); } catch (InterruptedException ie) { } if (isCanceled()) { LOGGER.debug("Transfer was canceled. Aborting!"); break; } if (System.currentTimeMillis() >= nextAliveAt) { fireTransferAliveEvents(); nextAliveAt = System.currentTimeMillis() + DateUtils.MILLIS_PER_MINUTE * 10; } } if (!isCanceled()) { LOGGER.info("Starting new transfer task"); transferTask.addTransferTaskListener(this); runTask(transferTask); } } //wait until all running tasks have finished while (getRunningTaskCount() != 0) { try { Thread.sleep(CHECK_DELAY); } catch (InterruptedException ie) { } if (System.currentTimeMillis() >= nextAliveAt) { fireTransferAliveEvents(); nextAliveAt = System.currentTimeMillis() + DateUtils.MILLIS_PER_MINUTE * 10; } } if (!isCanceled() && (finishedTasks.size() + failedTasks.size() == getTransferTasks().size())) { LOGGER.debug("All files were transferred successfully"); } return failedTasks.isEmpty(); }
From source file:net.sourceforge.vulcan.git.CommitLogParserTest.java
public void testParseTimestampInDifferentTimeZone() throws Exception { final LogEntryDateParseRule rule = new LogEntryDateParseRule(); final Date d1 = rule.parse("2012-01-31T23:59:42-08:30"); final Date d2 = rule.parse("2012-01-31T23:59:42-05:00"); final long timeZoneDelta = (DateUtils.MILLIS_PER_HOUR * 3) + DateUtils.MILLIS_PER_MINUTE * 30; assertEquals(Long.toString(timeZoneDelta), Long.toString(d1.getTime() - d2.getTime())); assertFalse(d1.equals(d2));/*from w w w.ja v a 2 s.co m*/ }
From source file:net.sourceforge.vulcan.web.JstlFunctionsTest.java
public void testElapsedTimeDayHoursMinutesAndSeconds() throws Exception { expect(wac.getMessage("time.days", null, request.getLocale())).andReturn("days"); expect(wac.getMessage("time.hours", null, request.getLocale())).andReturn("hours"); expect(wac.getMessage("time.minute", null, request.getLocale())).andReturn("minute"); expect(wac.getMessage("time.seconds", null, request.getLocale())).andReturn("seconds"); replay();//from ww w . j av a 2s .c o m assertEquals("3 days, 12 hours, 1 minute, 4 seconds", JstlFunctions.formatElapsedTime(pageContext, DateUtils.MILLIS_PER_DAY * 3 + DateUtils.MILLIS_PER_HOUR * 12 + DateUtils.MILLIS_PER_MINUTE + 4500, 4)); verify(); }
From source file:net.sourceforge.vulcan.web.JstlFunctionsTest.java
public void testElapsedTimeDayAndZeroHours() throws Exception { expect(wac.getMessage("time.days", null, request.getLocale())).andReturn("days"); expect(wac.getMessage("time.minutes", null, request.getLocale())).andReturn("minutes"); replay();//w w w.j a v a 2 s. c o m assertEquals("3 days, 29 minutes", JstlFunctions.formatElapsedTime(pageContext, DateUtils.MILLIS_PER_DAY * 3 + DateUtils.MILLIS_PER_MINUTE * 29, 2)); verify(); }
From source file:nl.strohalm.cyclos.utils.TimePeriod.java
public float getValueIn(final Field field) { final Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(0L);//from ww w. j ava 2 s .c o m final Calendar cal2 = add(cal); final float millisDiff = cal2.getTimeInMillis() - cal.getTimeInMillis(); switch (field) { case MILLIS: return millisDiff; case SECONDS: return millisDiff / DateUtils.MILLIS_PER_SECOND; case MINUTES: return millisDiff / DateUtils.MILLIS_PER_MINUTE; case HOURS: return millisDiff / DateUtils.MILLIS_PER_HOUR; case DAYS: return millisDiff / DateUtils.MILLIS_PER_DAY; case WEEKS: return millisDiff / (DateUtils.MILLIS_PER_DAY * 7); case MONTHS: return millisDiff / (DateUtils.MILLIS_PER_DAY * 30); case YEARS: return millisDiff / (DateUtils.MILLIS_PER_DAY * 365); } return 0F; }
From source file:org.apache.eagle.jobrunning.crawler.RMResourceFetcher.java
private List<Object> doFetchCompleteJobInfo(String appId) throws Exception { InputStream is = null;/*from w w w . java2s.c om*/ InputStream is2 = null; try { checkUrl(); String jobID = JobUtils.getJobIDByAppID(appId); String urlString = jobCompleteDetailServiceURLBuilder.build(selector.getSelectedUrl(), jobID); LOG.info("Going to fetch job completed information for " + jobID + " , url: " + urlString); is = InputStreamUtils.getInputStream(urlString, JobConstants.CompressionType.GZIP); final JobCompleteWrapper jobWrapper = OBJ_MAPPER.readValue(is, JobCompleteWrapper.class); String urlString2 = jobCompleteCounterServiceURLBuilder.build(historyBaseUrl, jobID); LOG.info("Going to fetch job completed counters for " + jobID + " , url: " + urlString2); is2 = InputStreamUtils.getInputStream(urlString2, JobConstants.CompressionType.NONE, (int) (2 * DateUtils.MILLIS_PER_MINUTE)); final Document doc = Jsoup.parse(is2, StandardCharsets.UTF_8.name(), urlString2); JobCountersParser parser = new JobCountersParserImpl(); Map<String, Long> counters = parser.parse(doc); return Arrays.asList(jobWrapper, counters); } finally { if (is != null) { try { is.close(); } catch (Exception e) { } } if (is2 != null) { try { is2.close(); } catch (Exception e) { } } } }