2 * Copyright (c) 2023 PANTHEON.tech s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.topology.callhome;
10 import java.util.concurrent.ConcurrentHashMap;
11 import java.util.concurrent.ConcurrentMap;
13 public abstract class AbstractCallHomeSessionContextManager<T extends CallHomeSessionContext>
14 implements CallHomeSessionContextManager<T> {
15 protected final ConcurrentMap<String, T> contexts = new ConcurrentHashMap<>();
18 public void register(final T context) {
19 contexts.put(context.id(), context);
23 public boolean exists(final String id) {
24 return contexts.containsKey(id);
28 public void remove(final String id) {
29 final var context = contexts.remove(id);
30 if (context != null) {
32 if (!context.settableFuture().isDone()) {
33 context.settableFuture().cancel(true);
39 public void close() throws Exception {
40 for (var it = contexts.entrySet().iterator(); it.hasNext(); ) {
41 it.next().getValue().close();