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:io.neba.core.resourcemodels.caching.RequestScopedResourceModelCacheTest.java

@Test
public void testLookupOfDifferentResourcePaths() throws Exception {
    request(new Callable<Object>() {
        @Override/*w w w  .  ja va 2  s  .com*/
        public Object call() throws Exception {

            withResourcePath("/junit/test/1");
            putModelInCache();

            withResourcePath("/junit/test/2");
            lookupModelFromCache();
            assertModelIsNotInCache();

            withResourcePath("/junit/test/1");
            lookupModelFromCache();
            assertModelWasFoundInCache();
            return null;
        }
    });
}

From source file:com.microsoft.windowsazure.management.sql.SqlManagementIntegrationTestBase.java

protected static void createService() throws Exception {
    // reinitialize configuration from known state
    Configuration config = createConfiguration();
    config.setProperty(ApacheConfigurationProperties.PROPERTY_RETRY_HANDLER,
            new DefaultHttpRequestRetryHandler());

    sqlManagementClient = SqlManagementService.create(config);
    addClient((ServiceClient<?>) sqlManagementClient, new Callable<Void>() {
        @Override/*from w  w w.  ja va 2 s  . c o  m*/
        public Void call() throws Exception {
            createService();
            return null;
        }
    });
}

From source file:org.apache.activemq.karaf.itest.ActiveMQBrokerFeatureTest.java

private void produceMessageWebConsole(String nameAndPayload) throws Exception {
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(new org.apache.http.auth.AuthScope("httpbin.org", 80),
            new org.apache.http.auth.UsernamePasswordCredentials(KarafShellHelper.USER,
                    KarafShellHelper.PASSWORD));
    CloseableHttpClient client = HttpClientBuilder.create() //
            .setDefaultCredentialsProvider(credsProvider).build();

    System.err.println(executeCommand("activemq:bstat").trim());
    System.err.println("attempting to access web console..");

    withinReason(new Callable<Boolean>() {
        public Boolean call() throws Exception {
            CloseableHttpResponse response = client.execute(new HttpGet(WEB_CONSOLE_URL + "index.jsp"));
            return response.getStatusLine().getStatusCode() != 200;
        }//from ww  w. j  av  a 2 s .  co  m
    });

    System.err.println("attempting publish via web console..");

    // need to first get the secret
    CloseableHttpResponse response = client.execute(new HttpGet(WEB_CONSOLE_URL + "send.jsp"));
    int code = response.getStatusLine().getStatusCode();
    assertEquals("getting send succeeded", 200, code);

    String secret = getSecret(EntityUtils.toString(response.getEntity()));

    URI sendUri = new URIBuilder(WEB_CONSOLE_URL + "sendMessage.action") //
            .addParameter("secret", secret) //
            .addParameter("JMSText", nameAndPayload).addParameter("JMSDestination", nameAndPayload)
            .addParameter("JMSDestinationType", "queue").build();
    HttpPost post = new HttpPost(sendUri);
    CloseableHttpResponse sendResponse = client.execute(post);
    assertEquals("post succeeded, " + post, 302, sendResponse.getStatusLine().getStatusCode());
    System.err.println(executeCommand("activemq:bstat").trim());
}

From source file:com.microsoft.windowsazure.management.network.StaticIPOperationsImpl.java

/**
* The Check Static IP operation retrieves the details for the availability
* of static IP addresses for the given virtual network.
*
* @param networkName Required. The name of the virtual network.
* @param ipAddress Required. The address of the static IP.
* @return A response that indicates the availability of a static IP
* address, and if not, provides a list of suggestions.
*///from   w w  w.j av  a 2  s  . c o  m
@Override
public Future<NetworkStaticIPAvailabilityResponse> checkAsync(final String networkName,
        final InetAddress ipAddress) {
    return this.getClient().getExecutorService().submit(new Callable<NetworkStaticIPAvailabilityResponse>() {
        @Override
        public NetworkStaticIPAvailabilityResponse call() throws Exception {
            return check(networkName, ipAddress);
        }
    });
}

From source file:com.parse.FileObjectStore.java

@Override
public Task<T> getAsync() {
    return Task.call(new Callable<T>() {
        @Override/*from   w w  w.j  a  va 2  s . c om*/
        public T call() throws Exception {
            if (!file.exists()) {
                return null;
            }
            return getFromDisk(coder, file, ParseObject.State.newBuilder(className));
        }
    }, ParseExecutors.io());
}

From source file:org.openscada.da.server.spring.DataItemInputOutputProperty.java

@Override
protected NotifyFuture<WriteResult> startWriteCalculatedValue(final Variant value,
        final OperationParameters operationParameters) {
    final FutureTask<WriteResult> task = new FutureTask<WriteResult>(new Callable<WriteResult>() {

        @Override/*from  ww w  . j av a 2 s  . c om*/
        public WriteResult call() throws Exception {
            processWriteCalculatedValue(value, operationParameters);
            return new WriteResult();
        }
    });
    this.executor.execute(task);
    return task;
}

From source file:com.barchart.http.handlers.TestCancellableRequestHandler.java

@Test
public void testCancellableRequest() throws Exception {

    final ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);

    final HttpGet get = new HttpGet("http://localhost:8888/client-disconnect");

    executor.schedule(new Runnable() {

        @Override/*  w  w w .ja  va  2 s  .c  o m*/
        public void run() {
            System.out.println("Aborting " + get);
            get.abort();
        }

    }, 250, TimeUnit.MILLISECONDS);

    try {
        System.out.println("Executing " + get);
        client.execute(get);
    } catch (final Exception e) {
    }

    CallableTest.waitFor(new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            return clientDisconnect.lastFuture != null && clientDisconnect.lastFuture.isCancelled();
        }
    });

    assertNotNull(clientDisconnect.lastFuture);
    assertTrue(clientDisconnect.lastFuture.isCancelled());

}

From source file:no.uis.fsws.proxy.StudinfoProxyImpl.java

@Override
public List<Studieprogram> getStudieprogram(final XMLGregorianCalendar arstall, final Terminkode terminkode,
        final Sprakkode sprak, final boolean medUPinfo, final String studieprogramkode) {
    final StudInfoImport svc = getServiceForPrincipal();
    try {//  ww w.  j  av a 2 s  .c o  m
        Future<List<Studieprogram>> future = executor.submit(new Callable<List<Studieprogram>>() {

            @Override
            public List<Studieprogram> call() throws Exception {
                final FsStudieinfo sinfo = svc.fetchStudyProgram(studieprogramkode, arstall.getYear(),
                        terminkode.toString(), medUPinfo, sprak.toString());
                return sinfo.getStudieprogram();
            }
        });

        return future.get(timeoutMinutes, TimeUnit.MINUTES);
    } catch (ExecutionException | InterruptedException | TimeoutException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.spotify.helios.system.DeploymentGroupTest.java

@Before
public void initialize() throws Exception {
    master = startDefaultMaster();/*from  www.j a  v a 2 s  .  com*/

    // Wait for master to come up
    Polling.await(LONG_WAIT_SECONDS, SECONDS, new Callable<String>() {
        @Override
        public String call() throws Exception {
            final String output = cli("masters");
            return output.contains(masterName()) ? output : null;
        }
    });
}

From source file:com.github.tomakehurst.wiremock.ResponseDelaySynchronousFailureAcceptanceTest.java

private List<Callable<HttpResponse>> getHttpRequestCallables(int requestCount) throws IOException {
    List<Callable<HttpResponse>> requests = new ArrayList<>();
    for (int i = 0; i < requestCount; i++) {
        requests.add(new Callable<HttpResponse>() {
            @Override//from  w  w w.  j  a  v a  2 s . c o  m
            public HttpResponse call() throws Exception {
                return HttpClientFactory.createClient(SOCKET_TIMEOUT_MILLISECONDS).execute(
                        new HttpGet(String.format("http://localhost:%d/delayed", wireMockRule.port())));
            }
        });
    }
    return requests;
}