import static java.util.Objects.requireNonNull;
+import com.google.common.base.MoreObjects.ToStringHelper;
import javax.annotation.Nonnull;
/**
- * Utility registration handle. It is a convenience for register-style method
- * which can return an AutoCloseable realized by a subclass of this class.
- * Invoking the close() method triggers unregistration of the state the method
- * installed.
+ * Utility registration handle. It is a convenience for register-style method which can return an AutoCloseable realized
+ * by a subclass of this class. Invoking the close() method triggers unregistration of the state the method installed.
*/
public abstract class AbstractObjectRegistration<T> extends AbstractRegistration implements ObjectRegistration<T> {
private final T instance;
}
@Override
- public String toString() {
- return "AbstractObjectRegistration{instance=" + instance + '}';
+ protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+ return super.addToStringAttributes(toStringHelper).add("instance", instance);
}
}
*/
package org.opendaylight.yangtools.concepts;
+import com.google.common.base.MoreObjects;
+import com.google.common.base.MoreObjects.ToStringHelper;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
/**
- * Utility registration handle. It is a convenience for register-style method
- * which can return an AutoCloseable realized by a subclass of this class.
- * Invoking the close() method triggers unregistration of the state the method
- * installed.
+ * Utility registration handle. It is a convenience for register-style method which can return an AutoCloseable realized
+ * by a subclass of this class. Invoking the close() method triggers unregistration of the state the method installed.
*/
-public abstract class AbstractRegistration implements AutoCloseable {
+public abstract class AbstractRegistration implements Registration {
private static final AtomicIntegerFieldUpdater<AbstractRegistration> CLOSED_UPDATER =
AtomicIntegerFieldUpdater.newUpdater(AbstractRegistration.class, "closed");
private volatile int closed = 0;
/**
- * Remove the state referenced by this registration. This method is
- * guaranteed to be called at most once. The referenced state must be
- * retained until this method is invoked.
+ * Remove the state referenced by this registration. This method is guaranteed to be called at most once.
+ * Referenced state must be retained until this method is invoked.
*/
protected abstract void removeRegistration();
/**
- * Query the state of this registration. Returns true if it was
- * closed.
+ * Query the state of this registration. Returns true if it was closed.
*
* @return true if the registration was closed, false otherwise.
*/
- protected final boolean isClosed() {
+ public final boolean isClosed() {
return closed != 0;
}
removeRegistration();
}
}
+
+ @Override
+ public final String toString() {
+ return addToStringAttributes(MoreObjects.toStringHelper(this).omitNullValues()).toString();
+ }
+
+ protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+ return toStringHelper.add("closed", closed);
+ }
}
import java.util.EventListener;
/**
- * Class representing a {@link Registration} of an {@link EventListener}. This
- * is interface provides the additional guarantee that the process of
- * unregistration cannot fail for predictable reasons.
+ * Class representing a {@link Registration} of an {@link EventListener}. This interface provides the additional
+ * guarantee that the process of unregistration cannot fail for predictable reasons.
*/
public interface ListenerRegistration<T extends EventListener> extends ObjectRegistration<T> {
/**
- * Unregister the listener. No events should be delivered to the listener
- * once this method returns successfully. While the interface contract
- * allows an implementation to ignore the occurrence of RuntimeExceptions,
- * implementations are strongly encouraged to deal with such exceptions
- * internally and to ensure invocations of this method do not fail in such
- * circumstances.
+ * Unregister the listener. Note that invocations enqueued to the listener are not subject to synchronization
+ * rules, and events may be delivered to the listener after this method completes.
+ * Unregister the listener.
+ *
+ * <p>
+ * While the interface contract allows an implementation to ignore the occurrence of RuntimeExceptions,
+ * implementations are strongly encouraged to deal with such exceptions internally and to ensure invocations of
+ * this method do not fail in such circumstances.
*/
@Override
void close();
import javax.annotation.Nonnull;
/**
- * Class representing a registration of an object. Such a registration is
- * a proper resource and should be cleaned up when no longer required, so
- * references to the object can be removed. This mechanism lies above the
- * usual Java reference mechanism, as the entity where the object is
- * registered may reside outside of the Java Virtual Machine.
+ * Class representing a registration of an object. Such a registration is a proper resource and should be cleaned up
+ * when no longer required, so references to the object can be removed. This mechanism lies above the usual Java
+ * reference mechanism, as the entity where the object is registered may reside outside of the Java Virtual Machine.
*/
public interface ObjectRegistration<T> extends Registration {
/**
*/
@Nonnull T getInstance();
- /**
- * Unregisters the object. This operation is required not to invoke
- * blocking operations. Implementations which require interaction
- * with outside world must provide guarantees that any work is done
- * behind the scenes and the unregistration process looks as if it
- * has already succeeded once this method returns.
- */
@Override
- void close() throws Exception;
+ void close();
}
package org.opendaylight.yangtools.concepts;
/**
- * Class representing a registration. Such a registration is a proper
- * resource and should be cleaned up when no longer required.
+ * Class representing a registration. Such a registration is a proper resource and should be cleaned up when no longer
+ * required.
*/
public interface Registration extends AutoCloseable {
/**
- * Unregisters the object. This operation is required not to invoke
- * blocking operations. Implementations which require interaction
- * with outside world must provide guarantees that any work is done
- * behind the scenes and the unregistration process looks as if it
- * has already succeeded once this method returns.
+ * Unregisters the object. This operation is required not to invoke blocking operations. Implementations which
+ * require interaction with outside world must provide guarantees that any work is done behind the scenes and
+ * the unregistration process looks as if it has already succeeded once this method returns.
*/
@Override
- void close() throws Exception;
+ void close();
}
import static java.util.Objects.requireNonNull;
+import com.google.common.base.MoreObjects.ToStringHelper;
import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceRepresentation;
import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
this.provider = requireNonNull(provider);
}
- protected final SchemaSourceProvider<?> getProvider() {
+ public final SchemaSourceProvider<?> getProvider() {
return provider;
}
+
+ @Override
+ protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
+ return super.addToStringAttributes(toStringHelper).add("provider", provider);
+ }
}