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;
private final DOMRpcService rpcService;
private final DOMNotificationService notificationService;
private final DOMMountPointService mountPointService;
- private final T wrapperServices;
+ private final Builder<Object> servicesProperties;
private ListenerRegistration<SchemaContextListener> listenerRegistration;
private SchemaContextHandler schemaCtxHandler;
+ private T wrapperServices;
+ // 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.wrapperServices = Preconditions.checkNotNull(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() {
+ 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();
+ }
}
import org.opendaylight.restconf.common.patch.PatchContext;
import org.opendaylight.restconf.common.patch.PatchStatusContext;
import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
+import org.opendaylight.restconf.nb.rfc8040.services.simple.api.UpdateHandlers;
import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
/**
* is a collection of configuration data and state data nodes.
*
*/
-public interface RestconfDataService {
+public interface RestconfDataService extends UpdateHandlers {
/**
* Get target data resource.
import javax.ws.rs.core.UriInfo;
import org.opendaylight.restconf.common.context.NormalizedNodeContext;
import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
+import org.opendaylight.restconf.nb.rfc8040.services.simple.api.UpdateHandlers;
import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
/**
* "rpc" statement. It is invoked using a POST method on the operation resource.
*
*/
-public interface RestconfInvokeOperationsService {
+public interface RestconfInvokeOperationsService extends UpdateHandlers {
/**
* Invoke RPC operation.
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import org.opendaylight.restconf.common.context.NormalizedNodeContext;
+import org.opendaylight.restconf.nb.rfc8040.services.simple.api.UpdateHandlers;
/**
* Subscribing to streams.
*
*/
-public interface RestconfStreamsSubscriptionService {
+public interface RestconfStreamsSubscriptionService extends UpdateHandlers {
/**
* Subscribing to receive notification from stream support.
private static final Logger LOG = LoggerFactory.getLogger(RestconfDataServiceImpl.class);
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MMM-dd HH:mm:ss");
- private final SchemaContextHandler schemaContextHandler;
- private final TransactionChainHandler transactionChainHandler;
- private final DOMMountPointServiceHandler mountPointServiceHandler;
+ private SchemaContextHandler schemaContextHandler;
+ private TransactionChainHandler transactionChainHandler;
+ private DOMMountPointServiceHandler mountPointServiceHandler;
private final RestconfStreamsSubscriptionService delegRestconfSubscrService;
this.delegRestconfSubscrService = delegRestconfSubscrService;
}
+ @Override
+ public synchronized void updateHandlers(final Object... handlers) {
+ for (final Object object : handlers) {
+ if (object instanceof SchemaContextHandler) {
+ schemaContextHandler = (SchemaContextHandler) object;
+ } else if (object instanceof DOMMountPointServiceHandler) {
+ mountPointServiceHandler = (DOMMountPointServiceHandler) object;
+ } else if (object instanceof TransactionChainHandler) {
+ transactionChainHandler = (TransactionChainHandler) object;
+ }
+ }
+ }
+
@Override
public Response readData(final UriInfo uriInfo) {
return readData(null, uriInfo);
*/
public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperationsService {
- private final RpcServiceHandler rpcServiceHandler;
- private final SchemaContextHandler schemaContextHandler;
+ private RpcServiceHandler rpcServiceHandler;
+ private SchemaContextHandler schemaContextHandler;
public RestconfInvokeOperationsServiceImpl(final RpcServiceHandler rpcServiceHandler,
final SchemaContextHandler schemaContextHandler) {
this.schemaContextHandler = schemaContextHandler;
}
+ @Override
+ public synchronized void updateHandlers(final Object... handlers) {
+ for (final Object object : handlers) {
+ if (object instanceof SchemaContextHandler) {
+ schemaContextHandler = (SchemaContextHandler) object;
+ } else if (object instanceof RpcServiceHandler) {
+ rpcServiceHandler = (RpcServiceHandler) object;
+ }
+ }
+ }
+
@Override
public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload,
final UriInfo uriInfo) {
private static final Logger LOG = LoggerFactory.getLogger(RestconfStreamsSubscriptionServiceImpl.class);
- private final HandlersHolder handlersHolder;
+ private HandlersHolder handlersHolder;
/**
* Initialize holder of handlers with holders as parameters.
transactionChainHandler, schemaHandler);
}
+ @Override
+ public synchronized void updateHandlers(final Object... handlers) {
+ for (final Object object : handlers) {
+ if (object instanceof HandlersHolder) {
+ handlersHolder = (HandlersHolder) object;
+ }
+ }
+ }
+
@Override
public NormalizedNodeContext subscribeToStream(final String identifier, final UriInfo uriInfo) {
final NotificationQueryParams notificationQueryParams = NotificationQueryParams.fromUriInfo(uriInfo);
* supported by the server.
*
*/
-public interface RestconfOperationsService {
+public interface RestconfOperationsService extends UpdateHandlers {
/**
* List of rpc or action operations supported by the server.
*
*/
@Path("/")
-public interface RestconfSchemaService {
+public interface RestconfSchemaService extends UpdateHandlers {
/**
* Get schema of specific module.
* Service for getting yang library version.
*
*/
-public interface RestconfService {
+public interface RestconfService extends UpdateHandlers {
/**
* Get yang library version.
--- /dev/null
+/*
+ * 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
+ */
+package org.opendaylight.restconf.nb.rfc8040.services.simple.api;
+
+/**
+ * Allow update of handlers in web application services, if needed.
+ */
+public interface UpdateHandlers {
+
+ /**
+ * Update method for handlers in specific service (resource) of web application.
+ * Has to be implemented as synchronized to avoid conflict of update variables in multithreaded application.
+ *
+ * @param handlers
+ * array of handlers
+ */
+ default void updateHandlers(final Object... handlers) {
+ throw new UnsupportedOperationException("This method it's not allowed for this service by default.");
+ }
+}
public class RestconfImpl implements RestconfService {
- private final SchemaContextHandler schemaContextHandler;
+ private SchemaContextHandler schemaContextHandler;
public RestconfImpl(final SchemaContextHandler schemaContextHandler) {
this.schemaContextHandler = schemaContextHandler;
Builders.leafBuilder((LeafSchemaNode) schemaNode).withValue(IetfYangLibrary.REVISION).build();
return new NormalizedNodeContext(iid, data);
}
+
+ @Override
+ public synchronized void updateHandlers(final Object... handlers) {
+ for (final Object object : handlers) {
+ if (object instanceof SchemaContextHandler) {
+ schemaContextHandler = (SchemaContextHandler) object;
+ }
+ }
+ }
}
private static final Logger LOG = LoggerFactory.getLogger(RestconfOperationsServiceImpl.class);
- private final SchemaContextHandler schemaContextHandler;
- private final DOMMountPointServiceHandler domMountPointServiceHandler;
+ private SchemaContextHandler schemaContextHandler;
+ private DOMMountPointServiceHandler domMountPointServiceHandler;
/**
* Set {@link SchemaContextHandler} for getting actual {@link SchemaContext}.
this.domMountPointServiceHandler = domMountPointServiceHandler;
}
+ @Override
+ public synchronized void updateHandlers(final Object... handlers) {
+ for (final Object object : handlers) {
+ if (object instanceof SchemaContextHandler) {
+ schemaContextHandler = (SchemaContextHandler) object;
+ } else if (object instanceof DOMMountPointServiceHandler) {
+ domMountPointServiceHandler = (DOMMountPointServiceHandler) object;
+ }
+ }
+ }
+
@Override
public NormalizedNodeContext getOperations(final UriInfo uriInfo) {
final SchemaContextRef ref = new SchemaContextRef(this.schemaContextHandler.get());
*/
public class RestconfSchemaServiceImpl implements RestconfSchemaService {
- private final SchemaContextHandler schemaContextHandler;
- private final DOMMountPointServiceHandler domMountPointServiceHandler;
+ private SchemaContextHandler schemaContextHandler;
+ private DOMMountPointServiceHandler domMountPointServiceHandler;
/**
* Set {@link SchemaContextHandler} for getting actual {@link SchemaContext}
return ParserIdentifier.toSchemaExportContextFromIdentifier(schemaContextRef.get(), identifier,
this.domMountPointServiceHandler.get());
}
+
+ @Override
+ public synchronized void updateHandlers(final Object... handlers) {
+ for (final Object object : handlers) {
+ if (object instanceof SchemaContextHandler) {
+ schemaContextHandler = (SchemaContextHandler) object;
+ } else if (object instanceof DOMMountPointServiceHandler) {
+ domMountPointServiceHandler = (DOMMountPointServiceHandler) object;
+ }
+ }
+ }
}