import java.util.concurrent.ConcurrentMap;
import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
-import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.concepts.ObjectRegistration;
import org.opendaylight.yangtools.sal.binding.generator.util.ClassLoaderUtils;
import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
}
}
- public Registration<YangModuleInfo> registerModuleInfo(YangModuleInfo yangModuleInfo) {
+ public ObjectRegistration<YangModuleInfo> registerModuleInfo(YangModuleInfo yangModuleInfo) {
YangModuleInfoRegistration registration = new YangModuleInfoRegistration(yangModuleInfo, this);
resolveModuleInfo(yangModuleInfo);
* Invoking the close() method triggers unregistration of the state the method
* installed.
*/
-public abstract class AbstractObjectRegistration<T> extends AbstractRegistration implements Registration<T> {
+public abstract class AbstractObjectRegistration<T> extends AbstractRegistration implements ObjectRegistration<T> {
private final T instance;
protected AbstractObjectRegistration(final T instance) {
* is interface provides the additional guarantee that the process of
* unregistration cannot fail for predictable reasons.
*/
-public interface ListenerRegistration<T extends EventListener> extends Registration<T> {
+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
--- /dev/null
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.concepts;
+
+/**
+ * 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<T> {
+ /**
+ * Return the object instance.
+ *
+ * @return Registered object.
+ */
+ @Override
+ 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;
+}
* Return the object instance.
*
* @return Registered object.
+ *
+ * @deprecated This class is currently deprecated pending its rework for
+ * general-purpose registration. This rework will remove the
+ * getInstance() method, such that the registration is no
+ * longer tied to a particular object. Please use
+ * {@link ObjectRegistration} to ensure your code does not
+ * break when that happens.
*/
+ @Deprecated
T getInstance();
/**
*/
package org.opendaylight.yangtools.yang.parser.impl.util;
+import static com.google.common.base.Preconditions.checkArgument;
+
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
import org.opendaylight.yangtools.concepts.Identifiable;
-import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.concepts.ObjectRegistration;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.util.repo.AdvancedSchemaSourceProvider;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
-import static com.google.common.base.Preconditions.checkArgument;
-
public class URLSchemaContextResolver implements AdvancedSchemaSourceProvider<InputStream> {
private static final Logger LOG = LoggerFactory.getLogger(URLSchemaContextResolver.class);
private YangSourceContext currentSourceContext;
private Optional<SchemaContext> currentSchemaContext = Optional.absent();
- public Registration<URL> registerSource(URL source) {
+ public ObjectRegistration<URL> registerSource(URL source) {
checkArgument(source != null, "Supplied source must not be null");
InputStream yangStream = getInputStream(source);
YangModelDependencyInfo modelInfo = YangModelDependencyInfo.fromInputStream(yangStream);
this.dependencyInfo = modelInfo;
}
+ @Override
public SourceIdentifier getIdentifier() {
return identifier;
}