2 * Copyright (c) 2013 Cisco Systems, 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.yangtools.concepts;
10 import java.util.concurrent.atomic.AtomicBoolean;
13 * Utility registration handle. It is a convenience for register-style method
14 * which can return an AutoCloseable realized by a subclass of this class.
15 * Invoking the close() method triggers unregistration of the state the method
18 public abstract class AbstractRegistration implements AutoCloseable {
19 private AtomicBoolean closed = new AtomicBoolean();
22 * Remove the state referenced by this registration. This method is
23 * guaranteed to be called at most once. The referenced state must be
24 * retained until this method is invoked.
26 protected abstract void removeRegistration();
29 public final void close() {
30 if (closed.compareAndSet(false, true)) {