List of usage examples for java.util.concurrent TimeUnit toMillis
public long toMillis(long duration)
From source file:net.pms.io.ThreadedProcessWrapper.java
/** * Creates and runs a new {@link Process} in a new thread using the * specified commands. The process result is returned as a {@link Future} * {@link ListProcessWrapperResult}.// w ww .ja va2 s. c o m * * @param timeout the process timeout in {@code timeUnit}. * @param timeUnit the {@link TimeUnit} for {@code timeout}. * @param terminateTimeoutMS the timeout in milliseconds for each * termination attempt before a new attempt is made. * @param command the command(s) used to create the {@link Process}. * @return The process result as a {@link Future} * {@link ListProcessWrapperResult}. */ @Nonnull public static Future<ListProcessWrapperResult> runProcessListOutput(long timeout, @Nonnull TimeUnit timeUnit, long terminateTimeoutMS, @Nonnull String... command) { return new ThreadedProcessWrapper<ListProcessWrapperConsumer, ListProcessWrapperResult, List<String>>( new ListProcessWrapperConsumer()).runProcess(timeUnit.toMillis(timeout), terminateTimeoutMS, command); }
From source file:net.pms.io.SimpleProcessWrapper.java
/** * Creates and runs a new {@link Process} in the same thread using the * specified commands. The process result is discarded. * * @param timeout the process timeout in {@code timeUnit}. * @param timeUnit the {@link TimeUnit} for {@code timeout}. * @param terminateTimeoutMS the timeout in milliseconds for each * termination attempt before a new attempt is made. * @param command the command(s) used to create the {@link Process}. * @throws InterruptedException If interrupted while waiting for the * {@link Process} to finish. *//*w ww . j a v a 2s. c o m*/ @Nonnull public static void runProcessNullOutput(long timeout, @Nonnull TimeUnit timeUnit, long terminateTimeoutMS, @Nonnull String... command) throws InterruptedException { new SimpleProcessWrapper<NullProcessWrapperConsumer, NullProcessWrapperResult, Void>( new NullProcessWrapperConsumer()).runProcess(timeUnit.toMillis(timeout), terminateTimeoutMS, command); }
From source file:net.pms.io.SimpleProcessWrapper.java
/** * Creates and runs a new {@link Process} in the same thread using the * specified commands. The process result is returned as a * {@link ByteProcessWrapperResult}./*from w w w.j a v a2 s . co m*/ * * @param timeout the process timeout in {@code timeUnit}. * @param timeUnit the {@link TimeUnit} for {@code timeout}. * @param terminateTimeoutMS the timeout in milliseconds for each * termination attempt before a new attempt is made. * @param command the command(s) used to create the {@link Process}. * @return The process result as a {@link ByteProcessWrapperResult}. * @throws InterruptedException If interrupted while waiting for the * {@link Process} to finish. */ @Nonnull public static ByteProcessWrapperResult runProcessByteOutput(long timeout, @Nonnull TimeUnit timeUnit, long terminateTimeoutMS, @Nonnull String... command) throws InterruptedException { return new SimpleProcessWrapper<ByteProcessWrapperConsumer, ByteProcessWrapperResult, byte[]>( new ByteProcessWrapperConsumer()).runProcess(timeUnit.toMillis(timeout), terminateTimeoutMS, command); }
From source file:net.pms.io.SimpleProcessWrapper.java
/** * Creates and runs a new {@link Process} in the same thread using the * specified commands. The process result is returned as a * {@link ListProcessWrapperResult}./*w w w.j av a 2 s. co m*/ * * @param timeout the process timeout in {@code timeUnit}. * @param timeUnit the {@link TimeUnit} for {@code timeout}. * @param terminateTimeoutMS the timeout in milliseconds for each * termination attempt before a new attempt is made. * @param command the command(s) used to create the {@link Process}. * @return The process result as a {@link ListProcessWrapperResult}. * @throws InterruptedException If interrupted while waiting for the * {@link Process} to finish. */ @Nonnull public static ListProcessWrapperResult runProcessListOutput(long timeout, @Nonnull TimeUnit timeUnit, long terminateTimeoutMS, @Nonnull String... command) throws InterruptedException { return new SimpleProcessWrapper<ListProcessWrapperConsumer, ListProcessWrapperResult, List<String>>( new ListProcessWrapperConsumer()).runProcess(timeUnit.toMillis(timeout), terminateTimeoutMS, command); }
From source file:com.hp.hpl.jena.sparql.engine.http.QueryEngineHTTP.java
private static long asMillis(long duration, TimeUnit timeUnit) { return (duration < 0) ? duration : timeUnit.toMillis(duration); }
From source file:org.cloudifysource.esc.util.Utils.java
/** * Executes a SSH command. An Ant BuildException is thrown in case of an error. * * @param host//ww w. ja v a2s .c o m * The host to run the command on * @param command * The command to execute * @param username * The name of the user executing the command * @param password * The password for the executing user, if used * @param keyFile * The key file, if used * @param timeout * The number of time-units to wait before throwing a TimeoutException * @param unit * The units (e.g. seconds) * @throws TimeoutException * Indicates the timeout was reached before the command completed */ public static void executeSSHCommand(final String host, final String command, final String username, final String password, final String keyFile, final long timeout, final TimeUnit unit) throws TimeoutException { final LoggerOutputStream loggerOutputStream = new LoggerOutputStream( Logger.getLogger(AgentlessInstaller.SSH_OUTPUT_LOGGER_NAME)); loggerOutputStream.setPrefix("[" + host + "] "); final org.cloudifysource.esc.util.SSHExec task = new org.cloudifysource.esc.util.SSHExec(); task.setCommand(command); task.setHost(host); task.setTrust(true); task.setUsername(username); task.setTimeout(unit.toMillis(timeout)); task.setFailonerror(true); task.setOutputStream(loggerOutputStream); task.setUsePty(true); if (keyFile != null) { task.setKeyfile(keyFile); } if (password != null) { task.setPassword(password); } task.execute(); loggerOutputStream.close(); }
From source file:com.android.example.github.util.RateLimiter.java
public RateLimiter(int timeout, TimeUnit timeUnit) { this.timeout = timeUnit.toMillis(timeout); }
From source file:com.sonatype.nexus.perftest.RequestRate.java
/** * @param rate average number of requests per time {@code unit} * @param unit time unit of {@code rate} parameter *//*from w w w. ja va 2 s. c o m*/ public RequestRate(int rate, TimeUnit unit) { this((int) (unit.toMillis(1) / rate)); }
From source file:Main.java
public TimeSliceTask(final long timeToLive, final TimeUnit timeUnit) { this.timeToLive = System.nanoTime() + timeUnit.toNanos(timeToLive); this.duration = timeUnit.toMillis(timeToLive); }
From source file:org.apache.bookkeeper.stream.storage.conf.StorageConfiguration.java
/** * Set the cluster controller schedule interval. * * @param time time value//w w w. j a v a 2s. c om * @param timeUnit time unit * @return storage configuration */ public StorageConfiguration setClusterControllerScheduleInterval(long time, TimeUnit timeUnit) { setProperty(CONTROLLER_SCHEDULE_INTERVAL_MS, timeUnit.toMillis(time)); return this; }