Examples of ExecutorService


Examples of java.util.concurrent.ExecutorService

        return add(path, new HttpToEventSourceHandler(handler));
    }

    @Override
    public synchronized NettyWebServer start() {
        ExecutorService exec1 = Executors.newSingleThreadExecutor();
        executorServices.add(exec1);
        ExecutorService exec2 = Executors.newSingleThreadExecutor();
        executorServices.add(exec2);
        bootstrap.setFactory(new NioServerSocketChannelFactory(exec1, exec2, 1));
        channel = bootstrap.bind(socketAddress);
        return this;
    }
View Full Code Here

Examples of java.util.concurrent.ExecutorService

            }
        }
    }

    public static void main(String[] args) throws Exception {
        ExecutorService webThread = newSingleThreadExecutor();
        final Pusher pusher = new Pusher();

        WebServer webServer = createWebServer(webThread, 9876)
                .add("/events", new EventSourceHandler() {
                    @Override
View Full Code Here

Examples of java.util.concurrent.ExecutorService

                    tables.put(shippedId, joinTable);
                }
                return map(contextSeq, dynEnv);
            }
            // threaded execution
            final ExecutorService ex = Executors.newSingleThreadExecutor();
            final Callable<JoinTable> call = new Callable<JoinTable>() {
                public JoinTable call() throws Exception {
                    final JoinTable joinTable = makeJoinTable(contextSeq, dynEnv);
                    if(shippedId != -1) {
                        tables.put(shippedId, joinTable);
                    }
                    return joinTable;
                }
            };
            final Future<JoinTable> future = ex.submit(call);
            final Sequence<? extends Item> mapped;
            try {
                mapped = map(contextSeq, dynEnv, future);
            } catch (InterruptedException e) {
                ex.shutdownNow();
                throw new IllegalStateException(e);
            } catch (ExecutionException e) {
                ex.shutdownNow();
                throw new IllegalStateException(e);
            }
            ex.shutdown(); // REVIEWME is really required?
            return mapped;
        }
View Full Code Here

Examples of java.util.concurrent.ExecutorService

        return result;
    }

    private static Sequence invokeRequestsInParallel(final List<String> endpoints, final BindingVariable hostVar, final PreparedQueryRequest request, final DynamicContext dynEnv) {
        final int numEndpoints = endpoints.size();
        final ExecutorService ex = ExecutorFactory.newFixedThreadPool(numEndpoints, "parallelRemoteExec");
        final Sequence[] results = new Sequence[numEndpoints];
        //final AtomicReferenceArray<Sequence> resultsRef = new AtomicReferenceArray<Sequence>(results);
        try {
            for(int i = 0; i < numEndpoints; i++) {
                final String endpoint = endpoints.get(i);
                final int at = i;
                Runnable r = new Runnable() {
                    public void run() {
                        final Sequence res;
                        try {
                            res = invokeRequest(endpoint, request);
                        } catch (XQueryException e) {
                            throw new IllegalStateException("An error caused while evaluating CompiledQueryRequest#"
                                    + request.getIdentifier() + " at " + endpoint, e);
                        }
                        results[at] = res;
                    }
                };
                ex.execute(r);
            }
        } finally {
            ExecutorUtils.shutdownAndAwaitTermination(ex);
        }
        assert (ex.isTerminated());
        return new PipelinedSequence(dynEnv, results);
    }
View Full Code Here

Examples of java.util.concurrent.ExecutorService

        URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
        assertNotNull(wsdl);
       
        SOAPService service = new SOAPService(wsdl, serviceName);
        assertNotNull(service);
        ExecutorService executor = Executors.newFixedThreadPool(5);
        service.setExecutor(executor);
        assertNotNull(service);

        String expectedString = new String("How are you Joe");
        try {
            Greeter greeter = (Greeter)service.getPort(portName, Greeter.class);
           
            Response<GreetMeSometimeResponse> response = greeter.greetMeSometimeAsync("Joe");
            while (!response.isDone()) {
                Thread.sleep(100);
            }
            GreetMeSometimeResponse reply = response.get();
            assertNotNull("no response received from service", reply);
            String s = reply.getResponseType();
            assertEquals(expectedString, s);  
        } catch (UndeclaredThrowableException ex) {
            throw (Exception)ex.getCause();
        }
        executor.shutdown();
    }
View Full Code Here

Examples of java.util.concurrent.ExecutorService

        URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
        assertNotNull(wsdl);
       
        SOAPService service = new SOAPService(wsdl, serviceName);
        assertNotNull(service);
        ExecutorService executor = Executors.newFixedThreadPool(5);
        service.setExecutor(executor);
        assertNotNull(service);

        final String expectedString = new String("How are you Joe");
         
        class Poller extends Thread {
            Response<GreetMeSometimeResponse> response;
            int tid;
           
            Poller(Response<GreetMeSometimeResponse> r, int t) {
                response = r;
                tid = t;
            }
            public void run() {
                if (tid % 2 > 0) {
                    while (!response.isDone()) {
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException ex) {
                            // ignore
                        }
                    }
                }
                GreetMeSometimeResponse reply = null;
                try {
                    reply = response.get();
                } catch (Exception ex) {
                    fail("Poller " + tid + " failed with " + ex);
                }
                assertNotNull("Poller " + tid + ": no response received from service", reply);
                String s = reply.getResponseType();
                assertEquals(expectedString, s);  
            }
        }
       
        Greeter greeter = (Greeter)service.getPort(portName, Greeter.class);
        Response<GreetMeSometimeResponse> response = greeter.greetMeSometimeAsync("Joe");
       
        Poller[] pollers = new Poller[4];
        for (int i = 0; i < pollers.length; i++) {
            pollers[i] = new Poller(response, i);
        }
        for (Poller p : pollers) {           
            p.start();
        }
       
        for (Poller p : pollers) {
            p.join();
        }
       
        executor.shutdown();   
    }
View Full Code Here

Examples of java.util.concurrent.ExecutorService

    public void testAsyncCallWithHandler() throws Exception {
        URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
        assertNotNull(wsdl);
       
        SOAPService service = new SOAPService(wsdl, serviceName);
        ExecutorService executor = Executors.newFixedThreadPool(5);
        service.setExecutor(executor);
        assertNotNull(service);
       
        MyHandler h = new MyHandler();
        MyHandler.invocationCount = 0;

        String expectedString = new String("How are you Joe");
        try {
            Greeter greeter = (Greeter)service.getPort(portName, Greeter.class);
            Future<?> f = greeter.greetMeSometimeAsync("Joe", h);
            int i = 0;
            while (!f.isDone() && i < 20) {
                Thread.sleep(100);
                i++;
            }
            assertEquals("callback was not executed or did not return the expected result",
                         expectedString, h.getReplyBuffer());
        } catch (UndeclaredThrowableException ex) {
            throw (Exception)ex.getCause();
        }
        assertEquals(1, MyHandler.invocationCount);      
        executor.shutdown();
    }
View Full Code Here

Examples of java.util.concurrent.ExecutorService

    public void testAsyncCallWithHandlerAndMultipleClients() throws Exception {
        URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
        assertNotNull(wsdl);
       
        SOAPService service = new SOAPService(wsdl, serviceName);
        ExecutorService executor = Executors.newFixedThreadPool(5);
        service.setExecutor(executor);
        assertNotNull(service);
       
        final MyHandler h = new MyHandler();
        MyHandler.invocationCount = 0;

        final String expectedString = new String("How are you Joe");
       
        class Poller extends Thread {
            Future<?> future;
            int tid;
           
            Poller(Future<?> f, int t) {
                future = f;
                tid = t;
            }
            public void run() {
                if (tid % 2 > 0) {
                    while (!future.isDone()) {
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException ex) {
                            // ignore
                        }
                    }
                }
                try {
                    future.get();
                } catch (Exception ex) {
                    fail("Poller " + tid + " failed with " + ex);
                }
                assertEquals("callback was not executed or did not return the expected result",
                             expectedString, h.getReplyBuffer());
            }
        }
       
        Greeter greeter = (Greeter)service.getPort(portName, Greeter.class);
        Future<?> f = greeter.greetMeSometimeAsync("Joe", h);
       
        Poller[] pollers = new Poller[4];
        for (int i = 0; i < pollers.length; i++) {
            pollers[i] = new Poller(f, i);
        }
        for (Poller p : pollers) {           
            p.start();
        }
       
        for (Poller p : pollers) {
            p.join();
        }
        assertEquals(1, MyHandler.invocationCount);  
        executor.shutdown();   
    }
View Full Code Here

Examples of java.util.concurrent.ExecutorService

    public void testFaults() throws Exception {
        URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
        assertNotNull(wsdl);
       
        SOAPService service = new SOAPService(wsdl, serviceName);
        ExecutorService ex = Executors.newFixedThreadPool(1);
        service.setExecutor(ex);
        assertNotNull(service);

        String noSuchCodeFault = "NoSuchCodeLitFault";
        String badRecordFault = "BadRecordLitFault";
View Full Code Here

Examples of java.util.concurrent.ExecutorService

    return SUCCESS;
  }

  private String guessFeedTitle(String url) {
    String title = null;
    ExecutorService service = null;
    try {
      FetchRssDataWorker worker = new FetchRssDataWorker(url);
      service = Executors.newFixedThreadPool(1);
      service.execute(worker);
      service.shutdown();
      service.awaitTermination(5, TimeUnit.SECONDS);
      title = worker.getRssTitle();
      logger.debug("detected RSS title: " + title);
    } catch (Exception e) {
      logger.debug(e);
    } finally {
      if (service != null) {
        try {
          service.shutdown();
        } catch (Exception e) {
          logger.debug(e);
        }
      }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.