Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Removed SISU use, since this lib is so simple, there was no actual ne…

…ed for it. A plain old java lib, that is what we became now.
  • Loading branch information...
commit ff46393befcfd548eb2a29b2d189373a9a6b9ae4 1 parent d1f736a
Tamas Cservenak authored August 17, 2011
15  pom.xml
@@ -41,21 +41,6 @@
41 41
       <optional>true</optional>
42 42
     </dependency>
43 43
 
44  
-    <!-- SISU -->
45  
-    <dependency>
46  
-      <groupId>org.sonatype.sisu</groupId>
47  
-      <artifactId>sisu-inject-bean</artifactId>
48  
-    </dependency>
49  
-    <dependency>
50  
-      <groupId>org.sonatype.sisu</groupId>
51  
-      <artifactId>sisu-guice</artifactId>
52  
-      <classifier>no_aop</classifier>
53  
-    </dependency>
54  
-    <dependency>
55  
-      <groupId>javax.inject</groupId>
56  
-      <artifactId>javax.inject</artifactId>
57  
-    </dependency>
58  
-
59 44
     <!-- logging -->
60 45
     <dependency>
61 46
       <groupId>org.slf4j</groupId>
15  src/main/java/org/sonatype/sisu/charger/internal/DefaultCharger.java
@@ -3,19 +3,19 @@
3 3
 import java.util.List;
4 4
 import java.util.concurrent.Callable;
5 5
 
6  
-import javax.inject.Named;
7  
-import javax.inject.Singleton;
8  
-
  6
+import org.sonatype.sisu.charger.CallableExecutor;
9 7
 import org.sonatype.sisu.charger.ChargeFuture;
10 8
 import org.sonatype.sisu.charger.ChargeStrategy;
11 9
 import org.sonatype.sisu.charger.Charger;
12 10
 import org.sonatype.sisu.charger.ExceptionHandler;
13  
-import org.sonatype.sisu.charger.CallableExecutor;
14 11
 
15 12
 import com.google.common.base.Preconditions;
16 13
 
17  
-@Singleton
18  
-@Named
  14
+/**
  15
+ * A default implementation of Charger.
  16
+ * 
  17
+ * @author cstamas
  18
+ */
19 19
 public class DefaultCharger
20 20
     implements Charger
21 21
 {
@@ -36,8 +36,7 @@
36 36
     }
37 37
 
38 38
     public <E> ChargeFuture<E> submit( final List<Callable<E>> callables, final ExceptionHandler exceptionHandler,
39  
-                                       final ChargeStrategy<E> strategy,
40  
-                                       final CallableExecutor executorServiceProvider )
  39
+                                       final ChargeStrategy<E> strategy, final CallableExecutor executorServiceProvider )
41 40
     {
42 41
         Preconditions.checkNotNull( callables );
43 42
 
11  src/main/java/org/sonatype/sisu/charger/shiro/DefaultShiroAwareCharger.java
... ...
@@ -1,15 +1,16 @@
1 1
 package org.sonatype.sisu.charger.shiro;
2 2
 
3  
-import javax.inject.Named;
4  
-import javax.inject.Singleton;
5  
-
6 3
 import org.apache.shiro.SecurityUtils;
7 4
 import org.sonatype.sisu.charger.ChargeStrategy;
8 5
 import org.sonatype.sisu.charger.internal.Charge;
9 6
 import org.sonatype.sisu.charger.internal.DefaultCharger;
10 7
 
11  
-@Singleton
12  
-@Named( "shiro" )
  8
+/**
  9
+ * A Charger implementation that is capable of running in Shiro-enabled environment, and will execute the Callables
  10
+ * under same realm as invoker thread is.
  11
+ * 
  12
+ * @author cstamas
  13
+ */
13 14
 public class DefaultShiroAwareCharger
14 15
     extends DefaultCharger
15 16
 {
52  src/test/java/org/sonatype/sisu/charger/ChargerTest.java
@@ -16,28 +16,38 @@
16 16
 import java.util.concurrent.TimeUnit;
17 17
 
18 18
 import org.hamcrest.Matchers;
  19
+import org.junit.After;
  20
+import org.junit.Before;
19 21
 import org.junit.Test;
20  
-import org.sonatype.guice.bean.containers.InjectedTestCase;
21 22
 import org.sonatype.sisu.charger.internal.AllArrivedChargeStrategy;
  23
+import org.sonatype.sisu.charger.internal.DefaultCharger;
22 24
 import org.sonatype.sisu.charger.internal.FirstArrivedChargeStrategy;
23 25
 import org.sonatype.sisu.charger.internal.FirstArrivedInOrderChargeStrategy;
24 26
 
25 27
 public class ChargerTest
26  
-    extends InjectedTestCase
27 28
 {
28  
-    private final CallableExecutor executorServiceProvider;
  29
+    private SimpleCallableExecutor executorServiceProvider;
29 30
 
30  
-    public ChargerTest()
  31
+    private Charger charger;
  32
+
  33
+    @Before
  34
+    public void before()
31 35
     {
32 36
         this.executorServiceProvider = new SimpleCallableExecutor();
  37
+
  38
+        this.charger = new DefaultCharger();
  39
+    }
  40
+
  41
+    @After
  42
+    public void after()
  43
+    {
  44
+        this.executorServiceProvider.shutdown();
33 45
     }
34 46
 
35 47
     @Test
36 48
     public void testSimple()
37 49
         throws Exception
38 50
     {
39  
-        Charger charger = lookup( Charger.class );
40  
-
41 51
         List<Callable<String>> callables = new ArrayList<Callable<String>>();
42 52
 
43 53
         callables.add( new HelloCallable( "Jason" ) );
@@ -55,8 +65,6 @@ public void testSimple()
55 65
     public void testEmptyAllArrivedChargeStrategy()
56 66
         throws Exception
57 67
     {
58  
-        Charger charger = lookup( Charger.class );
59  
-
60 68
         List<Callable<String>> callables = new ArrayList<Callable<String>>();
61 69
 
62 70
         ChargeFuture<String> cf =
@@ -71,8 +79,6 @@ public void testEmptyAllArrivedChargeStrategy()
71 79
     public void testEmptyFirstArrivedChargeStrategy()
72 80
         throws Exception
73 81
     {
74  
-        Charger charger = lookup( Charger.class );
75  
-
76 82
         List<Callable<String>> callables = new ArrayList<Callable<String>>();
77 83
 
78 84
         ChargeFuture<String> cf =
@@ -87,8 +93,6 @@ public void testEmptyFirstArrivedChargeStrategy()
87 93
     public void testEmptyFirstArrivedInOrderChargeStrategy()
88 94
         throws Exception
89 95
     {
90  
-        Charger charger = lookup( Charger.class );
91  
-
92 96
         List<Callable<String>> callables = new ArrayList<Callable<String>>();
93 97
 
94 98
         ChargeFuture<String> cf =
@@ -103,8 +107,6 @@ public void testEmptyFirstArrivedInOrderChargeStrategy()
103 107
     public void testBailingOut()
104 108
         throws Exception
105 109
     {
106  
-        Charger charger = lookup( Charger.class );
107  
-
108 110
         List<Callable<String>> callables = new ArrayList<Callable<String>>();
109 111
 
110 112
         callables.add( new BailingOutCallable<String>( true ) );
@@ -124,8 +126,6 @@ public void testBailingOut()
124 126
     public void testFailing()
125 127
         throws Exception
126 128
     {
127  
-        Charger charger = lookup( Charger.class );
128  
-
129 129
         List<Callable<String>> callables = new ArrayList<Callable<String>>();
130 130
 
131 131
         callables.add( new FailingCallable<String>( new IOException( "I failed!" ) ) );
@@ -152,8 +152,6 @@ public void testFailing()
152 152
     public void testFailingWithHanderHandlingIt()
153 153
         throws Exception
154 154
     {
155  
-        Charger charger = lookup( Charger.class );
156  
-
157 155
         List<Callable<String>> callables = new ArrayList<Callable<String>>();
158 156
 
159 157
         final SimpleExceptionHandler simpleExceptionHandler = new SimpleExceptionHandler( IOException.class );
@@ -185,8 +183,6 @@ public void testFailingWithHanderHandlingIt()
185 183
     public void testFailingWithHanderHandlingItWithError()
186 184
         throws Exception
187 185
     {
188  
-        Charger charger = lookup( Charger.class );
189  
-
190 186
         List<Callable<String>> callables = new ArrayList<Callable<String>>();
191 187
 
192 188
         final SimpleExceptionHandler simpleExceptionHandler = new SimpleExceptionHandler( IOException.class );
@@ -217,8 +213,6 @@ public void testFailingWithHanderHandlingItWithError()
217 213
     public void testFirstArrivedInOrderStrategyAllFineAndDandy()
218 214
         throws Exception
219 215
     {
220  
-        Charger charger = lookup( Charger.class );
221  
-
222 216
         List<Callable<String>> callables = new ArrayList<Callable<String>>();
223 217
 
224 218
         callables.add( new HelloCallable( "Tinkler" ) );
@@ -238,8 +232,6 @@ public void testFirstArrivedInOrderStrategyAllFineAndDandy()
238 232
     public void testFirstArrivedInOrderStrategyAllFineAndDandyButTasksFinishInOppositeOrder()
239 233
         throws Exception
240 234
     {
241  
-        Charger charger = lookup( Charger.class );
242  
-
243 235
         List<Callable<String>> callables = new ArrayList<Callable<String>>();
244 236
 
245 237
         callables.add( new SleepingWrapperCallable<String>( 2000, new HelloCallable( "Tinkler" ) ) );
@@ -271,8 +263,6 @@ public void testFirstArrivedInOrderStrategyAllFineAndDandyButTasksFinishInOpposi
271 263
     public void testAllArrivedStrategyAllFineAndDandyButTasksFinishInOppositeOrder()
272 264
         throws Exception
273 265
     {
274  
-        Charger charger = lookup( Charger.class );
275  
-
276 266
         List<Callable<String>> callables = new ArrayList<Callable<String>>();
277 267
 
278 268
         callables.add( new SleepingWrapperCallable<String>( 2000, new HelloCallable( "Tinkler" ) ) );
@@ -304,8 +294,6 @@ public void testAllArrivedStrategyAllFineAndDandyButTasksFinishInOppositeOrder()
304 294
     public void testFirstArrivedInOrderStrategyAllFineAndDandyButTasksFinishInOppositeOrderWithHandledErrors()
305 295
         throws Exception
306 296
     {
307  
-        Charger charger = lookup( Charger.class );
308  
-
309 297
         List<Callable<String>> callables = new ArrayList<Callable<String>>();
310 298
 
311 299
         // this will decide to bail out after 1 seconds
@@ -347,8 +335,6 @@ public void testFirstArrivedInOrderStrategyAllFineAndDandyButTasksFinishInOpposi
347 335
     public void testFirstArrivedInOrderStrategyAllFineAndDandyButTasksFinishInOppositeOrderWithNotHandledErrors()
348 336
         throws Exception
349 337
     {
350  
-        Charger charger = lookup( Charger.class );
351  
-
352 338
         List<Callable<String>> callables = new ArrayList<Callable<String>>();
353 339
 
354 340
         // this will decide to bail out after 1 seconds
@@ -403,8 +389,6 @@ public void testFirstArrivedInOrderStrategyAllFineAndDandyButTasksFinishInOpposi
403 389
     public void testFirstArrivedStrategyLastCallableSucceedsFirst()
404 390
         throws Exception
405 391
     {
406  
-        Charger charger = lookup( Charger.class );
407  
-
408 392
         List<Callable<String>> callables = new ArrayList<Callable<String>>();
409 393
         callables.add( new SleepingWrapperCallable<String>( 8000, new HelloCallable( "Sleepy" ) ) );
410 394
         callables.add( new SleepingWrapperCallable<String>( 4000, new HelloCallable( "Grumpy" ) ) );
@@ -427,8 +411,6 @@ public void testFirstArrivedStrategyLastCallableSucceedsFirst()
427 411
     public void testFirstArrivedStrategyCallableAlreadyDoneOnFirstCheck()
428 412
         throws Exception
429 413
     {
430  
-        Charger charger = lookup( Charger.class );
431  
-
432 414
         List<Callable<String>> callables = new ArrayList<Callable<String>>();
433 415
         callables.add( new SleepingWrapperCallable<String>( 8000, new HelloCallable( "Sleepy" ) ) );
434 416
         callables.add( new SleepingWrapperCallable<String>( 4000, new HelloCallable( "Grumpy" ) ) );
@@ -453,8 +435,6 @@ public void testFirstArrivedStrategyCallableAlreadyDoneOnFirstCheck()
453 435
     @Test
454 436
     public void testOverload()
455 437
     {
456  
-        Charger charger = lookup( Charger.class );
457  
-
458 438
         List<Callable<String>> callables = new ArrayList<Callable<String>>();
459 439
         for ( int i = 0; i < 10; i++ )
460 440
         {
5  src/test/java/org/sonatype/sisu/charger/SimpleCallableExecutor.java
@@ -20,4 +20,9 @@ public SimpleCallableExecutor()
20 20
     {
21 21
         return executorService.submit( task );
22 22
     }
  23
+    
  24
+    public void shutdown()
  25
+    {
  26
+        executorService.shutdownNow();
  27
+    }
23 28
 }

0 notes on commit ff46393

Please sign in to comment.
Something went wrong with that request. Please try again.