Package org.agilewiki.jactor2.core.reactors

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


public class SwingBoundReactorSample {
    public static void main(final String[] _args) throws Exception {
        //Create a plant with 5 threads.
        Plant plant = new Plant(5);

        new HelloWorld(new SwingBoundReactor()).createAndShowAOp().signal();
    }
View Full Code Here


        //Get a reference to the main thread.
        final Thread mainThread = Thread.currentThread();

        //Create a thread-bound processing.
        final ThreadBoundReactor reactor =
                new ThreadBoundReactor(new Runnable() {
                    @Override
                    public void run() {
                        //Interrupt the main thread when there are messages to process
                        mainThread.interrupt();
                    }
                });

        //Create an blades that uses the thread-bound processing.
        final SampleThreadBoundBlade threadBoundBlade = new SampleThreadBoundBlade(reactor);

        //Terminate the blades.
        new SOp<Void>("finBlade", threadBoundBlade.getReactor()) {
            @Override
            protected Void processSyncOperation(RequestImpl _requestImpl) throws Exception {
                threadBoundBlade.fin();
                return null;
            }
        }.signal();

        //Process messages when this thread is interrupted.
        while (true) {
            try {
                //Wait for an interrupt.
                Thread.sleep(60000);
            } catch (InterruptedException e) {
                //Process messages when the main thread is interrupted.
                reactor.run();
            }
        }
    }
View Full Code Here

public class ThreadBoundBladeBase extends BladeBase implements ThreadBoundBlade {
    /**
     * Create a Thread bound blade and a Thread bound reactor whose parent is the internal reactor of Plant.
     */
    public ThreadBoundBladeBase() throws Exception {
        _initialize(new ThreadBoundReactor());
    }
View Full Code Here

    ThreadBoundReactor reactor;

    public void testa() throws Exception {
        new Plant();
        try {
            reactor = new ThreadBoundReactor(new Runnable() {
                @Override
                public void run() {
                    reactor.run();
                    try {
                        Plant.close();
View Full Code Here

     *
     * @param _requestImpl    The reactor with the hung request.
     */
    public void onHungRequest(final RequestMtImpl<?> _requestImpl)
            throws Exception {
        final ReactorImpl reactor = _requestImpl.getTargetReactorImpl();
        reactor.error("request hung -> reactor close");
        reactor.fail("hung request");
    }
View Full Code Here

     * @param _requestImpl    The reactor with the hung request.
     * @param _error          The StackOverflowError.
     */
    public void onStackOverflowError(final RequestMtImpl<?> _requestImpl,
            final StackOverflowError _error) {
        final ReactorImpl reactor = _requestImpl.getTargetReactorImpl();
        reactor.error("stack overflow error -> reactor close", _error);
        try {
            reactor.fail("stack overflow");
        } catch (final Exception e) {

        }
    }
View Full Code Here

     * @param _requestImpl    The reactor with the hung request.
     * @param _exception      The runtime exception
     */
    public void onRuntimeException(final RequestMtImpl<?> _requestImpl,
            final RuntimeException _exception) {
        final ReactorImpl reactor = _requestImpl.getTargetReactorImpl();
        reactor.error("runtime exception -> reactor close", _exception);
        try {
            reactor.fail("runtime exception");
        } catch (final Exception e) {

        }
    }
View Full Code Here

     *
     * @param _response The response to this request.
     */
    @Override
    public void processAsyncResponse(final RESPONSE_TYPE _response) {
        final Timer timer = asyncOperation.getTimer();
        timer.updateNanos(timer.nanos() - start, true);
        processObjectResponse(_response);
    }
View Full Code Here

     *
     * @param _response An exception.
     */
    @Override
    public void processAsyncException(final Exception _response) {
        final Timer timer = asyncOperation.getTimer();
        timer.updateNanos(timer.nanos() - start, false);
        processObjectResponse(_response);
    }
View Full Code Here

        return syncOperation;
    }

    @Override
    protected void processRequestMessage() throws Exception {
        final Timer timer = syncOperation.getTimer();
        final long start = timer.nanos();
        boolean success = false;
        final RESPONSE_TYPE result;
        try {
            result = syncOperation.doSync(this);
            success = true;
        } finally {
            timer.updateNanos(timer.nanos() - start, success);
        }

        processObjectResponse(result);
    }
View Full Code Here

TOP

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

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.