List of usage examples for java.util.concurrent TimeUnit MILLISECONDS
TimeUnit MILLISECONDS
To view the source code for java.util.concurrent TimeUnit MILLISECONDS.
Click Source Link
From source file:com.aix.city.comm.OkHttpStack.java
@Override public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError { OkHttpClient client = mClient.clone(); int timeoutMs = request.getTimeoutMs(); client.setConnectTimeout(timeoutMs, TimeUnit.MILLISECONDS); client.setReadTimeout(timeoutMs, TimeUnit.MILLISECONDS); client.setWriteTimeout(timeoutMs, TimeUnit.MILLISECONDS); com.squareup.okhttp.Request.Builder okHttpRequestBuilder = new com.squareup.okhttp.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 a v a2 s . c o m for (final String name : additionalHeaders.keySet()) { okHttpRequestBuilder.addHeader(name, additionalHeaders.get(name)); } setConnectionParametersForRequest(okHttpRequestBuilder, request); com.squareup.okhttp.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:pdf.ConvertHtmlToPDFTest.java
@Test public void convertHtmlToPdf() { try {/*from www . java 2s. c o m*/ Html2PdfJob args = new Html2PdfJob(); args.setHtml("<b>Hello World</b>"); args.setFontEmbed(true); args.setMarginBottom(2); args.setMarginTop(2); args.setMarginLeft(2); args.setMarginRight(2); CFDocumentJob.Permission[] permissions = new CFDocumentJob.Permission[] { CFDocumentJob.Permission.AllowCopy, CFDocumentJob.Permission.AllowPrinting, CFDocumentJob.Permission.AllowScreenReaders }; args.setPermissions(permissions); Future<Map> resultFuture = pdfHtmlGateway.convertHtmlToPdf(args); Object result = resultFuture.get(defaultTimeout, TimeUnit.MILLISECONDS); Assert.assertTrue(result != null); Assert.assertEquals(38639, ((Html2PdfJob) result).getPdfBytes().length); } catch (Exception ex) { ex.printStackTrace(); Assert.fail(ex.getMessage()); } }
From source file:org.jetbrains.webdemo.authorization.AuthorizationTwitterHelper.java
@Override @Nullable/*w w w.j a v a 2 s . c om*/ public UserInfo verify(String oauthVerifier) { UserInfo userInfo = null; try { Verifier verifier = new Verifier(oauthVerifier); Token accessToken = twitterService.getAccessToken(requestToken, verifier); OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); request.setConnectTimeout(TIMEOUT, TimeUnit.MILLISECONDS); twitterService.signRequest(accessToken, request); // the access token from step 4 Response response = request.send(); userInfo = new UserInfo(); JsonNode obj = new ObjectMapper().readTree(response.getBody()); String id = obj.get("id").toString(); String name = obj.has("name") ? obj.get("name").asText() : ""; if (name != null && id != null) { userInfo.login(name, id, TYPE); } } catch (Throwable e) { ErrorWriter.ERROR_WRITER.writeExceptionToExceptionAnalyzer(e, SessionInfo.TypeOfRequest.AUTHORIZATION.name(), "unknown", "twitter"); } return userInfo; }
From source file:com.vmware.photon.controller.cloudstore.xenon.helpers.TestEnvironment.java
private TestEnvironment(int hostCount, HostClientFactory hostClientFactory, AgentControlClientFactory agentControlClientFactory) throws Throwable { assertTrue(hostCount > 0);//from w w w. ja va 2 s . co m hosts = new PhotonControllerXenonHost[hostCount]; for (int i = 0; i < hosts.length; i++) { String sandbox = generateStorageSandboxPath(); FileUtils.forceMkdir(new File(sandbox)); XenonConfig xenonConfig = new XenonConfig(); xenonConfig.setBindAddress(BIND_ADDRESS); xenonConfig.setPort(0); xenonConfig.setStoragePath(sandbox); hosts[i] = new PhotonControllerXenonHost(xenonConfig, hostClientFactory, agentControlClientFactory, null, null); CloudStoreServiceGroup cloudStoreServiceGroup = new CloudStoreServiceGroup(); hosts[i].registerCloudStore(cloudStoreServiceGroup); } // Disable host ping: we have fake hosts and don't want them to be marked as missing HostService.setInUnitTests(true); TaskSchedulerServiceStateBuilder.triggerInterval = TimeUnit.MILLISECONDS.toMicros(500); }
From source file:com.googlecode.icegem.cacheutils.signallistener.WaitforTool.java
/** * @param regionToListen// w w w. jav a 2s . c o m * region that will contain key. * @param key * key for listening. * @param timeout * how long util waits for key's appearance. * @param checkInterval * how often util checks region. * @return true if key was found, false otherwise. * */ public static boolean waitSignal(Region regionToListen, Object key, long timeout, long checkInterval) throws InterruptedException { if (regionToListen == null) throw new NullPointerException("region is null"); if (checkInterval > timeout) throw new IllegalArgumentException( "check interval (" + checkInterval + ") is longer then timeout(" + timeout + ")"); long fromTime = System.currentTimeMillis(); // todo: diff time (sec, millisec, etc) while ((System.currentTimeMillis() - fromTime) <= timeout) { if (regionToListen.containsKeyOnServer(key)) { return true; } TimeUnit.MILLISECONDS.sleep(checkInterval); } return false; }
From source file:showang.toolkit.api.framework.volley.OkHttpStack.java
@Override public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError { OkHttpClient client = mClient.clone(); int timeoutMs = request.getTimeoutMs(); client.setConnectTimeout(timeoutMs, TimeUnit.MILLISECONDS); client.setReadTimeout(timeoutMs, TimeUnit.MILLISECONDS); client.setWriteTimeout(timeoutMs, TimeUnit.MILLISECONDS); com.squareup.okhttp.Request.Builder okHttpRequestBuilder = new com.squareup.okhttp.Request.Builder(); okHttpRequestBuilder.url(request.getUrl()); Map<String, String> headers = request.getHeaders(); for (final String name : headers.keySet()) { okHttpRequestBuilder.addHeader(name, headers.get(name)); }/*from w w w . j a va 2s . c o m*/ for (final String name : additionalHeaders.keySet()) { okHttpRequestBuilder.addHeader(name, additionalHeaders.get(name)); } setConnectionParametersForRequest(okHttpRequestBuilder, request); com.squareup.okhttp.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.opera.core.systems.SelftestTest.java
@Test public void respectsTimeout() { driver.manage().timeouts().selftestTimeout(10, TimeUnit.MILLISECONDS); try {//ww w.j av a2s .c o m driver.selftest(ImmutableSet.of("about")); fail("Expected selftest to time out"); } catch (RuntimeException e) { assertThat(e, is(instanceOf(ResponseNotReceivedException.class))); assertThat(e.getMessage(), containsString("No response in a timely fashion")); } }
From source file:org.ow2.proactive.connector.iaas.cloud.provider.jclouds.JCloudsComputeServiceBuilder.java
/** * Sets the timeouts for the deployment. * // w ww.j a v a2 s .co m * @return Properties object with the timeout policy. */ private Properties getTimeoutPolicy() { Properties properties = new Properties(); long scriptTimeout = TimeUnit.MILLISECONDS.convert(1, TimeUnit.MINUTES); properties.setProperty("jclouds.ssh.max-retries", "100"); properties.setProperty("jclouds.max-retries", "1000"); properties.setProperty("jclouds.request-timeout", "10000"); properties.setProperty("jclouds.connection-timeout", "18000"); properties.setProperty(TIMEOUT_PORT_OPEN, scriptTimeout + ""); properties.setProperty(TIMEOUT_SCRIPT_COMPLETE, scriptTimeout + ""); return properties; }
From source file:net.ion.radon.cload.monitor.FileAlterationMonitor.java
public synchronized void start() throws Exception { Callable<Void> sjob = new Callable<Void>() { @Override//w ww . ja v a2s. c o m public Void call() throws Exception { try { for (FileAlterationObserver o : observers) { o.checkAndNotify(); } } catch (Exception e) { e.printStackTrace(); throw e; } finally { ses.schedule(this, interval, TimeUnit.MILLISECONDS); } return null; } }; ses.schedule(sjob, interval, TimeUnit.MILLISECONDS); }
From source file:com.vmware.photon.controller.housekeeper.helpers.xenon.TestEnvironment.java
public TestEnvironment(CloudStoreHelper cloudStoreHelper, HostClientFactory hostClientFactory, NsxClientFactory nsxClientFactory, int hostCount, boolean isBackgroudPaused) throws Throwable { assertTrue(hostCount > 0);/*from w w w. j a va 2s .co m*/ hosts = new PhotonControllerXenonHost[hostCount]; for (int i = 0; i < hosts.length; i++) { String sandbox = generateStorageSandboxPath(); FileUtils.forceMkdir(new File(sandbox)); XenonConfig xenonConfig = new XenonConfig(); xenonConfig.setBindAddress(BIND_ADDRESS); xenonConfig.setPort(0); xenonConfig.setStoragePath(sandbox); hosts[i] = new PhotonControllerXenonHost(xenonConfig, hostClientFactory, null, nsxClientFactory, cloudStoreHelper); HousekeeperServiceGroup housekeeperServiceGroup = new HousekeeperServiceGroup(); hosts[i].registerHousekeeper(housekeeperServiceGroup); SystemConfig.createInstance(hosts[i]); } TaskSchedulerServiceStateBuilder.triggerInterval = TimeUnit.MILLISECONDS.toMicros(500); }