Bug 9060: Remove un-used Instant getObjectCreated() from CloseTracked
[controller.git] / opendaylight / md-sal / mdsal-trace / dom-impl / src / main / java / org / opendaylight / controller / md / sal / trace / closetracker / impl / CloseTrackedTrait.java
1 /*
2  * Copyright (c) 2017 Red Hat, Inc. and others. All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.md.sal.trace.closetracker.impl;
9
10 import java.util.Objects;
11 import javax.annotation.Nullable;
12
13 /**
14  * Implementation of {@link CloseTracked} which can be used as a field in
15  * another class which implements {@link CloseTracked} and delegates its methods
16  * to this.
17  *
18  * <p>This is useful if that class already has another parent class.
19  * If it does not, then it's typically more convenient to just extend AbstractCloseTracked.
20  *
21  * @author Michael Vorburger.ch
22  */
23 public class CloseTrackedTrait<T extends CloseTracked<T>> implements CloseTracked<T> {
24
25     private final @Nullable Throwable allocationContext;
26     private final CloseTrackedRegistry<T> closeTrackedRegistry;
27
28     public CloseTrackedTrait(CloseTrackedRegistry<T> transactionChainRegistry) {
29         if (transactionChainRegistry.isDebugContextEnabled()) {
30             this.allocationContext = new Throwable("allocated at");
31         } else {
32             this.allocationContext = null;
33         }
34         this.closeTrackedRegistry = Objects.requireNonNull(transactionChainRegistry, "transactionChainRegistry");
35         this.closeTrackedRegistry.add(this);
36     }
37
38     @Override
39     public StackTraceElement[] getAllocationContextStackTrace() {
40         return allocationContext != null ? allocationContext.getStackTrace() : null;
41     }
42
43     public void removeFromTrackedRegistry() {
44         closeTrackedRegistry.remove(this);
45     }
46
47 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.