Example usage for java.util.concurrent TimeUnit MILLISECONDS

List of usage examples for java.util.concurrent TimeUnit MILLISECONDS

Introduction

In this page you can find the example usage for java.util.concurrent TimeUnit MILLISECONDS.

Prototype

TimeUnit MILLISECONDS

To view the source code for java.util.concurrent TimeUnit MILLISECONDS.

Click Source Link

Document

Time unit representing one thousandth of a second.

Usage

From source file:com.netflix.genie.client.GenieClientUtils.java

/**
 * Get a {@link Retrofit} instance given the parameters.
 *
 * @param url                       The url of the Genie Service.
 * @param interceptors              All desired interceptors for the client to be created
 * @param genieNetworkConfiguration A configuration object that provides network settings for HTTP calls.
 * @return A {@link Retrofit} instance configured with the given information
 * @throws GenieClientException If there is any problem creating the constructor
 *//* w  w  w.j a v a  2 s .co m*/
static Retrofit createRetrofitInstance(@NotBlank final String url,
        @Nullable final List<Interceptor> interceptors,
        @Nullable final GenieNetworkConfiguration genieNetworkConfiguration) throws GenieClientException {
    if (StringUtils.isBlank(url)) {
        throw new GenieClientException("Service URL cannot be empty or null");
    }

    final OkHttpClient.Builder builder = new OkHttpClient.Builder();

    if (genieNetworkConfiguration != null) {
        if (genieNetworkConfiguration.getConnectTimeout() != GenieNetworkConfiguration.DEFAULT_TIMEOUT) {
            builder.connectTimeout(genieNetworkConfiguration.getConnectTimeout(), TimeUnit.MILLISECONDS);
        }

        if (genieNetworkConfiguration.getReadTimeout() != GenieNetworkConfiguration.DEFAULT_TIMEOUT) {
            builder.readTimeout(genieNetworkConfiguration.getReadTimeout(), TimeUnit.MILLISECONDS);
        }

        if (genieNetworkConfiguration.getWriteTimeout() != GenieNetworkConfiguration.DEFAULT_TIMEOUT) {
            builder.writeTimeout(genieNetworkConfiguration.getWriteTimeout(), TimeUnit.MILLISECONDS);
        }

        builder.retryOnConnectionFailure(genieNetworkConfiguration.isRetryOnConnectionFailure());
    }

    // Add the interceptor to map the retrofit response code to corresponding Genie Exceptions in case of
    // 4xx and 5xx errors.
    builder.addInterceptor(new ResponseMappingInterceptor());
    if (interceptors != null) {
        interceptors.forEach(builder::addInterceptor);
    }

    return new Retrofit.Builder().baseUrl(url)
            .addConverterFactory(JacksonConverterFactory.create(GenieObjectMapper.getMapper()))
            .client(builder.build()).build();
}

From source file:com.kurento.kmf.content.internal.ContentApiExecutorService.java

/**
 * Post constructor method; instantiate thread pool.
 * /*from w ww  .  j av a  2 s  .c  o  m*/
 * @throws Exception
 *             Error in the creation of the thread pool
 */
@PostConstruct
public void afterPropertiesSet() throws Exception {
    executor = new ThreadPoolExecutor(config.getPoolCoreSize(), config.getPoolMaxSize(),
            config.getPoolExecutionTimeout(), TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>(config.getPoolMaxQueueSize()), new RejectedExecutionHandler() {
                @Override
                public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
                    ((RejectableRunnable) r).onExecutionRejected();
                }
            });
}

From source file:org.codelibs.fess.crawler.client.http.HcConnectionMonitorTarget.java

@Override
public void expired() {
    if (clientConnectionManager == null) {
        logger.warn("clientConnectionManager is null.");
        return;// w  w  w .  j  a v a2 s . c o m
    }

    try {
        // Close expired connections
        clientConnectionManager.closeExpiredConnections();
        // Close idle connections
        clientConnectionManager.closeIdleConnections(idleConnectionTimeout, TimeUnit.MILLISECONDS);
    } catch (final Exception e) {
        logger.warn("A connection monitoring exception occurs.", e);
    }
}

From source file:com.amazonaws.eclipse.core.accounts.profiles.SdkCredentialsFileContentMonitorTest.java

@Test
public void testFileChangedCallback() throws InterruptedException {

    final CountDownLatch latch = new CountDownLatch(1);

    SdkCredentialsFileContentMonitor monitor = new SdkCredentialsFileContentMonitor(targetFile,
            MONITOR_POLLING_INTERVAL_MILLIS, new FileAlterationListenerAdaptor() {

                @Override/*from www.j a  v  a  2s .  c  o  m*/
                public void onFileChange(final File changedFile) {
                    latch.countDown();
                }
            });
    monitor.setDebugMode(true);
    monitor.start();

    touch(targetFile);

    long waitTime = MONITOR_POLLING_INTERVAL_MILLIS * 2;
    Assert.assertTrue("File monitor callback not invoked after waiting for " + waitTime + " ms.",
            latch.await(waitTime, TimeUnit.MILLISECONDS));
}

From source file:com.espertech.esper.timer.EPLTimerTask.java

public final void run() {
    if (!isCancelled) {
        if (_enableStats) {
            // If we are called early, then delay will be positive. If we are called late, then the delay will be negative.
            // NOTE: don't allow _enableStats to be set until future has been set
            if (future != null) {
                _lastDrift = Math.abs(future.getDelay(TimeUnit.MILLISECONDS));
            }/*ww  w  .  j a  va2s.  c  o  m*/
            _totalDrift += _lastDrift;
            _invocationCount++;
            if (_lastDrift > _maxDrift)
                _maxDrift = _lastDrift;
        }

        try {
            callback.timerCallback();
        } catch (Throwable t) {
            log.error("Timer thread caught unhandled exception: " + t.getMessage(), t);
        }
    }
}

From source file:org.openspaces.bigdata.feeder.TaskScheduler.java

@PostConstruct
public void execute() {
    executorService.scheduleWithFixedDelay(task, delayInMs, delayInMs, TimeUnit.MILLISECONDS);
}

From source file:com.bt.aloha.stack.QueuedSipMessageLatch.java

public QueuedSipMessageLatch(long aSequenceNumber, String aRequestMethod, long queuedSipMessageBlockingInterval,
        ScheduledExecutorService scheduledExecutorService) {
    super(1);/*from  w  w  w  . j a  v  a 2s .com*/
    sequenceNumber = aSequenceNumber;
    requestMethod = aRequestMethod;

    future = scheduledExecutorService.schedule(new Runnable() {
        public void run() {
            LOG.debug(String.format("Expiring queued message %d, method %s", sequenceNumber, requestMethod));
            countDown();
        }
    }, queuedSipMessageBlockingInterval, TimeUnit.MILLISECONDS);
}

From source file:amqp.spring.camel.component.ContrivedLoadTest.java

@Test
public void testSynchronous() throws Exception {
    final int messageCount = 1000;
    int received = 0;
    ScheduledExecutorService executorService = new ScheduledThreadPoolExecutor(messageCount);
    List<Future<String>> futures = new ArrayList<Future<String>>();

    long startTime = System.currentTimeMillis();
    for (int i = 0; i < messageCount; ++i)
        futures.add(executorService.submit(new SynchronousRequestor(this.template)));
    LOG.info("Time to submit synchronous messages: {}", (System.currentTimeMillis() - startTime) / 1000.0f);

    startTime = System.currentTimeMillis();
    for (Future<String> future : futures) {
        String response = future.get(10000, TimeUnit.MILLISECONDS);
        if ("RESPONSE".equals(response))
            ++received;/*ww w .  ja v  a 2s.  c o m*/
    }
    float elapsedTime = (System.currentTimeMillis() - startTime) / 1000.0f;
    int maxPoolSize = this.camelContext.getExecutorServiceManager().getDefaultThreadPoolProfile()
            .getMaxPoolSize();
    LOG.info("Time to receive synchronous messages: {}", elapsedTime);

    Assert.assertEquals(messageCount, received);
    //Assuming 1 second delay per message, elapsed time shouldn't exceed the number of messages sent 
    //dividied by the number of messages that can be simultaneously consumed.
    Assert.assertTrue(
            String.format("Possible performance issue: %d messages took %f seconds with %d consumers",
                    messageCount, elapsedTime, maxPoolSize),
            elapsedTime < (messageCount / (double) maxPoolSize) + 1);
}

From source file:com.vsct.dt.hesperides.events.EventsAggregate.java

/**
 * The constructor of the aggregator/*  w w  w .ja va 2  s. co m*/
 * @param eventStore
 */
public EventsAggregate(final EventsConfiguration eventsConfiguration, final EventStore eventStore) {
    this.eventStore = eventStore;
    this.executor = new ThreadPoolExecutor(eventsConfiguration.getPoolMinSize(),
            eventsConfiguration.getPoolMaxSize(), 0L, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<>(eventsConfiguration.getQueueCapacity()));
}

From source file:com.newlandframework.test.RpcParallelTest.java

public static void multiTask(MultiCalculate calc, int parallel) throws InterruptedException {
    RpcParallelTest.parallelMultiCalcTask(calc, parallel);
    TimeUnit.MILLISECONDS.sleep(30);
}