Esempio n. 1
0
  /**
   * Create and initialize a pool of threads to serve clients requests.
   *
   * @param routingTable the Routing Table used to find WS.
   */
  public PoolClientConnection(RoutingTable routingTable) {
    super();
    PoolClientConnection.routingTable = routingTable;
    PoolClientConnection.mailBox = new MailBoxImpl();

    // Pool creation and initialisation
    // Max threads
    int sizeMax = Integer.parseInt(DispatcherMSG.CONFIGURATION.getProperty("clients.max"));
    pool = new PooledExecutor(sizeMax);

    // Min threads
    int sizeMin = Integer.parseInt(DispatcherMSG.CONFIGURATION.getProperty("clients.min"));
    pool.setMinimumPoolSize(sizeMin);

    // Keep alive time
    long keepAliveTime =
        Long.parseLong(DispatcherMSG.CONFIGURATION.getProperty("clients.keepAliveTime"));
    pool.setKeepAliveTime(keepAliveTime);

    // Pre-start threads
    int preCreateThread =
        Integer.parseInt(DispatcherMSG.CONFIGURATION.getProperty("clients.preCreateThreads"));
    pool.createThreads(preCreateThread);

    // Set the policy for blocked execution to be to wait until a thread is
    // available
    pool.waitWhenBlocked();
  }
  /**
   * Default Constructor.
   *
   * @param instRep The WorkflowInstanceRepository to be used by this engine.
   * @param queueSize The size of the queue that the workflow engine should use (irrelevant if
   *     unlimitedQueue is set to true)
   * @param maxPoolSize The minimum thread pool size.
   * @param minPoolSize The maximum thread pool size.
   * @param threadKeepAliveTime The amount of minutes that each thread in the pool should be kept
   *     alive.
   * @param unlimitedQueue Whether or not to use a queue whose bounds are dictated by the physical
   *     memory of the underlying hardware.
   * @param resUrl A URL pointer to a resource manager. If this is set Tasks will be wrapped as
   *     Resource Manager {@link Job}s and sent through the Resource Manager. If this parameter is
   *     not set, local execution (the default) will be used
   */
  public ThreadPoolWorkflowEngine(
      WorkflowInstanceRepository instRep,
      int queueSize,
      int maxPoolSize,
      int minPoolSize,
      long threadKeepAliveTime,
      boolean unlimitedQueue,
      URL resUrl) {

    this.instRep = instRep;
    Channel c = null;
    if (unlimitedQueue) {
      c = new LinkedQueue();
    } else {
      c = new BoundedBuffer(queueSize);
    }

    pool = new PooledExecutor(c, maxPoolSize);
    pool.setMinimumPoolSize(minPoolSize);
    pool.setKeepAliveTime(1000 * 60 * threadKeepAliveTime);

    workerMap = new HashMap();

    if (resUrl != null) rClient = new XmlRpcResourceManagerClient(resUrl);
  }
 static {
   JSONObject json =
       JSONObject.fromObject(PropertiesDeploy.getConfigureMap().get(Constant.OTHERS_HOST_NAME));
   othersPooledExecutor.setKeepAliveTime(
       Integer.parseInt(json.getString(Constant.KEEP_ALIVE_TIME)));
   othersPooledExecutor.createThreads(Integer.parseInt(json.getString(Constant.CREATE_SIZE)));
   othersPooledExecutor.setMinimumPoolSize(
       Integer.parseInt(json.getString(Constant.MIN_POOL_SIZE)));
   othersPooledExecutor.setMaximumPoolSize(
       Integer.parseInt(json.getString(Constant.MAX_POOL_SIZE)));
   othersPooledExecutor.abortWhenBlocked();
 }
Esempio n. 4
0
 public void onApplicationEvent(ApplicationEvent event) {
   try {
     threadPool.execute(new Worker(event));
   } catch (InterruptedException e) {
     logger.error("Failed to process event: " + event.toString(), e);
   }
 }
  /*
   * (non-Javadoc)
   *
   * @see org.apache.oodt.cas.workflow.engine.WorkflowEngine#startWorkflow(org.apache.oodt.cas.workflow.structs.Workflow,
   *      org.apache.oodt.cas.metadata.Metadata)
   */
  public synchronized WorkflowInstance startWorkflow(Workflow workflow, Metadata metadata)
      throws EngineException {
    // to start the workflow, we create a default workflow instance
    // populate it
    // persist it
    // add it to the worker map
    // start it

    WorkflowInstance wInst = new WorkflowInstance();
    wInst.setWorkflow(workflow);
    wInst.setCurrentTaskId(((WorkflowTask) workflow.getTasks().get(0)).getTaskId());
    wInst.setSharedContext(metadata);
    wInst.setStatus(CREATED);
    persistWorkflowInstance(wInst);

    IterativeWorkflowProcessorThread worker =
        new IterativeWorkflowProcessorThread(wInst, instRep, this.wmgrUrl);
    worker.setRClient(rClient);
    workerMap.put(wInst.getId(), worker);

    wInst.setStatus(QUEUED);
    persistWorkflowInstance(wInst);

    try {
      pool.execute(worker);
    } catch (InterruptedException e) {
      throw new EngineException(e);
    }

    return wInst;
  }
Esempio n. 6
0
 /**
  * Check, parse, verify the <code>req</code>. Attribute a client thread to serve the client.
  *
  * @see xsul.http_server.HttpMiniServlet#service(xsul.http_server.HttpServerRequest,
  *     xsul.http_server.HttpServerResponse)
  */
 public void service(HttpServerRequest req, HttpServerResponse resp) throws HttpServerException {
   // Thread allocation for the new client
   try {
     XmlElement el = builder.parseFragmentFromInputStream(req.getInputStream());
     // FIXME XmlElement el =
     // builder.parseFragmentFromInputStream(req.getInputStream(),
     // req.getCharset());
     SoapUtil soapUtil = SoapUtil.selectSoapFragrance(el, soapFragrances);
     String path = req.getPath();
     //          Path Treatment to get arguments
     String arguments = null;
     if (path != null) {
       // Analysiing path
       if (path.startsWith("/")) {
         path = path.substring(1);
       }
       String method = req.getMethod();
       if (method.equals("GET")) {
         // Remove arguments from path
         int argStart = path.indexOf('?');
         if (argStart != -1) {
           // There are some arguments
           arguments = path.substring(argStart, path.length());
           path = path.replaceAll("\\?.*", "");
         }
       }
     }
     ClientConnection client = new ClientConnection(path, arguments, el, soapUtil);
     pool.execute(
         client); // NOTE: pool will now "execute" client (the sentence may be delayed ...)
     // Successful HTTP message transmission
     // Send Ok to the client
     this.sendHttpOk(resp);
   } catch (Exception e) {
     SendError.send(resp, "500", "Thread Interrupted Exception");
     logger.warning("Couldn't allocate a thread to the client", e);
   }
 }
 @Override
 public void shutdown() {
   othersPooledExecutor.shutdownAfterProcessingCurrentlyQueuedTasks();
   othersPooledExecutor = null;
 }
 @Override
 public int getThreadSize() {
   return othersPooledExecutor.getPoolSize();
 }
 @Override
 public void execute(Runnable r) throws InterruptedException {
   othersPooledExecutor.execute(r);
 }