Author: csierra
Date: Fri Feb 23 08:54:50 2018
New Revision: 1825116

URL: http://svn.apache.org/viewvc?rev=1825116&view=rev
Log:
[Component-DSL] Register accepts Supplier

Modified:
    
aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/OSGi.java
    
aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/internal/ServiceRegistrationOSGiImpl.java

Modified: 
aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/OSGi.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/OSGi.java?rev=1825116&r1=1825115&r2=1825116&view=diff
==============================================================================
--- 
aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/OSGi.java
 (original)
+++ 
aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/OSGi.java
 Fri Feb 23 08:54:50 2018
@@ -186,17 +186,39 @@ public interface OSGi<T> extends OSGiRun
        static <T> OSGi<ServiceRegistration<T>> register(
                Class<T> clazz, T service, Map<String, Object> properties) {
 
+               return register(clazz, () -> service, () -> properties);
+       }
+
+       static <T> OSGi<ServiceRegistration<T>> register(
+               Class<T> clazz, ServiceFactory<T> service,
+               Map<String, Object> properties) {
+
+               return register(clazz, service, () -> properties);
+       }
+
+       static OSGi<ServiceRegistration<?>> register(
+               String[] classes, Object service, Map<String, ?> properties) {
+
+               return new ServiceRegistrationOSGiImpl(
+                       classes, () -> service, () -> properties);
+       }
+
+       static <T> OSGi<ServiceRegistration<T>> register(
+               Class<T> clazz, Supplier<T> service, Supplier<Map<String, ?>> 
properties) {
+
                return new ServiceRegistrationOSGiImpl<>(clazz, service, 
properties);
        }
 
        static <T> OSGi<ServiceRegistration<T>> register(
-               Class<T> clazz, ServiceFactory<T> service, Map<String, Object> 
properties) {
+               Class<T> clazz, ServiceFactory<T> service,
+               Supplier<Map<String, ?>> properties) {
 
                return new ServiceRegistrationOSGiImpl<>(clazz, service, 
properties);
        }
 
        static OSGi<ServiceRegistration<?>> register(
-               String[] classes, Object service, Map<String, ?> properties) {
+               String[] classes, Supplier<Object> service,
+               Supplier<Map<String, ?>> properties) {
 
                return new ServiceRegistrationOSGiImpl(classes, service, 
properties);
        }

Modified: 
aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/internal/ServiceRegistrationOSGiImpl.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/internal/ServiceRegistrationOSGiImpl.java?rev=1825116&r1=1825115&r2=1825116&view=diff
==============================================================================
--- 
aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/internal/ServiceRegistrationOSGiImpl.java
 (original)
+++ 
aries/trunk/component-dsl/component-dsl/src/main/java/org/apache/aries/osgi/functional/internal/ServiceRegistrationOSGiImpl.java
 Fri Feb 23 08:54:50 2018
@@ -25,6 +25,7 @@ import java.util.Map;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.function.Consumer;
 import java.util.function.Function;
+import java.util.function.Supplier;
 
 /**
  * @author Carlos Sierra Andrés
@@ -33,12 +34,13 @@ public class ServiceRegistrationOSGiImpl
        extends OSGiImpl<ServiceRegistration<T>> {
 
        public ServiceRegistrationOSGiImpl(
-               Class<T> clazz, T service, Map<String, Object> properties) {
+               Class<T> clazz, Supplier<T> service,
+               Supplier<Map<String, ?>> properties) {
 
                super((bundleContext, op) -> {
                        ServiceRegistration<?> serviceRegistration =
                                bundleContext.registerService(
-                                       clazz, service, 
getProperties(properties));
+                                       clazz, service.get(), 
getProperties(properties.get()));
 
                        return 
getServiceRegistrationOSGiResult(serviceRegistration, op);
                });
@@ -46,31 +48,33 @@ public class ServiceRegistrationOSGiImpl
 
        public ServiceRegistrationOSGiImpl(
                Class<T> clazz, ServiceFactory<T> serviceFactory,
-               Map<String, Object> properties) {
+               Supplier<Map<String, ?>> properties) {
 
                super((bundleContext, op) -> {
                        ServiceRegistration<?> serviceRegistration =
                                bundleContext.registerService(
-                                       clazz, serviceFactory, 
getProperties(properties));
+                                       clazz, serviceFactory,
+                                       getProperties(properties.get()));
 
                        return 
getServiceRegistrationOSGiResult(serviceRegistration, op);
                });
        }
 
        public ServiceRegistrationOSGiImpl(
-               String[] clazz, Object service, Map<String, ?> properties) {
+               String[] clazz, Supplier<Object> service,
+               Supplier<Map<String, ?>> properties) {
 
                super((bundleContext, op) -> {
                        ServiceRegistration<?> serviceRegistration =
                                bundleContext.registerService(
-                                       clazz, service, new 
Hashtable<>(properties));
+                                       clazz, service, new 
Hashtable<>(properties.get()));
 
                        return 
getServiceRegistrationOSGiResult(serviceRegistration, op);
                });
        }
 
        private static Hashtable<String, Object> getProperties(
-               Map<String, Object> properties) {
+               Map<String, ?> properties) {
 
                if (properties == null) {
                        return new Hashtable<>();


Reply via email to