Ejemplo n.º 1
0
 @Override
 public synchronized void clear() {
   allSimons.clear();
   rootSimon = new UnknownSimon(ROOT_SIMON_NAME, this);
   allSimons.put(ROOT_SIMON_NAME, rootSimon);
   callback.onManagerClear();
 }
Ejemplo n.º 2
0
 public EnabledManager(SimonClock clock) {
   this.clock = clock;
   rootSimon = new UnknownSimon(ROOT_SIMON_NAME, this);
   allSimons.put(ROOT_SIMON_NAME, rootSimon);
   configuration = new ManagerConfiguration(this);
   callback.initialize(this);
 }
Ejemplo n.º 3
0
  private synchronized AbstractSimon createOrReplaceUnknownSimon(
      String name, Class<? extends AbstractSimon> simonClass) {
    // we will rather check the map in synchronized block before we try to create/replace the Simon
    AbstractSimon simon = allSimons.get(name);
    if (simon != null && simonClass.isInstance(simon)) {
      return simon; // the same return like in non-synchronized getOrCreateSimon - you just never
      // know
    }

    if (simon == null) {
      if (name != null && !SimonUtils.checkName(name)) {
        throw new SimonException(
            "Simon name must match following pattern: '"
                + SimonUtils.NAME_PATTERN.pattern()
                + "', used name: "
                + name);
      }
      simon = newSimon(name, simonClass);
    } else if (simon instanceof UnknownSimon) {
      simon = replaceUnknownSimon(simon, simonClass);
    } else {
      throw new SimonException(
          "Simon named '"
              + name
              + "' already exists and its type is '"
              + simon.getClass().getName()
              + "' while requested type is '"
              + simonClass.getName()
              + "'.");
    }
    callback.onSimonCreated(simon);
    return simon;
  }
Ejemplo n.º 4
0
 @Override
 public synchronized void destroySimon(String name) {
   if (name.equals(ROOT_SIMON_NAME)) {
     throw new SimonException("Root Simon cannot be destroyed!");
   }
   AbstractSimon simon = allSimons.remove(name);
   if (simon.getChildren().size() > 0) {
     replaceUnknownSimon(simon, UnknownSimon.class);
   } else {
     ((AbstractSimon) simon.getParent()).replaceChild(simon, null);
   }
   callback.onSimonDestroyed(simon);
 }
Ejemplo n.º 5
0
 @Override
 public void warning(String warning, Exception cause) {
   callback.onManagerWarning(warning, cause);
 }
Ejemplo n.º 6
0
 @Override
 public void message(String message) {
   callback.onManagerMessage(message);
 }