Examples of TaskRunner


Examples of org.apache.activemq.thread.TaskRunner

                peer.transportListener.onCommand(new ShutdownInfo());
            } catch (Exception ignore) {
            }
         
         
            TaskRunner tr = null;
            try {
                enqueueValve.turnOff();
                if (!disposed) {
                    started = false;
                    disposed = true;
                    if (taskRunner != null) {
                        tr = taskRunner;
                        taskRunner = null;
                    }
                }
            } finally {
                stopping.set(false);
                enqueueValve.turnOn();
            }
            if (tr != null) {
                tr.shutdown(1000);
            }
           

        }
       
View Full Code Here

Examples of org.apache.activemq.thread.TaskRunner

              peer.transportListener.onException(new TransportDisposedIOException("Peer (" + peer.toString() + ") disposed."));
            } catch (Exception ignore) {
            }
         
         
            TaskRunner tr = null;
            try {
                enqueueValve.turnOff();
                if (!disposed) {
                    started = false;
                    disposed = true;
                    if (taskRunner != null) {
                        tr = taskRunner;
                        taskRunner = null;
                    }
                }
            } finally {
                stopping.set(false);
                enqueueValve.turnOn();
            }
            if (tr != null) {
                tr.shutdown(1000);
            }
           

        }
       
View Full Code Here

Examples of org.apache.activemq.thread.TaskRunner

    public void wakeup() {
        if (!dispatchedBySessionPool) {
            if (session.isSessionAsyncDispatch()) {
                try {
                    TaskRunner taskRunner = this.taskRunner;
                    if (taskRunner == null) {
                        synchronized (this) {
                            if (this.taskRunner == null) {
                                if (!isRunning()) {
                                    // stop has been called
                                    return;
                                }
                                this.taskRunner = session.connection.getSessionTaskRunner().createTaskRunner(this,
                                        "ActiveMQ Session: " + session.getSessionId());
                            }
                            taskRunner = this.taskRunner;
                        }
                    }
                    taskRunner.wakeup();
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                }
            } else {
                while (iterate()) {
View Full Code Here

Examples of org.apache.activemq.thread.TaskRunner

        final AtomicInteger queue = new AtomicInteger(0);
        final CountDownLatch doneCountDownLatch = new CountDownLatch(1);
        final int ENQUEUE_COUNT = 100000;
       
        TaskRunnerFactory factory = new TaskRunnerFactory();       
        final TaskRunner runner = factory.createTaskRunner(new Task() {           
            public boolean iterate() {
                if( queue.get()==0 ) {
                    return false;
                } else {
                    while(queue.get()>0) {
                        queue.decrementAndGet();
                        counter.incrementAndGet();
                    }
                    iterations.incrementAndGet();
                    if (counter.get()==ENQUEUE_COUNT)
                        doneCountDownLatch.countDown();
                    return true;
                }
            }
        }, "Thread Name");
       
        long start = System.currentTimeMillis();
        final int WORKER_COUNT=5;
        final CyclicBarrier barrier = new CyclicBarrier(WORKER_COUNT+1);
        for( int i=0; i< WORKER_COUNT; i++ ) {
            new Thread() {
                public void run() {
                    try {
                        barrier.await();
                        for( int i=0; i < ENQUEUE_COUNT/WORKER_COUNT; i++ ) {
                            queue.incrementAndGet();
                            runner.wakeup();
                            yield();
                        }
                    }
                    catch (BrokenBarrierException e) {
                    }
                    catch (InterruptedException e) {
                    }       
                }
            }.start();
        }
        barrier.await();
       
        boolean b = doneCountDownLatch.await(30, TimeUnit.SECONDS);
        long end = System.currentTimeMillis();
        log.info("Iterations: "+iterations.get());
        log.info("counter: "+counter.get());
        log.info("Dequeues/s: "+(1000.0*ENQUEUE_COUNT/(end-start)));
        log.info("duration: "+((end-start)/1000.0));
        assertTrue(b);
       
        runner.shutdown();
    }
View Full Code Here

Examples of org.apache.activemq.thread.TaskRunner

        stopping.set(true);
       
        // If stop() is called while being start()ed.. then we can't stop until we return to the start() method.
        if( enqueueValve.isOn() ) {

            TaskRunner tr = null;
            try {
                enqueueValve.turnOff();
                if (!disposed) {
                    started = false;
                    disposed = true;
                    if (taskRunner != null) {
                        tr = taskRunner;
                        taskRunner = null;
                    }
                }
            } finally {
                stopping.set(false);
                enqueueValve.turnOn();
            }
            if (tr != null) {
                tr.shutdown(1000);
            }
            // let the peer know that we are disconnecting..
            try {
                oneway(DISCONNECT);
            } catch (Exception ignore) {
View Full Code Here

Examples of org.apache.activemq.thread.TaskRunner

    public void wakeup() {
        if (!dispatchedBySessionPool) {
            if (session.isSessionAsyncDispatch()) {
                try {
                    TaskRunner taskRunner = this.taskRunner;
                    if (taskRunner == null) {
                        synchronized (this) {
                            if (this.taskRunner == null) {
                                this.taskRunner = session.connection.getSessionTaskRunner().createTaskRunner(this,
                                        "ActiveMQ Session: " + session.getSessionId());
                            }
                            taskRunner = this.taskRunner;
                        }
                    }
                    taskRunner.wakeup();
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                }
            } else {
                while (iterate()) {
View Full Code Here

Examples of org.apache.activemq.thread.TaskRunner

    void stop() throws JMSException {
        try {
            if (messageQueue.isRunning()) {
                messageQueue.stop();
                TaskRunner taskRunner = this.taskRunner;
                if (taskRunner != null) {
                    this.taskRunner = null;
                    taskRunner.shutdown();
                }
            }
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw JMSExceptionSupport.create(e);
View Full Code Here

Examples of org.apache.activemq.thread.TaskRunner

    public void stop() throws Exception {
        // Only need to do this once, all future oneway calls will now
        // fail as will any asnyc jobs in the task runner.
        if (disposed.compareAndSet(false, true)) {

            TaskRunner tr = taskRunner;
            LinkedBlockingQueue<Object> mq = this.messageQueue;

            taskRunner = null;
            messageQueue = null;

            if (mq != null) {
                mq.clear();
            }

            // Allow pending deliveries to finish up, but don't wait
            // forever in case of an stalled onCommand.
            if (tr != null) {
                try {
                    tr.shutdown(TimeUnit.SECONDS.toMillis(1));
                } catch(Exception e) {
                }
                taskRunner = null;
            }
View Full Code Here

Examples of org.apache.activemq.thread.TaskRunner

        }
        return result;
    }

    protected TaskRunner getTaskRunner() throws TransportDisposedIOException {
        TaskRunner result = taskRunner;
        if (result == null) {
            synchronized (this) {
                result = taskRunner;
                if (result == null) {
                    if (disposed.get()) {
View Full Code Here

Examples of org.apache.activemq.thread.TaskRunner

        // local VMTransport dispatcher is artificially delayed.
        final TaskRunnerFactory realTaskRunnerFactory = localBroker
                .getTaskRunnerFactory();
        localBroker.setTaskRunnerFactory(new TaskRunnerFactory() {
            public TaskRunner createTaskRunner(Task task, String name) {
                final TaskRunner realTaskRunner = realTaskRunnerFactory
                        .createTaskRunner(task, name);
                if (name.startsWith("ActiveMQ Connection Dispatcher: ")) {
                    return new TaskRunner() {
                        @Override
                        public void shutdown() throws InterruptedException {
                            realTaskRunner.shutdown();
                        }

                        @Override
                        public void shutdown(long timeout)
                                throws InterruptedException {
                            realTaskRunner.shutdown(timeout);
                        }

                        @Override
                        public void wakeup() throws InterruptedException {
                            Thread.sleep(taskRunnerDelay);
                            realTaskRunner.wakeup();
                        }
                    };
                } else {
                    return realTaskRunnerFactory.createTaskRunner(task, name);
                }
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.