package org.opendaylight.restconf.nb.rfc8040;
import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSet.Builder;
+import java.util.Set;
import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
import org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
-import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapperImpl;
+import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServiceWrapper;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
import org.slf4j.Logger;
* Provider for restconf draft18.
*
*/
-public class RestConnectorProvider implements RestconfConnector, AutoCloseable {
+public class RestConnectorProvider<T extends ServiceWrapper> implements RestconfConnector, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(RestConnectorProvider.class);
private final DOMRpcService rpcService;
private final DOMNotificationService notificationService;
private final DOMMountPointService mountPointService;
- private ListenerRegistration<SchemaContextListener> listenerRegistration;
+ private final Builder<Object> servicesProperties;
+ private ListenerRegistration<SchemaContextListener> listenerRegistration;
private SchemaContextHandler schemaCtxHandler;
+ private T wrapperServices;
- public RestConnectorProvider(final DOMDataBroker domDataBroker, final SchemaService schemaService, final DOMRpcService rpcService,
+ // FIXME: refactor this class and its users to interact via builder pattern, where individual
+ // services are injected and then the provider is created
+ public RestConnectorProvider(final DOMDataBroker domDataBroker,
+ final SchemaService schemaService, final DOMRpcService rpcService,
final DOMNotificationService notificationService, final DOMMountPointService mountPointService) {
+ this(domDataBroker, schemaService, rpcService, notificationService, mountPointService, null);
+ }
+
+ public RestConnectorProvider(final DOMDataBroker domDataBroker, final SchemaService schemaService,
+ final DOMRpcService rpcService,
+ final DOMNotificationService notificationService, final DOMMountPointService mountPointService,
+ final T wrapperServices) {
+ this.servicesProperties = ImmutableSet.<Object>builder();
+ this.wrapperServices = wrapperServices;
this.schemaService = Preconditions.checkNotNull(schemaService);
this.rpcService = Preconditions.checkNotNull(rpcService);
this.notificationService = Preconditions.checkNotNull(notificationService);
RestConnectorProvider.dataBroker = Preconditions.checkNotNull(domDataBroker);
}
- public void start() {
- final ServicesWrapperImpl wrapperServices = ServicesWrapperImpl.getInstance();
-
+ public synchronized void start() {
mountPointServiceHandler = new DOMMountPointServiceHandler(mountPointService);
+ servicesProperties.add(mountPointServiceHandler);
final DOMDataBrokerHandler brokerHandler = new DOMDataBrokerHandler(dataBroker);
+ servicesProperties.add(brokerHandler);
RestConnectorProvider.transactionChainHandler = new TransactionChainHandler(dataBroker
.createTransactionChain(RestConnectorProvider.TRANSACTION_CHAIN_LISTENER));
+ servicesProperties.add(transactionChainHandler);
this.schemaCtxHandler = new SchemaContextHandler(transactionChainHandler);
+ servicesProperties.add(schemaCtxHandler);
this.listenerRegistration = schemaService.registerSchemaContextListener(this.schemaCtxHandler);
final RpcServiceHandler rpcServiceHandler = new RpcServiceHandler(rpcService);
+ servicesProperties.add(rpcServiceHandler);
final NotificationServiceHandler notificationServiceHandler =
new NotificationServiceHandler(notificationService);
+ servicesProperties.add(notificationServiceHandler);
- wrapperServices.setHandlers(this.schemaCtxHandler, RestConnectorProvider.mountPointServiceHandler,
+ if (wrapperServices != null) {
+ wrapperServices.setHandlers(this.schemaCtxHandler, RestConnectorProvider.mountPointServiceHandler,
RestConnectorProvider.transactionChainHandler, brokerHandler, rpcServiceHandler,
notificationServiceHandler);
+ }
}
public DOMMountPointServiceHandler getMountPointServiceHandler() {
mountPointServiceHandler = null;
dataBroker = null;
}
+
+ public final synchronized Set<Object> getServicesProperties() {
+ return servicesProperties.build();
+ }
}