Regarding the rule that says that a session should not be used by
multiple threads, I wonder if the same applies to ObservationManager.

Take the following example:
public class SomeFactory {

  Map<String, SomeOtherClass> cache = Collections.synchronizedMap(new
HashMap<String, SomeOtherClass>());
  ObservationManager observationManager;

  public SomeFactory(Session session) {
     this.observationManager = session.getWorkspace().getObservationManager();
  }

  public get(String id) {
     if (!cache.containsKey(id)) {
        cache.put(id, new SomeOtherClass(this.observationManager, this));
     }
     return cache.get(id);
  }
}

public SomeOtherClass implements EventListener {

   private ObservationManager observationManager;
   private SomeFactory factory;

   public SomeOtherClass(ObservationManager observationManager,
SomeFactory factory) {
     this.factory = factory;
     this.observationManager = observationManager;
     this.observationManager.registerEventListener(this, ...);
  }

  public onEvent(EventIterator events) {
    // Invalidate ourselves in the factory's cache
    this.factory.cache.values().remove(this);
    this.observationManager.removeEventListener(this);
  }
}

Now, the case is that SomeFactory.get() can be called from different
threads, while SomeFactory.observationManager and SomeFactory.cache is
shared between threads.
Is this safe, or is the ObservationManager retrieved by
session.getWorkspace().getObservationManager() tied to the session
from which it was acquired?

-- 
Vidar S. Ramdal <[email protected]> - http://www.idium.no
Sommerrogata 13-15, N-0255 Oslo, Norway
+ 47 22 00 84 00 / +47 22 00 84 76
Quando omni flunkus moritatus!

Reply via email to