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.example.allen.frameworkexample.volley.OkHttp3Stack.java

@Override
public HttpResponse performRequest(com.android.volley.Request<?> request, Map<String, String> additionalHeaders)
        throws IOException, AuthFailureError {

    OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
    int timeoutMs = request.getTimeoutMs();

    clientBuilder.connectTimeout(timeoutMs, TimeUnit.MILLISECONDS);
    clientBuilder.readTimeout(timeoutMs, TimeUnit.MILLISECONDS);
    clientBuilder.writeTimeout(timeoutMs, TimeUnit.MILLISECONDS);

    okhttp3.Request.Builder okHttpRequestBuilder = new okhttp3.Request.Builder();
    okHttpRequestBuilder.url(request.getUrl());

    Map<String, String> headers = request.getHeaders();
    for (final String name : headers.keySet()) {
        okHttpRequestBuilder.addHeader(name, headers.get(name));
    }/*w w w.j ava2 s .c o m*/
    for (final String name : additionalHeaders.keySet()) {
        okHttpRequestBuilder.addHeader(name, additionalHeaders.get(name));
    }

    setConnectionParametersForRequest(okHttpRequestBuilder, request);
    OkHttpClient client = clientBuilder.build();
    okhttp3.Request okHttpRequest = okHttpRequestBuilder.build();
    Call okHttpCall = client.newCall(okHttpRequest);
    Response okHttpResponse = okHttpCall.execute();

    StatusLine responseStatus = new BasicStatusLine(parseProtocol(okHttpResponse.protocol()),
            okHttpResponse.code(), okHttpResponse.message());
    BasicHttpResponse response = new BasicHttpResponse(responseStatus);
    response.setEntity(entityFromOkHttpResponse(okHttpResponse));

    Headers responseHeaders = okHttpResponse.headers();
    for (int i = 0, len = responseHeaders.size(); i < len; i++) {
        final String name = responseHeaders.name(i), value = responseHeaders.value(i);
        if (name != null) {
            response.addHeader(new BasicHeader(name, value));
        }
    }

    return response;
}

From source file:com.web.server.util.FarmWarFileTransfer.java

private FarmWarFileTransfer(String deployDir, String farmwarDir, String clusterGroup) {
    this.deployDir = deployDir;
    this.farmwarDir = farmwarDir;
    this.clusterGroup = clusterGroup;
    ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor();
    FarmWarDirWatcher task = new FarmWarDirWatcher(farmwarDir, this);
    exec.scheduleAtFixedRate(task, 0, 1000, TimeUnit.MILLISECONDS);
}

From source file:org.jetbrains.webdemo.authorization.AuthorizationGithubHelper.java

@Nullable
@Override//from   w  w w.jav a  2s. c om
public UserInfo verify(String oauthVerifier) {
    UserInfo userInfo = null;
    try {
        Verifier verifier = new Verifier(oauthVerifier);
        Token accessToken = githubService.getAccessToken(EMPTY_TOKEN, verifier);
        OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL);
        request.setConnectTimeout(TIMEOUT, TimeUnit.MILLISECONDS);
        githubService.signRequest(accessToken, request);
        Response response = request.send();

        JsonNode object = new ObjectMapper().readTree(response.getBody());
        String name = object.get("name").textValue() != null ? object.get("name").textValue() : "Anonymous";
        userInfo = new UserInfo();
        userInfo.login(name, object.get("id").asText(), TYPE);
    } catch (Throwable e) {
        ErrorWriter.ERROR_WRITER.writeExceptionToExceptionAnalyzer(e,
                SessionInfo.TypeOfRequest.AUTHORIZATION.name(), "unknown", "github: " + oauthVerifier);
    }
    return userInfo;
}

From source file:ch.ivyteam.ivy.maven.TestStartEngine.java

@Test
@Ignore//  ww  w. j av  a 2s.  co  m
public void engineStartCanFailFast() throws Exception {
    StartTestEngineMojo mojo = rule.getMojo();
    File engineDir = installUpToDateEngineRule.getMojo().getRawEngineDirectory();
    File configDir = new File(engineDir, "configuration");
    File tmpConfigDir = new File(engineDir, "config.bkp");
    configDir.renameTo(tmpConfigDir);

    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    Executor startedProcess = null;
    try {
        startedProcess = mojo.startEngine();
        fail("Engine start should fail as no configuration directory exists.");
    } catch (RuntimeException ex) {
        stopWatch.stop();
        long seconds = TimeUnit.SECONDS.convert(stopWatch.getTime(), TimeUnit.MILLISECONDS);
        assertThat(seconds).describedAs("engine start should fail early if engine config is incomplete")
                .isLessThanOrEqualTo(20);
    } finally {
        kill(startedProcess);
        FileUtils.deleteDirectory(configDir);
        tmpConfigDir.renameTo(configDir);
    }
}

From source file:com.bodybuilding.argos.discovery.ClusterListDiscovery.java

@VisibleForTesting
ClusterListDiscovery(Collection<String> servers, RestTemplate restTemplate) {
    super(UPDATE_INTERVAL, TimeUnit.MILLISECONDS);
    Objects.requireNonNull(servers);
    LOG.debug("Configured with {}", servers);
    this.servers = new ArrayList<>(servers);
    this.restTemplate = restTemplate;
}

From source file:hws.core.Shared.java

/**
 * Waits for a key to exists. When the key happens to exist, the value associated with the key will be returned.
 * @param key the key associated with the shared data required.
 *//*  w w w  .j  a va2  s. com*/
public <T extends Object> T wait(String key) {
    String znode = znodeBase + encodeKey(key);
    this.zk.waitUntilExists(znode, TimeUnit.MILLISECONDS, 250);
    return get(key);
}

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

@Override
public void start() {
    synchronized (this) {
        playingFuture = executor.scheduleAtFixedRate(runnable, 0, 500, TimeUnit.MILLISECONDS);

    }/*from w  w  w  . jav a2 s  .  c om*/

    listener.onJukeboxTrackStart(this, track);
}

From source file:io.restassured.module.mockmvc.AsyncTest.java

@Test
public void exception_will_be_thrown_if_async_data_has_not_been_provided_in_defined_time_with_config_in_given() {
    // given//w ww . j  a v  a2 s.  c o m
    Exception exception = null;

    // when
    try {
        RestAssuredMockMvc.given().config(newConfig().asyncConfig(withTimeout(0, TimeUnit.MILLISECONDS)))
                .body("a string").when().async().post("/tooLongAwaiting").then().body(equalTo("a string"));
    } catch (IllegalStateException e) {
        exception = e;
    }

    // then
    assertThat(exception).isNotNull().hasMessageContaining("was not set during the specified timeToWait=0");
}

From source file:com.netflix.spinnaker.front50.model.S3Support.java

@PostConstruct
void startRefresh() {
    Observable.timer(refreshIntervalMs, TimeUnit.MILLISECONDS, scheduler).repeat().subscribe(interval -> {
        try {//w w  w  . j  a  v  a2 s .  co  m
            log.info("Refreshing");
            refresh();
            log.info("Refreshed");
        } catch (Exception e) {
            log.error("Unable to refresh", e);
        }
    });
}

From source file:outfox.dict.contest.util.HttpToolKit.java

/**
 * @param maxConnectPerHost/*from w  w  w  .java  2 s .c om*/
 * @param maxConnection
 * @param connectTimeOut
 * @param socketTimeOut
 * @param cookiePolicy
 * @param isAutoRetry
 * @param redirect
 */
public HttpToolKit(int maxConnectPerHost, int maxConnection, int connectTimeOut, int socketTimeOut,
        String cookiePolicy, boolean isAutoRetry, boolean redirect) {
    Scheme https = new Scheme("https", 443, SSLSocketFactory.getSocketFactory());
    Scheme http = new Scheme("http", 80, PlainSocketFactory.getSocketFactory());
    SchemeRegistry sr = new SchemeRegistry();
    sr.register(https);
    sr.register(http);

    connectionManager = new PoolingClientConnectionManager(sr, socketTimeOut, TimeUnit.MILLISECONDS);
    connectionManager.setDefaultMaxPerRoute(maxConnectPerHost);
    connectionManager.setMaxTotal(maxConnection);
    HttpParams params = new BasicHttpParams();
    params.setLongParameter(ClientPNames.CONN_MANAGER_TIMEOUT, connectTimeOut);
    params.setParameter(ClientPNames.COOKIE_POLICY, cookiePolicy);
    params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, redirect);
    params.setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, false);

    if (isAutoRetry) {
        client = new AutoRetryHttpClient(new DefaultHttpClient(connectionManager, params));
    } else {
        client = new DefaultHttpClient(connectionManager, params);
    }
}