示例#1
0
  @Override
  public Thing getThing(String thingName) {
    // 需要先从缓存中读取,否则当遍历iterator时每次都会读取新的,是否和World中的缓存重复呢?
    Thing thing = ThingCache.get(thingName);
    if (thing != null) {
      if (thing.getMetadata().isRemoved()) {
        // 如事物的文件被外部改动或事物已给标记为删除,需要重新读取
        thing = null;
      } else {
        return thing;
      }
    }

    thing = doLoadThing(thingName);
    if (thing != null) {
      for (ThingManagerListener listener : listeners) {
        listener.loaded(this, thing);
      }

      for (ThingManagerListener listener :
          World.getInstance().getThingManagerListeners(getName())) {
        listener.loaded(this, thing);
      }
    }

    return thing;
  }
示例#2
0
  @Override
  public boolean save(Thing thing) {
    boolean removed = doSaveThing(thing);
    if (thing != null) {
      for (ThingManagerListener listener : listeners) {
        listener.saved(this, thing);
      }

      for (ThingManagerListener listener :
          World.getInstance().getThingManagerListeners(getName())) {
        listener.saved(this, thing);
      }
    }

    return removed;
  }