Example usage for java.util.concurrent.atomic AtomicReference get

List of usage examples for java.util.concurrent.atomic AtomicReference get

Introduction

In this page you can find the example usage for java.util.concurrent.atomic AtomicReference get.

Prototype

public final V get() 

Source Link

Document

Returns the current value, with memory effects as specified by VarHandle#getVolatile .

Usage

From source file:com.hubrick.vertx.rest.converter.JacksonJsonHttpMessageConverter.java

@Override
public boolean canWrite(Class<?> clazz, MediaType mediaType) {
    if (!jackson23Available) {
        return (this.objectMapper.canSerialize(clazz) && canWrite(mediaType));
    }/*from ww w .j a  v a2 s .  c  o m*/
    AtomicReference<Throwable> causeRef = new AtomicReference<Throwable>();
    if (this.objectMapper.canSerialize(clazz, causeRef) && canWrite(mediaType)) {
        return true;
    }
    Throwable cause = causeRef.get();
    if (cause != null) {
        log.warn("Failed to evaluate serialization for type [{}]", clazz, cause);
    }
    return false;
}

From source file:com.gaodashang.demo.echo.CustomContainerWebSocketsApplicationTests.java

@Test
public void echoEndpoint() throws Exception {
    ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class)
                    .properties("websocket.uri:ws://localhost:" + PORT + "/ws/echo/websocket")
                    .run("--spring.main.web_environment=false");
    long count = context.getBean(ClientConfiguration.class).latch.getCount();
    AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class).messagePayload;
    context.close();//  w  w  w  .j av  a2 s . c o m
    assertEquals(0, count);
    assertEquals("Did you say \"Hello world!\"?", messagePayloadReference.get());
}

From source file:com.chiorichan.updater.Download.java

protected InputStream getConnectionInputStream(final URLConnection urlconnection) throws DownloadException {
    final AtomicReference<InputStream> is = new AtomicReference<InputStream>();

    for (int j = 0; j < 3 && is.get() == null; j++) {
        StreamThread stream = new StreamThread(urlconnection, is);
        stream.start();/*from   ww  w  .  j  a va  2 s . c o  m*/
        int iterationCount = 0;
        while (is.get() == null && iterationCount++ < 5)
            try {
                stream.join(1000L);
            } catch (InterruptedException ignore) {
            }

        if (stream.permDenied.get())
            throw new DownloadDeniedException("Permission denied!");

        if (is.get() != null)
            break;
        try {
            stream.interrupt();
            stream.join();
        } catch (InterruptedException ignore) {
        }
    }

    if (is.get() == null)
        throw new DownloadException("Unable to download file from " + urlconnection.getURL());
    return new BufferedInputStream(is.get());
}

From source file:org.openmrs.module.drughistory.api.DrugEventServiceTest.java

/**
 * @verifies throw exception when sinceWhen is in the future
 * @see DrugEventService#generateDrugEventsFromTrigger(org.openmrs.module.drughistory.DrugEventTrigger, java.util.Date)
 *//*from w ww .j a  va  2 s  .  co  m*/
@Test
@ExpectedException(IllegalArgumentException.class)
public void generateDrugEventsFromTrigger_shouldThrowExceptionWhenSinceWhenIsInTheFuture() throws Exception {
    GregorianCalendar gc = new GregorianCalendar();
    gc.add(GregorianCalendar.DAY_OF_MONTH, 1);
    AtomicReference<Date> sinceWhen = new AtomicReference<Date>();
    sinceWhen.set(gc.getTime());
    DrugEventTrigger trigger = new DrugEventTrigger();
    drugEventService.generateDrugEventsFromTrigger(trigger, sinceWhen.get());
}

From source file:com.aol.advertising.qiao.management.metrics.StatisticsStore.java

@ManagedOperation(description = "Get the specific metric")
public double getAverageIntervalMetric(String key) {
    AtomicReference<IntervalMetric> v = intvalStats.get(key);
    if (v == null)
        return 0;

    return v.get().avg();
}

From source file:com.aol.advertising.qiao.management.metrics.StatisticsStore.java

@Override
public IntervalMetric getIntervalMetric(String key) {
    AtomicReference<IntervalMetric> v = intvalStats.get(key);
    if (v == null)
        return null;

    return v.get();
}

From source file:net.technicpack.launchercore.mirror.download.Download.java

protected InputStream getConnectionInputStream(final URLConnection urlconnection) throws DownloadException {
    final AtomicReference<InputStream> is = new AtomicReference<InputStream>();

    for (int j = 0; (j < 3) && (is.get() == null); j++) {
        StreamThread stream = new StreamThread(urlconnection, is);
        stream.start();/* w ww  . j a v  a  2s. co  m*/
        int iterationCount = 0;
        while ((is.get() == null) && (iterationCount++ < 5)) {
            try {
                stream.join(1000L);
            } catch (InterruptedException ignore) {
            }
        }

        if (stream.permDenied.get()) {
            throw new PermissionDeniedException("Permission denied!");
        }

        if (is.get() != null) {
            break;
        }
        try {
            stream.interrupt();
            stream.join();
        } catch (InterruptedException ignore) {
        }
    }

    if (is.get() == null) {
        throw new DownloadException("Unable to download file from " + urlconnection.getURL());
    }
    return new BufferedInputStream(is.get());
}

From source file:com.github.jackygurui.vertxredissonrepository.repository.index.DefaultCompoundValueResolver.java

@Override
public String resolve(Object value, JsonObject root, String id, String fieldName, RedissonIndex index) {
    AtomicReference<String> s = new AtomicReference<>();
    if (StringUtils.isBlank(index.valueField())) {
        s.set(value instanceof String ? (String) value : Json.encode(value));
    } else {/*from   w  ww.  java  2  s .  co  m*/
        s.set(root.getString(index.valueField()));
    }
    Arrays.stream(index.compoundIndexFields()).forEach(
            e -> s.set(s.get().concat(RedisRepository.DEFAULT_SEPERATOR).concat(root.getValue(e).toString())));
    return s.get().concat(RedisRepository.DEFAULT_SEPERATOR).concat(id);
}

From source file:io.wcm.caravan.io.http.impl.CaravanHttpClientThreadingTest.java

private Thread subscribeWaitAndGetEmissionThread(Observable<CaravanHttpResponse> rxResponse)
        throws InterruptedException {

    AtomicReference<Thread> observerThread = new AtomicReference<>();
    AtomicReference<Throwable> error = new AtomicReference<>();

    rxResponse.subscribe(response -> observerThread.set(Thread.currentThread()), ex -> error.set(ex));

    while (observerThread.get() == null && error.get() == null) {
        Thread.sleep(1);/*from  www . j  a  v  a 2 s  . c  o  m*/
    }

    if (error.get() != null) {
        throw new RuntimeException("The response observable emitted an exception.", error.get());
    }

    return observerThread.get();
}

From source file:com.microsoft.tfs.core.clients.versioncontrol.engines.internal.BaselineFileDownloadOutput.java

/**
 * {@inheritDoc}/* w w w. ja va2  s .  c  o m*/
 */
@Override
public synchronized OutputStream getOutputStream() throws IOException {
    if (outputStream == null) {
        final String contentType = getActualContentType();
        Check.notNull(contentType, "Cannot open output stream until actual content type is set"); //$NON-NLS-1$

        String path = baselineFileNoSuffix.getAbsolutePath();
        if (contentType.equals(DownloadContentTypes.APPLICATION_GZIP)) {
            path = path + BaselineFolder.getGzipExtension();
        } else if (contentType.equals(DownloadContentTypes.APPLICATION_OCTET_STREAM)) {
            path = path + BaselineFolder.getRawExtension();
        } else {
            throw new VersionControlException(MessageFormat.format(
                    Messages.getString("VersionControlClient.UnsupportedContentTypeFormat"), //$NON-NLS-1$
                    contentType));

        }

        final AtomicBoolean tempCreated = new AtomicBoolean();

        final AtomicReference<String> pathReference = new AtomicReference<String>(path);
        outputStream = BaselineFolderCollection.createFile(pathReference, true, null /* ignored */,
                tempCreated);
        path = pathReference.get();

        outputStreamFile = new File(path);
        tempFileCreatedInsteadOfBaseline = tempCreated.get();
    }

    return outputStream;
}