List of usage examples for java.util.concurrent.atomic AtomicReference get
public final V get()
From source file:org.alfresco.repo.imap.AlfrescoImapServer.java
public void checkForOpeningExceptions(AtomicReference<Exception> serverOpeningExceptionRef) { synchronized (serverOpeningExceptionRef) { try {/*w w w . j a va 2s . c om*/ //wait for openServerSocket() method to finish serverOpeningExceptionRef.wait(); if (serverOpeningExceptionRef.get() != null) { throw new RuntimeException(serverOpeningExceptionRef.get()); } } catch (InterruptedException e) { if (logger.isDebugEnabled()) { logger.debug(e.getMessage(), e); } } } }
From source file:com.fiadot.springjsoncrypt.json.CryptMappingJacson2HttpMessageConverter.java
@Override public boolean canWrite(Class<?> clazz, MediaType mediaType) { if (!jackson23Available || !logger.isWarnEnabled()) { return (this.objectMapper.canSerialize(clazz) && canWrite(mediaType)); }/*from ww w . ja v a 2s. com*/ AtomicReference<Throwable> causeRef = new AtomicReference<Throwable>(); if (this.objectMapper.canSerialize(clazz) && canWrite(mediaType)) { return true; } Throwable cause = causeRef.get(); if (cause != null) { String msg = "Failed to evaluate serialization for type [" + clazz + "]"; if (logger.isDebugEnabled()) { logger.warn(msg, cause); } else { logger.warn(msg + ": " + cause); } } return false; }
From source file:org.obp.maritimecloud.MaritimeCloudAgent.java
public void startIntendedRouteBroadcast(final AtomicReference<Route> intendedRouteRef) { if (intendedRouteBroadcastEnabled) { logger.debug("start intended route broadcast"); broadcaster.scheduleAtFixedRate(() -> { IntendedRouteMsg msg = new IntendedRouteMsg(); msg.addAllWaypoints(MessageConverters.waypointsToMessages(intendedRouteRef.get().getWaypoints())); broadcast(msg, BROADCAST_RADIUS); }, BEACON_PERIOD, config.getBroadcastBeaconPeriod(), TimeUnit.SECONDS); }//from w w w . jav a2 s.c o m }
From source file:com.fiadot.springjsoncrypt.json.CryptMappingJacson2HttpMessageConverter.java
@Override public boolean canRead(Type type, Class<?> contextClass, MediaType mediaType) { JavaType javaType = getJavaType(type, contextClass); if (!jackson23Available || !logger.isWarnEnabled()) { return (this.objectMapper.canDeserialize(javaType) && canRead(mediaType)); }/*from www .j av a 2 s.co m*/ AtomicReference<Throwable> causeRef = new AtomicReference<Throwable>(); if (this.objectMapper.canDeserialize(javaType) && canRead(mediaType)) { 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; }
From source file:org.eclipse.mylyn.commons.repositories.http.tests.CommonHttpClientTest.java
@Test public void testHttpContextPerThread() throws Exception { RepositoryLocation location = new RepositoryLocation("http://mylyn.org/"); final CommonHttpClient client = new CommonHttpClient(location); final AtomicReference<HttpContext> otherThreadContext = new AtomicReference<HttpContext>(); Thread t = new Thread() { @Override//from w ww .j a v a2 s.c om public void run() { otherThreadContext.set(client.getContext()); }; }; t.start(); t.join(); assertNotNull(otherThreadContext.get()); assertNotNull(client.getContext()); assertFalse(otherThreadContext.get() == client.getContext()); }
From source file:com.kinglcc.spring.jms.core.converter.Jackson2JmsMessageConverter.java
private boolean canSerialize(Object payload) { if (!jackson23Available || !LOGGER.isWarnEnabled()) { return this.objectMapper.canSerialize(payload.getClass()); }/* w ww .ja v a 2 s .co m*/ AtomicReference<Throwable> causeRef = new AtomicReference<Throwable>(); if (this.objectMapper.canSerialize(payload.getClass(), causeRef)) { return true; } Throwable cause = causeRef.get(); if (cause != null) { String msg = "Failed to evaluate serialization for type [" + payload.getClass() + "]"; if (LOGGER.isDebugEnabled()) { LOGGER.warn(msg, cause); } else { LOGGER.warn(msg + ": " + cause); } } return false; }
From source file:com.twitter.aurora.scheduler.app.SchedulerIT.java
@Test public void testLaunch() throws Exception { expect(driverFactory.apply(null)).andReturn(driver).anyTimes(); ScheduledTask snapshotTask = makeTask("snapshotTask", ScheduleStatus.ASSIGNED); ScheduledTask transactionTask = makeTask("transactionTask", ScheduleStatus.RUNNING); Iterable<Entry> recoveredEntries = toEntries( LogEntry.snapshot(new Snapshot().setTasks(ImmutableSet.of(snapshotTask))), LogEntry.transaction(new Transaction( ImmutableList.of(Op.saveTasks(new SaveTasks(ImmutableSet.of(transactionTask)))), storageConstants.CURRENT_SCHEMA_VERSION))); expect(log.open()).andReturn(logStream); expect(logStream.readAll()).andReturn(recoveredEntries.iterator()).anyTimes(); // An empty saveTasks is an artifact of the fact that mutateTasks always writes a log operation // even if nothing is changed. streamMatcher.expectTransaction(Op.saveTasks(new SaveTasks(ImmutableSet.<ScheduledTask>of()))) .andReturn(nextPosition());// ww w . j a v a 2s . c o m streamMatcher.expectTransaction(Op.saveFrameworkId(new SaveFrameworkId(FRAMEWORK_ID))) .andReturn(nextPosition()); logStream.close(); expectLastCall().anyTimes(); final AtomicReference<Scheduler> scheduler = Atomics.newReference(); expect(driver.start()).andAnswer(new IAnswer<Status>() { @Override public Status answer() { scheduler.get().registered(driver, FrameworkID.newBuilder().setValue(FRAMEWORK_ID).build(), MasterInfo.getDefaultInstance()); return Status.DRIVER_RUNNING; } }); control.replay(); startScheduler(); scheduler.set(getScheduler()); awaitSchedulerReady(); assertEquals(0L, Stats.<Long>getVariable("task_store_PENDING").read().longValue()); assertEquals(1L, Stats.<Long>getVariable("task_store_ASSIGNED").read().longValue()); assertEquals(1L, Stats.<Long>getVariable("task_store_RUNNING").read().longValue()); assertEquals(0L, Stats.<Long>getVariable("task_store_UNKNOWN").read().longValue()); // TODO(William Farner): Send a thrift RPC to the scheduler. // TODO(William Farner): Also send an admin thrift RPC to verify capability (e.g. ROOT) mapping. }
From source file:com.vmware.admiral.adapter.docker.service.SystemImageRetrievalManagerTest.java
@Test public void testGetFromClassPath() throws Throwable { Path testXenonImagesPath = Files.createTempDirectory("test-xenon-images"); HostInitCommonServiceConfig.startServices(host); waitForServiceAvailability(ConfigurationFactoryService.SELF_LINK); waitForServiceAvailability(UriUtils.buildUriPath(UriUtils .buildUriPath(ConfigurationFactoryService.SELF_LINK, FileUtil.USER_RESOURCES_PATH_VARIABLE))); // Set expected configuration ConfigurationState config = new ConfigurationState(); config.documentSelfLink = UriUtils.buildUriPath(ConfigurationFactoryService.SELF_LINK, FileUtil.USER_RESOURCES_PATH_VARIABLE); config.key = FileUtil.USER_RESOURCES_PATH_VARIABLE; config.value = testXenonImagesPath.toAbsolutePath().toString(); doPost(config, ConfigurationFactoryService.SELF_LINK); File imageDir = new File(UriUtils.buildUriPath(testXenonImagesPath.toString(), SystemImageRetrievalManager.SYSTEM_IMAGES_PATH)); imageDir.mkdir();//from w ww . j ava2s . c om byte[] content = IOUtils .toByteArray(Thread.currentThread().getContextClassLoader().getResourceAsStream(TEST_IMAGE)); AdapterRequest req = new AdapterRequest(); req.resourceReference = host.getUri(); AtomicReference<byte[]> retrievedImageRef = new AtomicReference<>(); TestContext ctx = testCreate(1); retrievalManager.retrieveAgentImage(TEST_IMAGE, req, (image) -> { retrievedImageRef.set(image); ctx.completeIteration(); }); ctx.await(); byte[] image = retrievedImageRef.get(); Assert.assertEquals("Unexpected content", new String(content), new String(image)); }
From source file:eu.eubrazilcc.lvl.storage.LinkedInStateCollectionTest.java
@Test public void test() { System.out.println("LinkedInStateCollectionTest.test()"); try {// w w w. j a va2s . c om // insert final long issuedAt = currentTimeMillis() / 1000l; final LinkedInState state = LinkedInState.builder().state("1234567890abcdEFGhiJKlMnOpqrstUVWxyZ") .issuedAt(issuedAt).expiresIn(23l).redirectUri("http://localhost/redirect") .callback("http://localhost/callback").build(); LINKEDIN_STATE_DAO.insert(state); // find LinkedInState state2 = LINKEDIN_STATE_DAO.find(state.getState()); assertThat("linkedin state is not null", state2, notNullValue()); assertThat("linkedin state coincides with original", state2, equalTo(state)); System.out.println(state2.toString()); // update state.setExpiresIn(604800l); LINKEDIN_STATE_DAO.update(state); // find after update state2 = LINKEDIN_STATE_DAO.find(state.getState()); assertThat("linkedin state is not null", state2, notNullValue()); assertThat("linkedin state coincides with original", state2, equalTo(state)); System.out.println(state2.toString()); // list by issued date List<LinkedInState> states = LINKEDIN_STATE_DAO.listByIssuedDate(new Date(issuedAt)); assertThat("linkedin states are not null", states, notNullValue()); assertThat("linkedin states are not empty", !states.isEmpty(), equalTo(true)); assertThat("number of linkedin states coincides with expected", states.size(), equalTo(1)); assertThat("linkedin states coincide with original", states.get(0), equalTo(state)); // check validity final AtomicReference<String> redirectUriRef = new AtomicReference<String>(); final AtomicReference<String> callbackRef = new AtomicReference<String>(); boolean validity = LINKEDIN_STATE_DAO.isValid(state.getState(), redirectUriRef, callbackRef); assertThat("linkedin state is valid", validity, equalTo(true)); assertThat("linkedin redirect URI is not null", redirectUriRef.get(), notNullValue()); assertThat("linkedin redirect URI coincides with expected", redirectUriRef.get(), equalTo("http://localhost/redirect")); assertThat("linkedin callback URI is not null", callbackRef.get(), notNullValue()); assertThat("linkedin callback URI coincides with expected", callbackRef.get(), equalTo("http://localhost/callback")); // remove LINKEDIN_STATE_DAO.delete(state.getState()); final long numRecords = LINKEDIN_STATE_DAO.count(); assertThat("number of linkedin states stored in the database coincides with expected", numRecords, equalTo(0l)); // pagination final List<String> ids = newArrayList(); for (int i = 0; i < 11; i++) { final LinkedInState state3 = LinkedInState.builder().state(Integer.toString(i)).build(); ids.add(state3.getState()); LINKEDIN_STATE_DAO.insert(state3); } final int size = 3; int start = 0; states = null; final MutableLong count = new MutableLong(0l); do { states = LINKEDIN_STATE_DAO.list(start, size, null, null, null, count); if (states.size() != 0) { System.out.println("Paging: first item " + start + ", showing " + states.size() + " of " + count.getValue() + " items"); } start += states.size(); } while (!states.isEmpty()); for (final String id2 : ids) { LINKEDIN_STATE_DAO.delete(id2); } LINKEDIN_STATE_DAO.stats(System.out); } catch (Exception e) { e.printStackTrace(System.err); fail("LinkedInStateCollectionTest.test() failed: " + e.getMessage()); } finally { System.out.println("LinkedInStateCollectionTest.test() has finished"); } }
From source file:com.vmware.admiral.adapter.docker.service.SystemImageRetrievalManagerTest.java
@Test public void testGetFromUserResources() throws Throwable { Path testXenonImagesPath = Files.createTempDirectory("test-xenon-images"); HostInitCommonServiceConfig.startServices(host); waitForServiceAvailability(ConfigurationFactoryService.SELF_LINK); waitForServiceAvailability(UriUtils.buildUriPath(UriUtils .buildUriPath(ConfigurationFactoryService.SELF_LINK, FileUtil.USER_RESOURCES_PATH_VARIABLE))); // Set expected configuration ConfigurationState config = new ConfigurationState(); config.documentSelfLink = UriUtils.buildUriPath(ConfigurationFactoryService.SELF_LINK, FileUtil.USER_RESOURCES_PATH_VARIABLE); config.key = FileUtil.USER_RESOURCES_PATH_VARIABLE; config.value = testXenonImagesPath.toAbsolutePath().toString(); doPost(config, ConfigurationFactoryService.SELF_LINK); File imageDir = new File(UriUtils.buildUriPath(testXenonImagesPath.toString(), SystemImageRetrievalManager.SYSTEM_IMAGES_PATH)); imageDir.mkdir();// w ww . ja va2 s. c o m byte[] content = IOUtils .toByteArray(Thread.currentThread().getContextClassLoader().getResourceAsStream(TEST_IMAGE)); // Basically, rename it so it must be loaded from user resources for sure File tmpFile = new File(UriUtils.buildUriPath(imageDir.getAbsolutePath(), TEST_IMAGE_RES)); tmpFile.createNewFile(); try (OutputStream os = new FileOutputStream(tmpFile)) { os.write(content); } AdapterRequest req = new AdapterRequest(); req.resourceReference = host.getUri(); AtomicReference<byte[]> retrievedImageRef = new AtomicReference<>(); TestContext ctx = testCreate(1); retrievalManager.retrieveAgentImage(TEST_IMAGE_RES, req, (image) -> { retrievedImageRef.set(image); ctx.completeIteration(); }); ctx.await(); byte[] image = retrievedImageRef.get(); Assert.assertEquals("Unexpected content", new String(content), new String(image)); }