Example usage for java.util.concurrent TimeUnit toMillis

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

Introduction

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

Prototype

public long toMillis(long duration) 

Source Link

Document

Equivalent to #convert(long,TimeUnit) MILLISECONDS.convert(duration, this) .

Usage

From source file:org.openspaces.admin.internal.admin.DefaultAdmin.java

@Override
public void setSpaceMonitorInterval(long interval, TimeUnit timeUnit) {
    assertStateChangesPermitted();/*from w ww.java  2s.  c  o m*/
    synchronized (DefaultAdmin.this) {
        this.scheduledSpaceMonitorInterval = timeUnit.toMillis(interval);
        this.spaces.refreshScheduledSpaceMonitors();
    }
}

From source file:org.openspaces.admin.internal.admin.DefaultAdmin.java

@Override
public void setProcessingUnitMonitorInterval(long interval, TimeUnit timeUnit) {
    if (closeStarted.get()) {
        throw new AdminClosedException();
    }//  w w w.  jav a  2s .c om
    this.scheduledProcessingUnitMonitorInterval = timeUnit.toMillis(interval);
    if (scheduledProcessingUnitMonitorFuture != null) { // during initialization
        scheduledProcessingUnitMonitorFuture.cancel(false);
        scheduledProcessingUnitMonitorFuture = scheduleWithFixedDelay(new ScheduledProcessingUnitMonitor(),
                interval, interval, timeUnit);
    }
}

From source file:org.openspaces.admin.internal.admin.DefaultAdmin.java

@Override
public void setAgentProcessessMonitorInterval(long interval, TimeUnit timeUnit) {
    if (closeStarted.get()) {
        throw new AdminClosedException();
    }// w w w .  j ava  2  s  .  c o m
    this.scheduledAgentProcessesMonitorInterval = timeUnit.toMillis(interval);
    if (scheduledAgentProcessessMonitorFuture != null) { // during initialization
        scheduledAgentProcessessMonitorFuture.cancel(false);
        scheduledAgentProcessessMonitorFuture = scheduleWithFixedDelay(new ScheduledAgentProcessessMonitor(),
                interval, interval, timeUnit);
    }
}

From source file:org.apache.flume.api.NettyAvroRpcClient.java

/**
 * Internal only, for now/* w  ww  .j  a va  2  s. c o m*/
 * @param timeout
 * @param tu
 * @throws FlumeException
 */
private void connect(long timeout, TimeUnit tu) throws FlumeException {
    callTimeoutPool = Executors
            .newCachedThreadPool(new TransceiverThreadFactory("Flume Avro RPC Client Call Invoker"));
    NioClientSocketChannelFactory socketChannelFactory = null;

    try {

        ExecutorService bossExecutor = Executors.newCachedThreadPool(
                new TransceiverThreadFactory("Avro " + NettyTransceiver.class.getSimpleName() + " Boss"));
        ExecutorService workerExecutor = Executors.newCachedThreadPool(
                new TransceiverThreadFactory("Avro " + NettyTransceiver.class.getSimpleName() + " I/O Worker"));

        if (enableDeflateCompression || enableSsl) {
            if (maxIoWorkers >= 1) {
                socketChannelFactory = new SSLCompressionChannelFactory(bossExecutor, workerExecutor,
                        enableDeflateCompression, enableSsl, trustAllCerts, compressionLevel, truststore,
                        truststorePassword, truststoreType, excludeProtocols, maxIoWorkers);
            } else {
                socketChannelFactory = new SSLCompressionChannelFactory(bossExecutor, workerExecutor,
                        enableDeflateCompression, enableSsl, trustAllCerts, compressionLevel, truststore,
                        truststorePassword, truststoreType, excludeProtocols);
            }
        } else {
            if (maxIoWorkers >= 1) {
                socketChannelFactory = new NioClientSocketChannelFactory(bossExecutor, workerExecutor,
                        maxIoWorkers);
            } else {
                socketChannelFactory = new NioClientSocketChannelFactory(bossExecutor, workerExecutor);
            }
        }

        transceiver = new NettyTransceiver(this.address, socketChannelFactory, tu.toMillis(timeout));
        avroClient = SpecificRequestor.getClient(AvroSourceProtocol.Callback.class, transceiver);
    } catch (Throwable t) {
        if (callTimeoutPool != null) {
            callTimeoutPool.shutdownNow();
        }
        if (socketChannelFactory != null) {
            socketChannelFactory.releaseExternalResources();
        }
        if (t instanceof IOException) {
            throw new FlumeException(this + ": RPC connection error", t);
        } else if (t instanceof FlumeException) {
            throw (FlumeException) t;
        } else if (t instanceof Error) {
            throw (Error) t;
        } else {
            throw new FlumeException(this + ": Unexpected exception", t);
        }
    }

    setState(ConnState.READY);
}

From source file:org.rundeck.api.RundeckClient.java

/**
 * Run a Rundeck job (identified by the given ID), and wait until its execution is finished (or aborted) to return.
 * We will poll the Rundeck server at regular interval (configured by the poolingInterval/poolingUnit couple) to
 * know if the execution is finished (or aborted) or is still running.
 *
 * @param jobRun the RunJob, see {@link RunJobBuilder}
 * @param poolingInterval for checking the status of the execution. Must be > 0.
 * @param poolingUnit     unit (seconds, milli-seconds, ...) of the interval. Default to seconds.
 *
 * @return a {@link RundeckExecution} instance for the (finished/aborted) execution - won't be null
 *
 * @throws RundeckApiException      in case of error when calling the API (non-existent job with this ID)
 * @throws RundeckApiLoginException if the login fails (in case of login-based authentication)
 * @throws RundeckApiTokenException if the token is invalid (in case of token-based authentication)
 * @throws IllegalArgumentException if the jobId is blank (null, empty or whitespace)
 * @see #triggerJob(RunJob)//from www. ja v  a 2 s  . co m
 */
public RundeckExecution runJob(final RunJob jobRun, long poolingInterval, TimeUnit poolingUnit)
        throws RundeckApiException, RundeckApiLoginException, RundeckApiTokenException,
        IllegalArgumentException {

    if (poolingInterval <= 0) {
        poolingInterval = DEFAULT_POOLING_INTERVAL;
        poolingUnit = DEFAULT_POOLING_UNIT;
    }
    if (poolingUnit == null) {
        poolingUnit = DEFAULT_POOLING_UNIT;
    }

    RundeckExecution execution = triggerJob(jobRun);
    while (ExecutionStatus.RUNNING.equals(execution.getStatus())) {
        try {
            Thread.sleep(poolingUnit.toMillis(poolingInterval));
        } catch (InterruptedException e) {
            break;
        }
        execution = getExecution(execution.getId());
    }
    return execution;
}

From source file:org.rundeck.api.RundeckClient.java

/**
 * Run an ad-hoc script, and wait until its execution is finished (or aborted) to return. We will poll the Rundeck
 * server at regular interval (configured by the poolingInterval/poolingUnit couple) to know if the execution is
 * finished (or aborted) or is still running. The script will be dispatched to nodes, accordingly to the nodeFilters
 * parameter./*from  w  ww  .j  a  v a2 s .  c  o m*/
 *
 * @param script the RunAdhocScript, see {@link RunAdhocScriptBuilder}
 * @param poolingInterval for checking the status of the execution. Must be > 0.
 * @param poolingUnit unit (seconds, milli-seconds, ...) of the interval. Default to seconds.
 * @return a {@link RundeckExecution} instance for the (finished/aborted) execution - won't be null
 * @throws RundeckApiException in case of error when calling the API (non-existent project with this name)
 * @throws RundeckApiLoginException if the login fails (in case of login-based authentication)
 * @throws RundeckApiTokenException if the token is invalid (in case of token-based authentication)
 * @throws IllegalArgumentException if the project is blank (null, empty or whitespace) or the script is null
 * @throws IOException if we failed to read the file
 * @see #runAdhocScript(RunAdhocScript, long, TimeUnit)
 * @see #triggerAdhocScript(RunAdhocScript)
 */
public RundeckExecution runAdhocScript(final RunAdhocScript script, long poolingInterval, TimeUnit poolingUnit)
        throws RundeckApiException, RundeckApiLoginException, RundeckApiTokenException,
        IllegalArgumentException {
    if (poolingInterval <= 0) {
        poolingInterval = DEFAULT_POOLING_INTERVAL;
        poolingUnit = DEFAULT_POOLING_UNIT;
    }
    if (poolingUnit == null) {
        poolingUnit = DEFAULT_POOLING_UNIT;
    }

    RundeckExecution execution = triggerAdhocScript(script);
    while (ExecutionStatus.RUNNING.equals(execution.getStatus())) {
        try {
            Thread.sleep(poolingUnit.toMillis(poolingInterval));
        } catch (InterruptedException e) {
            break;
        }
        execution = getExecution(execution.getId());
    }
    return execution;
}

From source file:org.rundeck.api.RundeckClient.java

/**
 * Run an ad-hoc command, and wait until its execution is finished (or aborted) to return. We will poll the Rundeck
 * server at regular interval (configured by the poolingInterval/poolingUnit couple) to know if the execution is
 * finished (or aborted) or is still running. The command will be dispatched to nodes, accordingly to the
 * nodeFilters parameter./*ww  w . j  a v  a 2  s.  c o m*/
 *
 * @param command the RunAdhocCommand, see {@link RunAdhocCommandBuilder}
 * @param poolingInterval for checking the status of the execution. Must be > 0.
 * @param poolingUnit unit (seconds, milli-seconds, ...) of the interval. Default to seconds.
 * @return a {@link RundeckExecution} instance for the (finished/aborted) execution - won't be null
 * @throws RundeckApiException in case of error when calling the API (non-existent project with this name)
 * @throws RundeckApiLoginException if the login fails (in case of login-based authentication)
 * @throws RundeckApiTokenException if the token is invalid (in case of token-based authentication)
 * @throws IllegalArgumentException if the project or command is blank (null, empty or whitespace)
 * @see #triggerAdhocCommand(RunAdhocCommand)
 */
public RundeckExecution runAdhocCommand(RunAdhocCommand command, long poolingInterval, TimeUnit poolingUnit)
        throws RundeckApiException, RundeckApiLoginException, RundeckApiTokenException,
        IllegalArgumentException {
    if (poolingInterval <= 0) {
        poolingInterval = DEFAULT_POOLING_INTERVAL;
        poolingUnit = DEFAULT_POOLING_UNIT;
    }
    if (poolingUnit == null) {
        poolingUnit = DEFAULT_POOLING_UNIT;
    }

    RundeckExecution execution = triggerAdhocCommand(command);
    while (ExecutionStatus.RUNNING.equals(execution.getStatus())) {
        try {
            Thread.sleep(poolingUnit.toMillis(poolingInterval));
        } catch (InterruptedException e) {
            break;
        }
        execution = getExecution(execution.getId());
    }
    return execution;
}