当前位置: 首页>>代码示例>>Java>>正文


Java AtomicReference类代码示例

本文整理汇总了Java中java.util.concurrent.atomic.AtomicReference的典型用法代码示例。如果您正苦于以下问题:Java AtomicReference类的具体用法?Java AtomicReference怎么用?Java AtomicReference使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AtomicReference类属于java.util.concurrent.atomic包,在下文中一共展示了AtomicReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resultThrowingInOnSuccessDeliveredToPlugin

import java.util.concurrent.atomic.AtomicReference; //导入依赖的package包/类
@Test public void resultThrowingInOnSuccessDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!throwableRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable);
      }
    }
  });

  RecordingMaybeObserver<Result<String>> observer = subscriberRule.create();
  final RuntimeException e = new RuntimeException();
  service.result().subscribe(new ForwardingObserver<Result<String>>(observer) {
    @Override public void onSuccess(Result<String> value) {
      throw e;
    }
  });

  assertThat(throwableRef.get()).isSameAs(e);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:MaybeThrowingTest.java

示例2: FilteredClassPathImplementation

import java.util.concurrent.atomic.AtomicReference; //导入依赖的package包/类
FilteredClassPathImplementation(
    @NonNull final ClassPathImplementation delegate,
    @NonNull final AntProjectHelper helper,
    @NonNull final PropertyEvaluator eval,
    @NonNull final String filteredProp) {
    Parameters.notNull("delegate", delegate);   //NOI18N
    Parameters.notNull("helper", helper);       //NOI18N
    Parameters.notNull("eval", eval);   //NOI18N
    Parameters.notNull("filteredProp", filteredProp);   //NOI18N
    this.delegate = delegate;
    this.helper = helper;
    this.eval = eval;
    this.filteredProp = filteredProp;
    this.cache = new AtomicReference<List<PathResourceImplementation>>();
    this.listeners = new PropertyChangeSupport(this);
    this.delegate.addPropertyChangeListener(WeakListeners.propertyChange(this, this.delegate));
    this.eval.addPropertyChangeListener(WeakListeners.propertyChange(this, this.eval));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:ClassPathProviderImpl.java

示例3: singleElementOperatorDoNotSwallowExceptionWhenDone

import java.util.concurrent.atomic.AtomicReference; //导入依赖的package包/类
@Test
public void singleElementOperatorDoNotSwallowExceptionWhenDone() {
    final Throwable exception = new RuntimeException("some error");
    final AtomicReference<Throwable> error = new AtomicReference<Throwable>();

    try {
        RxJavaCommonPlugins.setErrorHandler(new Consumer<Throwable>() {
            @Override public void accept(final Throwable throwable) throws Exception {
                error.set(throwable);
            }
        });

        Observable.unsafeCreate(new ObservableSource<Integer>() {
            @Override public void subscribe(final Observer<? super Integer> observer) {
                observer.onComplete();
                observer.onError(exception);
            }
        }).singleElement().test().assertComplete();

        assertSame(exception, error.get().getCause());
    } finally {
        RxJavaCommonPlugins.reset();
    }
}
 
开发者ID:akarnokd,项目名称:RxJava3-preview,代码行数:25,代码来源:ObservableSingleTest.java

示例4: responseThrowingInOnCompleteDeliveredToPlugin

import java.util.concurrent.atomic.AtomicReference; //导入依赖的package包/类
@Test public void responseThrowingInOnCompleteDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> pluginRef = new AtomicReference<>();
  RxJavaPlugins.getInstance().registerErrorHandler(new RxJavaErrorHandler() {
    @Override public void handleError(Throwable throwable) {
      if (!pluginRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable); // Don't swallow secondary errors!
      }
    }
  });

  RecordingSubscriber<Response<String>> observer = subscriberRule.create();
  final RuntimeException e = new RuntimeException();
  service.response().unsafeSubscribe(new ForwardingSubscriber<Response<String>>(observer) {
    @Override public void onCompleted() {
      throw e;
    }
  });

  observer.assertAnyValue();
  assertThat(pluginRef.get()).isSameAs(e);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:ObservableThrowingTest.java

示例5: getAttribute

import java.util.concurrent.atomic.AtomicReference; //导入依赖的package包/类
@Override
public Object getAttribute(final File file, final String attrName) {
    final AtomicReference<Object> value = new AtomicReference();
    for (BaseAnnotationProvider provider : annotationProviders) {
        final InterceptionListener iListener = (provider != null) ? provider.getInterceptionListener() : null;
        if (iListener instanceof ProvidedExtensions) {
            runCheckCode(new Runnable() {
                public void run() {
                    value.set(((ProvidedExtensions) iListener).getAttribute(file, attrName));
                }
            });
        }
        if (value.get() != null) {
           return value.get();
        }
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:ProvidedExtensionsProxy.java

示例6: Phaser

import java.util.concurrent.atomic.AtomicReference; //导入依赖的package包/类
/**
 * Creates a new phaser with the given parent and number of
 * registered unarrived parties.  When the given parent is non-null
 * and the given number of parties is greater than zero, this
 * child phaser is registered with its parent.
 *
 * @param parent the parent phaser
 * @param parties the number of parties required to advance to the
 * next phase
 * @throws IllegalArgumentException if parties less than zero
 * or greater than the maximum number of parties supported
 */
public Phaser(Phaser parent, int parties) {
    if (parties >>> PARTIES_SHIFT != 0)
        throw new IllegalArgumentException("Illegal number of parties");
    int phase = 0;
    this.parent = parent;
    if (parent != null) {
        final Phaser root = parent.root;
        this.root = root;
        this.evenQ = root.evenQ;
        this.oddQ = root.oddQ;
        if (parties != 0)
            phase = parent.doRegister(1);
    }
    else {
        this.root = this;
        this.evenQ = new AtomicReference<QNode>();
        this.oddQ = new AtomicReference<QNode>();
    }
    this.state = (parties == 0) ? (long)EMPTY :
        ((long)phase << PHASE_SHIFT) |
        ((long)parties << PARTIES_SHIFT) |
        ((long)parties);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:36,代码来源:Phaser.java

示例7: getUrlEmpty

import java.util.concurrent.atomic.AtomicReference; //导入依赖的package包/类
/**
 * Make a GET request with an empty body response
 *
 * @throws Exception
 */
@Test
public void getUrlEmpty() throws Exception {
  final AtomicReference<String> method = new AtomicReference<String>();
  handler = new RequestHandler() {

    @Override
    public void handle(Request request, HttpServletResponse response) {
      method.set(request.getMethod());
      response.setStatus(HTTP_OK);
    }
  };
  HttpRequest request = get(new URL(url));
  assertNotNull(request.getConnection());
  int code = request.code();
  assertTrue(request.ok());
  assertFalse(request.created());
  assertFalse(request.noContent());
  assertFalse(request.badRequest());
  assertFalse(request.serverError());
  assertFalse(request.notFound());
  assertEquals("GET", method.get());
  assertEquals("OK", request.message());
  assertEquals(HTTP_OK, code);
  assertEquals("", request.body());
}
 
开发者ID:junicorn,项目名称:NiuBi,代码行数:31,代码来源:HttpRequestTest.java

示例8: forEach

import java.util.concurrent.atomic.AtomicReference; //导入依赖的package包/类
public void forEach(final Action1<? super T> onNext) {
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicReference<Throwable> exceptionFromOnError = new AtomicReference();
    BlockingUtils.awaitForComplete(latch, this.o.subscribe(new Subscriber<T>() {
        public void onCompleted() {
            latch.countDown();
        }

        public void onError(Throwable e) {
            exceptionFromOnError.set(e);
            latch.countDown();
        }

        public void onNext(T args) {
            onNext.call(args);
        }
    }));
    if (exceptionFromOnError.get() == null) {
        return;
    }
    if (exceptionFromOnError.get() instanceof RuntimeException) {
        throw ((RuntimeException) exceptionFromOnError.get());
    }
    throw new RuntimeException((Throwable) exceptionFromOnError.get());
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:26,代码来源:BlockingObservable.java

示例9: getResource

import java.util.concurrent.atomic.AtomicReference; //导入依赖的package包/类
private <T extends IResource> T getResource(String name, Class<T> resourceClass) {
	final File fileCandidate = getFullPath().append(name).toFile();
	final AtomicReference<T> actualRef = new AtomicReference<>();
	if (fileCandidate.exists()) {
		acceptUnsafe(resource -> {
			if (resource instanceof IExternalResource && resourceClass.isAssignableFrom(resource.getClass())) {
				if (fileCandidate.equals(((IExternalResource) resource).getExternalResource())) {
					actualRef.set(resourceClass.cast(resource));
					return false;
				}
			}
			return true;
		});
	}

	return actualRef.get(); // TODO return with missing instance?
}
 
开发者ID:eclipse,项目名称:n4js,代码行数:18,代码来源:ExternalProject.java

示例10: resultThrowingInOnSuccessDeliveredToPlugin

import java.util.concurrent.atomic.AtomicReference; //导入依赖的package包/类
@Test public void resultThrowingInOnSuccessDeliveredToPlugin() {
  server.enqueue(new MockResponse());

  final AtomicReference<Throwable> throwableRef = new AtomicReference<>();
  RxJavaPlugins.setErrorHandler(new Consumer<Throwable>() {
    @Override public void accept(Throwable throwable) throws Exception {
      if (!throwableRef.compareAndSet(null, throwable)) {
        throw Exceptions.propagate(throwable);
      }
    }
  });

  RecordingSingleObserver<Result<String>> observer = subscriberRule.create();
  final RuntimeException e = new RuntimeException();
  service.result().subscribe(new ForwardingObserver<Result<String>>(observer) {
    @Override public void onSuccess(Result<String> value) {
      throw e;
    }
  });

  assertThat(throwableRef.get()).isSameAs(e);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:SingleThrowingTest.java

示例11: postWithNumericQueryParams

import java.util.concurrent.atomic.AtomicReference; //导入依赖的package包/类
/**
 * Verify POST with numeric query parameters
 *
 * @throws Exception
 */
@Test
public void postWithNumericQueryParams() throws Exception {
  Map<Object, Object> inputParams = new HashMap<Object, Object>();
  inputParams.put(1, 2);
  inputParams.put(3, 4);
  final Map<String, String> outputParams = new HashMap<String, String>();
  final AtomicReference<String> method = new AtomicReference<String>();
  handler = new RequestHandler() {

    @Override
    public void handle(Request request, HttpServletResponse response) {
      method.set(request.getMethod());
      outputParams.put("1", request.getParameter("1"));
      outputParams.put("3", request.getParameter("3"));
      response.setStatus(HTTP_OK);
    }
  };
  HttpRequest request = post(url, inputParams, false);
  assertTrue(request.ok());
  assertEquals("POST", method.get());
  assertEquals("2", outputParams.get("1"));
  assertEquals("4", outputParams.get("3"));
}
 
开发者ID:junicorn,项目名称:NiuBi,代码行数:29,代码来源:HttpRequestTest.java

示例12: supports

import java.util.concurrent.atomic.AtomicReference; //导入依赖的package包/类
@Override
protected boolean supports(Class<?> clazz) {
    JavaType javaType = getJavaType(clazz);
    AtomicReference<Throwable> causeRef = new AtomicReference<Throwable>();
    if (this.objectMapper.canDeserialize(javaType, causeRef)) {
        return true;
    }
    Throwable cause = causeRef.get();
    if (cause != null) {
        String msg = "Failed to evaluate deserialization for type " + javaType;
        if (logger.isDebugEnabled()) {
            logger.warn(msg, cause);
        }
        else {
            logger.warn(msg + ": " + cause);
        }
    }
    return false;
}
 
开发者ID:devefx,项目名称:validator-web,代码行数:20,代码来源:AbstractJackson2HttpMessageReader.java

示例13: canRead

import java.util.concurrent.atomic.AtomicReference; //导入依赖的package包/类
@Override
public boolean canRead(Type type, Class<?> contextClass, MediaType mediaType) {
	if (!canRead(mediaType)) {
		return false;
	}
	JavaType javaType = getJavaType(type, contextClass);
	if (!jackson23Available || !logger.isWarnEnabled()) {
		return this.objectMapper.canDeserialize(javaType);
	}
	AtomicReference<Throwable> causeRef = new AtomicReference<Throwable>();
	if (this.objectMapper.canDeserialize(javaType, causeRef)) {
		return true;
	}
	Throwable cause = causeRef.get();
	if (cause != null) {
		String msg = "Failed to evaluate Jackson deserialization for type " + javaType;
		if (logger.isDebugEnabled()) {
			logger.warn(msg, cause);
		}
		else {
			logger.warn(msg + ": " + cause);
		}
	}
	return false;
}
 
开发者ID:JetBrains,项目名称:teamcity-hashicorp-vault-plugin,代码行数:26,代码来源:AbstractJackson2HttpMessageConverter.java

示例14: networkInterceptorInvokedForConditionalGet

import java.util.concurrent.atomic.AtomicReference; //导入依赖的package包/类
@Test public void networkInterceptorInvokedForConditionalGet() throws Exception {
  server.enqueue(new MockResponse()
      .addHeader("ETag: v1")
      .setBody("A"));
  server.enqueue(new MockResponse()
      .setResponseCode(HttpURLConnection.HTTP_NOT_MODIFIED));

  // Seed the cache.
  HttpUrl url = server.url("/");
  assertEquals("A", get(url).body().string());

  final AtomicReference<String> ifNoneMatch = new AtomicReference<>();
  client = client.newBuilder()
      .addNetworkInterceptor(new Interceptor() {
        @Override public Response intercept(Chain chain) throws IOException {
          ifNoneMatch.compareAndSet(null, chain.request().header("If-None-Match"));
          return chain.proceed(chain.request());
        }
      }).build();

  // Confirm the value is cached and intercepted.
  assertEquals("A", get(url).body().string());
  assertEquals("v1", ifNoneMatch.get());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:CacheTest.java

示例15: singleElementOperatorDoNotSwallowExceptionWhenDone

import java.util.concurrent.atomic.AtomicReference; //导入依赖的package包/类
@Test
public void singleElementOperatorDoNotSwallowExceptionWhenDone() {
    final Throwable exception = new RuntimeException("some error");
    final AtomicReference<Throwable> error = new AtomicReference<Throwable>();

    try {
        RxJavaCommonPlugins.setErrorHandler(new Consumer<Throwable>() {
            @Override public void accept(final Throwable throwable) throws Exception {
                error.set(throwable);
            }
        });

        singleElement(Flowable.unsafeCreate(new Publisher<Integer>() {
            @Override public void subscribe(final Subscriber<? super Integer> observer) {
                observer.onComplete();
                observer.onError(exception);
            }
        })).test().assertComplete();

        assertSame(exception, error.get().getCause());
    } finally {
        RxJavaCommonPlugins.reset();
    }
}
 
开发者ID:akarnokd,项目名称:RxJava3-preview,代码行数:25,代码来源:FlowableSingleTest.java


注:本文中的java.util.concurrent.atomic.AtomicReference类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。