public void start() {
    _mngmtLock.writeLock().lock();
    try {
      if (!checkState(State.INIT, State.RUNNING)) {
        __log.debug("start() ignored -- already started");
        return;
      }
      __log.debug("BPEL SERVER starting.");

      // Eventually running some migrations before starting
      if (!(new MigrationHandler(_contexts)
          .migrate(_registeredProcesses, _migrationTransactionTimeout))) {
        throw new BpelEngineException(
            "An error occurred while migrating your database to a newer version of the server. Please make sure that the required migration scripts have been executed before starting the server.");
      }

      _state = State.RUNNING;
      __log.info(__msgs.msgServerStarted());
      if (_dehydrationPolicy != null) {
        processDefReaper = new Thread(new ProcessDefReaper(), "Dehydrator");
        processDefReaper.setDaemon(true);
        processDefReaper.start();
      }
    } finally {
      _mngmtLock.writeLock().unlock();
    }
  }
    public void run() {
      __log.debug("Starting process definition reaper thread.");
      long pollingTime = 10000;
      try {
        while (true) {
          Thread.sleep(pollingTime);
          if (!_mngmtLock.writeLock().tryLock(100L, TimeUnit.MILLISECONDS)) continue;
          try {
            __log.debug("Kicking reaper, OProcess instances: " + OProcess.instanceCount);
            // Copying the runnning process list to avoid synchronization
            // problems and a potential mess if a policy modifies the list
            List<BpelProcess> candidates = new ArrayList<BpelProcess>(_registeredProcesses);
            CollectionsX.remove_if(
                candidates,
                new MemberOfFunction<BpelProcess>() {
                  public boolean isMember(BpelProcess o) {
                    return !o.hintIsHydrated();
                  }
                });

            // And the happy winners are...
            List<BpelProcess> ripped = _dehydrationPolicy.markForDehydration(candidates);
            // Bye bye
            for (BpelProcess process : ripped) {
              __log.debug("Dehydrating process " + process.getPID());
              process.dehydrate();
            }
          } finally {
            _mngmtLock.writeLock().unlock();
          }
        }
      } catch (InterruptedException e) {
        __log.debug(e);
      }
    }
  public void register(ProcessConf conf) {
    if (conf == null)
      throw new NullPointerException("must specify non-null process configuration.");

    __log.debug("register: " + conf.getProcessId());

    // Ok, IO out of the way, we will mod the server state, so need to get a
    // lock.
    try {
      _mngmtLock.writeLock().lockInterruptibly();
    } catch (InterruptedException ie) {
      __log.debug("register(...) interrupted.", ie);
      throw new BpelEngineException(__msgs.msgOperationInterrupted());
    }

    try {
      // If the process is already active, do nothing.
      if (_engine.isProcessRegistered(conf.getProcessId())) {
        __log.debug(
            "skipping doRegister" + conf.getProcessId() + ") -- process is already registered");
        return;
      }

      __log.debug("Registering process " + conf.getProcessId() + " with server.");

      BpelProcess process = createBpelProcess(conf);
      process._classLoader = Thread.currentThread().getContextClassLoader();

      _engine.registerProcess(process);
      _registeredProcesses.add(process);
      if (!isLazyHydratable(process)) {
        process.hydrate();
      } else {
        _engine.setProcessSize(process.getPID(), false);
      }

      __log.info(__msgs.msgProcessRegistered(conf.getProcessId()));

    } catch (Exception ex) {
      __log.error(ex);
      throw new BpelEngineException(ex);
    } finally {
      _mngmtLock.writeLock().unlock();
    }
  }
  public void stop() {
    _mngmtLock.writeLock().lock();
    try {
      if (!checkState(State.RUNNING, State.INIT)) {
        __log.debug("stop() ignored -- already stopped");
        return;
      }

      __log.debug("BPEL SERVER STOPPING");

      if (processDefReaper != null) {
        processDefReaper.interrupt();
        processDefReaper = null;
      }
      _contexts.scheduler.stop();
      _engine = null;
      _state = State.INIT;
      __log.info(__msgs.msgServerStopped());
    } finally {
      _mngmtLock.writeLock().unlock();
    }
  }
Example #5
0
 public Thread newThread(Runnable r) {
   threadNumber += 1;
   Thread t = new Thread(r, "ProcessStoreImpl-" + threadNumber);
   t.setDaemon(true);
   return t;
 }