summary |
shortlog |
log |
commit | commitdiff |
review |
tree
raw |
patch |
inline | side by side (from parent 1:
962d3ee)
It does not make sense to instantiated
GlobalBundleScanningSchemaServiceImpl without a bundlecontext, so let's
make it required in the constructor, making interactions more clear.
Change-Id: I7c36c88e2e26163e0ef41480ea8f5d1d79353e5f
Signed-off-by: Robert Varga <rovarga@cisco.com>
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class SchemaServiceImplSingletonModule extends
public final class SchemaServiceImplSingletonModule extends
- org.opendaylight.controller.config.yang.md.sal.dom.impl.AbstractSchemaServiceImplSingletonModule {
+org.opendaylight.controller.config.yang.md.sal.dom.impl.AbstractSchemaServiceImplSingletonModule {
private static final Logger LOG = LoggerFactory.getLogger(SchemaServiceImplSingletonModule.class);
BundleContext bundleContext;
private static final Logger LOG = LoggerFactory.getLogger(SchemaServiceImplSingletonModule.class);
BundleContext bundleContext;
- public SchemaServiceImplSingletonModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
- org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
+ public SchemaServiceImplSingletonModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
+ final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
super(identifier, dependencyResolver);
}
super(identifier, dependencyResolver);
}
- public SchemaServiceImplSingletonModule(org.opendaylight.controller.config.api.ModuleIdentifier identifier,
- org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
- SchemaServiceImplSingletonModule oldModule, java.lang.AutoCloseable oldInstance) {
+ public SchemaServiceImplSingletonModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier,
+ final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver,
+ final SchemaServiceImplSingletonModule oldModule, final java.lang.AutoCloseable oldInstance) {
super(identifier, dependencyResolver, oldModule, oldInstance);
}
@Override
super(identifier, dependencyResolver, oldModule, oldInstance);
}
@Override
- public boolean canReuseInstance(AbstractSchemaServiceImplSingletonModule oldModule) {
+ public boolean canReuseInstance(final AbstractSchemaServiceImplSingletonModule oldModule) {
- public void setBundleContext(BundleContext bundleContext) {
+ public void setBundleContext(final BundleContext bundleContext) {
this.bundleContext = bundleContext;
}
this.bundleContext = bundleContext;
}
return new GlobalSchemaServiceProxy(getBundleContext(), ref);
}
return new GlobalSchemaServiceProxy(getBundleContext(), ref);
}
- GlobalBundleScanningSchemaServiceImpl newInstance = new GlobalBundleScanningSchemaServiceImpl();
- newInstance.setContext(getBundleContext());
+ GlobalBundleScanningSchemaServiceImpl newInstance = new GlobalBundleScanningSchemaServiceImpl(getBundleContext());
newInstance.start();
return newInstance;
}
newInstance.start();
return newInstance;
}
private ServiceReference<SchemaService> reference;
private SchemaService delegate;
private ServiceReference<SchemaService> reference;
private SchemaService delegate;
- public GlobalSchemaServiceProxy(BundleContext bundleContext, ServiceReference<SchemaService> ref) {
+ public GlobalSchemaServiceProxy(final BundleContext bundleContext, final ServiceReference<SchemaService> ref) {
this.bundleContext = bundleContext;
this.reference = ref;
this.delegate = bundleContext.getService(reference);
this.bundleContext = bundleContext;
this.reference = ref;
this.delegate = bundleContext.getService(reference);
- public void addModule(Module arg0) {
+ public void addModule(final Module arg0) {
delegate.addModule(arg0);
}
delegate.addModule(arg0);
}
- public ListenerRegistration<SchemaServiceListener> registerSchemaServiceListener(SchemaServiceListener arg0) {
+ public ListenerRegistration<SchemaServiceListener> registerSchemaServiceListener(final SchemaServiceListener arg0) {
return delegate.registerSchemaServiceListener(arg0);
}
@Override
return delegate.registerSchemaServiceListener(arg0);
}
@Override
- public void removeModule(Module arg0) {
+ public void removeModule(final Module arg0) {
delegate.removeModule(arg0);
}
delegate.removeModule(arg0);
}
import org.slf4j.LoggerFactory;
import com.google.common.base.Optional;
import org.slf4j.LoggerFactory;
import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableList;
-public class GlobalBundleScanningSchemaServiceImpl implements //
-SchemaContextProvider, //
-SchemaService, //
-ServiceTrackerCustomizer<SchemaServiceListener, SchemaServiceListener>, //
-AutoCloseable {
+public class GlobalBundleScanningSchemaServiceImpl implements SchemaContextProvider, SchemaService, ServiceTrackerCustomizer<SchemaServiceListener, SchemaServiceListener>, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(GlobalBundleScanningSchemaServiceImpl.class);
private static final Logger LOG = LoggerFactory.getLogger(GlobalBundleScanningSchemaServiceImpl.class);
+ private final ListenerRegistry<SchemaServiceListener> listeners = new ListenerRegistry<>();
private final URLSchemaContextResolver contextResolver = new URLSchemaContextResolver();
private final BundleScanner scanner = new BundleScanner();
private final URLSchemaContextResolver contextResolver = new URLSchemaContextResolver();
private final BundleScanner scanner = new BundleScanner();
+ private final BundleContext context;
+
private ServiceTracker<SchemaServiceListener, SchemaServiceListener> listenerTracker;
private BundleTracker<Iterable<Registration<URL>>> bundleTracker;
private ServiceTracker<SchemaServiceListener, SchemaServiceListener> listenerTracker;
private BundleTracker<Iterable<Registration<URL>>> bundleTracker;
- private ListenerRegistry<SchemaServiceListener> listeners;
private boolean starting = true;
private boolean starting = true;
- private BundleContext context;
-
- public ListenerRegistry<SchemaServiceListener> getListeners() {
- return listeners;
- }
- public void setListeners(final ListenerRegistry<SchemaServiceListener> listeners) {
- this.listeners = listeners;
+ public GlobalBundleScanningSchemaServiceImpl(final BundleContext context) {
+ this.context = Preconditions.checkNotNull(context);
}
public BundleContext getContext() {
return context;
}
}
public BundleContext getContext() {
return context;
}
- public void setContext(final BundleContext context) {
- this.context = context;
- }
-
public void start() {
checkState(context != null);
public void start() {
checkState(context != null);
- if (listeners == null) {
- listeners = new ListenerRegistry<>();
- }
listenerTracker = new ServiceTracker<>(context, SchemaServiceListener.class, GlobalBundleScanningSchemaServiceImpl.this);
listenerTracker = new ServiceTracker<>(context, SchemaServiceListener.class, GlobalBundleScanningSchemaServiceImpl.this);
- bundleTracker = new BundleTracker<Iterable<Registration<URL>>>(context, BundleEvent.RESOLVED
- | BundleEvent.UNRESOLVED, scanner);
+ bundleTracker = new BundleTracker<>(context, BundleEvent.RESOLVED | BundleEvent.UNRESOLVED, scanner);
bundleTracker.open();
listenerTracker.open();
starting = false;
bundleTracker.open();
listenerTracker.open();
starting = false;
}
public synchronized void tryToUpdateSchemaContext() {
}
public synchronized void tryToUpdateSchemaContext() {
return;
}
Optional<SchemaContext> schema = contextResolver.tryToUpdateSchemaContext();
return;
}
Optional<SchemaContext> schema = contextResolver.tryToUpdateSchemaContext();
public class SchemaServiceActivator implements BundleActivator {
public class SchemaServiceActivator implements BundleActivator {
private ServiceRegistration<SchemaService> schemaServiceReg;
private GlobalBundleScanningSchemaServiceImpl schemaService;
@Override
private ServiceRegistration<SchemaService> schemaServiceReg;
private GlobalBundleScanningSchemaServiceImpl schemaService;
@Override
- public void start(BundleContext context) throws Exception {
- schemaService = new GlobalBundleScanningSchemaServiceImpl();
- schemaService.setContext(context);
+ public void start(final BundleContext context) {
+ schemaService = new GlobalBundleScanningSchemaServiceImpl(context);
schemaService.start();
schemaServiceReg = context.registerService(SchemaService.class, schemaService, new Hashtable<String,String>());
}
schemaService.start();
schemaServiceReg = context.registerService(SchemaService.class, schemaService, new Hashtable<String,String>());
}
- public void stop(BundleContext context) throws Exception {
+ public void stop(final BundleContext context) throws Exception {
schemaServiceReg.unregister();
schemaService.close();
}
schemaServiceReg.unregister();
schemaService.close();
}