Package org.agilewiki.jactor2.core.reactors

Examples of org.agilewiki.jactor2.core.reactors.Reactor


*/
public class CloseableSetTest extends TestCase {

    public void testReactor() throws Exception {
        System.out.println("R");
        new Plant();
        try {
            final Reactor reactor = new NonBlockingReactor();

            final MyCloseable mac1 = new MyCloseable();
            final MyCloseable mac2 = new MyCloseable();
View Full Code Here


     * @param _initialLocalQueueSize The initial size of the local queue.
     */
    public ReactorMtImpl(final NonBlockingReactor _parentReactor,
            final int _initialBufferSize, final int _initialLocalQueueSize) {
        closeableImpl = new CloseableImplImpl(this);
        final PlantConfiguration plantConfiguration = PlantMtImpl
                .getSingleton().getPlantConfiguration();
        @SuppressWarnings("resource")
        final NonBlockingReactorMtImpl parentReactorImpl = _parentReactor == null ? null
                : (NonBlockingReactorMtImpl) _parentReactor.asReactorImpl();
        recovery = _parentReactor == null ? plantConfiguration.getRecovery()
                : parentReactorImpl.getRecovery();
        plantScheduler = _parentReactor == null ? plantConfiguration
                .getPlantScheduler() : parentReactorImpl.getPlantScheduler();
        initialBufferSize = _initialBufferSize;
        initialLocalQueueSize = _initialLocalQueueSize;
        parentReactor = _parentReactor;
        logger = LoggerFactory.getLogger(Reactor.class);
View Full Code Here

    /**
     * Create a plant with the default configuration.
     */
    public Plant() throws Exception {
        new PlantMtImpl();
    }
View Full Code Here

     *
     * @param _reactorThreadPoolSize The number of threads to be created for the
     *                               reactor thread pool.
     */
    public Plant(final int _reactorThreadPoolSize) throws Exception {
        new PlantMtImpl(_reactorThreadPoolSize);
    }
View Full Code Here

     * Create a plant with the given configuration.
     *
     * @param _plantConfiguration The configuration to be used by the plant.
     */
    public Plant(final PlantConfiguration _plantConfiguration) throws Exception {
        new PlantMtImpl(_plantConfiguration);
    }
View Full Code Here

            }
        }

        shuttingDown = true;

        final PlantMtImpl plantImpl = PlantMtImpl.getSingleton();
        if ((plantImpl != null) && isRunning()
                && ((currentRequest == null) || !currentRequest.isComplete())) {
            timeoutSemaphore = plantImpl.schedulableSemaphore(recovery
                    .getThreadInterruptMillis(this));
            final Thread thread = getThreadReference().get();
            if (thread != null) {
                thread.interrupt();
                boolean timeout = false;
View Full Code Here

                final ReactorPoolThread currentThread = (ReactorPoolThread) Thread
                        .currentThread();
                while (true) {
                    try {
                        taskRequest.acquire();
                        PoolThreadReactorMtImpl reactor = reactors.poll();
                        if (reactor != null) {
                            AtomicReference<Thread> threadReference = reactor
                                    .getThreadReference();
                            if ((threadReference.get() == null)
                                    && threadReference.compareAndSet(null,
                                            currentThread)) {
                                currentThread.setCurrentReactor(reactor);
                                while (true) {
                                    try {
                                        reactor.run();
                                    } catch (final MigrationException me) {
                                        final boolean hasWork = reactor
                                                .hasWork();
                                        threadReference.set(null);
                                        if (reactor.isIdler() || hasWork
                                                || reactor.hasConcurrent()) {
                                            execute(reactor);
                                        }
                                        reactor = me.reactor;
                                        threadReference = reactor
                                                .getThreadReference();
                                        currentThread
                                                .setCurrentReactor(reactor);
                                        continue;
                                    } catch (final Throwable e) {
                                        logger.error(
                                                "Exception thrown by a targetReactor's run method",
                                                e);
                                    }
                                    final boolean hasWork = reactor.hasWork();
                                    threadReference.set(null);
                                    if (hasWork || reactor.hasConcurrent()) {
                                        execute(reactor);
                                    }
                                    break;
                                }
                                currentThread.setCurrentReactor(null);
View Full Code Here

     */
    @SuppressWarnings("unchecked")
    @Override
    public void doSend(final ReactorImpl _source,
            final AsyncResponseProcessor<RESPONSE_TYPE> _responseProcessor) {
        final ReactorMtImpl source = (ReactorMtImpl) _source;
        if (PlantMtImpl.DEBUG
                && (source.getThreadReference().get() != Thread.currentThread())) {
            throw new IllegalStateException("send from wrong thread");
        }
        use();
        responseProcessor = _responseProcessor;
        if (responseProcessor == null) {
            responseProcessor = (AsyncResponseProcessor<RESPONSE_TYPE>) OneWayResponseProcessor.SINGLETON;
        }
        requestSource = source;
        if (!source.isRunning()) {
            throw new IllegalStateException(
                    "A valid source sourceReactor can not be idle");
        }
        oldMessage = source.getCurrentRequest();
        if ((oldMessage != null) && oldMessage.getIsolationReactor() != null) {
            isolationReactor = oldMessage.getIsolationReactor();
        } else
            isolationReactor = source.isCommonReactor() ? null : (IsolationReactor) source.asReactor();
        if (!(targetReactor instanceof CommonReactor)) {
            if (isolationReactor != null && isolationReactor != targetReactor && (_responseProcessor != null)) {
                throw new UnsupportedOperationException(
                        "Isolated requests can not be nested, even indirectly:\n" + toString());
            }
            isolationReactor = (IsolationReactor) targetReactor;
        }
        sourceExceptionHandler = (ExceptionHandler<RESPONSE_TYPE>) source
                .getExceptionHandler();
        final boolean local = targetReactor == source.asReactor();
        if (local || !source.buffer(this, targetReactorImpl)) {
            targetReactorImpl.unbufferedAddMessage(this, local);
        }
    }
View Full Code Here

     * Process a response.
     */
    @SuppressWarnings("unchecked")
    protected void processResponseMessage() {
        oldMessage.responseReceived(this);
        final ReactorMtImpl sourceMessageProcessor = (ReactorMtImpl) requestSource;
        sourceMessageProcessor.setExceptionHandler(sourceExceptionHandler);
        sourceMessageProcessor.setCurrentRequest(oldMessage);
        if (response instanceof Exception) {
            oldMessage.processException(sourceMessageProcessor,
                    (Exception) response);
            oldMessage.responseProcessed();
            return;
View Full Code Here

     * @param _activeReactor The reactor providing the facility for processing the throwable.
     * @param _e             The exception to be processed.
     */
    public void processException(final ReactorMtImpl _activeReactor,
            final Exception _e) {
        final ReactorMtImpl activeMessageProcessor = _activeReactor;
        @SuppressWarnings("unchecked")
        final ExceptionHandler<RESPONSE_TYPE> exceptionHandler = (ExceptionHandler<RESPONSE_TYPE>) activeMessageProcessor
                .getExceptionHandler();
        if (exceptionHandler != null) {
            try {
                exceptionHandler.processException(_e,
                        new AsyncResponseProcessor<RESPONSE_TYPE>() {
                            @Override
                            public void processAsyncResponse(
                                    final Object _response) {
                                processObjectResponse(_response);
                            }
                        });
            } catch (final Throwable u) {
                if (!isOneWay()) {
                    if (!incomplete) {
                        return;
                    }
                    setResponse(u, activeMessageProcessor);
                    requestSource
                            .incomingResponse(this, activeMessageProcessor);
                } else {
                    activeMessageProcessor
                            .error("Thrown by exception handler and uncaught "
                                    + exceptionHandler.getClass().getName(), _e);
                }
            }
        } else {
            if (!incomplete) {
                return;
            }
            setResponse(_e, activeMessageProcessor);
            if (!isOneWay()) {
                requestSource.incomingResponse(this, activeMessageProcessor);
            } else {
                activeMessageProcessor.warn("Uncaught throwable", _e);
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.agilewiki.jactor2.core.reactors.Reactor

Copyright © 2018 www.massapicom. 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.