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.ksc.http.apache.client.impl.ApacheConnectionManagerFactory.java

@Override
public HttpClientConnectionManager create(final HttpClientSettings settings) {
    ConnectionSocketFactory sslsf = getPreferredSocketFactory(settings);

    final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(
            createSocketFactoryRegistry(sslsf), null, DefaultSchemePortResolver.INSTANCE,
            new DelegatingDnsResolver(settings.getDnsResolver()), settings.getConnectionPoolTTL(),
            TimeUnit.MILLISECONDS);

    cm.setDefaultMaxPerRoute(settings.getMaxConnections());
    cm.setMaxTotal(settings.getMaxConnections());
    cm.setDefaultSocketConfig(buildSocketConfig(settings));
    cm.setDefaultConnectionConfig(buildConnectionConfig(settings));

    return cm;//from www.ja  v  a  2 s  .  c o  m
}

From source file:com.aliyun.oss.common.comm.HttpClientFactory.java

public static PoolingClientConnectionManager createConnectionManager(ClientConfiguration config,
        HttpParams httpClientParams) {/*from w  w w. j  a  va  2 s  .  co m*/
    PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(
            SchemeRegistryFactory.createDefault(), config.getConnectionTTL(), TimeUnit.MILLISECONDS);
    connectionManager.setDefaultMaxPerRoute(config.getMaxConnections());
    connectionManager.setMaxTotal(config.getMaxConnections());
    if (config.isUseReaper()) {
        IdleConnectionReaper.registerConnectionManager(connectionManager);
    }
    return connectionManager;
}

From source file:org.blocks4j.reconf.infra.http.layer.SimpleHttpClient.java

private static RequestConfig createBasicHttpParams(long timeout, TimeUnit timeUnit) {
    int timemillis = (int) TimeUnit.MILLISECONDS.convert(timeout, timeUnit);
    return RequestConfig.custom().setCookieSpec(CookieSpecs.IGNORE_COOKIES).setConnectTimeout(timemillis)
            .setSocketTimeout(timemillis).setConnectionRequestTimeout(timemillis).build();
}

From source file:interactivespaces.service.audio.player.jukebox.ShuffleJukeboxOperation.java

@Override
public synchronized void start() {
    log.info("Starting music jukebox shuffle play");
    if (!isRunning) {
        playingFuture = executor.scheduleAtFixedRate(runnable, 0, 500, TimeUnit.MILLISECONDS);

        isRunning = true;/*from   w  w  w  .ja  v  a  2  s  .  c o  m*/
    }
}

From source file:j8583.example.Server.java

public void run() {
    int count = 0;
    byte[] lenbuf = new byte[2];
    try {/* ww w  .  j  a va2 s .c  om*/
        // For high volume apps you will be better off only reading the
        // stream in this thread
        // and then using another thread to parse the buffers and process
        // the requests
        // Otherwise the network buffer might fill up and you can miss a
        // request.
        while (socket != null && socket.isConnected() && Thread.currentThread().isAlive()
                && !Thread.currentThread().isInterrupted()) {
            if (socket.getInputStream().read(lenbuf) == 2) {
                int size = ((lenbuf[0] & 0xff) << 8) | (lenbuf[1] & 0xff);
                byte[] buf = new byte[size];
                // We're not expecting ETX in this case
                socket.getInputStream().read(buf);
                count++;
                // Set a job to parse the message and respond
                // Delay it a bit to pretend we're doing something important
                threadPool.schedule(new Processor(buf, socket), 400, TimeUnit.MILLISECONDS);
            }
        }
    } catch (IOException ex) {
        log.error("Exception occurred...", ex);
    }
    log.debug(String.format("Exiting after reading %d requests", count));
    try {
        socket.close();
    } catch (IOException ex) {
    }
}

From source file:com.linkedin.pinot.common.data.DateTimeGranularitySpec.java

/**
 * <ul>//www  . j  a v  a  2s  .c  om
 * <li>Convert a granularity to millis.
 * This method should not do validation of outputGranularity.
 * The validation should be handled by caller using {@link #isValidGranularity(String)}</li>
 * <ul>
 * <li>1) granularityToMillis(1:HOURS) = 3600000 (60*60*1000)</li>
 * <li>2) granularityToMillis(1:MILLISECONDS) = 1</li>
 * <li>3) granularityToMillis(15:MINUTES) = 900000 (15*60*1000)</li>
 * </ul>
 * </ul>
 * @return
 */
public Long granularityToMillis() {

    long granularityInMillis = 0;

    String[] granularityTokens = _granularity.split(COLON_SEPARATOR);
    if (granularityTokens.length == MAX_GRANULARITY_TOKENS) {
        granularityInMillis = TimeUnit.MILLISECONDS.convert(
                Integer.valueOf(granularityTokens[GRANULARITY_SIZE_POSITION]),
                TimeUnit.valueOf(granularityTokens[GRANULARITY_UNIT_POSITION]));
    }
    return granularityInMillis;
}

From source file:nebula.plugin.metrics.dispatcher.AbstractQueuedExecutionThreadService.java

@Override
protected final void run() throws Exception {
    while (isRunning() || !queue.isEmpty()) {
        E action = queue.poll(100, TimeUnit.MILLISECONDS);
        doExecute(action);//ww  w  . j  a va  2 s.c  o  m
    }
    logger.debug("Service is not running and queue is empty, returning from run()");
}

From source file:com.dsf.dbxtract.cdc.App.java

/**
 * Starts scanning services.//from  w  w w.  jav  a  2s.c  o  m
 * 
 * @throws ConfigurationException
 *             any configuration error
 */
public void start() throws ConfigurationException {

    // Get ZooKeeper's connection string
    String zkConnection = config.getZooKeeper();

    // Get interval (in milliseconds) between executions
    long interval = config.getDataSources().getInterval();

    scheduledService = Executors.newScheduledThreadPool(config.getThreadPoolSize());

    // Prepare the task's list. Each handler becomes a task.
    for (JournalHandler handler : config.getHandlers()) {

        Runnable executor = new JournalExecutor(config.getAgentName(), zkConnection, handler,
                config.getSourceByHandler(handler));
        scheduledService.scheduleAtFixedRate(executor, 0L, interval, TimeUnit.MILLISECONDS);
    }
}

From source file:org.simbasecurity.core.config.store.QuartzConfigurationStore.java

public String setValue(ConfigurationParameter parameter, String value) {
    try {//from www  .j av a  2s  . c  om
        JobDetail jobDetail = findJob(parameter);
        Trigger trigger = findTrigger(parameter);
        Trigger newTrigger;

        String oldValue;

        if (trigger instanceof SimpleTrigger) {
            newTrigger = new SimpleTrigger(trigger.getName(), SIMBA_JOB_GROUP,
                    SimpleTrigger.REPEAT_INDEFINITELY,
                    TimeUnit.MILLISECONDS.convert(Long.parseLong(value), parameter.getTimeUnit()));
            newTrigger.setStartTime(trigger.getNextFireTime());
            oldValue = String.valueOf(((SimpleTrigger) trigger).getRepeatInterval());
        } else if (trigger instanceof CronTrigger) {
            newTrigger = new CronTrigger(trigger.getName(), SIMBA_JOB_GROUP, value);
            oldValue = ((CronTrigger) trigger).getCronExpression();
        } else {
            throw new IllegalStateException("Type " + trigger.getClass().getName() + " not handled");
        }
        newTrigger.setJobName(jobDetail.getName());
        newTrigger.setJobGroup(SIMBA_JOB_GROUP);

        scheduler.rescheduleJob(trigger.getName(), SIMBA_JOB_GROUP, newTrigger);
        return oldValue;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:com.liferay.portal.search.solr.http.BasePoolingHttpClientFactory.java

@Override
public void shutdown() {
    if (_log.isDebugEnabled()) {
        _log.debug("Shut down");
    }/* ww w.j av  a 2 s  .c  o  m*/

    if (_poolingClientConnectionManager == null) {
        return;
    }

    int retry = 0;

    while (retry < 10) {
        PoolStats poolStats = _poolingClientConnectionManager.getTotalStats();

        int availableConnections = poolStats.getAvailable();

        if (availableConnections <= 0) {
            break;
        }

        if (_log.isDebugEnabled()) {
            _log.debug(toString() + " is waiting on " + availableConnections + " connections");
        }

        _poolingClientConnectionManager.closeIdleConnections(200, TimeUnit.MILLISECONDS);

        try {
            Thread.sleep(500);
        } catch (InterruptedException ie) {
        }

        retry++;
    }

    _poolingClientConnectionManager.shutdown();

    _poolingClientConnectionManager = null;

    if (_log.isDebugEnabled()) {
        _log.debug(toString() + " was shut down");
    }
}