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.smartitengineering.cms.spi.lock.impl.distributed.ZKLock.java
public boolean tryLock(long time, TimeUnit unit) throws InterruptedException { if (logger.isDebugEnabled()) { logger.debug("Attempting to attain lock with wait option of " + time + " " + unit.name()); }//from w w w . j av a 2s . c om if (isLockOwned()) { return true; } lock.lock(); try { final long waitInMilliSeconds = time > 0 ? TimeUnit.MILLISECONDS.convert(time, unit) : time; final long start = System.currentTimeMillis(); String lockId = config.getRegistrar().lock(key, this, waitInMilliSeconds); final long availableMillisForRemoteLock = waitInMilliSeconds - (System.currentTimeMillis() - start); return tryRemoteLock(lockId, availableMillisForRemoteLock); } finally { lock.unlock(); } }
From source file:com.aliyun.oss.common.comm.TimeoutServiceClient.java
@Override public ResponseMessage sendRequestCore(ServiceClient.Request request, ExecutionContext context) throws IOException { HttpRequestBase httpRequest = httpRequestFactory.createHttpRequest(request, context); HttpClientContext httpContext = HttpClientContext.create(); httpContext.setRequestConfig(this.requestConfig); CloseableHttpResponse httpResponse = null; HttpRequestTask httpRequestTask = new HttpRequestTask(httpRequest, httpContext); Future<CloseableHttpResponse> future = executor.submit(httpRequestTask); try {/* www .j av a 2 s. c om*/ httpResponse = future.get(this.config.getRequestTimeout(), TimeUnit.MILLISECONDS); } catch (InterruptedException e) { logException("[ExecutorService]The current thread was interrupted while waiting: ", e); httpRequest.abort(); throw new ClientException(e.getMessage(), e); } catch (ExecutionException e) { RuntimeException ex; httpRequest.abort(); if (e.getCause() instanceof IOException) { ex = ExceptionFactory.createNetworkException((IOException) e.getCause()); } else { ex = new OSSException(e.getMessage(), e); } logException("[ExecutorService]The computation threw an exception: ", ex); throw ex; } catch (TimeoutException e) { logException("[ExecutorService]The wait " + this.config.getRequestTimeout() + " timed out: ", e); httpRequest.abort(); throw new ClientException(e.getMessage(), OSSErrorCode.REQUEST_TIMEOUT, "Unknown", e); } return buildResponse(request, httpResponse); }
From source file:com.olacabs.fabric.compute.PipelineTestBench.java
/** * A constructor for getting an instance of {@code PipelineTestBench} that writes metrics to a csv file. * * @param dirPath The relative or absolute path of the directory to place csv files for each metric */// w ww .j a v a 2 s . c o m public PipelineTestBench(String dirPath) { Preconditions.checkArgument(!Strings.isNullOrEmpty(dirPath), "Provide a non-null and non-empty filePath"); File dir = new File(dirPath); Preconditions.checkArgument(dir.exists() || dir.mkdirs(), "Provide a directory path which either exists or can be created"); metricRegistry = SharedMetricRegistries.getOrCreate("metrics-registry"); reporter = CsvReporter.forRegistry(metricRegistry).convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS).filter(MetricFilter.ALL).build(dir); }
From source file:org.redisson.spring.cache.RedissonCache.java
public ValueWrapper putIfAbsent(Object key, Object value) { Object prevValue;//w w w . j av a2 s.co m if (mapCache != null) { prevValue = mapCache.putIfAbsent(key, value, config.getTTL(), TimeUnit.MILLISECONDS, config.getMaxIdleTime(), TimeUnit.MILLISECONDS); } else { prevValue = map.putIfAbsent(key, value); } return toValueWrapper(prevValue); }
From source file:burstcoin.jminer.core.network.task.NetworkRequestTriggerServerTask.java
private BlockchainStatus getBlockChainStatus() { BlockchainStatus blockchainStatus = null; try {/* w w w.ja v a 2 s .c o m*/ ContentResponse response = httpClient .newRequest( server + "/burst?requestType=getBlockchainStatus&random=" + new Random().nextFloat()) .timeout(connectionTimeout, TimeUnit.MILLISECONDS).send(); blockchainStatus = objectMapper.readValue(response.getContentAsString(), BlockchainStatus.class); } catch (Exception e) { LOG.warn("Error: Failed to 'getBlockchainStatus' from 'soloServer' to trigger server."); } return blockchainStatus; }
From source file:com.bia.yahoomailjava.YahooMailService.java
/** * * @param toAddresses mandatory/* w ww. j a va 2s .com*/ * @param subject mandatory * @param body optional * @return true email send, false invalid input */ public boolean sendEmail(String[] toAddresses, String subject, String body) { if (!isValidEmail(toAddresses) || !isValidSubject(subject)) { return false; } // Aysnc send email Runnable emailServiceAsync = new EmailServiceAsync(toAddresses, subject, body); executor.schedule(emailServiceAsync, 1, TimeUnit.MILLISECONDS); return true; }
From source file:com.clustercontrol.agent.SendQueue.java
/** * ????<BR>/*from w ww .j ava2s. c o m*/ * * ?????????<BR> * ?????? * @param msg */ public boolean put(Object info) { m_log.debug("put() start : " + info.getClass().getCanonicalName()); while (!ReceiveTopic.isHistoryClear()) { m_log.debug("put() while (!ReceiveTopic.isHistoryClear()) is true"); boolean sendQueueStatus = false; ExecutorService es = null; Future<Boolean> task = null; try { String id = ""; // Executor?? SenderThreadFactory threadFactory = new SenderThreadFactory(id); es = Executors.newSingleThreadExecutor(threadFactory); // Queue?? // ?Queue?????????????????? // Future.get()???????? m_log.debug("put() submit"); task = es.submit(new Sender(info)); sendQueueStatus = task.get(SEND_TIMEOUT, TimeUnit.MILLISECONDS); } catch (Exception e) { // Queue?????????????Future.get()??????? // ???? // ? m_log.warn("put() : Failed to connect to MGR " + e.getMessage(), e); } finally { // if (task != null) { task.cancel(true); } if (es != null) { es.shutdown(); } m_log.debug("put() end : " + info.getClass().getCanonicalName()); } // ??????????sleep???? // Queue???????? if (sendQueueStatus) { m_log.debug("put() return true : " + info.getClass().getCanonicalName()); return true; } else { // sleep???QueueConnection?QueueSession ?? try { m_log.debug("put() reput interval sleep: " + m_sendQueueReconnectionInterval + " sec"); Thread.sleep(m_sendQueueReconnectionInterval); } catch (InterruptedException e1) { m_log.error("put() reput interval sleep: ", e1); } } } // End While Loop return false; }
From source file:org.sonatype.nexus.internal.httpclient.SharedHttpClientConnectionManager.java
@Inject public SharedHttpClientConnectionManager(final List<SSLContextSelector> sslContextSelectors, @Named("${nexus.httpclient.connectionpool.size:-20}") final int connectionPoolSize, @Named("${nexus.httpclient.connectionpool.maxSize:-200}") final int connectionPoolMaxSize, @Named("${nexus.httpclient.connectionpool.idleTime:-30s}") final Time connectionPoolIdleTime, @Named("${nexus.httpclient.connectionpool.evictingDelayTime:-5s}") final Time connectionPoolEvictingDelayTime, @Named("${nexus.httpclient.connectionpool.validateAfterInactivityTime:-2s}") final Time connectionPoolValidateAfterInactivityTime) { super(new DefaultHttpClientConnectionOperator(createRegistry(sslContextSelectors), null, null), null, connectionPoolIdleTime.toMillis(), TimeUnit.MILLISECONDS); setMaxTotal(connectionPoolMaxSize);//w ww. j a v a 2s . c o m log.debug("Connection pool max-size: {}", connectionPoolMaxSize); setDefaultMaxPerRoute(Math.min(connectionPoolSize, connectionPoolMaxSize)); log.debug("Connection pool size: {}", connectionPoolSize); this.connectionPoolIdleTime = checkNotNull(connectionPoolIdleTime); this.connectionPoolEvictingDelayTime = checkNotNull(connectionPoolEvictingDelayTime); setValidateAfterInactivity(connectionPoolValidateAfterInactivityTime.toMillisI()); log.debug("Connection pool idle-time: {}, evicting delay: {}, validate after inactivity: {}", connectionPoolIdleTime, connectionPoolEvictingDelayTime, connectionPoolValidateAfterInactivityTime); }
From source file:org.sonatype.nexus.internal.httpclient.ConnectionEvictionThread.java
@Override public void run() { log.debug("Starting '{}' (delay {} millis)", getName(), evictingDelayMillis); try {// w ww. j av a2 s . c o m while (true) { synchronized (this) { wait(evictingDelayMillis); try { connectionManager.closeExpiredConnections(); } catch (Exception e) { log.warn("Failed to close expired connections", e); } try { connectionManager.closeIdleConnections(idleTimeMillis, TimeUnit.MILLISECONDS); } catch (Exception e) { log.warn("Failed to close idle connections", e); } } } } catch (InterruptedException e) { // ignore } log.debug("Stopped '{}'", getName()); }