当前位置: 首页>>代码示例>>Java>>正文


Java StopWatch类代码示例

本文整理汇总了Java中org.apache.camel.util.StopWatch的典型用法代码示例。如果您正苦于以下问题:Java StopWatch类的具体用法?Java StopWatch怎么用?Java StopWatch使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StopWatch类属于org.apache.camel.util包,在下文中一共展示了StopWatch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: restoreTimeoutMapFromAggregationRepository

import org.apache.camel.util.StopWatch; //导入依赖的package包/类
/**
 * Restores the timeout map with timeout values from the aggregation repository.
 * <p/>
 * This is needed in case the aggregator has been stopped and started again (for example a server restart).
 * Then the existing exchanges from the {@link AggregationRepository} must have their timeout conditions restored.
 */
protected void restoreTimeoutMapFromAggregationRepository() throws Exception {
    // grab the timeout value for each partly aggregated exchange
    Set<String> keys = aggregationRepository.getKeys();
    if (keys == null || keys.isEmpty()) {
        return;
    }

    StopWatch watch = new StopWatch();
    LOG.trace("Starting restoring CompletionTimeout for {} existing exchanges from the aggregation repository...", keys.size());

    for (String key : keys) {
        Exchange exchange = aggregationRepository.get(camelContext, key);
        // grab the timeout value
        long timeout = exchange.hasProperties() ? exchange.getProperty(Exchange.AGGREGATED_TIMEOUT, 0, long.class) : 0;
        if (timeout > 0) {
            LOG.trace("Restoring CompletionTimeout for exchangeId: {} with timeout: {} millis.", exchange.getExchangeId(), timeout);
            addExchangeToTimeoutMap(key, exchange, timeout);
        }
    }

    // log duration of this task so end user can see how long it takes to pre-check this upon starting
    LOG.info("Restored {} CompletionTimeout conditions in the AggregationTimeoutChecker in {}",
            timeoutMap.size(), TimeUtils.printDuration(watch.stop()));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:31,代码来源:AggregateProcessor.java

示例2: doForceCompletionOnStop

import org.apache.camel.util.StopWatch; //导入依赖的package包/类
private void doForceCompletionOnStop() {
    int expected = forceCompletionOfAllGroups();

    StopWatch watch = new StopWatch();
    while (inProgressCompleteExchanges.size() > 0) {
        LOG.trace("Waiting for {} inflight exchanges to complete", inProgressCompleteExchanges.size());
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            // break out as we got interrupted such as the JVM terminating
            LOG.warn("Interrupted while waiting for {} inflight exchanges to complete.", inProgressCompleteExchanges.size());
            break;
        }
    }

    if (expected > 0) {
        LOG.info("Forcing completion of all groups with {} exchanges completed in {}", expected, TimeUtils.printDuration(watch.stop()));
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:20,代码来源:AggregateProcessor.java

示例3: wrapProcessorInInterceptors

import org.apache.camel.util.StopWatch; //导入依赖的package包/类
public Processor wrapProcessorInInterceptors(final CamelContext context, final ProcessorDefinition<?> definition,
                                             final Processor target, final Processor nextTarget) throws Exception {
    return new DelegateAsyncProcessor(target) {
        @Override
        public boolean process(final Exchange exchange, final AsyncCallback callback) {
            debugger.beforeProcess(exchange, target, definition);
            final StopWatch watch = new StopWatch();

            return processor.process(exchange, new AsyncCallback() {
                public void done(boolean doneSync) {
                    long diff = watch.stop();
                    debugger.afterProcess(exchange, processor, definition, diff);

                    // must notify original callback
                    callback.done(doneSync);
                }
            });
        }

        @Override
        public String toString() {
            return "Debug[" + target + "]";
        }
    };
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:26,代码来源:Debug.java

示例4: awaitTermination

import org.apache.camel.util.StopWatch; //导入依赖的package包/类
@Override
public boolean awaitTermination(ExecutorService executorService, long shutdownAwaitTermination) throws InterruptedException {
    // log progress every 2nd second so end user is aware of we are shutting down
    StopWatch watch = new StopWatch();
    long interval = Math.min(2000, shutdownAwaitTermination);
    boolean done = false;
    while (!done && interval > 0) {
        if (executorService.awaitTermination(interval, TimeUnit.MILLISECONDS)) {
            done = true;
        } else {
            LOG.info("Waited {} for ExecutorService: {} to terminate...", TimeUtils.printDuration(watch.taken()), executorService);
            // recalculate interval
            interval = Math.min(2000, shutdownAwaitTermination - watch.taken());
        }
    }

    return done;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:DefaultExecutorServiceManager.java

示例5: awaitConsumer

import org.apache.camel.util.StopWatch; //导入依赖的package包/类
private DirectVmConsumer awaitConsumer() throws InterruptedException {
    DirectVmConsumer answer = null;

    StopWatch watch = new StopWatch();
    boolean done = false;
    while (!done) {
        // sleep a bit to give chance for the consumer to be ready
        Thread.sleep(500);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Waited {} for consumer to be ready", watch.taken());
        }

        answer = endpoint.getConsumer();
        if (answer != null) {
            return answer;
        }
        // we are done if we hit the timeout
        done = watch.taken() >= endpoint.getTimeout();
    }
    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:DirectVmBlockingProducer.java

示例6: awaitConsumer

import org.apache.camel.util.StopWatch; //导入依赖的package包/类
private DirectConsumer awaitConsumer() throws InterruptedException {
    DirectConsumer answer = null;

    StopWatch watch = new StopWatch();
    boolean done = false;
    while (!done) {
        // sleep a bit to give chance for the consumer to be ready
        Thread.sleep(500);
        if (LOG.isDebugEnabled()) {
            LOG.debug("Waited {} for consumer to be ready", watch.taken());
        }

        answer = endpoint.getConsumer();
        if (answer != null) {
            return answer;
        }
        // we are done if we hit the timeout
        done = watch.taken() >= endpoint.getTimeout();
    }
    return answer;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:DirectBlockingProducer.java

示例7: prepareOnStartup

import org.apache.camel.util.StopWatch; //导入依赖的package包/类
@Override
public void prepareOnStartup(GenericFileOperations<File> operations, GenericFileEndpoint<File> endpoint) {
    if (deleteOrphanLockFiles) {

        String dir = endpoint.getConfiguration().getDirectory();
        File file = new File(dir);

        LOG.debug("Prepare on startup by deleting orphaned lock files from: {}", dir);

        Pattern excludePattern = endpoint.getExclude() != null ? Pattern.compile(endpoint.getExclude()) : null;
        Pattern includePattern = endpoint.getInclude() != null ? Pattern.compile(endpoint.getInclude()) : null;
        String endpointPath = endpoint.getConfiguration().getDirectory();

        StopWatch watch = new StopWatch();
        deleteLockFiles(file, endpoint.isRecursive(), endpointPath, endpoint.getFilter(), endpoint.getAntFilter(), excludePattern, includePattern);

        // log anything that takes more than a second
        if (watch.taken() > 1000) {
            LOG.info("Prepared on startup by deleting orphaned lock files from: {} took {} millis to complete.", dir, watch.taken());
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:MarkerFileExclusiveReadLockStrategy.java

示例8: testRedeliveryErrorHandlerNoRedeliveryOnShutdown

import org.apache.camel.util.StopWatch; //导入依赖的package包/类
public void testRedeliveryErrorHandlerNoRedeliveryOnShutdown() throws Exception {
    getMockEndpoint("mock:foo").expectedMessageCount(1);
    getMockEndpoint("mock:deadLetter").expectedMessageCount(1);
    getMockEndpoint("mock:deadLetter").setResultWaitTime(25000);

    template.sendBody("seda:foo", "Hello World");

    getMockEndpoint("mock:foo").assertIsSatisfied();

    // should not take long to stop the route
    StopWatch watch = new StopWatch();
    // sleep 3 seconds to do some redeliveries before we stop
    Thread.sleep(3000);
    log.info("==== stopping route foo ====");
    context.stopRoute("foo");
    watch.stop();

    getMockEndpoint("mock:deadLetter").assertIsSatisfied();

    log.info("OnRedelivery processor counter {}", counter.get());

    assertTrue("Should stop route faster, was " + watch.taken(), watch.taken() < 7000);
    assertTrue("Redelivery counter should be >= 2 and < 12, was: " + counter.get(), counter.get() >= 2 && counter.get() < 12);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:RedeliveryDeadLetterErrorHandlerNoRedeliveryOnShutdownTest.java

示例9: timeSplitRoutes

import org.apache.camel.util.StopWatch; //导入依赖的package包/类
protected void timeSplitRoutes(int numberOfRequests) throws Exception {
    String[] endpoints = new String[]{"direct:splitSynchronizedAggregation", "direct:splitUnsynchronizedAggregation"};
    List<Future<File>> futures = new ArrayList<Future<File>>();
    StopWatch stopWatch = new StopWatch(false);

    for (String endpoint : endpoints) {
        stopWatch.restart();
        for (int requestIndex = 0; requestIndex < numberOfRequests; requestIndex++) {
            futures.add(template.asyncRequestBody(endpoint, null, File.class));
        }

        for (int i = 0; i < futures.size(); i++) {
            Future<File> future = futures.get(i);
            future.get();
        }
        stopWatch.stop();

        log.info(String.format("test%d.%s=%d\n", numberOfRequests, endpoint, stopWatch.taken()));
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:SplitterParallelAggregateTest.java

示例10: testRedelivery

import org.apache.camel.util.StopWatch; //导入依赖的package包/类
public void testRedelivery() throws Exception {
    StopWatch watch = new StopWatch();

    MockEndpoint before = getMockEndpoint("mock:foo");
    before.expectedMessageCount(1);

    template.sendBody("seda:start", "Hello World");

    assertMockEndpointsSatisfied();

    Thread.sleep(500);

    context.stopRoute("foo");

    // we should reject the task and stop quickly
    assertTrue("Should stop quickly: " + watch.taken(), watch.taken() < 5000);

    // should go to DLC
    Exchange dead = getMockEndpoint("mock:dead").getExchanges().get(0);
    assertNotNull(dead);

    Throwable cause = dead.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
    assertNotNull(cause);
    assertIsInstanceOf(RejectedExecutionException.class, cause);
    assertEquals("Redelivery not allowed while stopping", cause.getMessage());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:27,代码来源:NotAllowRedeliveryWhileStoppingDeadLetterChannelTest.java

示例11: testVmInOutChainedTimeout

import org.apache.camel.util.StopWatch; //导入依赖的package包/类
public void testVmInOutChainedTimeout() throws Exception {
    StopWatch watch = new StopWatch();
    
    try {
        template2.requestBody("vm:a?timeout=1000", "Hello World");
        fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
        // the chained vm caused the timeout
        ExchangeTimedOutException cause = assertIsInstanceOf(ExchangeTimedOutException.class, e.getCause());
        assertEquals(200, cause.getTimeout());
    }
    
    long delta = watch.stop();

    assertTrue("Should be faster than 1 sec, was: " + delta, delta < 1100);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:VmInOutChainedTimeoutTest.java

示例12: testJmsRequestReplySharedReplyTo

import org.apache.camel.util.StopWatch; //导入依赖的package包/类
@Test
public void testJmsRequestReplySharedReplyTo() throws Exception {
    StopWatch watch = new StopWatch();

    // shared is more slower than exclusive, due it need to use a JMS Message Selector
    // and has a receiveTimeout of 1 sec per default, so it react slower to new messages

    assertEquals("Hello A", template.requestBody("activemq:queue:foo?replyTo=bar&replyToType=Shared", "A"));
    assertEquals("Hello B", template.requestBody("activemq:queue:foo?replyTo=bar&replyToType=Shared", "B"));
    assertEquals("Hello C", template.requestBody("activemq:queue:foo?replyTo=bar&replyToType=Shared", "C"));
    assertEquals("Hello D", template.requestBody("activemq:queue:foo?replyTo=bar&replyToType=Shared", "D"));
    assertEquals("Hello E", template.requestBody("activemq:queue:foo?replyTo=bar&replyToType=Shared", "E"));

    long delta = watch.stop();
    assertTrue("Should be slower than about 2 seconds, was: " + delta, delta > 2000);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:JmsRequestReplySharedReplyToTest.java

示例13: testAsyncJmsInOut

import org.apache.camel.util.StopWatch; //导入依赖的package包/类
@Test
public void testAsyncJmsInOut() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(100);
    mock.expectsNoDuplicates(body());

    StopWatch watch = new StopWatch();

    for (int i = 0; i < 100; i++) {
        template.sendBody("seda:start", "" + i);
    }

    // just in case we run on slow boxes
    assertMockEndpointsSatisfied(20, TimeUnit.SECONDS);

    log.info("Took " + watch.stop() + " ms. to process 100 messages request/reply over JMS");
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:AsyncJmsInOutTest.java

示例14: testConnectionResourceRouter

import org.apache.camel.util.StopWatch; //导入依赖的package包/类
@Test
public void testConnectionResourceRouter() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(100);
    mock.expectsNoDuplicates(body());

    StopWatch watch = new StopWatch();

    for (int i = 0; i < 100; i++) {
        template.sendBody("seda:start", "" + i);
    }

    // just in case we run on slow boxes
    assertMockEndpointsSatisfied(20, TimeUnit.SECONDS);

    log.info("Took " + watch.stop() + " ms. to process 100 messages request/reply over JMS");
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:ConnectionResourceIT.java

示例15: testSynchronous

import org.apache.camel.util.StopWatch; //导入依赖的package包/类
@Test
public void testSynchronous() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(100);
    mock.expectsNoDuplicates(body());

    StopWatch watch = new StopWatch();

    for (int i = 0; i < 100; i++) {
        template.sendBody("seda:start", "" + i);
    }

    // just in case we run on slow boxes
    assertMockEndpointsSatisfied(20, TimeUnit.SECONDS);

    log.info("Took " + watch.stop() + " ms. to process 100 messages request/reply over JMS");
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:SyncJmsInOutTempDestIT.java


注:本文中的org.apache.camel.util.StopWatch类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。