Bug 5900 - Jenkins RaceContiditions - problem between Jersey and RestconfProvider 78/38978/1
authorJakub Toth <jatoth@cisco.com>
Tue, 17 May 2016 14:42:15 +0000 (16:42 +0200)
committerJakub Toth <jatoth@cisco.com>
Tue, 17 May 2016 14:43:07 +0000 (16:43 +0200)
Change-Id: I2b87b53c0679eede0fdbdea9de69568c14367ea7
Signed-off-by: Jakub Toth <jatoth@cisco.com>
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestConnectorProvider.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestconfApplication.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/RestconfApplicationService.java [deleted file]
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/impl/services/Draft11ServicesWrapperImpl.java

index add14df9f5153c40ecba90a0f1983c5a1fcfc57f..8dafecbf143f433461cc4c3546530eaf9331f213 100644 (file)
@@ -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> T getObjectFromBundleContext(final Class<T> 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
index 7ab0d4cad83a8cb80091a05a7c0fe4d25cede5b2..ae778993d5937c82301460b24f3d7cf5a21a5c93 100644 (file)
@@ -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<Class<?>> getClasses() {
@@ -45,18 +30,7 @@ public class RestconfApplication extends Application implements RestconfApplicat
     @Override
     public Set<Object> getSingletons() {
         final Set<Object> 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 (file)
index 497f6a5..0000000
+++ /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();
-}
index 1ef40ea8d92ef4e6c7c90b3f46befaffec64b637..05991cb97e5073c793bc7592da5224c9d6354139 100644 (file)
@@ -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);
+    }
+
 }