Dispatches the response on a generic scheduler through creating a worker.
340134
private void scheduleWorker(Scheduler scheduler, final CouchbaseResponse response,
        final Subject<CouchbaseResponse, CouchbaseResponse> observable) {
        final Scheduler.Worker worker = scheduler.createWorker();
        worker.schedule(new Action0() {
            @Override
            public void call() {
                completeResponse(response, observable);
                worker.unsubscribe();
            }
        });
    }
73684
function startWorker(port) {
        var worker = child.fork(serverWorker, [
            '--port', port,
            '--server', serverFile,
            '--allowForcedExit', allowForcedExit,
            '--config', JSON.stringify(config.app || {}),
            '--title', workerTitle
        ]);

        worker.on('exit', createWorkerExitHandler(port));
        return worker;
    }
209074
def _create_worker(self, method, *args, **kwargs):
        """"""
        # FIXME: this might be heavy...
        thread = QThread()
        worker = ClientWorker(method, args, kwargs)
        worker.moveToThread(thread)
        worker.sig_finished.connect(self._start)
        worker.sig_finished.connect(thread.quit)
        thread.started.connect(worker.start)
        self._queue.append(thread)
        self._threads.append(thread)
        self._workers.append(worker)
        self._start()
        return worker
71854
def job(name, **kwargs):
    ''''''
    return task(name=name, schedulable=True, base=JobTask,
                bind=True, **kwargs)
720289
def registerHandler(self, matcher, handler):
        '''
        
        '''
        self.handlers[matcher] = handler
        self.scheduler.register((matcher,), self)
        self._setDaemon()
373369
def _create_worker(self, method, *args, **kwargs):
        """"""
        thread = QThread()
        worker = RequestsDownloadWorker(method, args, kwargs)
        worker.moveToThread(thread)
        worker.sig_finished.connect(self._start)
        self._sig_download_finished.connect(worker.sig_download_finished)
        self._sig_download_progress.connect(worker.sig_download_progress)
        worker.sig_finished.connect(thread.quit)
        thread.started.connect(worker.start)
        self._queue.append(thread)
        self._threads.append(thread)
        self._workers.append(worker)
        self._start()
        return worker
1207480
def startResponse(self, status, headers, excInfo=None):
        
        self.status = status
        self.headers = headers
        self.reactor.callInThread(
            responseInColor, self.request, status, headers
        )
        return self.write
152170
def submit_comp_job(self, path, callback, method, *args, **kwargs):
        """"""
        if self.executor is None:
            with self.handling_exceptions():
                callback(getattr(self.comp, method)(*args, **kwargs))
        else:
            path = showpath(path)
            with logger.in_path(path):  # pickle the compiler in the path context
                future = self.executor.submit(multiprocess_wrapper(self.comp, method), *args, **kwargs)

            def callback_wrapper(completed_future):
                """Ensures that all errors are always caught, since errors raised in a callback won't be propagated."""
                with logger.in_path(path):  # handle errors in the path context
                    with self.handling_exceptions():
                        result = completed_future.result()
                        callback(result)
            future.add_done_callback(callback_wrapper)
122702
def new_worker(self, name: str):
        """"""
        if not self.running:
            return self.immediate_worker
        worker = self._new_worker(name)
        self._start_worker(worker)
        return worker
944230
def worker(compute, task_queue, result_queue, log_queue, complete,
               *context):
        """"""
        try:
            MapReduce._forked = True
            log.debug('Worker process starting...')

            configure_worker_logging(log_queue)

            for obj in iter(task_queue.get, POISON_PILL):
                if complete.is_set():
                    log.debug('Worker received signal - exiting early')
                    break

                log.debug('Worker got %s', obj)
                result_queue.put(compute(obj, *context))
                log.debug('Worker finished %s', obj)

            result_queue.put(POISON_PILL)
            log.debug('Worker process exiting')

        except Exception as e:  # pylint: disable=broad-except
            result_queue.put(ExceptionWrapper(e))
641879
function WorkQueue(obj) {
  if (!(this instanceof WorkQueue)) {
    return new WorkQueue(obj);
  }

  obj = obj || {};

  this.work = [];
  this.workers = [];
  this.nextWorker = 0;
}
14743
def app(environ, start_response):
    """"""
    r = HttpRequestHandler(environ, start_response, Router).dispatch()
    return r
473629
def _create_job(self, func, args=None, kwargs=None, commit=True,
                    result_ttl=None, ttl=None, id=None, description=None,
                    queue_name=None, timeout=None, meta=None):
        
        if args is None:
            args = ()
        if kwargs is None:
            kwargs = {}
        job = self.job_class.create(
                func, args=args, connection=self.connection,
                kwargs=kwargs, result_ttl=result_ttl, ttl=ttl, id=id,
                description=description, timeout=timeout, meta=meta)
        if self._queue is not None:
            job.origin = self._queue.name
        else:
            job.origin = queue_name or self.queue_name
        if commit:
            job.save()
        return job
1195850
def create_call(self, raw_request, **kwargs):
        """"""
        req = self.create_request(raw_request, **kwargs)
        res = self.create_response(**kwargs)
        rou = self.create_router(**kwargs)
        c = self.call_class(req, res, rou)
        return c
1321962
function createWorkerProxy(workersOrFunctions, opt_options) {
    var options = {
      // Automatically call the callback after a call if the return value is not
      // undefined.
      autoCallback: false,
      // Catch errors and automatically respond with an error callback. Off by
      // default since it breaks standard behavior.
      catchErrors: false,
      // A list of functions that can be called. This list will be used to make
      // the proxy functions available when Proxy is not supported. Note that
      // this is generally not needed since the worker will also publish its
      // known functions.
      functionNames: [],
      // Call console.time and console.timeEnd for calls sent though the proxy.
      timeCalls: false
    };

    if (opt_options) {
      for (var key in opt_options) {
        if (!(key in options)) continue;
        options[key] = opt_options[key];
      }
    }
    Object.freeze(options);

    // Ensure that we have an array of workers (even if only using one worker).
    if (typeof Worker != 'undefined' && (workersOrFunctions instanceof Worker)) {
      workersOrFunctions = [workersOrFunctions];
    }

    if (Array.isArray(workersOrFunctions)) {
      return sendCallsToWorker(workersOrFunctions, options);
    } else {
      receiveCallsFromOwner(workersOrFunctions, options);
    }
  }
470352
public void dispatchResponse(ManagerResponse response)
    {
        final String actionId;
        String internalActionId;
        SendActionCallback listener;

        // shouldn't happen
        if (response == null)
        {
            logger.error("Unable to dispatch null response. This should never happen. Please file a bug.");
            return;
        }

        actionId = response.getActionId();
        internalActionId = null;
        listener = null;

        if (actionId != null)
        {
            internalActionId = ManagerUtil.getInternalActionId(actionId);
            response.setActionId(ManagerUtil.stripInternalActionId(actionId));
        }

        if (logger.isDebugEnabled())
        {
            logger.debug("Dispatching response with internalActionId '" + internalActionId + "':\n" + response);
        }

        if (internalActionId != null)
        {
            synchronized (this.responseListeners)
            {
                listener = responseListeners.get(internalActionId);
                if (listener != null)
                {
                    this.responseListeners.remove(internalActionId);
                }
                else
                {
                    // when using the async sendAction it's ok not to register a
                    // callback so if we don't find a response handler thats ok
                    logger.debug("No response listener registered for " + "internalActionId '" + internalActionId + "'");
                }
            }
        }
        else
        {
            logger.error(
                    "Unable to retrieve internalActionId from response: " + "actionId '" + actionId + "':\n" + response);
        }

        if (listener != null)
        {
            try
            {
                listener.onResponse(response);
            }
            catch (Exception e)
            {
                logger.warn("Unexpected exception in response listener " + listener.getClass().getName(), e);
            }
        }
    }
1322694
@Override
    public void doPortletServeResource(
            IPortletWindowId portletWindowId,
            HttpServletRequest request,
            HttpServletResponse response) {
        final long timeout = getPortletResourceTimeout(portletWindowId, request);

        final IPortletExecutionWorker<Long> resourceWorker =
                this.portletWorkerFactory.createResourceWorker(request, response, portletWindowId);
        resourceWorker.submit();

        try {
            resourceWorker.get(timeout);
        } catch (Exception e) {
            // Log the exception but not this thread's stacktrace. The portlet worker has already
            // logged its stack trace
            this.logger.error(
                    "resource worker {} failed with exception {}", resourceWorker, e.toString());
            // render generic serveResource error
            try {
                if (!response.isCommitted()) {
                    response.sendError(
                            HttpServletResponse.SC_SERVICE_UNAVAILABLE, "resource unavailable");
                }
            } catch (IOException e1) {
                logger.error(
                        "caught IOException trying to send error response for failed resource worker",
                        e);
            }
        }

        // If the worker is still running add it to the hung-workers queue
        if (!resourceWorker.isComplete()) {
            cancelWorker(request, resourceWorker);
        }
    }