List of usage examples for org.joda.time Duration standardDays
public static Duration standardDays(long days)
From source file:com.arpnetworking.tsdcore.limiter.legacy.MetricsLimiterTestBase.java
License:Apache License
/** * Create a <code>MetricsLimiter</code> suitable for testing. * * TODO(vkoskela): This should be refactored into a TestBeanFactory [MAI-168]. * * @return New instance of <code>MetricsLimiter</code>. *///w w w. j ava 2 s . c o m public static DefaultMetricsLimiter testLimiter() { return new DefaultMetricsLimiter.Builder().setEnableStateAutoWriter(Boolean.FALSE) .setMaxAggregations(Long.MAX_VALUE) .setStateManagerBuilder(new MetricsLimiterStateManager.Builder() .setStateFile(Paths.get("/dev/null")) .setStateFileFlushInterval(Duration.standardDays(365 * 100)) // ~100 // years ).build(); }
From source file:com.example.suharshs.vango.RunKeyActivity.java
License:Open Source License
/** Called when the user clicks the Remote Inspect button */ public void runRemoteInspect(View view) { String email;/*w w w . java 2 s. c o m*/ try { email = mRemoteInspectors.invite("helper", Duration.standardDays(7)); } catch (VException e) { Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show(); return; } // This whole app lives to be thrown away after testing, so don't worry about // using resource ids for the strings. final Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("message/rfc822"); intent.putExtra(Intent.EXTRA_SUBJECT, "Please look at vango"); intent.putExtra(Intent.EXTRA_TEXT, email); if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } else { Toast.makeText(this, "No email client installed", Toast.LENGTH_LONG).show(); } }
From source file:com.github.dbourdette.otto.data.DataTableUtils.java
License:Apache License
/** * Finds best Duration of rows for a {@link SimpleDataTable} based on given table interval *//*from ww w .ja va2s . c o m*/ public static Duration findBest(Interval interval) { Duration duration = new Duration(interval.getStart(), interval.getEnd()); if (duration.isShorterThan(ONE_DAY) || duration.equals(ONE_DAY)) { return Duration.standardMinutes(5); } else if (duration.isShorterThan(FIVE_DAYS) || duration.equals(FIVE_DAYS)) { return Duration.standardMinutes(30); } else { return Duration.standardDays(1); } }
From source file:com.github.dbourdette.otto.web.form.ReportForm.java
License:Apache License
public SimpleDataTable buildTable(Source source) { if (advanced) { return source.buildTable(getReportConfig(), getInterval(), Duration.standardDays(1)); } else {// w ww. java 2 s . com return source.buildTable(getReportConfig(), period); } }
From source file:com.google.cloud.solutions.LogAnalyticsPipeline.java
License:Apache License
public static void main(String[] args) { PipelineOptionsFactory.register(LogAnalyticsPipelineOptions.class); LogAnalyticsPipelineOptions options = PipelineOptionsFactory.fromArgs(args).withValidation() .as(LogAnalyticsPipelineOptions.class); Pipeline p = Pipeline.create(options); PCollection<String> homeLogs; PCollection<String> browseLogs; PCollection<String> locateLogs; boolean outputWithTimestamp; /**/*from w ww . j a v a2s . c o m*/ * If the pipeline is started in "streaming" mode, treat the input sources as Pub/Sub subscriptions */ if (options.isStreaming()) { outputWithTimestamp = false; homeLogs = p.apply(PubsubIO.Read.named("homeLogsPubSubRead").subscription(options.getHomeLogSource())); browseLogs = p .apply(PubsubIO.Read.named("browseLogsPubSubRead").subscription(options.getBrowseLogSource())); locateLogs = p .apply(PubsubIO.Read.named("locateLogsPubSubRead").subscription(options.getLocateLogSource())); } /** * If the pipeline is not started in "streaming" mode, treat the input sources as Cloud Storage paths */ else { outputWithTimestamp = true; // [START readingData] homeLogs = p.apply(TextIO.Read.named("homeLogsTextRead").from(options.getHomeLogSource())); browseLogs = p.apply(TextIO.Read.named("browseLogsTextRead").from(options.getBrowseLogSource())); locateLogs = p.apply(TextIO.Read.named("locateLogsTextRead").from(options.getLocateLogSource())); // [END readingData] } /** * Flatten all input PCollections into a single PCollection */ // [START flattenCollections] PCollection<String> allLogs = PCollectionList.of(homeLogs).and(browseLogs).and(locateLogs) .apply(Flatten.<String>pCollections()); // [END flattenCollections] /** * Transform "allLogs" PCollection<String> to PCollection<LogMessage> and apply custom windowing scheme */ // [START transformStringToLogMessage] PCollection<LogMessage> allLogMessages = allLogs.apply(ParDo.named("allLogsToLogMessage") .of(new EmitLogMessageFn(outputWithTimestamp, options.getLogRegexPattern()))); // [END transformStringToLogMessage] // [START applyWindowing] PCollection<LogMessage> allLogMessagesDaily = allLogMessages.apply( Window.named("allLogMessageToDaily").<LogMessage>into(FixedWindows.of(Duration.standardDays(1)))); // [END applyWindowing] /** * Transform "allLogs" PCollection<LogMessage> to PCollection<TableRow> */ // [START logMessageToTableRow] PCollection<TableRow> logsAsTableRows = allLogMessagesDaily .apply(ParDo.named("logMessageToTableRow").of(new LogMessageTableRowFn())); // [END logMessageToTableRow] /** * Output "allLogs" PCollection<TableRow> to BigQuery */ TableSchema allLogsTableSchema = TableRowOutputTransform.createTableSchema(options.getAllLogsTableSchema()); // [START allLogsToBigQuery] logsAsTableRows.apply(BigQueryIO.Write.named("allLogsToBigQuery").to(options.getAllLogsTableName()) .withSchema(allLogsTableSchema).withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_APPEND) .withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED)); // [END allLogsToBigQuery] /** * Create new PCollection<KV<String,Double>> * - Contains "destination->responseTime" key-value pairs * - Used for computing responseTime aggregations */ PCollection<KV<String, Double>> destResponseTimeCollection = allLogMessagesDaily .apply(ParDo.named("logMessageToDestRespTime").of(new DoFn<LogMessage, KV<String, Double>>() { @Override public void processElement(ProcessContext processContext) throws Exception { LogMessage l = processContext.element(); processContext.output(KV.of(l.getDestination(), l.getResponseTime())); } })); /** * Transform PCollection<KV<String,Double>> to PCollection<TableRow> * - First aggregate "destination->responseTime" key-value pairs into * - destination->maxResponseTime and destination->meanResponseTime * - Use custom PTransform to output PCollection to BigQuery */ // [START computeAggregations] PCollection<KV<String, Double>> destMaxRespTime = destResponseTimeCollection .apply(Combine.<String, Double, Double>perKey(new Max.MaxDoubleFn())); PCollection<KV<String, Double>> destMeanRespTime = destResponseTimeCollection .apply(Mean.<String, Double>perKey()); // [END computeAggregations] PCollection<TableRow> destMaxRespTimeRows = destMaxRespTime.apply(new TableRowOutputTransform( options.getMaxRespTimeTableSchema(), options.getMaxRespTimeTableName())); PCollection<TableRow> destMeanRespTimeRows = destMeanRespTime.apply(new TableRowOutputTransform( options.getMeanRespTimeTableSchema(), options.getMeanRespTimeTableName())); PipelineResult r = p.run(); LOG.info(r.toString()); }
From source file:com.linkedin.pinot.controller.validation.ValidationManager.java
License:Apache License
/** * Computes a list of missing intervals, given a list of existing intervals and the expected frequency of the * intervals./*from www . j a va 2 s. c om*/ * * @param segmentIntervals The list of existing intervals * @param frequency The expected interval frequency * @return The list of missing intervals */ public static List<Interval> computeMissingIntervals(List<Interval> segmentIntervals, Duration frequency) { // Sanity check for freuency if (frequency == null) { return Collections.emptyList(); } // Default segment granularity to day level if its small than hours. if (frequency.getMillis() < Duration.standardHours(1).getMillis()) { frequency = Duration.standardDays(1); } // If there are less than two segments, none can be missing if (segmentIntervals.size() < 2) { return Collections.emptyList(); } // Sort the intervals by ascending starting time List<Interval> sortedSegmentIntervals = new ArrayList<Interval>(segmentIntervals); Collections.sort(sortedSegmentIntervals, new Comparator<Interval>() { @Override public int compare(Interval first, Interval second) { if (first.getStartMillis() < second.getStartMillis()) return -1; else if (second.getStartMillis() < first.getStartMillis()) return 1; return 0; } }); // Find the minimum starting time and maximum ending time final long startTime = sortedSegmentIntervals.get(0).getStartMillis(); long endTime = Long.MIN_VALUE; for (Interval sortedSegmentInterval : sortedSegmentIntervals) { if (endTime < sortedSegmentInterval.getEndMillis()) { endTime = sortedSegmentInterval.getEndMillis(); } } final long frequencyMillis = frequency.getMillis(); int lastEndIntervalCount = 0; List<Interval> missingIntervals = new ArrayList<Interval>(10); for (Interval segmentInterval : sortedSegmentIntervals) { int startIntervalCount = (int) ((segmentInterval.getStartMillis() - startTime) / frequencyMillis); int endIntervalCount = (int) ((segmentInterval.getEndMillis() - startTime) / frequencyMillis); // If there is at least one complete missing interval between the end of the previous interval and the start of // the current interval, then mark the missing interval(s) as missing if (lastEndIntervalCount < startIntervalCount - 1) { for (int missingIntervalIndex = lastEndIntervalCount + 1; missingIntervalIndex < startIntervalCount; ++missingIntervalIndex) { missingIntervals.add(new Interval(startTime + frequencyMillis * missingIntervalIndex, startTime + frequencyMillis * (missingIntervalIndex + 1) - 1)); } } lastEndIntervalCount = Math.max(lastEndIntervalCount, endIntervalCount); } return missingIntervals; }
From source file:com.mastfrog.acteur.ClasspathResourcePage.java
License:Open Source License
@Deprecated @SuppressWarnings("LeakingThisInConstructor") protected ClasspathResourcePage(final Application app, final HttpEvent event, ActeurFactory f, DateTime serverStartTime, String... patterns) { this.path = event.getPath(); responseHeaders.setLastModified(serverStartTime); responseHeaders.addCacheControl(CacheControlTypes.Public); responseHeaders.addCacheControl(CacheControlTypes.must_revalidate); responseHeaders.addCacheControl(CacheControlTypes.max_age, Duration.standardDays(100)); responseHeaders.setContentLengthProvider(this); responseHeaders.setETagProvider(this); getResponseHeaders().setMaxAge(Duration.standardDays(100)); getResponseHeaders().addVaryHeader(Headers.CONTENT_ENCODING); add(f.matchPath(patterns));/*ww w . j a v a2s .c o m*/ add(f.matchMethods(com.mastfrog.acteur.headers.Method.GET, com.mastfrog.acteur.headers.Method.HEAD)); add(HasStreamAction.class); add(f.sendNotModifiedIfETagHeaderMatches()); add(f.sendNotModifiedIfIfModifiedSinceHeaderMatches()); if (event.getMethod() != com.mastfrog.acteur.headers.Method.HEAD) { add(WriteBodyActeur.class); } else { add(f.responseCode(HttpResponseStatus.OK)); } }
From source file:com.mastfrog.acteur.resources.DefaultExpiresPolicy.java
License:Open Source License
public DateTime get(MediaType mimeType, Path path) { if (!production) { return null; }/*from w w w . j av a2 s.co m*/ Long expires = settings.getLong("expires." + mimeType.type() + '/' + mimeType.subtype()); if (expires != null) { return DateTime.now().plus(Duration.millis(expires)); } if ("image".equals(mimeType.type())) { return DateTime.now().plus(Duration.standardDays(30)); } return null; }
From source file:com.metamx.druid.http.FileRequestLogger.java
License:Open Source License
@LifecycleStart public void start() { try {//from ww w. jav a 2s. c o m baseDir.mkdirs(); MutableDateTime mutableDateTime = new DateTime().toMutableDateTime(); mutableDateTime.setMillisOfDay(0); currentDay = mutableDateTime.toDateTime(); fileWriter = new FileWriter(new File(baseDir, currentDay.toString("yyyy-MM-dd'.log'")), true); long nextDay = currentDay.plusDays(1).getMillis(); Duration delay = new Duration(nextDay - new DateTime().getMillis()); ScheduledExecutors.scheduleWithFixedDelay(exec, delay, Duration.standardDays(1), new Callable<ScheduledExecutors.Signal>() { @Override public ScheduledExecutors.Signal call() { currentDay = currentDay.plusDays(1); try { synchronized (lock) { Closeables.closeQuietly(fileWriter); fileWriter = new FileWriter(new File(baseDir, currentDay.toString()), true); } } catch (Exception e) { Throwables.propagate(e); } return ScheduledExecutors.Signal.REPEAT; } }); } catch (IOException e) { Throwables.propagate(e); } }
From source file:com.microsoft.azure.management.graphrbac.samples.ManageServicePrincipal.java
License:Open Source License
private static ActiveDirectoryApplication createActiveDirectoryApplication(Azure.Authenticated authenticated) throws Exception { String name = SdkContext.randomResourceName("adapp-sample", 20); //create a self-sighed certificate String domainName = name + ".com"; String certPassword = "StrongPass!12"; Certificate certificate = Certificate.createSelfSigned(domainName, certPassword); // create Active Directory application ActiveDirectoryApplication activeDirectoryApplication = authenticated.activeDirectoryApplications() .define(name).withSignOnUrl("https://github.com/Azure/azure-sdk-for-java/" + name) // password credentials definition .definePasswordCredential("password").withPasswordValue("P@ssw0rd") .withDuration(Duration.standardDays(700)).attach() // certificate credentials definition .defineCertificateCredential("cert").withAsymmetricX509Certificate() .withPublicKey(Files.readAllBytes(Paths.get(certificate.getCerPath()))) .withDuration(Duration.standardDays(100)).attach().create(); System.out.println(activeDirectoryApplication.id() + " - " + activeDirectoryApplication.applicationId()); return activeDirectoryApplication; }