List of usage examples for org.joda.time Duration Duration
public Duration(ReadableInstant start, ReadableInstant end)
From source file:org.apache.druid.segment.realtime.appenderator.AppenderatorPlumber.java
License:Apache License
private void startPersistThread() { final Granularity segmentGranularity = schema.getGranularitySpec().getSegmentGranularity(); final Period windowPeriod = config.getWindowPeriod(); final DateTime truncatedNow = segmentGranularity.bucketStart(DateTimes.nowUtc()); final long windowMillis = windowPeriod.toStandardDuration().getMillis(); log.info("Expect to run at [%s]", DateTimes.nowUtc().plus(new Duration(System.currentTimeMillis(), segmentGranularity.increment(truncatedNow).getMillis() + windowMillis))); String threadName = StringUtils.format("%s-overseer-%d", schema.getDataSource(), config.getShardSpec().getPartitionNum()); ThreadRenamingCallable<ScheduledExecutors.Signal> threadRenamingCallable = new ThreadRenamingCallable<ScheduledExecutors.Signal>( threadName) {//from ww w. ja va2 s . c o m @Override public ScheduledExecutors.Signal doCall() { if (stopped) { log.info("Stopping merge-n-push overseer thread"); return ScheduledExecutors.Signal.STOP; } mergeAndPush(); if (stopped) { log.info("Stopping merge-n-push overseer thread"); return ScheduledExecutors.Signal.STOP; } else { return ScheduledExecutors.Signal.REPEAT; } } }; Duration initialDelay = new Duration(System.currentTimeMillis(), segmentGranularity.increment(truncatedNow).getMillis() + windowMillis); Duration rate = new Duration(truncatedNow, segmentGranularity.increment(truncatedNow)); ScheduledExecutors.scheduleAtFixedRate(scheduledExecutor, initialDelay, rate, threadRenamingCallable); }
From source file:org.apache.druid.segment.realtime.plumber.FlushingPlumber.java
License:Apache License
private void startFlushThread() { final Granularity segmentGranularity = schema.getGranularitySpec().getSegmentGranularity(); final DateTime truncatedNow = segmentGranularity.bucketStart(DateTimes.nowUtc()); final long windowMillis = config.getWindowPeriod().toStandardDuration().getMillis(); log.info("Expect to run at [%s]", DateTimes.nowUtc().plus(new Duration(System.currentTimeMillis(), schema.getGranularitySpec().getSegmentGranularity().increment(truncatedNow).getMillis() + windowMillis))); String threadName = StringUtils.format("%s-flusher-%d", getSchema().getDataSource(), getConfig().getShardSpec().getPartitionNum()); ThreadRenamingCallable<ScheduledExecutors.Signal> threadRenamingCallable = new ThreadRenamingCallable<ScheduledExecutors.Signal>( threadName) {/*from w w w . j a v a2s.co m*/ @Override public ScheduledExecutors.Signal doCall() { if (stopped) { log.info("Stopping flusher thread"); return ScheduledExecutors.Signal.STOP; } long minTimestamp = segmentGranularity .bucketStart(getRejectionPolicy().getCurrMaxTime().minus(windowMillis)).getMillis(); List<Map.Entry<Long, Sink>> sinksToPush = new ArrayList<>(); for (Map.Entry<Long, Sink> entry : getSinks().entrySet()) { final Long intervalStart = entry.getKey(); if (intervalStart < minTimestamp) { log.info("Adding entry[%s] to flush.", entry); sinksToPush.add(entry); } } for (final Map.Entry<Long, Sink> entry : sinksToPush) { flushAfterDuration(entry.getKey(), entry.getValue()); } if (stopped) { log.info("Stopping flusher thread"); return ScheduledExecutors.Signal.STOP; } else { return ScheduledExecutors.Signal.REPEAT; } } }; Duration initialDelay = new Duration(System.currentTimeMillis(), schema.getGranularitySpec().getSegmentGranularity().increment(truncatedNow).getMillis() + windowMillis); Duration rate = new Duration(truncatedNow, segmentGranularity.increment(truncatedNow)); ScheduledExecutors.scheduleAtFixedRate(flushScheduledExec, initialDelay, rate, threadRenamingCallable); }
From source file:org.apache.druid.segment.realtime.plumber.RealtimePlumber.java
License:Apache License
protected void startPersistThread() { final Granularity segmentGranularity = schema.getGranularitySpec().getSegmentGranularity(); final Period windowPeriod = config.getWindowPeriod(); final DateTime truncatedNow = segmentGranularity.bucketStart(DateTimes.nowUtc()); final long windowMillis = windowPeriod.toStandardDuration().getMillis(); log.info("Expect to run at [%s]", DateTimes.nowUtc().plus(new Duration(System.currentTimeMillis(), segmentGranularity.increment(truncatedNow).getMillis() + windowMillis))); String threadName = StringUtils.format("%s-overseer-%d", schema.getDataSource(), config.getShardSpec().getPartitionNum()); ThreadRenamingCallable<ScheduledExecutors.Signal> threadRenamingCallable = new ThreadRenamingCallable<ScheduledExecutors.Signal>( threadName) {/*from w w w . ja v a 2 s . co m*/ @Override public ScheduledExecutors.Signal doCall() { if (stopped) { log.info("Stopping merge-n-push overseer thread"); return ScheduledExecutors.Signal.STOP; } mergeAndPush(); if (stopped) { log.info("Stopping merge-n-push overseer thread"); return ScheduledExecutors.Signal.STOP; } else { return ScheduledExecutors.Signal.REPEAT; } } }; Duration initialDelay = new Duration(System.currentTimeMillis(), segmentGranularity.increment(truncatedNow).getMillis() + windowMillis); Duration rate = new Duration(truncatedNow, segmentGranularity.increment(truncatedNow)); ScheduledExecutors.scheduleAtFixedRate(scheduledExecutor, initialDelay, rate, threadRenamingCallable); }
From source file:org.apache.niolex.common.joda.Calculate.java
License:Apache License
public static void calcWorkTime(DateTime start, DateTime end) { long worked = new Duration(start, end).minus(FORMAL_TIME.plus(RESET_TIME).toStandardDuration()).getMillis(); StringBuffer sb = new StringBuffer(); if (worked < 0) { sb.append("Worked not enough! Still need work : "); PRINTER.printTo(sb, new Period(Math.abs(worked)), Locale.CHINESE); } else {//from w w w . j a v a2 s .c om sb.append("Good job! Worked : "); PRINTER.printTo(sb, new Period(Math.abs(worked)).plusHours(FORMAL_TIME.getHours()), Locale.CHINESE); } System.out.println(sb.toString()); }
From source file:org.apache.pig.Main.java
License:Apache License
private static void printScriptRunTime(DateTime startTime) { DateTime endTime = new DateTime(); Duration duration = new Duration(startTime, endTime); Period period = duration.toPeriod().normalizedStandard(PeriodType.time()); log.info("Pig script completed in " + PeriodFormat.getDefault().print(period) + " (" + duration.getMillis() + " ms)"); }
From source file:org.artifactory.repo.db.importexport.DbRepoImportHandler.java
License:Open Source License
private void commitTransaction(TransactionStatus status) { log.debug("{}: Committing transaction artifacts count: {} after {} seconds", repo.getKey(), progressAccumulator.getSuccessfulItemsCount(), new Duration(transactionStartTime, DateTime.now()).getStandardSeconds()); getTransactionManager().commit(status); }
From source file:org.atlasapi.media.entity.Broadcast.java
License:Apache License
public Broadcast(String broadcastOn, DateTime transmissionTime, DateTime transmissionEndTime, Boolean activelyPublished) { this.broadcastOn = broadcastOn; this.transmissionTime = transmissionTime; this.transmissionEndTime = transmissionEndTime; this.broadcastDuration = (int) new Duration(transmissionTime, transmissionEndTime).getStandardSeconds(); this.activelyPublished = activelyPublished; }
From source file:org.axonframework.eventhandling.scheduling.java.SimpleEventScheduler.java
License:Apache License
@Override public ScheduleToken schedule(DateTime triggerDateTime, Object event) { return schedule(new Duration(null, triggerDateTime), event); }
From source file:org.bubblecloud.ilves.site.DefaultSiteUI.java
License:Apache License
/** * Adds handler for credential posts./*from w w w . j a va 2s . co m*/ */ private void addCredentialPostRequestHandler() { // Add handler for credentials post. VaadinSession.getCurrent().addRequestHandler(new RequestHandler() { @Override public boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException { if (!StringUtils.isEmpty(request.getParameter("username")) && !StringUtils.isEmpty(request.getParameter("password")) && getSession() != null && getSession().getSession().getAttribute("user") == null) { final String emailAddress = request.getParameter("username"); final String password = request.getParameter("password"); final EntityManager entityManager = getSite().getSiteContext().getEntityManager(); final Locale locale = getLocale(); final Company company = resolveCompany(entityManager, (VaadinServletRequest) request); final User user = UserDao.getUser(entityManager, company, emailAddress); final String errorKey = LoginService.login(getSite().getSiteContext(), company, user, emailAddress, password); if (errorKey == null) { // Login success final List<Group> groups = UserDao.getUserGroups(entityManager, company, user); DefaultSiteUI.getSecurityProvider().setUser(user, groups); // Check for imminent password expiration. if (user.getPasswordExpirationDate() != null && new DateTime().plusDays(14).toDate() .getTime() > user.getPasswordExpirationDate().getTime()) { final DateTime expirationDate = new DateTime(user.getPasswordExpirationDate()); final DateTime currentDate = new DateTime(); final long daysUntilExpiration = new Duration(currentDate.toDate().getTime(), expirationDate.toDate().getTime()).getStandardDays(); setNotification(DefaultSiteUI.getLocalizationProvider().localize( "message-password-expires-in-days", locale) + ": " + daysUntilExpiration, Notification.Type.WARNING_MESSAGE); } else { setNotification(DefaultSiteUI.getLocalizationProvider().localize( "message-login-success", locale), Notification.Type.TRAY_NOTIFICATION); } } else { // Login failure setNotification(DefaultSiteUI.getLocalizationProvider().localize(errorKey, locale), Notification.Type.WARNING_MESSAGE); } } return false; // No response was written } }); }
From source file:org.cish4380.groupproject.utility.ApplicationPerformanceCounter.java
@Override public String getDuration() { return new Duration(startTime, DateTime.now()).toPeriod(PeriodType.millis()).toString(); }