2 * Copyright (c) 2017 Red Hat, Inc. 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.controller.md.sal.trace.closetracker.impl;
11 import java.util.concurrent.ConcurrentSkipListSet;
12 import javax.annotation.concurrent.ThreadSafe;
15 * Registry of {@link CloseTracked} instances.
17 * @author Michael Vorburger.ch
20 public class CloseTrackedRegistry<T extends CloseTracked<T>> {
22 // unused OK for now, at least we'll be able to see this in HPROF heap dumps and know what is which
23 private final @SuppressWarnings("unused") Object anchor;
24 private final @SuppressWarnings("unused") String createDescription;
26 private final Set<CloseTracked<T>> tracked = new ConcurrentSkipListSet<>(
27 (o1, o2) -> o1.getObjectCreated().compareTo(o2.getObjectCreated()));
29 private final boolean isDebugContextEnabled;
35 * object where this registry is stored in, used for human output in
36 * logging and other output
37 * @param createDescription
38 * description of creator of instances of this registry, typically
39 * e.g. name of method in the anchor class
40 * @param isDebugContextEnabled
41 * whether or not the call stack should be preserved; this is (of
42 * course) an expensive operation, and should only be used during
45 public CloseTrackedRegistry(Object anchor, String createDescription, boolean isDebugContextEnabled) {
47 this.createDescription = createDescription;
48 this.isDebugContextEnabled = isDebugContextEnabled;
51 public boolean isDebugContextEnabled() {
52 return isDebugContextEnabled;
55 // package protected, not public; only CloseTrackedTrait invokes this
56 void add(CloseTracked<T> closeTracked) {
57 tracked.add(closeTracked);
60 // package protected, not public; only CloseTrackedTrait invokes this
61 void remove(CloseTracked<T> closeTracked) {
62 tracked.remove(closeTracked);
65 // TODO Later add methods to dump & query what's not closed, by creation time, incl. creation stack trace
67 // TODO we could even support add/close of Object instead of CloseTracked, by creating a wrapper?