List of usage examples for org.joda.time Duration standardSeconds
public static Duration standardSeconds(long seconds)
From source file:org.trellisldp.rosid.file.streaming.FileProcessingPipeline.java
License:Apache License
/** * Get the beam pipeline/*from www. ja va2 s .c om*/ * @return the pipeline */ public Pipeline getPipeline() { LOGGER.debug("Building Beam Pipeline"); final PipelineOptions options = PipelineOptionsFactory.create(); final Pipeline p = Pipeline.create(options); // Add membership triples p.apply(getKafkaReader(bootstrapServers).withTopic(TOPIC_LDP_MEMBERSHIP_ADD).withoutMetadata()) .apply(ParDo.of(new BeamProcessor(dataConfiguration, LDP.PreferMembership.getIRIString(), true))) .apply(getKafkaWriter(bootstrapServers).withTopic(TOPIC_CACHE_AGGREGATE)); // Delete membership triples p.apply(getKafkaReader(bootstrapServers).withTopic(TOPIC_LDP_MEMBERSHIP_DELETE).withoutMetadata()) .apply(ParDo.of(new BeamProcessor(dataConfiguration, LDP.PreferMembership.getIRIString(), false))) .apply(getKafkaWriter(bootstrapServers).withTopic(TOPIC_CACHE_AGGREGATE)); // Add containment triples p.apply(getKafkaReader(bootstrapServers).withTopic(TOPIC_LDP_CONTAINMENT_ADD).withoutMetadata()) .apply(ParDo.of(new BeamProcessor(dataConfiguration, LDP.PreferContainment.getIRIString(), true))) .apply(getKafkaWriter(bootstrapServers).withTopic(TOPIC_CACHE_AGGREGATE)); // Delete containment triples p.apply(getKafkaReader(bootstrapServers).withTopic(TOPIC_LDP_CONTAINMENT_DELETE).withoutMetadata()) .apply(ParDo.of(new BeamProcessor(dataConfiguration, LDP.PreferContainment.getIRIString(), false))) .apply(getKafkaWriter(bootstrapServers).withTopic(TOPIC_CACHE_AGGREGATE)); if (aggregateSeconds > 0) { // Aggregate cache writes p.apply(getKafkaReader(bootstrapServers).withTopic(TOPIC_CACHE_AGGREGATE).withoutMetadata()) .apply(Window .<KV<String, String>>into(FixedWindows.of(Duration.standardSeconds(aggregateSeconds))) .triggering(AfterProcessingTime.pastFirstElementInPane() .plusDelayOf(Duration.standardSeconds(aggregateSeconds))) .discardingFiredPanes().withAllowedLateness(Duration.ZERO)) .apply(Combine.perKey(x -> x.iterator().next())) .apply(getKafkaWriter(bootstrapServers).withTopic(TOPIC_CACHE)); } else { // Skip aggregation p.apply(getKafkaReader(bootstrapServers).withTopic(TOPIC_CACHE_AGGREGATE).withoutMetadata()) .apply(getKafkaWriter(bootstrapServers).withTopic(TOPIC_CACHE)); } // Write to cache and dispatch to the event bus p.apply(getKafkaReader(bootstrapServers).withTopic(TOPIC_CACHE).withoutMetadata()) .apply(ParDo.of(new CacheWriter(dataConfiguration))) .apply(ParDo.of(new EventProcessor(baseUrlConfiguration))) .apply(getKafkaWriter(bootstrapServers).withTopic(TOPIC_EVENT)); return p; }
From source file:org.wisdom.cache.ehcache.CachedActionInterceptor.java
License:Apache License
/** * Intercepts a @Cached action method./*from w ww . j ava 2 s. c o m*/ * If the result of the action is cached, returned it immediately without having actually invoked the action method. * In this case, the interception chain is cut. * <p> * If the result is not yet cached, the interception chain continues, and the result is cached to be used during * the next invocation. * * @param configuration the interception configuration * @param context the interception context * @return the result. * @throws Exception something bad happened */ @Override public Result call(Cached configuration, RequestContext context) throws Exception { // Can we use the Cached version ? boolean nocache = HeaderNames.NOCACHE_VALUE .equalsIgnoreCase(context.context().header(HeaderNames.CACHE_CONTROL)); String key; if (Strings.isNullOrEmpty(configuration.key())) { key = context.request().uri(); } else { key = configuration.key(); } Result result = null; if (!nocache) { result = (Result) cache.get(key); } if (result == null) { result = context.proceed(); } else { LOGGER.info("Returning cached result for {} (key:{})", context.request().uri(), key); return result; } Duration duration; if (configuration.duration() == 0) { // Eternity == 1 year. duration = Duration.standardDays(365); } else { duration = Duration.standardSeconds(configuration.duration()); } cache.set(key, result, duration); LoggerFactory.getLogger(this.getClass()).info("Caching result of {} for {} seconds (key:{})", context.request().uri(), configuration.duration(), key); return result; }
From source file:org.wisdom.cache.ehcache.MyCachedController.java
License:Apache License
/** * @return 100 the first time, 101 the second one. *//*from w ww. j a va 2 s . co m*/ @Route(method = HttpMethod.GET, uri = "/cache") public Result retrieve() { Integer r = cache.get("result"); if (r == null) { r = 100; cache.set("result", 101, Duration.standardSeconds(2)); } return ok(Integer.toString(r)); }
From source file:syncthing.android.ui.session.MyDeviceCard.java
License:Open Source License
@Bindable public String getUptimeText() { return uptimeFormatter.print(Duration.standardSeconds(getUptime()).toPeriod()); }
From source file:ws.kotonoha.android.services.DataService.java
License:Apache License
@Override public void onCreate() { confSvc = new ConfigService(this); confSvc.load();/*from w w w. ja va2 s . com*/ super.onCreate(); httpClient = AndroidHttpClient.newInstance("Kotonoha/1.0"); HttpConnectionParams.setConnectionTimeout(httpClient.getParams(), 3000); HttpConnectionParams.setSoTimeout(httpClient.getParams(), 10000); markSvc = new MarkService(this); cardSvc = new CardService(this); wordSvc = new WordService(this); eventSvc = new EventService(this); AuthObject ao = confSvc.config().getAuthObject(); if (ao != null) { createRestSvc(ao); } esReg = new EventualSvcRegistry(this); Scheduler.delayed(esReg, Duration.standardSeconds(30)); }