/*
 * #%L
 * %%
 * Copyright (C) 2017 BMW Car IT GmbH
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */
package io.joynr.provider;

import java.util.HashMap;
import java.util.Map;

import com.google.inject.Inject;

import io.joynr.dispatching.RequestCallerFactory;
import io.joynr.exceptions.JoynrRuntimeException;

public class ProviderContainerFactory {
    private final Map<Object, ProviderContainer> providerContainers;
    private final SubscriptionPublisherFactory subscriptionPublisherFactory;
    private final RequestCallerFactory requestCallerFactory;

    @Inject
    public ProviderContainerFactory(SubscriptionPublisherFactory subscriptionPublisherFactory,
                                    RequestCallerFactory requestCallerFactory) {
        this.subscriptionPublisherFactory = subscriptionPublisherFactory;
        this.requestCallerFactory = requestCallerFactory;
        providerContainers = new HashMap<>();
    }

    public ProviderContainer create(final Object provider) {
        if (providerContainers.get(provider) == null) {
            providerContainers.put(provider, createInternal(provider));
        }
        return providerContainers.get(provider);
    }

    private ProviderContainer createInternal(final Object provider) throws JoynrRuntimeException {
        return new ProviderContainer(ProviderAnnotations.getInterfaceName(provider),
                                     ProviderAnnotations.getProvidedInterface(provider),
                                     ProviderAnnotations.getMajorVersion(provider),
                                     requestCallerFactory.create(provider),
                                     subscriptionPublisherFactory.create(provider));
    }

    public void removeProviderContainer(JoynrProvider provider) {
        providerContainers.remove(provider);
    }
}

@@ -669,34 +669,33 @@
 til.
-HashMap;%0Aimport java.util.
+concurrent.ConcurrentHash
 Map;
@@ -889,16 +889,30 @@
 e final 
+ConcurrentHash
 Map%3CObje
@@ -1446,16 +1446,26 @@
 s = new 
+Concurrent
 HashMap%3C
@@ -1469,16 +1469,16 @@
 ap%3C%3E();%0A
-
     %7D%0A%0A 
@@ -1549,13 +1549,9 @@
     
-if (p
+P
 rovi
@@ -1566,46 +1566,20 @@
 iner
-s.get(provider) == null) %7B%0A           
+ container =
  pro
@@ -1594,18 +1594,30 @@
 tainers.
-pu
+computeIfAbsen
 t(provid
@@ -1619,16 +1619,21 @@
 rovider,
+ k -%3E
  createI
@@ -1640,24 +1640,17 @@
 nternal(
-provider
+k
 ));%0A    
@@ -1657,57 +1657,24 @@
     
-%7D%0A        return providerContainers.get(provider)
+return container
 ;%0A  

Make ProviderContainerFactory thread safe