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.callhome.server;
11 import java.util.concurrent.ConcurrentHashMap;
13 public abstract class AbstractCallHomeSessionContextManager<T extends CallHomeSessionContext>
14 implements CallHomeSessionContextManager<T> {
16 protected final Map<String, T> contexts = new ConcurrentHashMap<>();
19 public void register(final T context) {
20 contexts.put(context.id(), context);
24 public boolean exists(final String id) {
25 return contexts.containsKey(id);
29 public void remove(final String id) {
30 final var context = contexts.remove(id);
31 if (context != null) {
33 if (!context.settableFuture().isDone()) {
34 context.settableFuture().cancel(true);
40 public void close() throws Exception {
41 for (var it = contexts.entrySet().iterator(); it.hasNext(); ) {
42 it.next().getValue().close();