Skip to content

Commit 75ba2f1

Browse files
Remove SLF4J dependency
1 parent 00ddac9 commit 75ba2f1

3 files changed

Lines changed: 83 additions & 15 deletions

File tree

rxjava-core/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ sourceCompatibility = JavaVersion.VERSION_1_6
77
targetCompatibility = JavaVersion.VERSION_1_6
88

99
dependencies {
10-
compile 'org.slf4j:slf4j-api:1.7.0'
1110
provided 'junit:junit-dep:4.10'
1211
provided 'org.mockito:mockito-core:1.8.5'
1312
}

rxjava-core/src/main/java/rx/subscriptions/CompositeSubscription.java

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,19 @@
1515
*/
1616
package rx.subscriptions;
1717

18+
import static org.junit.Assert.*;
19+
20+
import java.util.ArrayList;
21+
import java.util.Collection;
1822
import java.util.List;
1923
import java.util.concurrent.ConcurrentLinkedQueue;
2024
import java.util.concurrent.atomic.AtomicBoolean;
25+
import java.util.concurrent.atomic.AtomicInteger;
2126

22-
import org.slf4j.Logger;
23-
import org.slf4j.LoggerFactory;
27+
import org.junit.Test;
2428

2529
import rx.Subscription;
26-
import rx.util.functions.Functions;
30+
import rx.util.CompositeException;
2731

2832
/**
2933
* Subscription that represents a group of Subscriptions that are unsubscribed together.
@@ -32,8 +36,6 @@
3236
*/
3337
public class CompositeSubscription implements Subscription {
3438

35-
private static final Logger logger = LoggerFactory.getLogger(Functions.class);
36-
3739
/*
3840
* The reason 'synchronized' is used on 'add' and 'unsubscribe' is because AtomicBoolean/ConcurrentLinkedQueue are both being modified so it needs to be done atomically.
3941
*
@@ -67,13 +69,80 @@ public synchronized void add(Subscription s) {
6769
@Override
6870
public synchronized void unsubscribe() {
6971
if (unsubscribed.compareAndSet(false, true)) {
72+
Collection<Exception> es = null;
7073
for (Subscription s : subscriptions) {
7174
try {
7275
s.unsubscribe();
7376
} catch (Exception e) {
74-
logger.error("Failed to unsubscribe.", e);
77+
if (es == null) {
78+
es = new ArrayList<Exception>();
79+
}
80+
es.add(e);
7581
}
7682
}
83+
if (es != null) {
84+
throw new CompositeException("Failed to unsubscribe to 1 or more subscriptions.", es);
85+
}
86+
}
87+
}
88+
89+
public static class UnitTest {
90+
91+
@Test
92+
public void testSuccess() {
93+
final AtomicInteger counter = new AtomicInteger();
94+
CompositeSubscription s = new CompositeSubscription();
95+
s.add(new Subscription() {
96+
97+
@Override
98+
public void unsubscribe() {
99+
counter.incrementAndGet();
100+
}
101+
});
102+
103+
s.add(new Subscription() {
104+
105+
@Override
106+
public void unsubscribe() {
107+
counter.incrementAndGet();
108+
}
109+
});
110+
111+
s.unsubscribe();
112+
113+
assertEquals(2, counter.get());
114+
}
115+
116+
@Test
117+
public void testException() {
118+
final AtomicInteger counter = new AtomicInteger();
119+
CompositeSubscription s = new CompositeSubscription();
120+
s.add(new Subscription() {
121+
122+
@Override
123+
public void unsubscribe() {
124+
throw new RuntimeException("failed on first one");
125+
}
126+
});
127+
128+
s.add(new Subscription() {
129+
130+
@Override
131+
public void unsubscribe() {
132+
counter.incrementAndGet();
133+
}
134+
});
135+
136+
try {
137+
s.unsubscribe();
138+
fail("Expecting an exception");
139+
} catch (CompositeException e) {
140+
// we expect this
141+
assertEquals(1, e.getExceptions().size());
142+
}
143+
144+
// we should still have unsubscribed to the second one
145+
assertEquals(1, counter.get());
77146
}
78147
}
79148

rxjava-core/src/main/java/rx/util/functions/Functions.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
import java.util.Collection;
1919
import java.util.concurrent.ConcurrentHashMap;
2020

21-
import org.slf4j.Logger;
22-
import org.slf4j.LoggerFactory;
23-
2421
/**
2522
* Allows execution of functions from multiple different languages.
2623
* <p>
@@ -30,8 +27,6 @@
3027
*/
3128
public class Functions {
3229

33-
private static final Logger logger = LoggerFactory.getLogger(Functions.class);
34-
3530
private final static ConcurrentHashMap<Class<?>, FunctionLanguageAdaptor> languageAdaptors = new ConcurrentHashMap<Class<?>, FunctionLanguageAdaptor>();
3631

3732
static {
@@ -49,12 +44,17 @@ private static boolean loadLanguageAdaptor(String name) {
4944
Class<?> c = Class.forName(className);
5045
FunctionLanguageAdaptor a = (FunctionLanguageAdaptor) c.newInstance();
5146
registerLanguageAdaptor(a.getFunctionClass(), a);
52-
logger.info("Successfully loaded function language adaptor: " + name + " with path: " + className);
47+
/*
48+
* Using System.err/System.out as this is the only place in the library where we do logging and it's only at startup.
49+
* I don't want to include SL4J/Log4j just for this and no one uses Java Logging.
50+
*/
51+
System.out.println("RxJava => Successfully loaded function language adaptor: " + name + " with path: " + className);
5352
} catch (ClassNotFoundException e) {
54-
logger.info("Could not find function language adaptor: " + name + " with path: " + className);
53+
System.err.println("RxJava => Could not find function language adaptor: " + name + " with path: " + className);
5554
return false;
5655
} catch (Exception e) {
57-
logger.error("Failed trying to initialize function language adaptor: " + className, e);
56+
System.err.println("RxJava => Failed trying to initialize function language adaptor: " + className);
57+
e.printStackTrace();
5858
return false;
5959
}
6060
return true;

0 commit comments

Comments
 (0)