List of usage examples for java.util.concurrent TimeUnit SECONDS
TimeUnit SECONDS
To view the source code for java.util.concurrent TimeUnit SECONDS.
Click Source Link
From source file:org.kordamp.javatrove.example04.controller.AppController.java
public void load() { Observable<Repository> observable = github.repositories(model.getOrganization()); if (model.getLimit() > 0) { observable = observable.take(model.getLimit()); }/*from w ww. ja v a 2s . c o m*/ model.setDisposable(observable.timeout(10, TimeUnit.SECONDS) .doOnSubscribe(disposable -> model.setState(RUNNING)).doOnTerminate(() -> model.setState(READY)) .doOnError(throwable -> eventBus.publishAsync(new ThrowableEvent(throwable))) .subscribeOn(Schedulers.io()).subscribe(model.getRepositories()::add)); }
From source file:com.isoftstone.proxy.utils.ProxyPool.java
/** * ???./*ww w. j ava2 s . c o m*/ * @param proxyList ?. */ public void insertProxyList(List<ProxyVo> proxyList) { if (CollectionUtils.isEmpty(proxyList)) { return; } //--HashSet??. HashSet<ProxyVo> hashSet = new HashSet<ProxyVo>(); if (CollectionUtils.isNotEmpty(this.proxyQueue)) { hashSet.addAll(this.proxyQueue); } hashSet.addAll(proxyList); this.proxyQueue.clear(); try { for (ProxyVo proxyVo : hashSet) { this.proxyQueue.offer(proxyVo, 1, TimeUnit.SECONDS); } } catch (InterruptedException e) { LOG.error("InterruptedException", e); } }
From source file:com.alibaba.jstorm.daemon.worker.timer.TimerTrigger.java
public void register() { register(TimeUnit.SECONDS); }
From source file:ch.cyberduck.core.io.ThreadedStreamCloser.java
@Override public void close(final InputStream in) throws ConnectionTimeoutException { final CountDownLatch signal = new CountDownLatch(1); threadFactory.newThread(new Runnable() { @Override/*from w ww . ja v a 2 s.com*/ public void run() { IOUtils.closeQuietly(in); signal.countDown(); } }).start(); try { if (!signal.await(preferences.getInteger("connection.timeout.seconds"), TimeUnit.SECONDS)) { throw new StreamCloseTimeoutException("Timeout closing input stream", null); } } catch (InterruptedException e) { throw new ConnectionTimeoutException(e.getMessage(), e); } }
From source file:co.cask.cdap.gateway.handlers.hooks.MetricsReporterHookTestRun.java
@Test public void testMetricsSuccess() throws Exception { String context = "tag=namespace:system&tag=component:appfabric&tag=handler:PingHandler&tag=method:ping"; // todo: better fix needed: CDAP-2174 TimeUnit.SECONDS.sleep(1); long received = getMetricValue(context, "system.request.received"); long successful = getMetricValue(context, "system.response.successful"); long clientError = getMetricValue(context, "system.response.client-error"); // Make a successful call HttpResponse response = GatewayFastTestsSuite.doGet("/ping"); Assert.assertEquals(HttpResponseStatus.OK.getCode(), response.getStatusLine().getStatusCode()); // received and successful should have increased by one, clientError should be the same verifyMetrics(received + 1, context, "system.request.received"); verifyMetrics(successful + 1, context, "system.response.successful"); verifyMetrics(clientError, context, "system.response.client-error"); }
From source file:de.elomagic.mag.WebDAVTest.java
@Test public void testMain() throws Exception { greeUser.deliver(createMimeMessage("TestFile.pdf")); main.start();//from www .j a va 2s .co m Future future = createPutServletFuture(putServlet); future.get(500, TimeUnit.SECONDS); InputStream in = getClass().getResourceAsStream("/TestFile.pdf"); int fileSize = in.available(); byte[] send = IOUtils.readFully(in, fileSize); Assert.assertEquals(fileSize, putServlet.lastContentLength); Assert.assertArrayEquals(send, putServlet.lastContent); Assert.assertTrue("Put filename doesn't match.", putServlet.requestedUri.startsWith("/inbox/unsorted/TestFile") && putServlet.requestedUri.endsWith(".pdf")); Assert.assertNotEquals("/inbox/unsorted/TestFile", putServlet.requestedUri); }
From source file:com.stimulus.util.TempFiles.java
public void startDaemon() { scheduledTask = scheduler.scheduleAtFixedRate(this, 1, 1, TimeUnit.SECONDS); }
From source file:ejp.examples.MultiThreadedWithConnectionPooling.java
static void execute(final DatabaseManager dbm) throws DatabaseException, InterruptedException { long time = System.currentTimeMillis(); ExecutorService exec = Executors.newFixedThreadPool(100); System.out.println("\n\nWorking ..."); Runnable runnable = new Runnable() { public void run() { for (int t = 0; t < 100; t++) { try { new UpdateManager(dbm) { public void run() throws DatabaseException { for (int j = 0; j < 100; j++) { saveObject(new Dog(String.valueOf(Count.get()), Count.get())); Count.count(); }//w w w.jav a2 s . c o m } }.executeBatchUpdates(); } catch (DatabaseException e) { e.printStackTrace(); } } } }; for (int i = 0; i < 100; i++) { exec.execute(runnable); } exec.shutdown(); exec.awaitTermination(100, TimeUnit.SECONDS); time = (System.currentTimeMillis() - time) / 1000; System.out.println("\n\n" + Count.count + " dogs added to database in " + time + " seconds"); Long count = ((Collection<Long>) dbm.executeQuery(new ArrayList<Long>(), true, "select count(*) from dog")) .toArray(new Long[1])[0]; System.out.println("select count(*) from dog = " + count); }
From source file:com.frostwire.android.MediaScanner.java
private static void scanFiles(final Context context, List<String> paths, int retries) { if (paths.size() == 0) { return;/*from w w w . ja va 2 s . co m*/ } LOG.info("About to scan files n: " + paths.size() + ", retries: " + retries); final LinkedList<String> failedPaths = new LinkedList<>(); final CountDownLatch finishSignal = new CountDownLatch(paths.size()); MediaScannerConnection.scanFile(context, paths.toArray(new String[0]), null, (path, uri) -> { try { boolean success = true; if (uri == null) { success = false; failedPaths.add(path); } else { // verify the stored size four faulty scan long size = getSize(context, uri); if (size == 0) { LOG.warn("Scan returned an uri but stored size is 0, path: " + path + ", uri:" + uri); success = false; failedPaths.add(path); } } if (!success) { LOG.info("Scan failed for path: " + path + ", uri: " + uri); } } finally { finishSignal.countDown(); } }); try { finishSignal.await(10, TimeUnit.SECONDS); } catch (InterruptedException e) { // ignore } if (failedPaths.size() > 0 && retries > 0) { // didn't want to do this, but there is a serious timing issue with the SD // and storage in general SystemClock.sleep(2000); scanFiles(context, failedPaths, retries - 1); } }
From source file:co.cask.cdap.spark.service.SparkServiceIntegrationTestRun.java
@Test public void testSparkWithService() throws Exception { ApplicationManager applicationManager = deployApplication(TestSparkServiceIntegrationApp.class); startService(applicationManager);/* www . jav a 2 s. c o m*/ SparkManager sparkManager = applicationManager .getSparkManager(TestSparkServiceIntegrationApp.SparkServiceProgram.class.getSimpleName()).start(); sparkManager.waitForFinish(120, TimeUnit.SECONDS); DataSetManager<KeyValueTable> datasetManager = applicationManager.getDataSet("result"); KeyValueTable results = datasetManager.get(); for (int i = 1; i <= 5; i++) { byte[] key = String.valueOf(i).getBytes(Charsets.UTF_8); Assert.assertEquals((i * i), Integer.parseInt(Bytes.toString(results.read(key)))); } }