From dd41150a7b76d0919347aa0d45d2a0c1e09cb139 Mon Sep 17 00:00:00 2001 From: Jakub Toth Date: Tue, 17 May 2016 16:42:15 +0200 Subject: [PATCH] Bug 5900 - Jenkins RaceContiditions - problem between Jersey and RestconfProvider Change-Id: I2b87b53c0679eede0fdbdea9de69568c14367ea7 Signed-off-by: Jakub Toth --- .../restconf/rest/RestConnectorProvider.java | 23 ++++------- .../restconf/rest/RestconfApplication.java | 30 +------------- .../rest/RestconfApplicationService.java | 38 ------------------ .../services/Draft11ServicesWrapperImpl.java | 40 ++++++++++--------- 4 files changed, 31 insertions(+), 100 deletions(-) delete mode 100644 restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestconfApplicationService.java diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestConnectorProvider.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestConnectorProvider.java index add14df9f5..8dafecbf14 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestConnectorProvider.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestConnectorProvider.java @@ -17,11 +17,11 @@ import org.opendaylight.controller.sal.core.api.model.SchemaService; import org.opendaylight.netconf.sal.rest.api.RestConnector; import org.opendaylight.restconf.rest.api.schema.context.SchemaContextHandler; import org.opendaylight.restconf.rest.handlers.api.DOMMountPointServiceHandler; +import org.opendaylight.restconf.rest.handlers.impl.DOMMountPointServiceHandlerImpl; +import org.opendaylight.restconf.rest.impl.schema.context.SchemaContextHandlerImpl; +import org.opendaylight.restconf.rest.impl.services.Draft11ServicesWrapperImpl; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.model.api.SchemaContextListener; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.ServiceReference; /** * Provider for restconf draft11. @@ -34,20 +34,13 @@ public class RestConnectorProvider implements Provider, RestConnector, AutoClose @Override public void onSessionInitiated(final ProviderSession session) { final SchemaService schemaService = Preconditions.checkNotNull(session.getService(SchemaService.class)); - final RestconfApplication restApp = getObjectFromBundleContext(RestconfApplication.class, - RestconfApplicationService.class.getName()); - Preconditions.checkNotNull(restApp, "RestconfApplication service doesn't exist."); - final SchemaContextHandler schemaContextHandler = restApp.getSchemaContextHandler(); - final DOMMountPointServiceHandler domMountPointServiceHandler = restApp.getDOMMountPointServiceHandler(); + final DOMMountPointServiceHandler domMountPointServiceHandler = new DOMMountPointServiceHandlerImpl(); + final SchemaContextHandler schemaCtxHandler = new SchemaContextHandlerImpl(); domMountPointServiceHandler.setDOMMountPointService(session.getService(DOMMountPointService.class)); + final Draft11ServicesWrapperImpl wrapperServices = Draft11ServicesWrapperImpl.getInstance(); + this.listenerRegistration = schemaService.registerSchemaContextListener(schemaCtxHandler); - this.listenerRegistration = schemaService.registerSchemaContextListener(schemaContextHandler); - } - - private T getObjectFromBundleContext(final Class type, final String serviceRefName) { - final BundleContext bundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext(); - final ServiceReference serviceReference = bundleContext.getServiceReference(serviceRefName); - return (T) bundleContext.getService(serviceReference); + wrapperServices.setHandlers(schemaCtxHandler, domMountPointServiceHandler); } @Override diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestconfApplication.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestconfApplication.java index 7ab0d4cad8..ae778993d5 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestconfApplication.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestconfApplication.java @@ -15,24 +15,9 @@ import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContentYangBodyWr import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContentYinBodyWriter; import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter; import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeXmlBodyWriter; -import org.opendaylight.restconf.rest.api.schema.context.SchemaContextHandler; -import org.opendaylight.restconf.rest.handlers.api.DOMMountPointServiceHandler; -import org.opendaylight.restconf.rest.handlers.impl.DOMMountPointServiceHandlerImpl; -import org.opendaylight.restconf.rest.impl.schema.context.SchemaContextHandlerImpl; import org.opendaylight.restconf.rest.impl.services.Draft11ServicesWrapperImpl; -import org.osgi.framework.FrameworkUtil; -public class RestconfApplication extends Application implements RestconfApplicationService { - - private final SchemaContextHandler schemaContextHandler; - private final DOMMountPointServiceHandler domMountPointServiceHandler; - - public RestconfApplication() { - this.schemaContextHandler = new SchemaContextHandlerImpl(); - this.domMountPointServiceHandler = new DOMMountPointServiceHandlerImpl(); - FrameworkUtil.getBundle(getClass()).getBundleContext().registerService(RestconfApplicationService.class.getName(), - this, null); - } +public class RestconfApplication extends Application { @Override public Set> getClasses() { @@ -45,18 +30,7 @@ public class RestconfApplication extends Application implements RestconfApplicat @Override public Set getSingletons() { final Set singletons = new HashSet<>(); - singletons.add(this.schemaContextHandler); - singletons.add(new Draft11ServicesWrapperImpl(this.schemaContextHandler, this.domMountPointServiceHandler)); + singletons.add(Draft11ServicesWrapperImpl.getInstance()); return singletons; } - - @Override - public SchemaContextHandler getSchemaContextHandler() { - return this.schemaContextHandler; - } - - @Override - public DOMMountPointServiceHandler getDOMMountPointServiceHandler() { - return this.domMountPointServiceHandler; - } } diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestconfApplicationService.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestconfApplicationService.java deleted file mode 100644 index 497f6a55b1..0000000000 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestconfApplicationService.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2016 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.restconf.rest; - -import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; -import org.opendaylight.restconf.rest.api.schema.context.SchemaContextHandler; -import org.opendaylight.restconf.rest.handlers.api.DOMMountPointServiceHandler; -import org.opendaylight.yangtools.yang.model.api.SchemaContextListener; -import org.osgi.framework.BundleContext; - -/** - * Interface for register RestconfApplication service via {@link BundleContext}. - * - */ -public interface RestconfApplicationService { - - /** - * Get {@link SchemaContextHandler} via service. Actually use by - * {@link RestConnectorProvider} to register {@link SchemaContextListener} - * of {@link SchemaContextHandler}. - * - * @return {@link SchemaContextHandler} - */ - SchemaContextHandler getSchemaContextHandler(); - - /** - * Get {@link DOMMountPointServiceHandler} via service. Actually use by - * {@link RestConnectorProvider} to set {@link DOMMountPointService}. - * - * @return {@link DOMMountPointServiceHandler} - */ - DOMMountPointServiceHandler getDOMMountPointServiceHandler(); -} diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/impl/services/Draft11ServicesWrapperImpl.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/impl/services/Draft11ServicesWrapperImpl.java index 1ef40ea8d9..05991cb97e 100644 --- a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/impl/services/Draft11ServicesWrapperImpl.java +++ b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/impl/services/Draft11ServicesWrapperImpl.java @@ -17,7 +17,6 @@ import org.opendaylight.restconf.rest.api.services.RestconfOperationsService; import org.opendaylight.restconf.rest.api.services.RestconfStreamsService; import org.opendaylight.restconf.rest.api.services.schema.RestconfSchemaService; import org.opendaylight.restconf.rest.handlers.api.DOMMountPointServiceHandler; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; /** * Implementation of {@link Draft11ServicesWrapper} @@ -25,25 +24,12 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext; */ public class Draft11ServicesWrapperImpl implements Draft11ServicesWrapper { - private final RestconfModulesService delegRestModService; - private final RestconfOperationsService delegRestOpsService; - private final RestconfStreamsService delegRestStrsService; - private final RestconfSchemaService delegRestSchService; + private RestconfModulesService delegRestModService; + private RestconfOperationsService delegRestOpsService; + private RestconfStreamsService delegRestStrsService; + private RestconfSchemaService delegRestSchService; - /** - * Creating delegates to all implemented services - * - * @param schemaContextHandler - * - for handling {@link SchemaContext} - * @param domMountPointServiceHandler - * - for handling {@link DOMMountPointServiceHandler} - */ - public Draft11ServicesWrapperImpl(final SchemaContextHandler schemaContextHandler, - final DOMMountPointServiceHandler domMountPointServiceHandler) { - this.delegRestModService = new RestconfModulesServiceImpl(schemaContextHandler, domMountPointServiceHandler); - this.delegRestOpsService = new RestconfOperationsServiceImpl(schemaContextHandler, domMountPointServiceHandler); - this.delegRestStrsService = new RestconfStreamsServiceImpl(schemaContextHandler); - this.delegRestSchService = new RestconfSchemaServiceImpl(schemaContextHandler, domMountPointServiceHandler); + private Draft11ServicesWrapperImpl() { } @Override @@ -81,4 +67,20 @@ public class Draft11ServicesWrapperImpl implements Draft11ServicesWrapper { return this.delegRestSchService.getSchema(mountAndModuleId); } + public static Draft11ServicesWrapperImpl getInstance() { + return InstanceHolder.INSTANCE; + } + + private static class InstanceHolder { + public static final Draft11ServicesWrapperImpl INSTANCE = new Draft11ServicesWrapperImpl(); + } + + public void setHandlers(final SchemaContextHandler schemaCtxHandler, + final DOMMountPointServiceHandler domMountPointServiceHandler) { + this.delegRestModService = new RestconfModulesServiceImpl(schemaCtxHandler, domMountPointServiceHandler); + this.delegRestOpsService = new RestconfOperationsServiceImpl(schemaCtxHandler, domMountPointServiceHandler); + this.delegRestSchService = new RestconfSchemaServiceImpl(schemaCtxHandler, domMountPointServiceHandler); + this.delegRestStrsService = new RestconfStreamsServiceImpl(schemaCtxHandler); + } + } -- 2.36.6