Ejemplo n.º 1
0
  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.

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

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

    ODEProcess process = new ODEProcess(this, conf, null, _myRoleMexCache);

    for (Endpoint e : process.getServiceNames()) {
      __log.debug("Register process: serviceId=" + e + ", process=" + process);
      // Get the list of processes associated with the given service
      List<ODEProcess> processes = _serviceMap.get(e.serviceName);
      if (processes == null) {
        // Create an empty list, if no processes were associated
        _serviceMap.put(e.serviceName, processes = new ArrayList<ODEProcess>());
      }
      // Remove any older version of the process from the list
      for (int i = 0; i < processes.size(); i++) {
        ODEProcess cachedVersion = processes.get(i);
        __log.debug(
            "cached version "
                + cachedVersion.getPID()
                + " vs registering version "
                + process.getPID());
        if (cachedVersion.getProcessType().equals(process.getProcessType())) {
          processes.remove(cachedVersion);
        }
      }
      // Add the given process to the list associated with the given service
      processes.add(process);
    }

    process.activate(_contexts);

    _registeredProcesses.put(process.getPID(), process);
    if (_dehydrationPolicy == null) process.hydrate();

    __log.info(__msgs.msgProcessRegistered(conf.getProcessId()));
  }
Ejemplo n.º 2
0
    public void run() {
      __log.debug("Starting process definition reaper thread.");
      long pollingTime = 10000;
      try {
        while (true) {
          Thread.sleep(pollingTime);
          // Copying the runnning process list to avoid synchronizatMessageExchangeInterion
          // problems and a potential mess if a policy modifies the list
          List<ODEProcess> candidates = new ArrayList<ODEProcess>(_registeredProcesses.values());
          CollectionsX.remove_if(
              candidates,
              new MemberOfFunction<ODEProcess>() {
                public boolean isMember(ODEProcess o) {
                  return !o.hintIsHydrated();
                }
              });

          // And the happy winners are...
          List<ODEProcess> ripped = _dehydrationPolicy.markForDehydration(candidates);
          // Bye bye
          for (ODEProcess process : ripped) {
            __log.debug("Dehydrating process " + process.getPID());
            process.dehydrate();
          }
        }
      } catch (InterruptedException e) {
        __log.info(e);
      }
    }