List of usage examples for java.time Duration isZero
public boolean isZero()
From source file:Main.java
public static void main(String[] args) { Duration duration = Duration.between(LocalTime.MIDNIGHT, LocalTime.NOON); System.out.println(duration.isZero()); }
From source file:com.orange.cepheus.broker.Subscriptions.java
/** * Add a subscription./* w ww . j av a 2 s . c o m*/ * @param subscribeContext * @return the subscriptionId * @throws SubscriptionException, SubscriptionPersistenceException */ public String addSubscription(SubscribeContext subscribeContext) throws SubscriptionException, SubscriptionPersistenceException { //if duration is not present, then lb set duration to P1M Duration duration = convertDuration(subscribeContext.getDuration()); if (duration.isNegative()) { throw new SubscriptionException("negative duration is not allowed", new Throwable()); } if (duration.isZero()) { duration = convertDuration("P1M"); } // Compile all entity patterns now to check for conformance (result is cached for later use) try { subscribeContext.getEntityIdList().forEach(patterns::getPattern); } catch (PatternSyntaxException e) { throw new SubscriptionException("bad pattern", e); } // Generate a subscription id String subscriptionId = UUID.randomUUID().toString(); //create subscription and set the expiration date and subscriptionId Subscription subscription = new Subscription(subscriptionId, Instant.now().plus(duration), subscribeContext); //save subscription subscriptionsRepository.saveSubscription(subscription); subscriptions.put(subscriptionId, subscription); return subscriptionId; }
From source file:com.orange.cepheus.broker.LocalRegistrations.java
/** * Add or update a new context registration. * When the duration of the context is set to zero, this is handled as a remove. * @param registerContext/*w w w. j a v a2 s.co m*/ * @return contextRegistrationId */ public String updateRegistrationContext(RegisterContext registerContext) throws RegistrationException, RegistrationPersistenceException { Duration duration = registrationDuration(registerContext); String registrationId = registerContext.getRegistrationId(); // Handle a zero duration as a special remove operation if (duration.isZero() && registrationId != null) { registrationsRepository.removeRegistration(registrationId); registrations.remove(registrationId); remoteRegistrations.removeRegistration(registrationId); return registrationId; } // Compile all entity patterns now to check for conformance (result is cached for later use) try { registerContext.getContextRegistrationList() .forEach(c -> c.getEntityIdList().forEach(patterns::getPattern)); } catch (PatternSyntaxException e) { throw new RegistrationException("bad pattern", e); } // Generate a registration id if none was provided or if it does not refer to an existing registration if (registrationId == null || registrations.get(registrationId) == null) { registrationId = UUID.randomUUID().toString(); registerContext.setRegistrationId(registrationId); } // Exists in database Instant expirationDate = Instant.now().plus(duration); Registration registration; //TODO: instead of use insert or update, use replace instruction of sqlite try { registration = registrationsRepository.getRegistration(registerContext.getRegistrationId()); // update registration registration.setExpirationDate(expirationDate); registration.setRegisterContext(registerContext); registrationsRepository.updateRegistration(registration); } catch (EmptyResultDataAccessException e) { // Create registration and set the expiration date registration = new Registration(expirationDate, registerContext); registrationsRepository.saveRegistration(registration); } registrations.put(registrationId, registration); // Forward to remote broker remoteRegistrations.registerContext(registerContext, registrationId); return registrationId; }
From source file:org.apache.samza.test.framework.TestRunner.java
/** * Run the application with the specified timeout * * @param timeout time to wait for the application to finish. This timeout does not include * input stream initialization time or the assertion time over output streams. This timeout just accounts * for time that samza job takes run. Timeout must be greater than 0. * @throws SamzaException if Samza job fails with exception and returns UnsuccessfulFinish as the statuscode *//*from w w w .ja v a 2 s . c om*/ public void run(Duration timeout) { Preconditions.checkNotNull(app); Preconditions.checkState(!timeout.isZero() || !timeout.isNegative(), "Timeouts should be positive"); // Cleaning store directories to ensure current run does not pick up state from previous run deleteStoreDirectories(); Config config = new MapConfig(JobPlanner.generateSingleJobConfig(configs)); final LocalApplicationRunner runner = new LocalApplicationRunner(app, config); runner.run(externalContext); if (!runner.waitForFinish(timeout)) { throw new SamzaException("Timed out waiting for application to finish"); } ApplicationStatus status = runner.status(); deleteStoreDirectories(); if (status.getStatusCode() == ApplicationStatus.StatusCode.UnsuccessfulFinish) { throw new SamzaException("Application could not finish successfully", status.getThrowable()); } }
From source file:org.janusgraph.graphdb.database.management.ManagementSystem.java
/** * Sets time-to-live for those schema types that support it * * @param type/*from w w w . ja v a 2 s . c om*/ * @param duration Note that only 'seconds' granularity is supported */ @Override public void setTTL(final JanusGraphSchemaType type, final Duration duration) { if (!graph.getBackend().getStoreFeatures().hasCellTTL()) throw new UnsupportedOperationException("The storage engine does not support TTL"); if (type instanceof VertexLabelVertex) { Preconditions.checkArgument(((VertexLabelVertex) type).isStatic(), "must define vertex label as static to allow setting TTL"); } else { Preconditions.checkArgument(type instanceof EdgeLabelVertex || type instanceof PropertyKeyVertex, "TTL is not supported for type " + type.getClass().getSimpleName()); } Preconditions.checkArgument(type instanceof JanusGraphSchemaVertex); Integer ttlSeconds = (duration.isZero()) ? null : (int) duration.getSeconds(); setTypeModifier(type, ModifierType.TTL, ttlSeconds); }
From source file:org.janusgraph.graphdb.log.StandardTransactionLogProcessor.java
public StandardTransactionLogProcessor(StandardJanusGraph graph, Instant startTime) { Preconditions.checkArgument(graph != null && graph.isOpen()); Preconditions.checkArgument(startTime != null); Preconditions.checkArgument(graph.getConfiguration().hasLogTransactions(), "Transaction logging must be enabled for recovery to work"); Duration maxTxLength = graph.getConfiguration().getMaxCommitTime(); if (maxTxLength.compareTo(MIN_TX_LENGTH) < 0) maxTxLength = MIN_TX_LENGTH;// w w w.j av a2 s. c o m Preconditions.checkArgument(maxTxLength != null && !maxTxLength.isZero(), "Max transaction time cannot be 0"); this.graph = graph; this.serializer = graph.getDataSerializer(); this.times = graph.getConfiguration().getTimestampProvider(); this.txLog = graph.getBackend().getSystemTxLog(); this.persistenceTime = graph.getConfiguration().getMaxWriteTime(); this.verboseLogging = graph.getConfiguration().getConfiguration() .get(GraphDatabaseConfiguration.VERBOSE_TX_RECOVERY); this.txCache = CacheBuilder.newBuilder().concurrencyLevel(2).initialCapacity(100) .expireAfterWrite(maxTxLength.toNanos(), TimeUnit.NANOSECONDS) .removalListener(new RemovalListener<StandardTransactionId, TxEntry>() { @Override public void onRemoval(RemovalNotification<StandardTransactionId, TxEntry> notification) { RemovalCause cause = notification.getCause(); Preconditions.checkArgument(cause == RemovalCause.EXPIRED, "Unexpected removal cause [%s] for transaction [%s]", cause, notification.getKey()); TxEntry entry = notification.getValue(); if (entry.status == LogTxStatus.SECONDARY_FAILURE || entry.status == LogTxStatus.PRIMARY_SUCCESS) { failureTxCounter.incrementAndGet(); fixSecondaryFailure(notification.getKey(), entry); } else { successTxCounter.incrementAndGet(); } } }).build(); ReadMarker start = ReadMarker.fromTime(startTime); this.txLog.registerReader(start, new TxLogMessageReader()); cleaner = new BackgroundCleaner(); cleaner.start(); }