vancetang / reflections

Automatically exported from code.google.com/p/reflections
Do What The F*ck You Want To Public License
0 stars 0 forks source link

Patch -- Gae/J Executors ConfigurationBuilder method #54

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago

Index: reflections/src/main/java/org/reflections/Reflections.java
===================================================================
--- reflections/src/main/java/org/reflections/Reflections.java  (revision 102)
+++ reflections/src/main/java/org/reflections/Reflections.java  (working copy)
@@ -127,7 +127,13 @@

         long time = System.currentTimeMillis();

-        ExecutorService executorService = 
configuration.getExecutorServiceSupplier().get();
+        ExecutorService executorService = null;
+        try {      
Class.forName("com.google.appengine.api.datastore.DatastoreService");
+        } catch (ClassNotFoundException e) {
+            configuration.getExecutorServiceSupplier().get();
+        }
         List<Future<?>> futures = Lists.newArrayList();
         try {
             for (URL url : configuration.getUrls()) {
@@ -140,7 +146,7 @@
                 }

                 for (final Vfs.File file : files) {
-                    Future<?> future = executorService.submit(new Runnable() {
+                    final Runnable runnable = new Runnable() {
                         public void run() {
                             String input = file.getRelativePath().replace('/', '.');
                             if (configuration.acceptsInput(input)) {
@@ -151,13 +157,16 @@
                                 }
                             }
                         }
-                    });
-                    futures.add(future);
+                    };
+                    if(executorService!=null){
+                        Future<?> future = executorService.submit(runnable);
+                        futures.add(future);
+                    }   else runnable.run();
                 }
             }
         } finally {
             //todo use CompletionService
-            for (Future future : futures) {
+           if(null != executorService){ for (Future future : futures) {
                 try {
                     future.get();
                 } catch (InterruptedException e) {
@@ -166,7 +175,7 @@
                     throw new RuntimeException(e);
                 }
             }
-            executorService.shutdown();
+            executorService.shutdown();}
         }

         time = System.currentTimeMillis() - time;

Original issue reported on code.google.com by northrup...@gmail.com on 3 Sep 2010 at 9:04

GoogleCodeExporter commented 9 years ago
this patch checks for a Datastore which would be present in a GAE/J project 
classpath, and avoids the nasty business of GAE/J thread limitations

without this patch the lines patched would generally be where you would find 
Exceptions due to executor usage if you were running under the Appengine 
Classloader. 

Original comment by northrup...@gmail.com on 3 Sep 2010 at 9:06

GoogleCodeExporter commented 9 years ago
no way :)

Original comment by ronm...@gmail.com on 30 Aug 2011 at 11:45

GoogleCodeExporter commented 9 years ago
Is there a particular reason this won't be fixed?  We're using reflections over 
at gwt-validation and would really like to increase the GAE interoperability 
because, well, it's GWT and people like to use GWT/GAE.

Original comment by chris.ru...@gmail.com on 16 Jan 2012 at 10:21