Package io.apigee.trireme.core

Examples of io.apigee.trireme.core.ScriptTask


        public void onWriteComplete(int bytesWritten, boolean inScriptThread, Object context)
        {
            // Always deliver the write callback on the next tick, because the caller expects to add a
            // callback to the return value before it can be invoked.
            final Scriptable req = (Scriptable)context;
            runtime.enqueueTask(new ScriptTask() {
                @Override
                public void execute(Context cx, Scriptable scope)
                {
                    deliverWriteCallback(cx, req, null);
                }
View Full Code Here


        @Override
        public void onWriteError(final String err, boolean inScriptThread, Object context)
        {
            final Scriptable req = (Scriptable)context;
            runtime.enqueueTask(new ScriptTask() {
                @Override
                public void execute(Context cx, Scriptable scope)
                {
                    deliverWriteCallback(cx, req, err);
                }
View Full Code Here

        public void onReadComplete(final ByteBuffer buf, boolean inScriptThread, Object context)
        {
            if (inScriptThread) {
                deliverReadCallback(Context.getCurrentContext(), buf, null);
            } else {
                runtime.enqueueTask(new ScriptTask() {
                    @Override
                    public void execute(Context cx, Scriptable scope)
                    {
                        deliverReadCallback(cx, buf, null);
                    }
View Full Code Here

        public void onReadError(final String err, boolean inScriptThread, Object context)
        {
            if (inScriptThread) {
                deliverReadCallback(Context.getCurrentContext(), null, err);
            } else {
                runtime.enqueueTask(new ScriptTask() {
                    @Override
                    public void execute(Context cx, Scriptable scope)
                    {
                        deliverReadCallback(cx, null, err);
                    }
View Full Code Here

                {
                    try {
                        final Connection jdbcConn = DriverManager.getConnection(url, finalProps);

                        self.runtime.pin();
                        self.runtime.enqueueTask(new ScriptTask() {
                            @Override
                            public void execute(Context cx, Scriptable scope)
                            {
                                try {
                                    JdbcConnection conn =
                                        (JdbcConnection)cx.newObject(self, JdbcConnection.CLASS_NAME);
                                    conn.init(jdbcConn, self.runtime);
                                    cb.call(cx, cb, self, new Object[] {Undefined.instance, conn});
                                } finally {
                                    self.runtime.unPin();
                                }
                            }
                        }, domain);

                    } catch (final SQLException sqle) {
                        self.runtime.enqueueTask(new ScriptTask() {
                            @Override
                            public void execute(Context cx, Scriptable scope)
                            {
                                cb.call(cx, cb, self, new Object[] { makeSqlError(cx, scope, sqle) });
                            }
View Full Code Here

                        self.runtime.enqueueCallback(cb, cb, self, domain, new Object[] {
                            Undefined.instance, cx.newArray(self, rowArray), (rowCount < maxRows)
                        });

                    } catch (final SQLException sqle) {
                        self.runtime.enqueueTask(new ScriptTask() {
                            @Override
                            public void execute(Context cx, Scriptable scope)
                            {
                                cb.call(cx, cb, self, new Object[] {
                                    JdbcWrap.makeSqlError(cx, scope, sqle)
View Full Code Here

                    if (log.isDebugEnabled()) {
                        log.debug("Error on JDBC close. Ignoring it: {}", e);
                    }
                }

                self.runtime.enqueueTask(new ScriptTask() {
                    @Override
                    public void execute(Context cx, Scriptable scope)
                    {
                        if (cb != null) {
                            cb.call(cx, cb, self, ScriptRuntime.emptyArgs);
View Full Code Here

    private void returnError(final Function cb, Scriptable domain, final SQLException se)
    {
        if (log.isDebugEnabled()) {
            log.debug("Error in SQL: {}", se);
        }
        runtime.enqueueTask(new ScriptTask() {
            @Override
            public void execute(Context cx, Scriptable scope)
            {
                cb.call(cx, cb, JdbcConnection.this,
                        new Object[] { JdbcWrap.makeSqlError(cx, JdbcConnection.this, se) });
View Full Code Here

                    task.run();
                    task = engine.getDelegatedTask();
                }

                // Now back to the script thread in order to keep running with the result.
                runtime.enqueueTask(new ScriptTask() {
                    @Override
                    public void execute(Context cx, Scriptable scope)
                    {
                        encodeLoop(cx);
                    }
View Full Code Here

            if (log.isDebugEnabled()) {
                log.debug("Received HTTP onRequest: {} self contained = {}", request, request.isSelfContained());
            }

            // Queue up a task to process the request
            runner.enqueueTask(new ScriptTask()
            {
                @Override
                public void execute(Context cx, Scriptable scope)
                {
                    RequestAdapter reqAdapter =
                        (RequestAdapter)cx.newObject(ServerContainer.this, RequestAdapter.CLASS_NAME);
                    reqAdapter.init(request);

                    ResponseAdapter respAdapter =
                        (ResponseAdapter)cx.newObject(ServerContainer.this, ResponseAdapter.CLASS_NAME);
                    respAdapter.init(response, ServerContainer.this);

                    Scriptable socketInfo = makeSocketInfo(cx, request);

                    Scriptable socketObj = (Scriptable)makeSocket.call(cx, makeSocket, null,
                                                                       new Object[] { socketInfo });
                    Scriptable requestObj = (Scriptable)makeRequest.call(cx, makeRequest, null,
                                                                         new Object[] { reqAdapter, socketObj });
                    Scriptable responseObj = (Scriptable)makeResponse.call(cx, makeResponse, null,
                                                                           new Object[] { respAdapter, socketObj, timeoutOpts });

                    request.setScriptObject(requestObj);
                    response.setScriptObject(responseObj);

                    onHeaders.call(cx, onHeaders, ServerContainer.this, new Object[] { requestObj, responseObj });
                }
            });

            if (request.isSelfContained()) {
                final ByteBuffer requestData =
                    (request.hasData() ? request.getData() : null);
                // Queue up another task for the data. Noderunner guarantees that this will run after
                // the previous task. However, do this in a separate tick because it's highly likely that
                // the revious request to call "onHeaders" will register more event handlers
                runner.enqueueTask(new ScriptTask()
                {
                    @Override
                    public void execute(Context cx, Scriptable scope)
                    {
                        callOnData(cx, scope, request, requestData);
                    }
                });
                runner.enqueueTask(new ScriptTask()
                {
                    @Override
                    public void execute(Context cx, Scriptable scope)
                    {
                        callOnComplete(cx, request);
View Full Code Here

TOP

Related Classes of io.apigee.trireme.core.ScriptTask

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.