Example usage for java.util.concurrent Callable Callable

List of usage examples for java.util.concurrent Callable Callable

Introduction

In this page you can find the example usage for java.util.concurrent Callable Callable.

Prototype

Callable

Source Link

Usage

From source file:com.sishuok.chapter3.web.interceptor.MyCallableController.java

@RequestMapping("/myCallable2")
@ResponseBody//from   w  w w  . j av  a2 s  . c  o m
public Callable<String> callable2() {
    return new Callable<String>() {
        @Override
        public String call() throws Exception {
            Thread.sleep(31L * 1000);
            System.out.println("====Callable call");
            return "success";
        }
    };
}

From source file:com.rogiel.httpchannel.util.HttpClientUtils.java

public static Future<String> executeAsync(final HttpClient client, final HttpUriRequest request)
        throws IOException {
    return threadPool.submit(new Callable<String>() {
        @Override//from  w ww . j a v a2  s . c  om
        public String call() throws Exception {
            return HttpClientUtils.toString(client.execute(request));
        }
    });
}

From source file:com.sf.ddao.TxHelper.java

public static <SK> void execInTx(TransactionableDao dao, final Runnable runnable, SK... shardKeys)
        throws Exception {
    execInTx(dao, new Callable<Object>() {
        public Object call() throws Exception {
            runnable.run();/*from www  .j  a  v  a2 s  .c  om*/
            return null;
        }
    }, shardKeys);
}

From source file:de.ii.xtraplatform.ogc.csw.client.CSWRequest.java

public ListenableFuture<HttpEntity> getResponse() {
    return pool.submit(new Callable<HttpEntity>() {
        @Override/*from www . j  a v a  2 s  .c om*/
        public HttpEntity call() throws Exception {
            return csw.request(operation);
        }
    });

}

From source file:org.xwalk.core.internal.xwview.test.UserAgentTest.java

protected XWalkSettingsInternal getXWalkSettingsOnUiThread() throws Exception {
    return runTestOnUiThreadAndGetResult(new Callable<XWalkSettingsInternal>() {
        @Override//from   ww w. j  a va 2 s  .co m
        public XWalkSettingsInternal call() throws Exception {
            return getXWalkView().getSettings();
        }
    });
}

From source file:com.jayway.restassured.module.mockmvc.http.PostAsyncController.java

@RequestMapping(value = "/stringBody", method = POST)
public @ResponseBody Callable<String> stringBody(final @RequestBody String body) {
    return new Callable<String>() {
        public String call() throws Exception {
            return body;
        }//from  w w  w. j av  a2s .c  om
    };
}

From source file:bb.io.TarUtil.java

/**
* May be used either to archive to or extract from a TAR file.
* The action to perform and all of its specifications are embedded as command line switches in args.
* <p>/*from   w  w w  .ja va2s . co  m*/
* If archiving,
* the source path(s) to be archived (which can be either normal files or directories)
* are specified as the (key/value) command line switch <code>-pathsToArchive <i>commaSeparatedListOfPaths</i></code>.
* The target TAR archive file is the (key/value) command line switch <code>-tarFile <i>insertPathHere</i></code>.
* The following optional switches may also be supplied:
* <ol>
*  <li><code>-appendBackup</code> appends <code>_backup</code> to the TAR file's name</li>
*  <li><code>-appendTimeStamp</code> appends <code>_</code> followed by a timestamp to the TAR file's name</li>
*  <li><code>-appendExtension</code> appends <code>.tar</code> to the TAR file's name</li>
*  <li><code>-appendAll</code> is equivalent to supplying all the above append options</li>
*  <li>
*      <code>-filter <i>fullyQualifiedClassName</i></code>
*      specifies the name of a FileFilter which limits what gets archived.
*      Since this FileFilter class will be instantiated by a call to Class.forName,
*      it must have a no-arg constructor.
*  </li>
* </ol>
* For example, here is a complete command line that archives just the class files found under two different class directories:
* <pre><code>
   java  bb.io.TarUtil  -tarFile ../log/test.tar  -pathsToArchive ../class1,../class2  -filter bb.io.filefilter.ClassFilter
* </code></pre>
* <p>
* If extracting,
* the target directory to extract into is always specified as the command line switch <code>-directoryExtraction <i>insertPathHere</i></code>.
* The source TAR archive file is the same <code>-tarFile</code> command line switch mentioned before.
* An optional switch <code>-overwrite <i>true/false</i></code> may also be supplied
* to control if overwriting of existing normal files is allowed or not.
* By default overwriting is not allowed (an Exception will be thrown if extraction needs to overwrite an existing file).
* For example, here is a complete command line that extracts a TAR file to a specific directory, overwriting any existing files:
* <pre><code>
   java  bb.io.TarUtil  -tarFile ../log/test.tar  -directoryExtraction ../log/tarExtractOutput  -overwrite true
* </code></pre>
* <p>
* Optional GZIP compression/decompression may also be done when archiving/extracting a TAR file.
* Normally, the value for the <code>-tarFile</code> switch must be a path
* which ends in a ".tar" (case insensitive) extension.
* However, this program will also accept either ".tar.gz" or ".tgz" extensions,
* in which case it will automatically perform GZIP compression/decompression on the TAR file.
* <p>
* Note that the switches may appear in any order on the command line.
* <p>
* If this method is this Java process's entry point (i.e. first <code>main</code> method),
* then its final action is a call to {@link System#exit System.exit}, which means that <i>this method never returns</i>;
* its exit code is 0 if it executes normally, 1 if it throws a Throwable (which will be caught and logged).
* Otherwise, this method returns and leaves the JVM running.
*/
public static void main(final String[] args) {
    Execute.thenExitIfEntryPoint(new Callable<Void>() {
        public Void call() throws Exception {
            Check.arg().notEmpty(args);

            Properties2 switches = new Properties2(args);
            if (switches.containsKey(pathsToArchive_key)) {
                switches.checkKeys(keysLegal_archive);

                File tarFile = ZipUtil.getArchiveFile(switches, tarFile_key, "tar");
                File[] pathsToArchive = ZipUtil.getPathsToArchive(switches);
                FileFilter filter = ZipUtil.getFileFilter(switches);

                archive(tarFile, filter, pathsToArchive);
            } else if (switches.containsKey(directoryExtraction_key)) {
                switches.checkKeys(keysLegal_extract);

                File tarFile = ZipUtil.getArchiveFile(switches, tarFile_key, "tar");
                File directoryExtraction = switches.getFile(directoryExtraction_key).getCanonicalFile();
                boolean overwrite = switches.getBoolean(overwrite_key, false);

                extract(tarFile, directoryExtraction, overwrite);
            } else {
                throw new IllegalArgumentException("args failed to specify a legitimate operation to perform");
            }

            return null;
        }
    });
}

From source file:com.yufei.dataget.dataretriver.HttpDataRetriverUsingFirefoxDriverWithTimeOut.java

@Override
public String getHtmlContent() {
    final HttpDataRetriverUsingFirefoxDriver hdrufd = new HttpDataRetriverUsingFirefoxDriver(
            this.dataRetrieverFeatures);

    String htmlContent = null;/*from   w  w  w .j a v  a2  s  .  c  o m*/
    try {
        htmlContent = TimeOutUtils.runWithTimeout(new Callable<String>() {

            @Override
            public String call() throws Exception {
                hdrufd.setUrl(url);
                hdrufd.connect();

                return hdrufd.getHtmlContent();
            }
        }, this.dataRetrieverFeatures.getRequestTimeout(), TimeUnit.MILLISECONDS);
    } catch (TimeoutException e) {
        mLog.info("got timeout!");
    } catch (Exception ex) {
        Logger.getLogger(HttpDataRetriverUsingFirefoxDriverWithTimeOut.class.getName()).log(Level.SEVERE, null,
                ex);
    } finally {
        hdrufd.disconnect();

    }
    return htmlContent;
}

From source file:net.eusashead.hateoas.conditional.interceptor.AsyncTestController.java

@RequestMapping(method = RequestMethod.GET)
public Callable<ResponseEntity<String>> get() {
    return new Callable<ResponseEntity<String>>() {

        @Override/*from   w ww  .  j a v a 2s.  c o m*/
        public ResponseEntity<String> call() throws Exception {
            HttpHeaders headers = new HttpHeaders();
            headers.setETag("\"123456\"");
            return new ResponseEntity<String>("hello", headers, HttpStatus.OK);
        }
    };

}

From source file:com.vaadin.tools.ReportUsage.java

public static FutureTask<Void> checkForUpdatesInBackgroundThread() {
    FutureTask<Void> task = new FutureTask<>(new Callable<Void>() {
        @Override/*from ww  w . ja v a  2s  .  c o  m*/
        public Void call() throws Exception {
            ReportUsage.report();
            return null;
        }
    });
    Thread checkerThread = new Thread(task, "Vaadin Update Checker");
    checkerThread.setDaemon(true);
    checkerThread.start();
    return task;
}