Package org.jruby

Examples of org.jruby.RubyThread$SleepTask


        // No timeout in critical section
        if (runtime.getThreadService().getCritical()) {
            return raiseBecauseCritical(context);
        }

        final RubyThread currentThread = context.getThread();
        final AtomicBoolean latch = new AtomicBoolean(false);

        IRubyObject id = new RubyObject(runtime, runtime.getObject());
        Runnable timeoutRunnable = prepareRunnable(currentThread, runtime, latch, id);
        Future timeoutFuture = null;
View Full Code Here


        // No timeout in critical section
        if (runtime.getThreadService().getCritical()) {
            return raiseBecauseCritical(context);
        }

        final RubyThread currentThread = context.getThread();
        final AtomicBoolean latch = new AtomicBoolean(false);

        IRubyObject id = new RubyObject(runtime, runtime.getObject());
        RubyClass anonException = (RubyClass)runtime.getClassFromPath("Timeout::AnonymousException");
        Runnable timeoutRunnable = exceptionType.isNil() ?
View Full Code Here

                if (data.parent == null) return;
               
                data.queue.shutdown();
            }

            RubyThread thread = this.thread;
            if (thread != null) {
                thread.dieFromFinalizer();

                // interrupt Ruby thread to break out of queue sleep, blocking IO
                thread.interrupt();

                // null out references to aid GC
                data = null;
                thread = null;
            }
View Full Code Here

    public IRubyObject accept(ThreadContext context) {
        Ruby runtime = context.runtime;
        RubyTCPSocket socket = new RubyTCPSocket(runtime, runtime.getClass("TCPSocket"));

        try {
            RubyThread thread = context.getThread();

            while (true) {
                boolean ready = thread.select(this, SelectionKey.OP_ACCEPT);

                if (!ready) {
                    // we were woken up without being selected...poll for thread events and go back to sleep
                    context.pollThreadEvents();
View Full Code Here

        try {
            if (blockingThreads == null) {
                return;
            }
            for (int i = 0; i < blockingThreads.size(); i++) {
                RubyThread thread = blockingThreads.get(i);

                // raise will also wake the thread from selection
                thread.raise(new IRubyObject[]{runtime.newIOError("stream closed").getException()}, Block.NULL_BLOCK);
            }
        } finally {
            if (locked) unlock();
        }
    }
View Full Code Here

    private int doSelect(ThreadContext context) {
        int result;
        int lerrno;
        double limit = 0;
        long wait_rest;
        RubyThread th = context.getThread();

        // Sets up a specific time by which select should timeout
//        if (timeout != null) {
//            limit = timeofday();
//            limit += (double)timeout->tv_sec+(double)timeout->tv_usec*1e-6;
//            wait_rest = *timeout;
//            timeout = &wait_rest;
//        }

        retry:
        lerrno = 0;

        try {
            result = th.executeTask(context, this, SelectTask);
        } catch (InterruptedException ie) {
            throw context.runtime.newErrnoEINTRError();
        }

        context.pollThreadEvents();
View Full Code Here

                throw runtime.newArgumentError("time interval must be positive");
            }
           
            // If all streams are nil, just sleep the specified time (JRUBY-4699)
            if (args[0].isNil() && args[1].isNil() && args[2].isNil()) {
                RubyThread thread = context.getThread();
                if (has_timeout) {
                    if (timeout > 0) {
                        long now = System.currentTimeMillis();
                        thread.sleep(timeout);
                        // Guard against spurious wakeup
                        while (System.currentTimeMillis() < now + timeout) {
                            thread.sleep(1);
                        }
                    }
                } else {
                    thread.sleep(0);
                }
            } else {
                doSelect(runtime, has_timeout, timeout);
                processSelectedKeys(runtime);
                processPendingAndUnselectable();
View Full Code Here

TOP

Related Classes of org.jruby.RubyThread$SleepTask

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.