List of usage examples for java.util.concurrent Callable Callable
Callable
From source file:com.spotify.helios.system.EnvironmentVariableTest.java
@Test public void test() throws Exception { startDefaultMaster();//w ww . j ava 2 s. co m startDefaultAgent(testHost(), "--env", "SPOTIFY_POD=PODNAME", "SPOTIFY_ROLE=ROLENAME", "BAR=badfood"); awaitHostStatus(testHost(), UP, LONG_WAIT_SECONDS, SECONDS); // Wait for the agent to report environment vars Polling.await(LONG_WAIT_SECONDS, SECONDS, new Callable<Object>() { @Override public Object call() throws Exception { final Map<String, HostStatus> status = Json.read(cli("hosts", testHost(), "--json"), new TypeReference<Map<String, HostStatus>>() { }); return status.get(testHost()).getEnvironment(); } }); try (final DockerClient dockerClient = getNewDockerClient()) { final List<String> command = asList("sh", "-c", "echo pod: $SPOTIFY_POD; " + "echo role: $SPOTIFY_ROLE; " + "echo foo: $FOO; " + "echo bar: $BAR"); // Create job final JobId jobId = createJob(testJobName, testJobVersion, BUSYBOX, command, ImmutableMap.of("FOO", "4711", "BAR", "deadbeef")); // deploy deployJob(jobId, testHost()); final TaskStatus taskStatus = awaitTaskState(jobId, testHost(), EXITED); final LogStream logs = dockerClient.logs(taskStatus.getContainerId(), stdout(), stderr()); final String log = logs.readFully(); assertThat(log, containsString("pod: PODNAME")); assertThat(log, containsString("role: ROLENAME")); assertThat(log, containsString("foo: 4711")); // Verify that the the BAR environment variable in the job overrode the agent config assertThat(log, containsString("bar: deadbeef")); final Map<String, HostStatus> status = Json.read(cli("hosts", testHost(), "--json"), new TypeReference<Map<String, HostStatus>>() { }); assertEquals(ImmutableMap.of("SPOTIFY_POD", "PODNAME", "SPOTIFY_ROLE", "ROLENAME", "BAR", "badfood"), status.get(testHost()).getEnvironment()); assertEquals(ImmutableMap.of("SPOTIFY_POD", "PODNAME", "SPOTIFY_ROLE", "ROLENAME", "BAR", "deadbeef", "FOO", "4711"), status.get(testHost()).getStatuses().get(jobId).getEnv()); } }
From source file:net.eusashead.hateoas.conditional.interceptor.AsyncTestController.java
@RequestMapping(method = RequestMethod.PUT) public Callable<ResponseEntity<Void>> put() { return new Callable<ResponseEntity<Void>>() { @Override/*from w ww.j a va 2 s . c o m*/ public ResponseEntity<Void> call() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setETag("\"123456\""); return new ResponseEntity<Void>(headers, HttpStatus.NO_CONTENT); } }; }
From source file:MdDetect.java
/** * Create instances of the process function per file * * @param file the file to process//from w w w . j a v a 2 s . co m * @return nothing */ private static Callable<Void> newProcessFileAction(final File file) { return new Callable<Void>() { @Override public Void call() throws Exception { // read the lines of the 'in'-file List<String> inLines = FileUtils.readLines(file); // queue up the output List<String> outLines = new ArrayList<>(); // flip/flop for blocks boolean inBlock = false; // line counter int ii = 0; for (String line : inLines) { if (line.matches(MD_CODE_REGEX)) { // is the line the start of a code block? line = line.trim(); // clean it up // flip the block toggle inBlock = !inBlock; if (inBlock && !isAlreadyAnnotated(line)) { // there needs to be a kind of 'look-ahead' here to figure out what tag to use... // lets do a best effort to figure our what it is // how about we grab the next few lines and so some casual checks List<String> codeBlockLines = new ArrayList<>(); // grab the rest of this code block grabCodeBlock(inLines, ii, codeBlockLines); // grab the tag to use String tag = supposeLang(codeBlockLines); // then use it line = line.replace("```", "```" + tag); } } outLines.add(line); ii++; // increment the lines counter } // write the outlines over the old file.... FileUtils.writeLines(file, outLines); return null; } }; }
From source file:org.jasig.portlet.blackboardvcportlet.dao.impl.SessionRecordingDaoImplTest.java
@Test public void testEmptyQueries() throws Exception { this.execute(new Callable<Object>() { @Override// w w w . j a va 2s. com public Object call() { final Set<SessionRecording> allRecordings = sessionRecordingDao.getAllRecordings(); assertEquals(0, allRecordings.size()); return null; } }); }
From source file:com.pepperonas.appregistry.AppRegistry.java
/** * Instantiates a new App registry.// www . j a v a2 s .c o m * * @param builder the builder */ public AppRegistry(final Builder builder) { ThreadUtils.runInBackground(new Callable<Void>() { @Override public Void call() throws Exception { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost( "http://ccmp.kochab.uberspace.de/app_registry/user_validation.php"); if (builder.activity instanceof OnRegisterResultListener) { mListener = (OnRegisterResultListener) builder.activity; } String responseString = DEFAULT_RESPONSE_STRING; int httpStatus = 0; try { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("dev_id", builder.devId)); nameValuePairs.add(new BasicNameValuePair("app_id", builder.appId)); nameValuePairs.add(new BasicNameValuePair("user_id", builder.userId)); nameValuePairs.add(new BasicNameValuePair("stamp", "")); nameValuePairs.add(new BasicNameValuePair("expires", String.valueOf(builder.expires))); nameValuePairs.add(new BasicNameValuePair("any_text", builder.anyText)); nameValuePairs.add(new BasicNameValuePair("any_int", String.valueOf(builder.anyInt))); nameValuePairs .add(new BasicNameValuePair("reg_stamp", String.valueOf(System.currentTimeMillis()))); nameValuePairs.add(new BasicNameValuePair("sdk", String.valueOf(Build.VERSION.SDK_INT))); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); httpStatus = response.getStatusLine().getStatusCode(); HttpEntity entity = response.getEntity(); responseString = EntityUtils.toString(entity, "UTF-8"); } catch (IOException e) { if (mListener != null) { mListener.onFailed(StatusCode.IO_EXCEPTION, httpStatus, null); } if (builder.listener != null) { builder.listener.onFailed(StatusCode.IO_EXCEPTION, httpStatus, null); } e.printStackTrace(); } catch (Exception e) { if (mListener != null) { mListener.onFailed(StatusCode.EXCEPTION, httpStatus, null); } if (builder.listener != null) { builder.listener.onFailed(StatusCode.EXCEPTION, httpStatus, null); } } if (responseString.contains("user_exists")) { Log.d(TAG, "call " + responseString); Long stamp = null; String extraString = null; Integer extraInt = null; try { stamp = Long.valueOf(responseString.split("<reg_stamp>")[1].split("</reg_stamp>")[0]); } catch (Exception e) { Log.e(TAG, "Exception while getting timestamp"); } try { extraString = responseString.split("<extra_string>")[1].split("</extra_string>")[0]; } catch (Exception e) { Log.e(TAG, "Exception while getting extraString"); } try { extraInt = Integer .parseInt(responseString.split("<extra_int>")[1].split("</extra_int>")[0]); } catch (Exception e) { Log.e(TAG, "Exception while getting extraInt"); } if (mListener != null) { mListener.onUserExists(responseString, stamp, extraString, extraInt); } if (builder.listener != null) { builder.listener.onUserExists(responseString, stamp, extraString, extraInt); } return null; } else if (responseString.contains("user_registered")) { if (mListener != null) { mListener.onUserRegistered(responseString); } if (builder.listener != null) { builder.listener.onUserRegistered(responseString); } return null; } else if (mListener != null) { mListener.onFailed(StatusCode.UNKNOWN_FAILURE, httpStatus, responseString); } if (builder.listener != null) { builder.listener.onFailed(StatusCode.UNKNOWN_FAILURE, httpStatus, responseString); } return null; } }); }
From source file:org.apache.mina.springrpc.example.gettingstarted.AbstractHelloServiceClientTests.java
private List<Callable<HelloResponse>> createTasks(final HelloService service) { List<Callable<HelloResponse>> tasks = new ArrayList<Callable<HelloResponse>>(RUN_TIMES); for (int i = 0; i < RUN_TIMES; i++) { Callable<HelloResponse> task = new Callable<HelloResponse>() { @Override//from w w w . j a v a 2s . c o m public HelloResponse call() throws Exception { HelloResponse response = service.sayHello(new HelloRequest()); logger.info(response.toString()); counter.incrementAndGet(); return response; } }; tasks.add(task); } return tasks; }
From source file:net.pms.io.ListProcessWrapperConsumer.java
@Override @Nullable/*from ww w. j av a 2 s. com*/ public FutureTask<List<String>> consume(@Nullable final InputStream inputStream, @Nullable String threadName) { if (inputStream == null) { return null; } Callable<List<String>> callable = new Callable<List<String>>() { @Override public List<String> call() throws Exception { List<String> result = new ArrayList<>(); Charset outputCharset; if (Services.WINDOWS_CONSOLE != null) { outputCharset = Services.WINDOWS_CONSOLE; } else { outputCharset = StandardCharsets.UTF_8; } try (BufferedReader reader = new BufferedReader( new InputStreamReader(inputStream, outputCharset))) { String line; while ((line = reader.readLine()) != null) { result.add(line); } } if (LOGGER.isTraceEnabled()) { for (String line : result) { LOGGER.trace("Process output: {}", line); } } return result; } }; FutureTask<List<String>> result = new FutureTask<List<String>>(callable); Thread runner; if (isBlank(threadName)) { runner = new Thread(result); } else { runner = new Thread(result, threadName); } runner.start(); return result; }
From source file:com.bao.sample.SampleController.java
@RequestMapping("/call") public Callable<String> call() { return new Callable<String>() { @Override/*from w w w. j a v a2s. co m*/ public String call() throws Exception { int millis = SampleController.this.random.nextInt(1000); Thread.sleep(millis); SampleController.this.tracer.addTag("callable-sleep-millis", String.valueOf(millis)); Span currentSpan = SampleController.this.accessor.getCurrentSpan(); return "async hi: " + currentSpan; } }; }
From source file:com.atomicleopard.thundr.ftp.FtpSession.java
public boolean deleteDirectory(final String directory) { return timeLogAndCatch("Delete directory", new Callable<Boolean>() { @Override//from w w w .j a v a 2 s.co m public Boolean call() throws Exception { return preparedClient.removeDirectory(directory); } }); }
From source file:mondrian.olap4j.MondrianInprocProxy.java
public Future<byte[]> submit(final XmlaOlap4jServerInfos infos, final String request) { return this.executor.submit(new Callable<byte[]>() { public byte[] call() throws Exception { return get(infos, request); }// w w w. jav a2 s .c o m }); }