import org.opendaylight.controller.eos.akka.registry.listener.owner.command.ListenerCommand;
import org.opendaylight.controller.eos.akka.registry.listener.type.command.CandidatesChanged;
import org.opendaylight.controller.eos.akka.registry.listener.type.command.EntityOwnerChanged;
+import org.opendaylight.controller.eos.akka.registry.listener.type.command.TerminateListener;
import org.opendaylight.controller.eos.akka.registry.listener.type.command.TypeListenerCommand;
import org.opendaylight.mdsal.eos.dom.api.DOMEntity;
import org.opendaylight.mdsal.eos.dom.api.DOMEntityOwnershipListener;
return newReceiveBuilder()
.onMessage(CandidatesChanged.class, this::onCandidatesChanged)
.onMessage(EntityOwnerChanged.class, this::onOwnerChanged)
+ .onMessage(TerminateListener.class, this::onTerminate)
.build();
}
return this;
}
+ private Behavior<TypeListenerCommand> onTerminate(final TerminateListener command) {
+ LOG.debug("Terminating listener for type: {}, listener: {}", entityType, listener);
+ return Behaviors.stopped();
+ }
+
private static String encodeEntityToActorName(final DOMEntity entity) {
return "type=" + entity.getType() + ",entity="
+ entity.getIdentifier().getLastPathArgument().getNodeType().getLocalName() + "-" + UUID.randomUUID();
import java.util.Map;
import java.util.UUID;
import org.opendaylight.controller.eos.akka.registry.listener.type.command.RegisterListener;
+import org.opendaylight.controller.eos.akka.registry.listener.type.command.TerminateListener;
import org.opendaylight.controller.eos.akka.registry.listener.type.command.TypeListenerCommand;
import org.opendaylight.controller.eos.akka.registry.listener.type.command.TypeListenerRegistryCommand;
import org.opendaylight.controller.eos.akka.registry.listener.type.command.UnregisterListener;
private Behavior<TypeListenerRegistryCommand> onUnregisterListener(final UnregisterListener command) {
LOG.debug("Stopping entity type listener actor for: {}", command.getEntityType());
- getContext().stop(spawnedListenerActors.remove(command.getDelegateListener()));
+ spawnedListenerActors.remove(command.getDelegateListener()).tell(TerminateListener.INSTANCE);
return this;
}
--- /dev/null
+/*
+ * Copyright (c) 2021 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.eos.akka.registry.listener.type.command;
+
+/**
+ * Sent to the listener actor to stop it on demand ie during listener unregistration.
+ */
+public final class TerminateListener extends TypeListenerCommand {
+
+ public static final TerminateListener INSTANCE = new TerminateListener();
+
+ private TerminateListener() {
+ // Hidden on purpose
+ }
+}