Beispiel #1
0
 /**
  * Adds a state to the FSM. The name of the state is taken from the state object. The first state
  * added automatically becomes the initial state that the FSM starts in.
  *
  * @param state state behavior.
  */
 public void add(State state) {
   if (states.containsKey(state.name)) throw new FjageError("Duplicate state name: " + state.name);
   states.put(state.getName(), state);
   state.fsm = this;
   state.log = log;
   if (initial == FINAL) initial = state;
 }
  private Throwable checkpoint(Throwable accumulate) {
    if (logger.isDebugEnabled())
      logger.debug("Checkpointing update:{}, obsolete:{}", staged.update, staged.obsolete);

    if (staged.isEmpty()) return accumulate;

    Set<SSTableReader> toUpdate = toUpdate();
    Set<SSTableReader> fresh = copyOf(fresh());

    // check the current versions of the readers we're replacing haven't somehow been replaced by
    // someone else
    checkNotReplaced(filterIn(toUpdate, staged.update));

    // ensure any new readers are in the compacting set, since we aren't done with them yet
    // and don't want anyone else messing with them
    // apply atomically along with updating the live set of readers
    tracker.apply(
        compose(updateCompacting(emptySet(), fresh), updateLiveSet(toUpdate, staged.update)));

    // log the staged changes and our newly marked readers
    marked.addAll(fresh);
    logged.log(staged);

    // setup our tracker, and mark our prior versions replaced, also releasing our references to
    // them
    // we do not replace/release obsoleted readers, since we may need to restore them on rollback
    accumulate = setReplaced(filterOut(toUpdate, staged.obsolete), accumulate);
    accumulate = release(selfRefs(filterOut(toUpdate, staged.obsolete)), accumulate);

    staged.clear();
    return accumulate;
  }
Beispiel #3
0
 @Override
 void setOwner(Agent agent) {
   super.setOwner(agent);
   for (State s : states.values()) s.log = log;
 }