List of usage examples for java.time Duration isNegative
public boolean isNegative()
From source file:Main.java
public static void main(String[] args) { Duration duration = Duration.between(LocalTime.MIDNIGHT, LocalTime.NOON); System.out.println(duration.isNegative()); duration = Duration.between(LocalTime.NOON, LocalTime.MIDNIGHT); System.out.println(duration.isNegative()); }
From source file:com.orange.cepheus.broker.Subscriptions.java
/** * Add a subscription./*from w w w. ja va2s .c om*/ * @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.offbynull.peernetic.debug.actornetwork.messages.TransitMessage.java
/** * Constructs a {@link TransitMessage} object. * @param source source//w ww .j a v a 2 s . c o m * @param destination destination * @param data contents * @param departTime time packet departed * @param duration duration the packet should stay in transit (before arriving) * @throws NullPointerException if any arguments are {@code null} * @throws IllegalArgumentException if {@code duration} is negative */ public TransitMessage(A source, A destination, ByteBuffer data, Instant departTime, Duration duration) { Validate.notNull(source); Validate.notNull(destination); Validate.notNull(data); Validate.notNull(departTime); Validate.notNull(duration); Validate.isTrue(!duration.isNegative()); this.source = source; this.destination = destination; this.data = ByteBuffer.allocate(data.remaining()); this.data.put(data); this.data.flip(); this.departTime = departTime; this.duration = duration; }
From source file:org.apache.samza.table.remote.couchbase.BaseCouchbaseTableFunction.java
/** * Set the timeout limit on the read / write operations. Default value is Duration.ZERO, which means no timeout. * See <a href="https://docs.couchbase.com/java-sdk/2.7/client-settings.html#timeout-options"></a>. * @param timeout Timeout duration/*from www . j av a 2 s .c o m*/ * @param <T> type of this instance * @return Self */ public <T extends BaseCouchbaseTableFunction<V>> T withTimeout(Duration timeout) { Preconditions.checkArgument(timeout != null && !timeout.isNegative(), "Timeout should not be null or negative"); this.timeout = timeout; return (T) this; }
From source file:org.apache.samza.table.remote.couchbase.BaseCouchbaseTableFunction.java
/** * Set the TTL for the data writen to Couchbase. Default value Duration.ZERO means no TTL, data will be stored forever. * See <a href="https://docs.couchbase.com/java-sdk/2.7/core-operations.html#expiry"></a>. * @param ttl TTL duration//from w ww. j a v a 2 s . c o m * @param <T> type of this instance * @return Self */ public <T extends BaseCouchbaseTableFunction<V>> T withTtl(Duration ttl) { Preconditions.checkArgument(ttl != null && !ttl.isNegative(), "TTL should not be null or negative"); this.ttl = ttl; return (T) this; }
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 www .j a v a 2 s . co m*/ 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()); } }