Search in sources :

Example 91 with Duration

use of java.time.Duration in project jdk8u_jdk by JetBrains.

the class TCKOffsetDateTime method test_plus_Duration.

//-----------------------------------------------------------------------
// plus(Duration)
//-----------------------------------------------------------------------
@Test
public void test_plus_Duration() {
    Duration dur = Duration.ofSeconds(62, 3);
    OffsetDateTime t = TEST_2008_6_30_11_30_59_000000500.plus(dur);
    assertEquals(t, OffsetDateTime.of(2008, 6, 30, 11, 32, 1, 503, OFFSET_PONE));
}
Also used : OffsetDateTime(java.time.OffsetDateTime) Duration(java.time.Duration) Test(org.testng.annotations.Test)

Example 92 with Duration

use of java.time.Duration in project VocabHunter by VocabHunter.

the class SessionWordsToolImpl method timedCollect.

private static <T extends List<?>> T timedCollect(final String type, final Supplier<T> s, final Path file) {
    Instant start = Instant.now();
    T words = s.get();
    Instant end = Instant.now();
    Duration duration = Duration.between(start, end);
    String filename = FileNameTool.filename(file);
    LOG.info("Read filter file and found {} words marked as {} in {}ms ({})", words.size(), type, duration.toMillis(), filename);
    return words;
}
Also used : Instant(java.time.Instant) Duration(java.time.Duration)

Example 93 with Duration

use of java.time.Duration in project VocabHunter by VocabHunter.

the class FileStreamer method analyse.

public AnalysisResult analyse(final Path file) {
    Instant start = Instant.now();
    List<String> stream = lines(file);
    String filename = FileNameTool.filename(file);
    AnalysisResult result = analyser.analyse(stream, filename);
    int count = result.getOrderedUses().size();
    Instant end = Instant.now();
    Duration duration = Duration.between(start, end);
    LOG.info("Analysed text and found {} words in {}ms ({})", count, duration.toMillis(), filename);
    return result;
}
Also used : Instant(java.time.Instant) Duration(java.time.Duration) AnalysisResult(io.github.vocabhunter.analysis.model.AnalysisResult)

Example 94 with Duration

use of java.time.Duration in project logback-access-spring-boot-starter by akihyro.

the class AccessEventAssert method hasElapsedTime.

/**
     * Verifies that the elapsed time is in given range.
     *
     * @param start the start value of range (inclusive).
     * @param end the end value of range (exclusive).
     * @return this instance.
     * @see IAccessEvent#getElapsedTime()
     */
public S hasElapsedTime(LocalDateTime start, LocalDateTime end) {
    long actualElapsedTimeAsLong = actual.getElapsedTime();
    Duration actualElapsedTime = Duration.ofMillis(actualElapsedTimeAsLong);
    Assertions.assertThat(actualElapsedTime).isGreaterThanOrEqualTo(Duration.ofMillis(0L)).isLessThanOrEqualTo(Duration.between(start, end));
    return myself;
}
Also used : Duration(java.time.Duration)

Example 95 with Duration

use of java.time.Duration in project aries by apache.

the class AbstractPushStreamImpl method window.

@Override
public <R> PushStream<R> window(Supplier<Duration> time, IntSupplier maxEvents, Executor ex, BiFunction<Long, Collection<T>, R> f) {
    AtomicLong timestamp = new AtomicLong();
    AtomicLong counter = new AtomicLong();
    Object lock = new Object();
    AtomicReference<Queue<T>> queueRef = new AtomicReference<Queue<T>>(null);
    // This code is declared as a separate block to avoid any confusion
    // about which instance's methods and variables are in scope
    Consumer<AbstractPushStreamImpl<R>> begin = p -> {
        synchronized (lock) {
            timestamp.lazySet(System.nanoTime());
            long count = counter.get();
            scheduler.schedule(getWindowTask(p, f, time, maxEvents, lock, count, queueRef, timestamp, counter, ex), time.get().toNanos(), NANOSECONDS);
        }
        queueRef.set(getQueueForInternalBuffering(maxEvents.getAsInt()));
    };
    @SuppressWarnings("resource") AbstractPushStreamImpl<R> eventStream = new IntermediatePushStreamImpl<R>(psp, ex, scheduler, this) {

        @Override
        protected void beginning() {
            begin.accept(this);
        }
    };
    AtomicBoolean endPending = new AtomicBoolean(false);
    updateNext((event) -> {
        try {
            if (eventStream.closed.get() == CLOSED) {
                return ABORT;
            }
            Queue<T> queue;
            if (!event.isTerminal()) {
                long elapsed;
                long newCount;
                synchronized (lock) {
                    for (; ; ) {
                        queue = queueRef.get();
                        if (queue == null) {
                            if (endPending.get()) {
                                return ABORT;
                            } else {
                                continue;
                            }
                        } else if (queue.offer(event.getData())) {
                            return CONTINUE;
                        } else {
                            queueRef.lazySet(null);
                            break;
                        }
                    }
                    long now = System.nanoTime();
                    elapsed = now - timestamp.get();
                    timestamp.lazySet(now);
                    newCount = counter.get() + 1;
                    counter.lazySet(newCount);
                    // This is a non-blocking call, and must happen in the
                    // synchronized block to avoid re=ordering the executor
                    // enqueue with a subsequent incoming close operation
                    aggregateAndForward(f, eventStream, event, queue, ex, elapsed);
                }
                // These must happen outside the synchronized block as we
                // call out to user code
                queueRef.set(getQueueForInternalBuffering(maxEvents.getAsInt()));
                scheduler.schedule(getWindowTask(eventStream, f, time, maxEvents, lock, newCount, queueRef, timestamp, counter, ex), time.get().toNanos(), NANOSECONDS);
                return CONTINUE;
            } else {
                long elapsed;
                synchronized (lock) {
                    queue = queueRef.get();
                    queueRef.lazySet(null);
                    endPending.set(true);
                    long now = System.nanoTime();
                    elapsed = now - timestamp.get();
                    counter.lazySet(counter.get() + 1);
                }
                Collection<T> collected = queue == null ? emptyList() : queue;
                ex.execute(() -> {
                    try {
                        eventStream.handleEvent(PushEvent.data(f.apply(Long.valueOf(NANOSECONDS.toMillis(elapsed)), collected)));
                    } catch (Exception e) {
                        close(PushEvent.error(e));
                    }
                });
            }
            ex.execute(() -> eventStream.handleEvent(event.nodata()));
            return ABORT;
        } catch (Exception e) {
            close(PushEvent.error(e));
            return ABORT;
        }
    });
    return eventStream;
}
Also used : Arrays(java.util.Arrays) BiFunction(java.util.function.BiFunction) AbstractQueue(java.util.AbstractQueue) Deferred(org.osgi.util.promise.Deferred) EventType(org.osgi.util.pushstream.PushEvent.EventType) AtomicReferenceArray(java.util.concurrent.atomic.AtomicReferenceArray) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Collector(java.util.stream.Collector) PushStreamBuilder(org.osgi.util.pushstream.PushStreamBuilder) Collections.emptyList(java.util.Collections.emptyList) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) BlockingQueue(java.util.concurrent.BlockingQueue) Collectors(java.util.stream.Collectors) BinaryOperator(java.util.function.BinaryOperator) Promise(org.osgi.util.promise.Promise) PushStreamProvider(org.osgi.util.pushstream.PushStreamProvider) List(java.util.List) Optional(java.util.Optional) Queue(java.util.Queue) ConcurrentModificationException(java.util.ConcurrentModificationException) PushEvent(org.osgi.util.pushstream.PushEvent) LongAdder(java.util.concurrent.atomic.LongAdder) NANOSECONDS(java.util.concurrent.TimeUnit.NANOSECONDS) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PushStream(org.osgi.util.pushstream.PushStream) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) PushEventSource(org.osgi.util.pushstream.PushEventSource) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) LinkedList(java.util.LinkedList) NoSuchElementException(java.util.NoSuchElementException) IntSupplier(java.util.function.IntSupplier) IntFunction(java.util.function.IntFunction) Iterator(java.util.Iterator) ReentrantLock(java.util.concurrent.locks.ReentrantLock) Executor(java.util.concurrent.Executor) Semaphore(java.util.concurrent.Semaphore) State(org.apache.aries.pushstream.AbstractPushStreamImpl.State) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) Lock(java.util.concurrent.locks.Lock) PushEventConsumer(org.osgi.util.pushstream.PushEventConsumer) Comparator(java.util.Comparator) Collections(java.util.Collections) AtomicReference(java.util.concurrent.atomic.AtomicReference) ConcurrentModificationException(java.util.ConcurrentModificationException) NoSuchElementException(java.util.NoSuchElementException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) AbstractQueue(java.util.AbstractQueue) BlockingQueue(java.util.concurrent.BlockingQueue) Queue(java.util.Queue)

Aggregations

Duration (java.time.Duration)195 Test (org.testng.annotations.Test)135 Instant (java.time.Instant)17 Test (org.junit.Test)16 List (java.util.List)6 Map (java.util.Map)4 ZonedDateTime (java.time.ZonedDateTime)3 ArrayList (java.util.ArrayList)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 ReplSetHeartbeatReply (com.torodb.mongodb.commands.signatures.internal.ReplSetHeartbeatReply)2 LocalDateTime (java.time.LocalDateTime)2 OffsetDateTime (java.time.OffsetDateTime)2 ZoneId (java.time.ZoneId)2 DateTimeFormatter (java.time.format.DateTimeFormatter)2 Iterator (java.util.Iterator)2 Optional (java.util.Optional)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Collectors (java.util.stream.Collectors)2 Edge (org.apache.tinkerpop.gremlin.structure.Edge)2 JSONLexer (com.alibaba.fastjson.parser.JSONLexer)1