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.cloudifysource.esc.installer.AgentlessInstaller.java

/******
 * Performs installation on a remote machine with a known IP.
 * /*from ww w .j  av a 2 s .co m*/
 * @param details
 *            the installation details.
 * @param timeout
 *            the timeout duration.
 * @param unit
 *            the timeout unit.
 * @throws InterruptedException .
 * @throws TimeoutException .
 * @throws InstallerException .
 */
public void installOnMachineWithIP(final InstallationDetails details, final long timeout, final TimeUnit unit)
        throws TimeoutException, InterruptedException, InstallerException {

    final long end = System.currentTimeMillis() + unit.toMillis(timeout);

    if (details.getLocator() == null) {
        // We are installing the lus now
        details.setLocator(details.getPrivateIp());
    }

    logger.fine("Executing agentless installer with the following details:\n" + details.toString());

    // this is the right way to get the target, but the naming is off.
    final String targetHost = details.isConnectedToPrivateIp() ? details.getPrivateIp() : details.getPublicIp();

    if (StringUtils.isBlank(targetHost)) {
        throw new InstallerException("Target host is blank. Connect to private: "
                + details.isConnectedToPrivateIp() + ", Private IP: " + details.getPrivateIp() + ", Public IP: "
                + details.getPublicIp() + ". Details: " + details);
    }
    final int port = Utils.getFileTransferPort(details.getInstallerConfiguration(),
            details.getFileTransferMode());

    publishEvent("attempting_to_access_vm", targetHost);
    checkConnection(targetHost, port, details.getInstallerConfiguration(), CalcUtils.millisUntil(end),
            TimeUnit.MILLISECONDS);

    File environmentFile = null;
    // create the environment file
    try {
        environmentFile = createEnvironmentFile(details);
        // upload bootstrap files
        publishEvent("uploading_files_to_node", targetHost);
        uploadFilesToServer(details, environmentFile, end, targetHost);

    } catch (final IOException e) {
        throw new InstallerException("Failed to create environment file", e);
    } finally {
        // delete the temp directory and temp env file.
        if (environmentFile != null) {
            FileUtils.deleteQuietly(environmentFile.getParentFile());
        }
    }

    // launch the cloudify agent
    publishEvent("launching_agent_on_node", targetHost);
    remoteExecuteAgentOnServer(details, end, targetHost);

    publishEvent("install_completed_on_node", targetHost);

}

From source file:com.serphacker.serposcope.scraper.http.extensions.CloseableBasicHttpClientConnectionManager.java

@Override
public synchronized void closeIdleConnections(final long idletime, final TimeUnit tunit) {
    Args.notNull(tunit, "Time unit");
    if (this.isShutdown.get()) {
        return;//w w w  .  ja v  a  2  s.  c om
    }
    if (!this.leased) {
        long time = tunit.toMillis(idletime);
        if (time < 0) {
            time = 0;
        }
        final long deadline = System.currentTimeMillis() - time;
        if (this.updated <= deadline) {
            closeConnection();
        }
    }
}

From source file:org.apache.metron.profiler.bolt.ProfileBuilderBolt.java

public ProfileBuilderBolt withPeriodDuration(int duration, TimeUnit units) {
    return withPeriodDurationMillis(units.toMillis(duration));
}

From source file:org.apache.metron.profiler.bolt.ProfileBuilderBolt.java

public ProfileBuilderBolt withProfileTimeToLive(int duration, TimeUnit units) {
    return withProfileTimeToLiveMillis(units.toMillis(duration));
}

From source file:org.cloudifysource.esc.driver.provisioning.storage.aws.EbsStorageDriver.java

@Override
public void deleteVolume(final String location, final String volumeId, final long duration,
        final TimeUnit timeUnit) throws TimeoutException, StorageProvisioningException {
    final long end = System.currentTimeMillis() + timeUnit.toMillis(duration);
    deleteVolume(volumeId);/*from   ww  w . j  a  va  2 s. c o m*/
    try {
        // according to the documentation, the volume should stay
        // in 'deleting' status for a few minutes. 
        waitForVolumeToReachStatus(Status.DELETING, end, volumeId);
    } catch (final StorageProvisioningException e) {
        // Volume was not found. Do nothing.
    }
    logger.fine("Volume with id " + volumeId + " deleted successfully");
}

From source file:org.cloudifysource.esc.driver.provisioning.storage.aws.EbsStorageDriver.java

@Override
public void attachVolume(final String volumeId, final String device, final String ip, final long duration,
        final TimeUnit timeUnit) throws TimeoutException, StorageProvisioningException {

    final long end = System.currentTimeMillis() + timeUnit.toMillis(duration);
    NodeMetadata nodeMetadata = deployer.getServerWithIP(ip);
    try {/*from   w ww  . j  a v a  2 s. c  om*/
        String instanceId = nodeMetadata.getProviderId();
        logger.log(Level.FINE, "Attaching volume with id " + volumeId + " to machine with id " + instanceId);
        this.ebsClient.attachVolumeInRegion(this.region, volumeId, instanceId, device);
    } catch (final Exception e) {
        throw new StorageProvisioningException("Failed attaching volume to machine. Reason: " + e.getMessage(),
                e);
    }
    waitForVolumeToReachStatus(Status.IN_USE, end, volumeId);
}

From source file:com.reactivetechnologies.analytics.core.handlers.ModelCombinerComponent.java

/**
 * /* ww  w  . j  a  va 2s . co  m*/
 * @param duration
 * @param unit
 * @return
 * @throws InterruptedException
 */
private boolean signalAndAwait(long duration, TimeUnit unit) throws InterruptedException {
    synchronized (this) {
        mCount.set(hzService.size());
        processing = true;
        try {
            sendMessage(DUMP_MODEL_REQ);
            log.debug("Waiting for dump response..");
            wait(unit.toMillis(duration));

        } finally {
            processing = false;
        }
    }
    return mCount.get() == 0;

}

From source file:org.apache.camel.component.hawtdb.HawtDBAggregationRepository.java

public void setRecoveryInterval(long interval, TimeUnit timeUnit) {
    this.recoveryInterval = timeUnit.toMillis(interval);
}

From source file:org.apache.geode.internal.process.FileProcessController.java

/**
 * Constructs an instance for controlling a local process.
 * //from   www  .j a v  a 2 s  .c  o  m
 * @param parameters details about the controllable process
 * @param pid process id identifying the process to control
 * @param timeout the timeout that operations must complete within
 * @param units the units of the timeout
 * 
 * @throws IllegalArgumentException if pid is not a positive integer
 */
FileProcessController(final FileControllerParameters parameters, final int pid, final long timeout,
        final TimeUnit units) {
    notNull(parameters, "Invalid parameters '" + parameters + "' specified");
    isTrue(pid > 0, "Invalid pid '" + pid + "' specified");
    isTrue(timeout >= 0, "Invalid timeout '" + timeout + "' specified");
    notNull(units, "Invalid units '" + units + "' specified");

    this.pid = pid;
    this.parameters = parameters;
    this.statusTimeoutMillis = units.toMillis(timeout);
}

From source file:net.pms.io.ThreadedProcessWrapper.java

/**
 * Runs a process with the given command {@link List}.
 *
 * @param command an array of {@link String} used to build the command line.
 * @param timeout the process timeout in {@code timeUnit} after which the
 *            process is terminated. Use zero for no timeout, but be aware
 *            of the <a href=/*from   www.  ja v  a 2  s.  c  o m*/
 *            "https://web.archive.org/web/20121201070147/http://kylecartmell.com/?p=9"
 *            >pitfalls</a>
 * @param timeUnit the {@link TimeUnit} for {@code timeout}.
 * @param terminateTimeoutMS the timeout in milliseconds to wait for each
 *            termination attempt.
 * @return The {@link ProcessWrapperResult} from running the process.
 * @throws IllegalArgumentException If {@code command} is {@code null} or
 *             empty.
 */
@Nonnull
public Future<R> runProcess(@Nonnull List<String> command, long timeout, @Nonnull TimeUnit timeUnit,
        long terminateTimeoutMS) {
    return runProcess(command, timeUnit.toMillis(timeout), terminateTimeoutMS);
}