Package net.jcores.jre.options

Examples of net.jcores.jre.options.KillSwitch


     * @since 1.0
     * @return This async object.
     */
    public Async<T> onNext(final F1<T, Void> f, Option... options) {
        final Options options$ = Options.$(this.commonCore, options);
        final KillSwitch killswitch = options$.killswitch();

        $.sys.oneTime(new F0() {
            @Override
            public void f() {
                while (true) {
                    try {
                        // Get the elements, and wait.
                        final QEntry<T> take = Async.this.queue.take();
                        if(take == EOQ) return;
                       
                        // And feed them to the listener
                        try {
                            f.f(take.object);
                        } catch (Exception e) {
                            $.report(MessageType.EXCEPTION, "Function f() passed to Async.onNext() threw an exception " + e.getMessage());                           
                        }
                       
                    } catch (InterruptedException e) {
                        if (killswitch != null && killswitch.terminated()) return;
                        $.report(MessageType.EXCEPTION, "Unexpected Interrupt while waiting at Async.onNext(). Terminating handler");
                        return;
                    }
                }
            }
View Full Code Here


    @SupportsOption(options = { KillSwitch.class })
    public <R> Async<R> async(final F1<T, R> f, Option... options) {
        final Queue<R> queue = Async.Queue();
        final Async<R> async = new Async<R>(this.commonCore, queue);
        final Options options$ = Options.$(this.commonCore, options);
        final KillSwitch killswitch = options$.killswitch();

        this.commonCore.sys.oneTime(new F0() {
            @Override
            public void f() {
                try {
                    // Now process all elements
                    for (T t : CoreObject.this) {
                        // Check if we should terminate.
                        if(killswitch != null && killswitch.terminated())  return;
                       
                        // Otherwise process next element.
                        try {
                            queue.add(Async.QEntry(f.f(t)));
                        } catch (Exception e) {
View Full Code Here

     * @param options May accept a {@link KillSwitch}.
     */
    @SupportsOption(options = { KillSwitch.class })
    public void manyTimes(final F0 f0, final long delay, final Option... options) {
        final Options options$ = Options.$(this.commonCore, options);
        final KillSwitch killswitch = options$.killswitch();
        final Future<?> submit = this.commonCore.executor().getExecutor().submit(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    try {
                        f0.f();
                        sleep(delay, options);
                    } catch (Exception e) {
                        options$.failure(f0, e, "manytimes:run", "Exception while executing f().");
                    }

                    // Check if we should terminate
                    if (killswitch != null && killswitch.terminated()) return;
                }
            }
        });

        // Register the future
        if (killswitch != null) killswitch.register(submit);
    }
View Full Code Here

     * @param options May accept a {@link KillSwitch}.
     */
    @SupportsOption(options = { KillSwitch.class })
    public void oneTime(final F0 f0, final long delay, final Option... options) {
        final Options options$ = Options.$(this.commonCore, options);
        final KillSwitch killswitch = options$.killswitch();
        final Future<?> submit = this.commonCore.executor().getExecutor().submit(new Runnable() {
            @Override
            public void run() {
                try {
                    sleep(delay, options);

                    // Check if we should terminate
                    if (killswitch != null && killswitch.terminated()) return;

                    f0.f();
                } catch (Exception e) {
                    options$.failure(f0, e, "onetime:run", "Exception while executing f().");
                }
            }
        });

        // Register the future
        if (killswitch != null) killswitch.register(submit);
    }
View Full Code Here

TOP

Related Classes of net.jcores.jre.options.KillSwitch

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.