+ listenerLock.writeLock().lock();
+ try {
+ if (entityTypeListenerMap.remove(entityType, listener)) {
+ ListenerActorRefEntry listenerEntry = listenerActorMap.get(listener);
+
+ LOG.debug("{}: Found {}", logId, listenerEntry);
+
+ listenerEntry.referenceCount--;
+ if (listenerEntry.referenceCount <= 0) {
+ listenerActorMap.remove(listener);
+
+ if (listenerEntry.actorRef != null) {
+ LOG.debug("Killing EntityOwnershipListenerActor {}", listenerEntry.actorRef);
+ listenerEntry.actorRef.tell(PoisonPill.getInstance(), ActorRef.noSender());
+ }
+ }
+ }
+ } finally {
+ listenerLock.writeLock().unlock();
+ }