List of usage examples for java.util.concurrent Callable Callable
Callable
From source file:de.msg.terminfindung.gui.administration.TerminfindungWatchdog.java
@Override public void afterPropertiesSet() throws Exception { addPruefung("Datenbank", new Callable<Boolean>() { @Override/*from ww w. ja va 2 s .c o m*/ public Boolean call() throws Exception { final String watchdogQuery = konfiguration.getAsString(CONF_ADMIN_WATCHDOG_VALIDATION_QUERY); entityManager.createNativeQuery(watchdogQuery).getSingleResult(); return true; } }); }
From source file:com.sishuok.chapter3.web.controller.WebAsyncTaskController.java
@RequestMapping("/webAsyncTask2") public WebAsyncTask<String> webAsyncTask2(final Model model) { long timeout = 10L * 1000; // 1 WebAsyncTask webAsyncTask = new WebAsyncTask(timeout, new Callable() { @Override/*from w ww .j ava 2 s . c o m*/ public String call() throws Exception { Thread.sleep(2L * 1000); throw new RuntimeException(""); } }); return webAsyncTask; }
From source file:org.zenoss.zep.dao.impl.DaoUtilsTest.java
@Test public void testDeadlockRetryAllFailed() throws Exception { final AtomicInteger i = new AtomicInteger(); try {// w ww. j a va2 s .c o m DaoUtils.deadlockRetry(new Callable<Integer>() { @Override public Integer call() throws Exception { throw new DeadlockLoserDataAccessException(String.valueOf(i.incrementAndGet()), null); } }); fail("Should have thrown an exception after 5 retries"); } catch (DeadlockLoserDataAccessException e) { assertEquals("5", e.getMessage()); } }
From source file:com.microsoft.windowsazure.management.scheduler.SchedulerIntegrationTestBase.java
protected static void createManagementClient() throws Exception { Configuration config = createConfiguration(); managementClient = ManagementService.create(config); addClient((ServiceClient<?>) managementClient, new Callable<Void>() { @Override// w w w . ja va 2s .c o m public Void call() throws Exception { createManagementClient(); return null; } }); }
From source file:org.jspringbot.keyword.expression.ELEvaluate.java
@Override public Object execute(final Object[] params) throws Exception { List<Object> variables = new ArrayList<Object>(); if (params.length > 1) { variables.addAll(Arrays.asList(params).subList(1, params.length)); }//from ww w .ja va 2 s. c om return helper.variableScope(variables, new Callable<Object>() { @Override public Object call() throws Exception { return helper.evaluate(String.valueOf(params[0])); } }); }
From source file:com.jayway.restassured.module.mockmvc.http.PostAsyncController.java
@RequestMapping(value = "/tooLongAwaiting", method = POST) public @ResponseBody Callable<String> tooLongAwaiting(final @RequestBody String body) { return new Callable<String>() { public String call() throws Exception { Thread.sleep(10);/*from www . ja va 2s. c o m*/ return body; } }; }
From source file:com.streamsets.pipeline.cluster.ClusterFunctionImpl.java
private static synchronized void initialize(Properties properties, Integer id, String rootDataDir) throws Exception { if (initialized) { return;// w w w. j a v a 2 s. c o m } File dataDir = new File(System.getProperty("user.dir"), "data"); FileUtils.copyDirectory(new File(rootDataDir), dataDir); System.setProperty("sdc.data.dir", dataDir.getAbsolutePath()); // must occur before creating the EmbeddedSDCPool as // the hdfs target validation evaluates the sdc:id EL NumberFormat numberFormat = NumberFormat.getInstance(); numberFormat.setMinimumIntegerDigits(6); numberFormat.setGroupingUsed(false); final String sdcId = numberFormat.format(id); Utils.setSdcIdCallable(new Callable<String>() { @Override public String call() { return sdcId; } }); sdcPool = new EmbeddedSDCPool(properties); initialized = true; }
From source file:com.github.marcosalis.kraken.utils.concurrent.ExpirableFutureTest.java
/** * Test for {@link ExpirableFutureTask#isExpired()} * //from w ww .j a v a 2 s. c o m * @throws InterruptedException */ public void testIsExpired() throws InterruptedException { final long expiration = 100; // ms // test future expiration ExpirableFutureTask<JSONObject> future = new ExpirableFutureTask<JSONObject>(new Callable<JSONObject>() { @Override public JSONObject call() throws Exception { return null; } }, expiration); // sleep enough time for the future to expire Thread.sleep(expiration + 1); assertTrue("Future should be expired", future.isExpired()); // test future validity ExpirableFutureTask<JSONObject> validFuture = new ExpirableFutureTask<JSONObject>( new Callable<JSONObject>() { @Override public JSONObject call() throws Exception { return null; } }, expiration * 2); // sleep less time than expiration period Thread.sleep(expiration); assertFalse("Future should not be expired", validFuture.isExpired()); }
From source file:net.javacrumbs.futureconverter.common.test.spring.SpringOriginalFutureTestHelper.java
@Override public ListenableFuture<String> createExceptionalFuture(final Exception exception) { return executor.submitListenable(new Callable<String>() { @Override//w ww. jav a 2 s. c om public String call() throws Exception { throw exception; } }); }
From source file:org.fishwife.jrugged.spring.retry.ExtendedRetryTemplate.java
/*** * Construct a {@link Callable} which wraps the given {@link RetryCallback}, * and who's {@link java.util.concurrent.Callable#call()} method will execute * the callback via this {@link ExtendedRetryTemplate} * * @param callback The callback to wrap/*from w w w.jav a2 s.c om*/ * @param <T> The return type of the callback * @return */ public <T> Callable<T> asCallable(final RetryCallback<T> callback) { return new Callable<T>() { public T call() throws Exception { return ExtendedRetryTemplate.this.execute(callback); } }; }