本文整理了Java中java.util.concurrent.atomic.AtomicReference.<init>()
方法的一些代码示例,展示了AtomicReference.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AtomicReference.<init>()
方法的具体详情如下:
包路径:java.util.concurrent.atomic.AtomicReference
类名称:AtomicReference
方法名:<init>
[英]Creates a new AtomicReference with null initial value.
[中]创建初始值为null的新AtomicReference。
代码示例来源:origin: spring-projects/spring-framework
@Override
protected boolean canConvertTo(Object payload, @Nullable MessageHeaders headers) {
if (!supportsMimeType(headers)) {
return false;
}
AtomicReference<Throwable> causeRef = new AtomicReference<>();
if (this.objectMapper.canSerialize(payload.getClass(), causeRef)) {
return true;
}
logWarningIfNecessary(payload.getClass(), causeRef.get());
return false;
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public boolean canWrite(Class<?> clazz, @Nullable MediaType mediaType) {
if (!canWrite(mediaType)) {
return false;
}
AtomicReference<Throwable> causeRef = new AtomicReference<>();
if (this.objectMapper.canSerialize(clazz, causeRef)) {
return true;
}
logWarningIfNecessary(clazz, causeRef.get());
return false;
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public boolean canRead(Type type, @Nullable Class<?> contextClass, @Nullable MediaType mediaType) {
if (!canRead(mediaType)) {
return false;
}
JavaType javaType = getJavaType(type, contextClass);
AtomicReference<Throwable> causeRef = new AtomicReference<>();
if (this.objectMapper.canDeserialize(javaType, causeRef)) {
return true;
}
logWarningIfNecessary(javaType, causeRef.get());
return false;
}
代码示例来源:origin: spring-projects/spring-framework
@Override
protected boolean canConvertFrom(Message<?> message, @Nullable Class<?> targetClass) {
if (targetClass == null || !supportsMimeType(message.getHeaders())) {
return false;
}
JavaType javaType = this.objectMapper.constructType(targetClass);
AtomicReference<Throwable> causeRef = new AtomicReference<>();
if (this.objectMapper.canDeserialize(javaType, causeRef)) {
return true;
}
logWarningIfNecessary(javaType, causeRef.get());
return false;
}
代码示例来源:origin: spring-projects/spring-framework
private ServerHttpRequest adaptFromForwardedHeaders(MockServerHttpRequest.BaseBuilder<?> builder) {
AtomicReference<ServerHttpRequest> requestRef = new AtomicReference<>();
MockServerWebExchange exchange = MockServerWebExchange.from(builder);
new ForwardedHeaderFilter().filter(exchange, exchange2 -> {
requestRef.set(exchange2.getRequest());
return Mono.empty();
}).block();
return requestRef.get();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testHelloWorld2() {
final AtomicReference<String> v = new AtomicReference<String>();
Single.just("Hello World!").subscribe(new SingleObserver<String>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onSuccess(String value) {
v.set(value);
}
@Override
public void onError(Throwable error) {
}
});
assertEquals("Hello World!", v.get());
}
代码示例来源:origin: ReactiveX/RxJava
@Test(timeout = 6000)
public void schedulePeriodicallyDirectDecoratesRunnable() throws InterruptedException {
final Scheduler scheduler = getScheduler();
if (scheduler instanceof TrampolineScheduler) {
// Can't properly stop a trampolined periodic task.
return;
}
final AtomicReference<Disposable> disposable = new AtomicReference<Disposable>();
try {
assertRunnableDecorated(new Runnable() {
@Override
public void run() {
disposable.set(scheduler.schedulePeriodicallyDirect(Functions.EMPTY_RUNNABLE, 1, 10000, TimeUnit.MILLISECONDS));
}
});
} finally {
disposable.get().dispose();
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void success() {
String expected = "one";
AtomicReference<Object> actual = new AtomicReference<>();
ListenableFuture<String> future = new MonoToListenableFutureAdapter<>(Mono.just(expected));
future.addCallback(actual::set, actual::set);
assertEquals(expected, actual.get());
}
代码示例来源:origin: ReactiveX/RxJava
@Test(timeout = 5000)
public void subscribeTwoCallbacksNormal() {
final AtomicReference<Throwable> err = new AtomicReference<Throwable>();
final AtomicBoolean complete = new AtomicBoolean();
normal.completable.subscribe(new Action() {
@Override
public void run() {
complete.set(true);
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable e) {
err.set(e);
}
});
Assert.assertNull(err.get());
Assert.assertTrue("Not completed", complete.get());
}
代码示例来源:origin: ReactiveX/RxJava
@Test(timeout = 5000)
public void subscribeTwoCallbacksError() {
final AtomicReference<Throwable> err = new AtomicReference<Throwable>();
final AtomicBoolean complete = new AtomicBoolean();
error.completable.subscribe(new Action() {
@Override
public void run() {
complete.set(true);
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable e) {
err.set(e);
}
});
Assert.assertTrue(err.get() instanceof TestException);
Assert.assertFalse("Not completed", complete.get());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testDoOnEach() {
final AtomicReference<String> r = new AtomicReference<String>();
String output = Observable.just("one").doOnNext(new Consumer<String>() {
@Override
public void accept(String v) {
r.set(v);
}
}).blockingSingle();
assertEquals("one", output);
assertEquals("one", r.get());
}
代码示例来源:origin: ReactiveX/RxJava
@Test(timeout = 5000)
public void doOnErrorNoError() {
final AtomicReference<Throwable> error = new AtomicReference<Throwable>();
Completable c = normal.completable.doOnError(new Consumer<Throwable>() {
@Override
public void accept(Throwable e) {
error.set(e);
}
});
c.blockingAwait();
Assert.assertNull(error.get());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void failure() {
Throwable expected = new IllegalStateException("oops");
AtomicReference<Object> actual = new AtomicReference<>();
ListenableFuture<String> future = new MonoToListenableFutureAdapter<>(Mono.error(expected));
future.addCallback(actual::set, actual::set);
assertEquals(expected, actual.get());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testOnErrorCalledOnScheduler() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Thread> thread = new AtomicReference<Thread>();
Observable.<String>error(new Exception())
.delay(0, TimeUnit.MILLISECONDS, Schedulers.newThread())
.doOnError(new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
thread.set(Thread.currentThread());
latch.countDown();
}
})
.onErrorResumeNext(Observable.<String>empty())
.subscribe();
latch.await();
assertNotEquals(Thread.currentThread(), thread.get());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testOnErrorCalledOnScheduler() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Thread> thread = new AtomicReference<Thread>();
Single.<String>error(new Exception())
.delay(0, TimeUnit.MILLISECONDS, Schedulers.newThread())
.doOnError(new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
thread.set(Thread.currentThread());
latch.countDown();
}
})
.onErrorResumeNext(Single.just(""))
.subscribe();
latch.await();
assertNotEquals(Thread.currentThread(), thread.get());
}
代码示例来源:origin: ReactiveX/RxJava
@Test(timeout = 5000)
public void subscribeOnNormal() {
final AtomicReference<String> name = new AtomicReference<String>();
Completable c = Completable.unsafeCreate(new CompletableSource() {
@Override
public void subscribe(CompletableObserver observer) {
name.set(Thread.currentThread().getName());
EmptyDisposable.complete(observer);
}
}).subscribeOn(Schedulers.computation());
c.blockingAwait();
Assert.assertTrue(name.get().startsWith("RxComputation"));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testOnErrorCalledOnScheduler() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Thread> thread = new AtomicReference<Thread>();
Completable.error(new Exception())
.delay(0, TimeUnit.MILLISECONDS, Schedulers.newThread())
.doOnError(new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
thread.set(Thread.currentThread());
latch.countDown();
}
})
.onErrorComplete()
.subscribe();
latch.await();
assertNotEquals(Thread.currentThread(), thread.get());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void onCompleteFailure() {
AtomicReference<Throwable> onError = new AtomicReference<Throwable>();
try {
OBSERVER_ONCOMPLETED_FAIL(onError).onComplete();
fail("expects exception to be thrown");
} catch (Exception e) {
assertNull(onError.get());
assertTrue(e instanceof SafeObserverTestException);
assertEquals("onCompleteFail", e.getMessage());
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void onCompleteFailure() {
AtomicReference<Throwable> onError = new AtomicReference<Throwable>();
try {
OBSERVER_ONCOMPLETED_FAIL(onError).onComplete();
fail("expects exception to be thrown");
} catch (Exception e) {
assertNull(onError.get());
assertTrue(e instanceof SafeSubscriberTestException);
assertEquals("onCompleteFail", e.getMessage());
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void onNextFailure() {
AtomicReference<Throwable> onError = new AtomicReference<Throwable>();
try {
OBSERVER_ONNEXT_FAIL(onError).onNext("one");
fail("expects exception to be thrown");
} catch (Exception e) {
assertNull(onError.get());
assertTrue(e instanceof SafeObserverTestException);
assertEquals("onNextFail", e.getMessage());
}
}
内容来源于网络,如有侵权,请联系作者删除!