List of usage examples for org.joda.time Duration ZERO
Duration ZERO
To view the source code for org.joda.time Duration ZERO.
Click Source Link
From source file:com.mastfrog.acteur.DefaultRequestLogger.java
License:Open Source License
@Override public void onRespond(RequestID rid, Event<?> event, HttpResponseStatus status) { int reqNum = rid == null ? -1 : rid.getIndex(); StringBuilder sb = new StringBuilder(120).append(reqNum).append('\t') .append(FORMAT.print(rid == null ? Duration.ZERO.toPeriod() : rid.getDuration().toPeriod())) .append('\t').append(event.getRemoteAddress()).append("\t").append(status).append("\t") .append(event);/*from www. j a v a2 s. com*/ if (event instanceof HttpEvent) { String referrer = ((HttpEvent) event).getHeader(Headers.REFERRER); if (referrer != null) { sb.append('\t').append(referrer); } } System.out.println(sb); }
From source file:com.metamx.http.client.HttpClientConfig.java
License:Apache License
@Deprecated // Use the builder instead public HttpClientConfig(int numConnections, SSLContext sslContext) { this(numConnections, sslContext, Duration.ZERO, null, DEFAULT_BOSS_COUNT, DEFAULT_WORKER_COUNT); }
From source file:com.metamx.http.client.HttpClientInit.java
License:Apache License
@Deprecated public static HttpClient createClient(ResourcePoolConfig config, final SSLContext sslContext, Lifecycle lifecycle) {//from w w w.j av a 2s. c o m return createClient(new HttpClientConfig(config.getMaxPerKey(), sslContext, Duration.ZERO), lifecycle); }
From source file:com.moosemorals.movieeditor.Splitter.java
License:Open Source License
public static void split(Config config, List<TimingPair> pairs) throws IOException { File temp = File.createTempFile("scratch", "tmp"); File finalResult = new File(config.getOutputFile()); if (finalResult.exists()) { finalResult.delete();/*from www.ja v a 2 s.c om*/ } Duration length = Duration.ZERO; try (PrintWriter out = new PrintWriter(new FileWriter(temp))) { for (TimingPair pair : pairs) { File partFile = File.createTempFile("part-", ".ts", config.getTempDir()); partFile.deleteOnExit(); String[] cmd = { "/usr/bin/ffmpeg", "-hide_banner", "-progress", buildTargetURI(config, "start", TimingPair.format(pair.getStart()), "duration", TimingPair.format(pair.getDuration())), "-loglevel", "0", "-y", "-ss", TimingPair.format(pair.getStart()), "-t", TimingPair.format(pair.getDuration()), "-i", config.getInputFile(), "-f", "mpegts", "-c", "copy", "-avoid_negative_ts", "1", "-copyts", partFile.getAbsolutePath() }; int result = runProcess(cmd); log.info("Process result {}", result); if (result != 0) { throw new IOException("ffmpeg error, no details. Sorry."); } out.printf("file '%s'\n", partFile.getAbsolutePath()); length = length.plus(pair.getDuration()); } out.flush(); } String[] cmd = { "/usr/bin/ffmpeg", "-hide_banner", "-progress", buildTargetURI(config, "start", TimingPair.format(Duration.ZERO), "duration", TimingPair.format(length)), "-loglevel", "0", "-f", "concat", "-safe", "0", "-i", temp.getAbsolutePath(), "-c", "copy", finalResult.getAbsolutePath() }; int result = runProcess(cmd); log.debug("Process result {}", result); }
From source file:com.spotify.scio.bigtable.BigtableBulkWriter.java
License:Apache License
@VisibleForTesting static PCollection<Iterable<KV<ByteString, Iterable<Mutation>>>> createBulkShards( final PCollection<KV<ByteString, Iterable<Mutation>>> input, final int numOfShards, final Duration flushInterval) { return input.apply("Assign To Shard", ParDo.of(new AssignToShard(numOfShards))).apply("Window", Window .<KV<Long, KV<ByteString, Iterable<Mutation>>>>into(new GlobalWindows()) .triggering(/*from w w w . j a v a2 s . com*/ Repeatedly.forever(AfterProcessingTime.pastFirstElementInPane().plusDelayOf(flushInterval))) .discardingFiredPanes().withAllowedLateness(Duration.ZERO)) .apply("Group By Shard", GroupByKey.create()).apply("Gets Mutations", ParDo.of( new DoFn<KV<Long, Iterable<KV<ByteString, Iterable<Mutation>>>>, Iterable<KV<ByteString, Iterable<Mutation>>>>() { @ProcessElement public void process(ProcessContext c) { c.output(c.element().getValue()); } })); }
From source file:com.threewks.thundr.session.CookieSessionStore.java
License:Apache License
@Override public void clear() { resp.withCookie(cookie(cookieName, "", Duration.ZERO)); }
From source file:com.yahoo.bard.webservice.web.apirequest.ApiRequestImpl.java
License:Apache License
/** * Extracts the set of intervals from the api request. * * @param now The 'now' for which time macros will be relatively calculated * @param apiIntervalQuery API string containing the intervals in ISO 8601 format, values separated by ','. * @param granularity The granularity to generate the date based on period or macros. * @param dateTimeFormatter The formatter to parse date time interval segments * * @return Set of jodatime interval objects. * @throws BadApiRequestException if the requested interval is not found. *///w w w .j a v a 2s. c om protected static List<Interval> generateIntervals(DateTime now, String apiIntervalQuery, Granularity granularity, DateTimeFormatter dateTimeFormatter) throws BadApiRequestException { try (TimedPhase timer = RequestLog.startTiming("GeneratingIntervals")) { List<Interval> generated = new ArrayList<>(); if (apiIntervalQuery == null || apiIntervalQuery.equals("")) { LOG.debug(INTERVAL_MISSING.logFormat()); throw new BadApiRequestException(INTERVAL_MISSING.format()); } List<String> apiIntervals = Arrays.asList(apiIntervalQuery.split(",")); // Split each interval string into the start and stop instances, parse them, and add the interval to the // list for (String apiInterval : apiIntervals) { String[] split = apiInterval.split("/"); // Check for both a start and a stop if (split.length != 2) { String message = "Start and End dates are required."; LOG.debug(INTERVAL_INVALID.logFormat(apiIntervalQuery, message)); throw new BadApiRequestException(INTERVAL_INVALID.format(apiIntervalQuery, message)); } try { String start = split[0].toUpperCase(Locale.ENGLISH); String end = split[1].toUpperCase(Locale.ENGLISH); //If start & end intervals are period then marking as invalid interval. //Becacuse either one should be macro or actual date to generate an interval if (start.startsWith("P") && end.startsWith("P")) { LOG.debug(INTERVAL_INVALID.logFormat(start)); throw new BadApiRequestException(INTERVAL_INVALID.format(apiInterval)); } Interval interval; //If start interval is period, then create new interval with computed end date //possible end interval could be next,current, date if (start.startsWith("P")) { interval = new Interval(Period.parse(start), getAsDateTime(now, granularity, split[1], dateTimeFormatter)); //If end string is period, then create an interval with the computed start date //Possible start & end string could be a macro or an ISO 8601 DateTime } else if (end.startsWith("P")) { interval = new Interval(getAsDateTime(now, granularity, split[0], dateTimeFormatter), Period.parse(end)); } else { //start and end interval could be either macros or actual datetime interval = new Interval(getAsDateTime(now, granularity, split[0], dateTimeFormatter), getAsDateTime(now, granularity, split[1], dateTimeFormatter)); } // Zero length intervals are invalid if (interval.toDuration().equals(Duration.ZERO)) { LOG.debug(INTERVAL_ZERO_LENGTH.logFormat(apiInterval)); throw new BadApiRequestException(INTERVAL_ZERO_LENGTH.format(apiInterval)); } generated.add(interval); } catch (IllegalArgumentException iae) { // Handle poor JodaTime message (special case) String internalMessage = iae.getMessage().equals("The end instant must be greater the start") ? "The end instant must be greater than the start instant" : iae.getMessage(); LOG.debug(INTERVAL_INVALID.logFormat(apiIntervalQuery, internalMessage), iae); throw new BadApiRequestException(INTERVAL_INVALID.format(apiIntervalQuery, internalMessage), iae); } } return generated; } }
From source file:com.yahoo.bard.webservice.web.DataApiRequest.java
License:Apache License
/** * Extracts the set of intervals from the api request. * * @param apiIntervalQuery API string containing the intervals in ISO 8601 format, values separated by ','. * @param granularity The granularity to generate the date based on period or macros. * @param dateTimeFormatter The formatter to parse date time interval segments * * @return Set of jodatime interval objects. * @throws BadApiRequestException if the requested interval is not found. *//*from w ww. j a v a 2 s. c o m*/ protected static Set<Interval> generateIntervals(String apiIntervalQuery, Granularity granularity, DateTimeFormatter dateTimeFormatter) throws BadApiRequestException { Set<Interval> generated = new LinkedHashSet<>(); if (apiIntervalQuery == null || apiIntervalQuery.equals("")) { LOG.debug(INTERVAL_MISSING.logFormat()); throw new BadApiRequestException(INTERVAL_MISSING.format()); } List<String> apiIntervals = Arrays.asList(apiIntervalQuery.split(",")); // Split each interval string into the start and stop instances, parse them, and add the interval to the list for (String apiInterval : apiIntervals) { String[] split = apiInterval.split("/"); // Check for both a start and a stop if (split.length != 2) { String message = "Start and End dates are required."; LOG.debug(INTERVAL_INVALID.logFormat(apiIntervalQuery, message)); throw new BadApiRequestException(INTERVAL_INVALID.format(apiIntervalQuery, message)); } try { String start = split[0].toUpperCase(Locale.ENGLISH); String end = split[1].toUpperCase(Locale.ENGLISH); //If start & end intervals are period then marking as invalid interval. //Becacuse either one should be macro or actual date to generate an interval if (start.startsWith("P") && end.startsWith("P")) { LOG.debug(INTERVAL_INVALID.logFormat(start)); throw new BadApiRequestException(INTERVAL_INVALID.format(apiInterval)); } Interval interval; DateTime now = new DateTime(); //If start interval is period, then create new interval with computed end date //possible end interval could be next,current, date if (start.startsWith("P")) { interval = new Interval(Period.parse(start), getAsDateTime(now, granularity, split[1], dateTimeFormatter)); //If end string is period, then create an interval with the computed start date //Possible start & end string could be a macro or an ISO 8601 DateTime } else if (end.startsWith("P")) { interval = new Interval(getAsDateTime(now, granularity, split[0], dateTimeFormatter), Period.parse(end)); } else { //start and end interval could be either macros or actual datetime interval = new Interval(getAsDateTime(now, granularity, split[0], dateTimeFormatter), getAsDateTime(now, granularity, split[1], dateTimeFormatter)); } // Zero length intervals are invalid if (interval.toDuration().equals(Duration.ZERO)) { LOG.debug(INTERVAL_ZERO_LENGTH.logFormat(apiInterval)); throw new BadApiRequestException(INTERVAL_ZERO_LENGTH.format(apiInterval)); } generated.add(interval); } catch (IllegalArgumentException iae) { LOG.debug(INTERVAL_INVALID.logFormat(apiIntervalQuery, iae.getMessage()), iae); throw new BadApiRequestException(INTERVAL_INVALID.format(apiIntervalQuery, iae.getMessage()), iae); } } return generated; }
From source file:debop4k.timeperiod.samples.TimeBlockPeriodRelationTestData.java
License:Apache License
public TimeBlockPeriodRelationTestData(DateTime start, DateTime end, Duration duration) { assert duration.compareTo(Duration.ZERO) >= 0 : "duration ? 0 ??? ? ."; reference = new TimeBlock(start, end, true); val beforeEnd = start.minus(duration); val beforeStart = beforeEnd.minus(reference.getDuration()); val insideStart = start.plus(duration); val insideEnd = end.minus(duration); val afterStart = end.plus(duration); val afterEnd = afterStart.plus(reference.getDuration()); after = new TimeBlock(beforeStart, beforeEnd, true); startTouching = new TimeBlock(beforeStart, start, true); startInside = new TimeBlock(beforeStart, insideStart, true); insideStartTouching = new TimeBlock(start, afterStart, true); enclosingStartTouching = new TimeBlock(start, insideEnd, true); enclosing = new TimeBlock(insideStart, insideEnd, true); enclosingEndTouching = new TimeBlock(insideStart, end, true); exactMatch = new TimeBlock(start, end, true); inside = new TimeBlock(beforeStart, afterEnd, true); insideEndTouching = new TimeBlock(beforeStart, end, true); endInside = new TimeBlock(insideEnd, afterEnd, true); endTouching = new TimeBlock(end, afterEnd, true); before = new TimeBlock(afterStart, afterEnd, true); allPeriods.addAll(Arrays.asList(reference, after, startTouching, startInside, insideStartTouching, enclosingStartTouching, enclosing, enclosingEndTouching, exactMatch, inside, insideEndTouching, endInside, endTouching, before)); }
From source file:debop4k.timeperiod.samples.TimeRangePeriodRelationTestData.java
License:Apache License
public TimeRangePeriodRelationTestData(DateTime start, DateTime end, Duration duration) { assert duration.compareTo(Duration.ZERO) >= 0 : "duration ? 0 ??? ? ."; reference = new TimeRange(start, end, true); val beforeEnd = start.minus(duration); val beforeStart = beforeEnd.minus(reference.getDuration()); val insideStart = start.plus(duration); val insideEnd = end.minus(duration); val afterStart = end.plus(duration); val afterEnd = afterStart.plus(reference.getDuration()); after = new TimeRange(beforeStart, beforeEnd, true); startTouching = new TimeRange(beforeStart, start, true); startInside = new TimeRange(beforeStart, insideStart, true); insideStartTouching = new TimeRange(start, afterStart, true); enclosingStartTouching = new TimeRange(start, insideEnd, true); enclosing = new TimeRange(insideStart, insideEnd, true); enclosingEndTouching = new TimeRange(insideStart, end, true); exactMatch = new TimeRange(start, end, true); inside = new TimeRange(beforeStart, afterEnd, true); insideEndTouching = new TimeRange(beforeStart, end, true); endInside = new TimeRange(insideEnd, afterEnd, true); endTouching = new TimeRange(end, afterEnd, true); before = new TimeRange(afterStart, afterEnd, true); allPeriods.addAll(Arrays.asList(reference, after, startTouching, startInside, insideStartTouching, enclosingStartTouching, enclosing, enclosingEndTouching, exactMatch, inside, insideEndTouching, endInside, endTouching, before)); }