deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject [1/2] git commit: DELTASPIKE-474 deactivatable services
Date Fri, 20 Dec 2013 14:50:36 GMT
Updated Branches:
  refs/heads/master 3b6277460 -> edbdaa8e6


DELTASPIKE-474 deactivatable services


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/f216f036
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/f216f036
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/f216f036

Branch: refs/heads/master
Commit: f216f03671a16520be543597a8b48862cfd37c57
Parents: 3b62774
Author: gpetracek <gpetracek@apache.org>
Authored: Fri Dec 20 14:45:15 2013 +0100
Committer: gpetracek <gpetracek@apache.org>
Committed: Fri Dec 20 15:01:47 2013 +0100

----------------------------------------------------------------------
 .../deltaspike/core/util/ServiceUtils.java      | 36 +++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/f216f036/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ServiceUtils.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ServiceUtils.java
b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ServiceUtils.java
index 0c1b994..92fa6c4 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ServiceUtils.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ServiceUtils.java
@@ -18,11 +18,14 @@
  */
 package org.apache.deltaspike.core.util;
 
+import org.apache.deltaspike.core.spi.activation.Deactivatable;
+
 import javax.enterprise.inject.Typed;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.ServiceLoader;
+import java.util.logging.Logger;
 
 /**
  * Allows handling the lookup (with fallbacks) in a central place.
@@ -31,6 +34,8 @@ import java.util.ServiceLoader;
 @Typed()
 public abstract class ServiceUtils
 {
+    private static final Logger LOG = Logger.getLogger(ServiceUtils.class.getName());
+
     private ServiceUtils()
     {
         // prevent instantiation
@@ -38,6 +43,12 @@ public abstract class ServiceUtils
 
     public static <T> List<T> loadServiceImplementations(Class<T> serviceType)
     {
+        return loadServiceImplementations(serviceType, false);
+    }
+
+    public static <T> List<T> loadServiceImplementations(Class<T> serviceType,
+                                                         boolean ignoreServicesWithMissingDependencies)
+    {
         List<T> result = new ArrayList<T>();
 
         Iterator<T> servicesIterator = ServiceLoader.load(serviceType).iterator();
@@ -50,7 +61,30 @@ public abstract class ServiceUtils
 
         while (servicesIterator.hasNext())
         {
-            result.add(servicesIterator.next());
+            try
+            {
+                T service = servicesIterator.next();
+
+                if (service instanceof Deactivatable &&
+                        !ClassDeactivationUtils.isActivated((Class<? extends Deactivatable>)
service.getClass()))
+                {
+                    LOG.info("deactivated service: " + service.getClass().getName());
+
+                    continue;
+                }
+                result.add(service);
+            }
+            catch (Throwable t)
+            {
+                if (!ignoreServicesWithMissingDependencies)
+                {
+                    throw ExceptionUtils.throwAsRuntimeException(t);
+                }
+                else
+                {
+                    LOG.info("service filtered - caused by " + t.getMessage());
+                }
+            }
         }
         return result;
     }


Mime
View raw message