<groupId>org.opendaylight.yangtools</groupId>
<artifactId>concepts</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.checkerframework</groupId>
+ <artifactId>checker-qual</artifactId>
+ </dependency>
<dependency>
<groupId>org.osgi</groupId>
- <artifactId>osgi.core</artifactId>
+ <artifactId>osgi.cmpn</artifactId>
</dependency>
<dependency>
- <groupId>org.checkerframework</groupId>
- <artifactId>checker-qual</artifactId>
+ <groupId>javax.annotation</groupId>
+ <artifactId>javax.annotation-api</artifactId>
+ <scope>provided</scope>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>com.guicedee.services</groupId>
+ <artifactId>javax.inject</artifactId>
+ <optional>true</optional>
</dependency>
<!-- Testing dependencies -->
* 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.bgpcep.programming.impl;
import static java.util.Objects.requireNonNull;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import io.netty.util.Timer;
-import java.util.Dictionary;
-import java.util.Hashtable;
import java.util.concurrent.Executors;
-import org.gaul.modernizer_maven_annotations.SuppressModernizer;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Singleton;
import org.opendaylight.bgpcep.programming.spi.InstructionScheduler;
import org.opendaylight.bgpcep.programming.spi.InstructionSchedulerFactory;
import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.mdsal.binding.api.NotificationPublishService;
import org.opendaylight.mdsal.binding.api.RpcProviderService;
import org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public final class InstructionSchedulerFactoryImpl implements InstructionSchedulerFactory {
-
- private static final Logger LOG = LoggerFactory.getLogger(InstructionSchedulerFactoryImpl.class);
+@Component(immediate = true, service = InstructionSchedulerFactory.class)
+@Singleton
+public final class DefaultInstructionSchedulerFactory implements InstructionSchedulerFactory, AutoCloseable {
+ private static final Logger LOG = LoggerFactory.getLogger(DefaultInstructionSchedulerFactory.class);
private final DataBroker dataProvider;
private final NotificationPublishService notifs;
private final Timer timer;
private final RpcProviderService rpcProviderRegistry;
- private final BundleContext bundleContext;
private final ClusterSingletonServiceProvider cssp;
private final ListeningExecutorService exec = MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor());
- public InstructionSchedulerFactoryImpl(
- final DataBroker dataProvider,
- final RpcProviderService rpcProviderRegistry,
- final NotificationPublishService notifs,
- final Timer timer,
- final ClusterSingletonServiceProvider cssp,
- final BundleContext bundleContext) {
+ @Inject
+ @Activate
+ public DefaultInstructionSchedulerFactory(@Reference final DataBroker dataProvider,
+ @Reference final RpcProviderService rpcProviderRegistry,
+ @Reference final NotificationPublishService notifs,
+ @Reference(target = "(type=global-timer)") final Timer timer,
+ @Reference final ClusterSingletonServiceProvider cssp) {
this.dataProvider = requireNonNull(dataProvider);
this.notifs = requireNonNull(notifs);
this.timer = requireNonNull(timer);
this.rpcProviderRegistry = requireNonNull(rpcProviderRegistry);
- this.bundleContext = requireNonNull(bundleContext);
this.cssp = requireNonNull(cssp);
}
@Override
- @SuppressModernizer
public InstructionScheduler createInstructionScheduler(final String instructionId) {
LOG.info("Creating Instruction Scheduler {}.", instructionId);
+ return new ProgrammingServiceImpl(dataProvider, notifs, exec, rpcProviderRegistry, cssp, timer, instructionId);
+ }
- final ProgrammingServiceImpl programmingInst = new ProgrammingServiceImpl(this.dataProvider, this.notifs,
- this.exec, this.rpcProviderRegistry, this.cssp, this.timer, instructionId);
- final Dictionary<String, String> properties = new Hashtable<>();
- properties.put(InstructionScheduler.class.getName(), instructionId);
- final ServiceRegistration<?> serviceRegistration = this.bundleContext
- .registerService(InstructionScheduler.class.getName(), programmingInst, properties);
- programmingInst.setServiceRegistration(serviceRegistration);
- return programmingInst;
+ @Deactivate
+ @PreDestroy
+ @Override
+ public void close() {
+ // FIXME: This can have weird effects: should we keep track of all schedulers and refcount?
+ exec.shutdown();
}
}
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcResult;
-import org.osgi.framework.ServiceRegistration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public final class ProgrammingServiceImpl implements ClusterSingletonService, InstructionScheduler,
- ProgrammingService {
+final class ProgrammingServiceImpl implements ClusterSingletonService, InstructionScheduler, ProgrammingService {
private static final Logger LOG = LoggerFactory.getLogger(ProgrammingServiceImpl.class);
private final Map<InstructionId, InstructionImpl> insns = new HashMap<>();
private final RpcProviderService rpcProviderRegistry;
@GuardedBy("this")
private ObjectRegistration<ProgrammingService> reg;
- @GuardedBy("this")
- private ServiceRegistration<?> serviceRegistration;
private final class InstructionPusher implements QueueInstruction {
private final InstructionBuilder builder = new InstructionBuilder();
}
@Override
- @SuppressWarnings("checkstyle:IllegalCatch")
public synchronized void close() {
- if (this.csspReg != null) {
- try {
- this.csspReg.close();
- } catch (final Exception e) {
- LOG.error("Failed to close Instruction Scheduler service", e);
- }
- }
- if (this.serviceRegistration != null) {
- this.serviceRegistration.unregister();
- this.serviceRegistration = null;
- }
- }
-
- void setServiceRegistration(final ServiceRegistration<?> serviceRegistration) {
- this.serviceRegistration = serviceRegistration;
+ this.csspReg.close();
}
}
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- vi: set et smarttab sw=4 tabstop=4: -->
-<!--
- Copyright (c) 2017 Pantheon Technologies s.r.o. 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
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0">
-
- <reference id="dataBroker" interface="org.opendaylight.mdsal.binding.api.DataBroker"/>
- <reference id="rpcRegistry" interface="org.opendaylight.mdsal.binding.api.RpcProviderService"/>
- <reference id="notificationService"
- interface="org.opendaylight.mdsal.binding.api.NotificationPublishService"/>
- <reference id="timer" interface="io.netty.util.Timer" odl:type="global-timer"/>
- <reference id="clusterSingletonServiceProvider"
- interface="org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider"/>
-
- <bean id="IntructionFactory" class="org.opendaylight.bgpcep.programming.impl.InstructionSchedulerFactoryImpl">
- <argument ref="dataBroker"/>
- <argument ref="rpcRegistry"/>
- <argument ref="notificationService"/>
- <argument ref="timer"/>
- <argument ref="clusterSingletonServiceProvider"/>
- <argument ref="blueprintBundleContext"/>
- </bean>
-
- <service ref="IntructionFactory"
- interface="org.opendaylight.bgpcep.programming.spi.InstructionSchedulerFactory"/>
-</blueprint>