From d7380114a60a105c5882ebe9b256c9effef540ef Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Sun, 4 Nov 2012 14:54:31 -0800 Subject: [PATCH] Enforce use of Atomics.newReference via Checkstyle Avoids duplicating types. --- .../config/DeltacloudRestClientModule.java | 3 ++- .../config/EC2ComputeServiceContextModule.java | 3 ++- .../PasswordCredentialsFromWindowsInstance.java | 3 ++- .../EC2CreateNodesInGroupThenAddToSet.java | 3 ++- .../loaders/FindSecurityGroupOrCreate.java | 3 ++- ...AllocateAndAddFloatingIpToNodeExpectTest.java | 5 +++-- ...rityGroupWithNameAndReturnTrueExpectTest.java | 5 +++-- .../jclouds/sqs/internal/BaseSQSApiLiveTest.java | 3 ++- .../compute/internal/BaseComputeService.java | 9 +++++---- .../compute/util/ConcurrentOpenSocketFinder.java | 6 ++++-- .../compute/functions/PollNodeRunningTest.java | 9 +++++---- .../predicates/AtomicNodePredicatesTest.java | 16 +++++++++------- ...AddToGoodMapOrPutExceptionIntoBadMapTest.java | 5 +++-- .../http/functions/ParseFirstJsonValueNamed.java | 3 ++- .../org/jclouds/lifecycle/BaseLifeCycle.java | 3 ++- .../java/org/jclouds/rest/config/RestModule.java | 3 ++- .../org/jclouds/json/GsonExperimentsTest.java | 3 ++- ...tNotOnAuthorizationExceptionSupplierTest.java | 11 ++++++----- ...dThrowAuthorizationExceptionSupplierTest.java | 9 +++++---- .../internal/BaseLoadBalancerService.java | 3 ++- .../AWSEC2ComputeServiceContextModule.java | 3 ++- resources/checkstyle.xml | 4 ++++ .../sdn/filters/AddSessionTokenToRequest.java | 4 +++- .../functionloader/CurrentFunctionLoader.java | 4 +++- .../functions/CredentialsFromAdminAccess.java | 3 ++- 25 files changed, 79 insertions(+), 47 deletions(-) diff --git a/apis/deltacloud/src/main/java/org/jclouds/deltacloud/config/DeltacloudRestClientModule.java b/apis/deltacloud/src/main/java/org/jclouds/deltacloud/config/DeltacloudRestClientModule.java index 0bff28c1e1..fbc2fc9083 100644 --- a/apis/deltacloud/src/main/java/org/jclouds/deltacloud/config/DeltacloudRestClientModule.java +++ b/apis/deltacloud/src/main/java/org/jclouds/deltacloud/config/DeltacloudRestClientModule.java @@ -55,6 +55,7 @@ import com.google.common.base.Objects; import com.google.common.base.Predicate; import com.google.common.base.Supplier; import com.google.common.collect.Iterables; +import com.google.common.util.concurrent.Atomics; import com.google.inject.Provides; /** @@ -77,7 +78,7 @@ public class DeltacloudRestClientModule extends RestClientModule authException = new AtomicReference(); + protected AtomicReference authException = Atomics.newReference(); @Provides @Singleton diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2ComputeServiceContextModule.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2ComputeServiceContextModule.java index 433cf79cdb..6e47e54ee6 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2ComputeServiceContextModule.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/config/EC2ComputeServiceContextModule.java @@ -47,6 +47,7 @@ import com.google.common.base.Throwables; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableSet; +import com.google.common.util.concurrent.Atomics; import com.google.inject.Injector; import com.google.inject.Key; import com.google.inject.Provides; @@ -103,7 +104,7 @@ public class EC2ComputeServiceContextModule extends BaseComputeServiceContextMod protected Supplier> provideRegionAndNameToImageSupplierCacheLoader( final RegionAndIdToImage delegate) { return Suppliers.>ofInstance(new CacheLoader() { - private final AtomicReference authException = new AtomicReference(); + private final AtomicReference authException = Atomics.newReference(); @Override public Image load(final RegionAndName key) throws Exception { diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/PasswordCredentialsFromWindowsInstance.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/PasswordCredentialsFromWindowsInstance.java index b2c7b6f661..c618708742 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/PasswordCredentialsFromWindowsInstance.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/PasswordCredentialsFromWindowsInstance.java @@ -46,6 +46,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.base.Strings; +import com.google.common.util.concurrent.Atomics; /** * @author Adrian Cole @@ -82,7 +83,7 @@ public class PasswordCredentialsFromWindowsInstance implements Function data = new AtomicReference(); + final AtomicReference data = Atomics.newReference(); Predicate passwordReady = new Predicate() { @Override public boolean apply(@Nullable String s) { diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/EC2CreateNodesInGroupThenAddToSet.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/EC2CreateNodesInGroupThenAddToSet.java index d1bda670e9..10989febfa 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/EC2CreateNodesInGroupThenAddToSet.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/strategy/EC2CreateNodesInGroupThenAddToSet.java @@ -63,6 +63,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet.Builder; import com.google.common.collect.Iterables; import com.google.common.collect.Multimap; +import com.google.common.util.concurrent.Atomics; /** * creates futures that correlate to @@ -200,7 +201,7 @@ public class EC2CreateNodesInGroupThenAddToSet implements CreateNodesInGroupThen // block until instance is running logger.debug(">> awaiting status running instance(%s)", coordinates); - AtomicReference node = new AtomicReference(runningInstanceToNodeMetadata.apply(startedInstance)); + AtomicReference node = Atomics.newReference(runningInstanceToNodeMetadata.apply(startedInstance)); nodeRunning.apply(node); logger.trace("<< running instance(%s)", coordinates); logger.debug(">> associating elastic IP %s to instance %s", ip, coordinates); diff --git a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/loaders/FindSecurityGroupOrCreate.java b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/loaders/FindSecurityGroupOrCreate.java index 1b05256924..bb72af035e 100644 --- a/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/loaders/FindSecurityGroupOrCreate.java +++ b/apis/openstack-nova/src/main/java/org/jclouds/openstack/nova/v2_0/compute/loaders/FindSecurityGroupOrCreate.java @@ -33,6 +33,7 @@ import org.jclouds.openstack.nova.v2_0.domain.zonescoped.ZoneSecurityGroupNameAn import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.cache.CacheLoader; +import com.google.common.util.concurrent.Atomics; /** * @@ -54,7 +55,7 @@ public class FindSecurityGroupOrCreate extends CacheLoader securityGroupInZoneRef = new AtomicReference(checkNotNull(in, + AtomicReference securityGroupInZoneRef = Atomics.newReference(checkNotNull(in, "zoneSecurityGroupNameAndPorts")); if (returnSecurityGroupExistsInZone.apply(securityGroupInZoneRef)) { return returnExistingSecurityGroup(securityGroupInZoneRef); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/AllocateAndAddFloatingIpToNodeExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/AllocateAndAddFloatingIpToNodeExpectTest.java index 97f763de2d..74c81d5ad3 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/AllocateAndAddFloatingIpToNodeExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/compute/functions/AllocateAndAddFloatingIpToNodeExpectTest.java @@ -39,6 +39,7 @@ import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; +import com.google.common.util.concurrent.Atomics; /** * Tests the compute service abstraction of the nova api. @@ -77,7 +78,7 @@ public class AllocateAndAddFloatingIpToNodeExpectTest extends BaseNovaComputeSer .put(addFloatingIPRequest, addFloatingIPResponse).build()).getContext().utils().injector() .getInstance(AllocateAndAddFloatingIpToNode.class); - AtomicReference nodeRef = new AtomicReference(node); + AtomicReference nodeRef = Atomics.newReference(node); fn.apply(nodeRef); NodeMetadata node1 = nodeRef.get(); assertNotNull(node1); @@ -124,7 +125,7 @@ public class AllocateAndAddFloatingIpToNodeExpectTest extends BaseNovaComputeSer listResponseForUnassigned).build()).getContext().utils().injector() .getInstance(AllocateAndAddFloatingIpToNode.class); - AtomicReference nodeRef = new AtomicReference(node); + AtomicReference nodeRef = Atomics.newReference(node); fn.apply(nodeRef); NodeMetadata node1 = nodeRef.get(); assertNotNull(node1); diff --git a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/functions/FindSecurityGroupWithNameAndReturnTrueExpectTest.java b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/functions/FindSecurityGroupWithNameAndReturnTrueExpectTest.java index 8bdba651cb..630745f8c4 100644 --- a/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/functions/FindSecurityGroupWithNameAndReturnTrueExpectTest.java +++ b/apis/openstack-nova/src/test/java/org/jclouds/openstack/nova/v2_0/functions/FindSecurityGroupWithNameAndReturnTrueExpectTest.java @@ -37,6 +37,7 @@ import org.testng.annotations.Test; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.Iterables; +import com.google.common.util.concurrent.Atomics; /** * @@ -61,7 +62,7 @@ public class FindSecurityGroupWithNameAndReturnTrueExpectTest extends BaseNovaAp FindSecurityGroupWithNameAndReturnTrue predicate = new FindSecurityGroupWithNameAndReturnTrue( apiWhenSecurityGroupsExist); - AtomicReference securityGroupInZoneRef = new AtomicReference(ZoneAndName + AtomicReference securityGroupInZoneRef = Atomics.newReference(ZoneAndName .fromZoneAndName("az-1.region-a.geo-1", "name1")); // we can find it @@ -91,7 +92,7 @@ public class FindSecurityGroupWithNameAndReturnTrueExpectTest extends BaseNovaAp ZoneAndName zoneAndGroup = ZoneAndName.fromZoneAndName("az-1.region-a.geo-1", "name2"); - AtomicReference securityGroupInZoneRef = new AtomicReference(zoneAndGroup); + AtomicReference securityGroupInZoneRef = Atomics.newReference(zoneAndGroup); // we cannot find it assertFalse(predicate.apply(securityGroupInZoneRef)); diff --git a/apis/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java b/apis/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java index 1ebe3b622a..71ec931b5b 100644 --- a/apis/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java +++ b/apis/sqs/src/test/java/org/jclouds/sqs/internal/BaseSQSApiLiveTest.java @@ -42,6 +42,7 @@ import com.google.common.base.Splitter; import com.google.common.collect.FluentIterable; import com.google.common.collect.Sets; import com.google.common.reflect.TypeToken; +import com.google.common.util.concurrent.Atomics; import com.google.common.util.concurrent.Uninterruptibles; /** @@ -81,7 +82,7 @@ public class BaseSQSApiLiveTest extends BaseContextLiveTest policy = new AtomicReference(); + final AtomicReference policy = Atomics.newReference(); assertEventually(new Runnable() { public void run() { String policyForAuthorizationByAccount = api().getQueueApi().getAttribute(queue, "Policy"); diff --git a/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java b/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java index 9a49b544dd..f3a76b1062 100644 --- a/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java +++ b/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java @@ -105,6 +105,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.Multimap; +import com.google.common.util.concurrent.Atomics; import com.google.common.util.concurrent.ListenableFuture; /** @@ -294,7 +295,7 @@ public class BaseComputeService implements ComputeService { protected NodeMetadata doDestroyNode(final String id) { checkNotNull(id, "id"); logger.debug(">> destroying node(%s)", id); - final AtomicReference node = new AtomicReference(); + final AtomicReference node = Atomics.newReference(); RetryablePredicate tester = new RetryablePredicate(new Predicate() { @Override @@ -419,7 +420,7 @@ public class BaseComputeService implements ComputeService { public void rebootNode(String id) { checkNotNull(id, "id"); logger.debug(">> rebooting node(%s)", id); - AtomicReference node = new AtomicReference(rebootNodeStrategy.rebootNode(id)); + AtomicReference node = Atomics.newReference(rebootNodeStrategy.rebootNode(id)); boolean successful = nodeRunning.apply(node); logger.debug("<< rebooted node(%s) success(%s)", id, successful); } @@ -450,7 +451,7 @@ public class BaseComputeService implements ComputeService { public void resumeNode(String id) { checkNotNull(id, "id"); logger.debug(">> resuming node(%s)", id); - AtomicReference node = new AtomicReference(resumeNodeStrategy.resumeNode(id)); + AtomicReference node = Atomics.newReference(resumeNodeStrategy.resumeNode(id)); boolean successful = nodeRunning.apply(node); logger.debug("<< resumed node(%s) success(%s)", id, successful); } @@ -481,7 +482,7 @@ public class BaseComputeService implements ComputeService { public void suspendNode(String id) { checkNotNull(id, "id"); logger.debug(">> suspending node(%s)", id); - AtomicReference node = new AtomicReference(suspendNodeStrategy.suspendNode(id)); + AtomicReference node = Atomics.newReference(suspendNodeStrategy.suspendNode(id)); boolean successful = nodeSuspended.apply(node); logger.debug("<< suspended node(%s) success(%s)", id, successful); } diff --git a/compute/src/main/java/org/jclouds/compute/util/ConcurrentOpenSocketFinder.java b/compute/src/main/java/org/jclouds/compute/util/ConcurrentOpenSocketFinder.java index ee2821706e..4298e99f2e 100644 --- a/compute/src/main/java/org/jclouds/compute/util/ConcurrentOpenSocketFinder.java +++ b/compute/src/main/java/org/jclouds/compute/util/ConcurrentOpenSocketFinder.java @@ -30,10 +30,12 @@ import com.google.common.base.Predicate; import com.google.common.base.Throwables; import com.google.common.collect.ImmutableSet; import com.google.common.net.HostAndPort; +import com.google.common.util.concurrent.Atomics; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.MoreExecutors; import com.google.inject.Inject; + public class ConcurrentOpenSocketFinder implements OpenSocketFinder { @Resource @@ -62,7 +64,7 @@ public class ConcurrentOpenSocketFinder implements OpenSocketFinder { long period = timeUnits.convert(1, TimeUnit.SECONDS); // For storing the result; needed because predicate will just tell us true/false - final AtomicReference result = new AtomicReference(); + final AtomicReference result = Atomics.newReference(); Predicate> concurrentOpenSocketFinder = new Predicate>() { @@ -109,7 +111,7 @@ public class ConcurrentOpenSocketFinder implements OpenSocketFinder { * @throws InterruptedException */ private HostAndPort findOpenSocket(final Collection sockets) { - final AtomicReference result = new AtomicReference(); + final AtomicReference result = Atomics.newReference(); final CountDownLatch latch = new CountDownLatch(1); final AtomicInteger completeCount = new AtomicInteger(); diff --git a/compute/src/test/java/org/jclouds/compute/functions/PollNodeRunningTest.java b/compute/src/test/java/org/jclouds/compute/functions/PollNodeRunningTest.java index d6664d8154..416a679448 100644 --- a/compute/src/test/java/org/jclouds/compute/functions/PollNodeRunningTest.java +++ b/compute/src/test/java/org/jclouds/compute/functions/PollNodeRunningTest.java @@ -38,6 +38,7 @@ import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.testng.annotations.Test; import com.google.common.base.Predicate; +import com.google.common.util.concurrent.Atomics; /** * @author Adrian Cole @@ -60,7 +61,7 @@ public class PollNodeRunningTest { }; - AtomicReference atomicNode = new AtomicReference(pendingNode); + AtomicReference atomicNode = Atomics.newReference(pendingNode); try { new PollNodeRunning(nodeRunning).apply(atomicNode); } finally { @@ -84,7 +85,7 @@ public class PollNodeRunningTest { }; - AtomicReference atomicNode = new AtomicReference(pendingNode); + AtomicReference atomicNode = Atomics.newReference(pendingNode); try { new PollNodeRunning(nodeRunning).apply(atomicNode); } finally { @@ -107,7 +108,7 @@ public class PollNodeRunningTest { }; - AtomicReference atomicNode = new AtomicReference(pendingNode); + AtomicReference atomicNode = Atomics.newReference(pendingNode); try { new PollNodeRunning(nodeRunning).apply(atomicNode); } finally { @@ -131,7 +132,7 @@ public class PollNodeRunningTest { return super.nodeRunning(statusRunning, timeouts, period); } }.nodeRunning(nodeRunning, timeouts, period); - AtomicReference atomicNode = new AtomicReference(pendingNode); + AtomicReference atomicNode = Atomics.newReference(pendingNode); // Simulate transient error: first call returns null; subsequent calls // return the running node diff --git a/compute/src/test/java/org/jclouds/compute/predicates/AtomicNodePredicatesTest.java b/compute/src/test/java/org/jclouds/compute/predicates/AtomicNodePredicatesTest.java index 2969939961..a4b065b177 100644 --- a/compute/src/test/java/org/jclouds/compute/predicates/AtomicNodePredicatesTest.java +++ b/compute/src/test/java/org/jclouds/compute/predicates/AtomicNodePredicatesTest.java @@ -25,6 +25,8 @@ import static org.easymock.EasyMock.verify; import java.util.concurrent.atomic.AtomicReference; +import com.google.common.util.concurrent.Atomics; + import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadataBuilder; import org.jclouds.compute.domain.NodeMetadata.Status; @@ -53,7 +55,7 @@ public class AtomicNodePredicatesTest { replay(computeService); AtomicNodeRunning nodeRunning = new AtomicNodeRunning(computeService); - AtomicReference reference = new AtomicReference(running); + AtomicReference reference = Atomics.newReference(running); Assert.assertTrue(nodeRunning.apply(reference)); Assert.assertEquals(reference.get(), running); @@ -71,7 +73,7 @@ public class AtomicNodePredicatesTest { replay(computeService); AtomicNodeRunning nodeRunning = new AtomicNodeRunning(computeService); - AtomicReference reference = new AtomicReference(pending); + AtomicReference reference = Atomics.newReference(pending); Assert.assertFalse(nodeRunning.apply(reference)); Assert.assertEquals(reference.get(), pending); @@ -95,7 +97,7 @@ public class AtomicNodePredicatesTest { replay(computeService); AtomicNodeRunning nodeRunning = new AtomicNodeRunning(computeService); - AtomicReference reference = new AtomicReference(newNode); + AtomicReference reference = Atomics.newReference(newNode); Assert.assertFalse(nodeRunning.apply(reference)); Assert.assertEquals(reference.get(), pending); @@ -113,7 +115,7 @@ public class AtomicNodePredicatesTest { replay(computeService); AtomicNodeRunning nodeRunning = new AtomicNodeRunning(computeService); - AtomicReference reference = new AtomicReference(pending); + AtomicReference reference = Atomics.newReference(pending); Assert.assertTrue(nodeRunning.apply(reference)); Assert.assertEquals(reference.get(), running); @@ -139,7 +141,7 @@ public class AtomicNodePredicatesTest { replay(computeService); AtomicNodeRunning nodeRunning = new AtomicNodeRunning(computeService); - AtomicReference reference = new AtomicReference(node); + AtomicReference reference = Atomics.newReference(node); Assert.assertTrue(nodeRunning.apply(reference)); Assert.assertEquals(reference.get(), node); } @@ -152,7 +154,7 @@ public class AtomicNodePredicatesTest { replay(computeService); AtomicNodeRunning nodeRunning = new AtomicNodeRunning(computeService); - AtomicReference reference = new AtomicReference(node); + AtomicReference reference = Atomics.newReference(node); nodeRunning.apply(reference); Assert.assertEquals(reference.get(), node); } @@ -165,7 +167,7 @@ public class AtomicNodePredicatesTest { replay(computeService); AtomicNodeRunning nodeRunning = new AtomicNodeRunning(computeService); - AtomicReference reference = new AtomicReference(node); + AtomicReference reference = Atomics.newReference(node); nodeRunning.apply(reference); Assert.assertEquals(reference.get(), node); } diff --git a/compute/src/test/java/org/jclouds/compute/strategy/CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapTest.java b/compute/src/test/java/org/jclouds/compute/strategy/CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapTest.java index 12d914ef9f..699bc9eb82 100644 --- a/compute/src/test/java/org/jclouds/compute/strategy/CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapTest.java +++ b/compute/src/test/java/org/jclouds/compute/strategy/CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapTest.java @@ -47,6 +47,7 @@ import com.google.common.collect.LinkedHashMultimap; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.google.common.collect.Sets; +import com.google.common.util.concurrent.Atomics; /** * @author Adrian Cole @@ -81,7 +82,7 @@ public class CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapTest { // replay mocks replay(initScriptRunnerFactory, openSocketFinder); // run - AtomicReference atomicNode = new AtomicReference(pendingNode); + AtomicReference atomicNode = Atomics.newReference(pendingNode); new CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap(pollNodeRunning, openSocketFinder, templateOptionsToStatement, initScriptRunnerFactory, options, atomicNode, goodNodes, badNodes, customizationResponses).apply(atomicNode); @@ -126,7 +127,7 @@ public class CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMapTest { replay(initScriptRunnerFactory, openSocketFinder); // run - AtomicReference atomicNode = new AtomicReference(pendingNode); + AtomicReference atomicNode = Atomics.newReference(pendingNode); new CustomizeNodeAndAddToGoodMapOrPutExceptionIntoBadMap(pollNodeRunning, openSocketFinder, templateOptionsToStatement, initScriptRunnerFactory, options, atomicNode, goodNodes, badNodes, customizationResponses).apply(atomicNode); diff --git a/core/src/main/java/org/jclouds/http/functions/ParseFirstJsonValueNamed.java b/core/src/main/java/org/jclouds/http/functions/ParseFirstJsonValueNamed.java index a19bde3fcf..5fd5ddbf0a 100644 --- a/core/src/main/java/org/jclouds/http/functions/ParseFirstJsonValueNamed.java +++ b/core/src/main/java/org/jclouds/http/functions/ParseFirstJsonValueNamed.java @@ -38,6 +38,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.io.Closeables; +import com.google.common.util.concurrent.Atomics; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonToken; import com.google.inject.TypeLiteral; @@ -69,7 +70,7 @@ public class ParseFirstJsonValueNamed implements Function { reader = new JsonReader(new InputStreamReader(arg0.getPayload().getInput())); // in case keys are not in quotes reader.setLenient(true); - AtomicReference name = new AtomicReference(); + AtomicReference name = Atomics.newReference(); JsonToken token = reader.peek(); for (; token != JsonToken.END_DOCUMENT && nnn(this.name, reader, token, name); token = skipAndPeek(token, reader)) { diff --git a/core/src/main/java/org/jclouds/lifecycle/BaseLifeCycle.java b/core/src/main/java/org/jclouds/lifecycle/BaseLifeCycle.java index 1314629eee..8859b36c78 100644 --- a/core/src/main/java/org/jclouds/lifecycle/BaseLifeCycle.java +++ b/core/src/main/java/org/jclouds/lifecycle/BaseLifeCycle.java @@ -28,6 +28,7 @@ import javax.annotation.PreDestroy; import javax.annotation.Resource; import com.google.common.collect.Lists; +import com.google.common.util.concurrent.Atomics; import org.jclouds.logging.Logger; @@ -44,7 +45,7 @@ public abstract class BaseLifeCycle implements Runnable, LifeCycle { protected final List dependencies; protected final Object statusLock; protected volatile Status status; - protected AtomicReference exception = new AtomicReference(); + protected AtomicReference exception = Atomics.newReference(); public BaseLifeCycle(ExecutorService executor, LifeCycle... dependencies) { this.executorService = executor; diff --git a/core/src/main/java/org/jclouds/rest/config/RestModule.java b/core/src/main/java/org/jclouds/rest/config/RestModule.java index 96b7390a14..8b23e775ab 100644 --- a/core/src/main/java/org/jclouds/rest/config/RestModule.java +++ b/core/src/main/java/org/jclouds/rest/config/RestModule.java @@ -61,6 +61,7 @@ import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; +import com.google.common.util.concurrent.Atomics; import com.google.inject.AbstractModule; import com.google.inject.Inject; import com.google.inject.Injector; @@ -78,7 +79,7 @@ public class RestModule extends AbstractModule { public static final TypeLiteral> URI_SUPPLIER_TYPE = new TypeLiteral>() { }; protected final Map, Class> sync2Async; - protected final AtomicReference authException = new AtomicReference(); + protected final AtomicReference authException = Atomics.newReference(); public RestModule() { this(ImmutableMap., Class> of()); diff --git a/core/src/test/java/org/jclouds/json/GsonExperimentsTest.java b/core/src/test/java/org/jclouds/json/GsonExperimentsTest.java index ea974ee888..8c7bf156cb 100644 --- a/core/src/test/java/org/jclouds/json/GsonExperimentsTest.java +++ b/core/src/test/java/org/jclouds/json/GsonExperimentsTest.java @@ -34,6 +34,7 @@ import org.testng.annotations.Test; import com.google.common.base.Optional; import com.google.common.collect.Lists; +import com.google.common.util.concurrent.Atomics; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; @@ -173,7 +174,7 @@ public class GsonExperimentsTest { } protected T parseThingFromReaderOrNull(String toFind, JsonReader reader, Type type) throws IOException { - AtomicReference name = new AtomicReference(); + AtomicReference name = Atomics.newReference(); JsonToken token = reader.peek(); for (; token != JsonToken.END_DOCUMENT && nnn(toFind, reader, token, name); token = skipAndPeek(token, reader)) ; diff --git a/core/src/test/java/org/jclouds/rest/suppliers/MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplierTest.java b/core/src/test/java/org/jclouds/rest/suppliers/MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplierTest.java index 32114b4f1b..9687811ab1 100644 --- a/core/src/test/java/org/jclouds/rest/suppliers/MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplierTest.java +++ b/core/src/test/java/org/jclouds/rest/suppliers/MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplierTest.java @@ -41,6 +41,7 @@ import org.testng.annotations.Test; import com.google.common.base.Function; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; +import com.google.common.util.concurrent.Atomics; /** * @@ -51,7 +52,7 @@ import com.google.common.base.Suppliers; public class MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplierTest { @Test public void testLoaderNormal() { - AtomicReference authException = new AtomicReference(); + AtomicReference authException = Atomics.newReference(); assertEquals(new SetAndThrowAuthorizationExceptionSupplierBackedLoader(Suppliers.ofInstance("foo"), authException).load("KEY"), "foo"); assertEquals(authException.get(), null); @@ -59,7 +60,7 @@ public class MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplierTest { @Test(expectedExceptions = AuthorizationException.class) public void testLoaderThrowsAuthorizationExceptionAndAlsoSetsExceptionType() { - AtomicReference authException = new AtomicReference(); + AtomicReference authException = Atomics.newReference(); try { new SetAndThrowAuthorizationExceptionSupplierBackedLoader(new Supplier() { @@ -75,7 +76,7 @@ public class MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplierTest { @Test(expectedExceptions = AuthorizationException.class) public void testLoaderThrowsAuthorizationExceptionAndAlsoSetsExceptionTypeWhenNested() { - AtomicReference authException = new AtomicReference(); + AtomicReference authException = Atomics.newReference(); try { new SetAndThrowAuthorizationExceptionSupplierBackedLoader(new Supplier() { @@ -91,7 +92,7 @@ public class MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplierTest { @Test(expectedExceptions = RuntimeException.class) public void testLoaderThrowsOriginalExceptionAndAlsoSetsExceptionTypeWhenNestedAndNotAuthorizationException() { - AtomicReference authException = new AtomicReference(); + AtomicReference authException = Atomics.newReference(); try { new SetAndThrowAuthorizationExceptionSupplierBackedLoader(new Supplier() { @@ -214,7 +215,7 @@ public class MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplierTest { private void supplierThreadSafe(Function, Supplier> memoizer) throws Throwable { final AtomicInteger count = new AtomicInteger(0); - final AtomicReference thrown = new AtomicReference(null); + final AtomicReference thrown = Atomics.newReference(null); final int numThreads = 3; final Thread[] threads = new Thread[numThreads]; final long timeout = TimeUnit.SECONDS.toNanos(60); diff --git a/core/src/test/java/org/jclouds/rest/suppliers/SetAndThrowAuthorizationExceptionSupplierTest.java b/core/src/test/java/org/jclouds/rest/suppliers/SetAndThrowAuthorizationExceptionSupplierTest.java index a94f094a6a..7a3024dc01 100644 --- a/core/src/test/java/org/jclouds/rest/suppliers/SetAndThrowAuthorizationExceptionSupplierTest.java +++ b/core/src/test/java/org/jclouds/rest/suppliers/SetAndThrowAuthorizationExceptionSupplierTest.java @@ -28,6 +28,7 @@ import org.testng.annotations.Test; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; +import com.google.common.util.concurrent.Atomics; /** * @@ -37,7 +38,7 @@ import com.google.common.base.Suppliers; public class SetAndThrowAuthorizationExceptionSupplierTest { @Test public void testNormal() { - AtomicReference authException = new AtomicReference(); + AtomicReference authException = Atomics.newReference(); assertEquals( new SetAndThrowAuthorizationExceptionSupplier(Suppliers.ofInstance("foo"), authException).get(), "foo"); @@ -46,7 +47,7 @@ public class SetAndThrowAuthorizationExceptionSupplierTest { @Test(expectedExceptions = AuthorizationException.class) public void testThrowsAuthorizationExceptionAndAlsoSetsExceptionType() { - AtomicReference authException = new AtomicReference(); + AtomicReference authException = Atomics.newReference(); try { new SetAndThrowAuthorizationExceptionSupplier(new Supplier() { @@ -62,7 +63,7 @@ public class SetAndThrowAuthorizationExceptionSupplierTest { @Test(expectedExceptions = AuthorizationException.class) public void testThrowsAuthorizationExceptionAndAlsoSetsExceptionTypeWhenNested() { - AtomicReference authException = new AtomicReference(); + AtomicReference authException = Atomics.newReference(); try { new SetAndThrowAuthorizationExceptionSupplier(new Supplier() { @@ -78,7 +79,7 @@ public class SetAndThrowAuthorizationExceptionSupplierTest { @Test(expectedExceptions = RuntimeException.class) public void testThrowsOriginalExceptionAndAlsoSetsExceptionTypeWhenNestedAndNotAuthorizationException() { - AtomicReference authException = new AtomicReference(); + AtomicReference authException = Atomics.newReference(); try { new SetAndThrowAuthorizationExceptionSupplier(new Supplier() { diff --git a/loadbalancer/src/main/java/org/jclouds/loadbalancer/internal/BaseLoadBalancerService.java b/loadbalancer/src/main/java/org/jclouds/loadbalancer/internal/BaseLoadBalancerService.java index 6f8f649e77..c8f5a134c1 100644 --- a/loadbalancer/src/main/java/org/jclouds/loadbalancer/internal/BaseLoadBalancerService.java +++ b/loadbalancer/src/main/java/org/jclouds/loadbalancer/internal/BaseLoadBalancerService.java @@ -48,6 +48,7 @@ import org.jclouds.predicates.RetryablePredicate; import com.google.common.base.Predicate; import com.google.common.base.Supplier; +import com.google.common.util.concurrent.Atomics; import com.google.inject.Inject; /** @@ -136,7 +137,7 @@ public class BaseLoadBalancerService implements LoadBalancerService { public void destroyLoadBalancer(final String id) { checkNotNull(id, "id"); logger.debug(">> destroying load balancer(%s)", id); - final AtomicReference loadBalancer = new AtomicReference(); + final AtomicReference loadBalancer = Atomics.newReference(); RetryablePredicate tester = new RetryablePredicate(new Predicate() { @Override diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceContextModule.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceContextModule.java index f305db6d45..bee2cae775 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceContextModule.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/compute/config/AWSEC2ComputeServiceContextModule.java @@ -68,6 +68,7 @@ import com.google.common.base.Throwables; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableSet; +import com.google.common.util.concurrent.Atomics; import com.google.inject.Injector; import com.google.inject.Key; import com.google.inject.Provides; @@ -132,7 +133,7 @@ public class AWSEC2ComputeServiceContextModule extends BaseComputeServiceContext protected Supplier> provideRegionAndNameToImageSupplierCacheLoader( final RegionAndIdToImage delegate) { return Suppliers.>ofInstance(new CacheLoader() { - private final AtomicReference authException = new AtomicReference(); + private final AtomicReference authException = Atomics.newReference(); @Override public Image load(final RegionAndName key) throws Exception { diff --git a/resources/checkstyle.xml b/resources/checkstyle.xml index fcb311a4bd..e85c2ec089 100644 --- a/resources/checkstyle.xml +++ b/resources/checkstyle.xml @@ -56,6 +56,10 @@ + + + + diff --git a/sandbox-apis/nirvanix/src/main/java/org/jclouds/nirvanix/sdn/filters/AddSessionTokenToRequest.java b/sandbox-apis/nirvanix/src/main/java/org/jclouds/nirvanix/sdn/filters/AddSessionTokenToRequest.java index d01577cfac..b0d7cdea4f 100644 --- a/sandbox-apis/nirvanix/src/main/java/org/jclouds/nirvanix/sdn/filters/AddSessionTokenToRequest.java +++ b/sandbox-apis/nirvanix/src/main/java/org/jclouds/nirvanix/sdn/filters/AddSessionTokenToRequest.java @@ -26,6 +26,8 @@ import javax.inject.Provider; import javax.inject.Singleton; import javax.ws.rs.core.UriBuilder; +import com.google.commons.util.concurrent.Atomitcs; + import org.jclouds.http.HttpException; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequestFilter; @@ -82,7 +84,7 @@ public class AddSessionTokenToRequest implements HttpRequestFilter { public AddSessionTokenToRequest(@SessionToken Provider authTokenProvider, Provider builder) { this.builder = builder; this.authTokenProvider = authTokenProvider; - authToken = new AtomicReference(); + authToken = Atomics.newReference(); } @Override diff --git a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/functionloader/CurrentFunctionLoader.java b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/functionloader/CurrentFunctionLoader.java index 6e2f4ee01e..f5545acbad 100644 --- a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/functionloader/CurrentFunctionLoader.java +++ b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/functionloader/CurrentFunctionLoader.java @@ -20,12 +20,14 @@ package org.jclouds.scriptbuilder.functionloader; import java.util.concurrent.atomic.AtomicReference; +import com.google.common.util.concurrent.Atomics; + /** * Means to access the current {@link FunctionLoader} instance; */ public class CurrentFunctionLoader { - private static final AtomicReference ref = new AtomicReference( + private static final AtomicReference ref = Atomics.newReference( BasicFunctionLoader.INSTANCE); public static FunctionLoader get() { diff --git a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/functions/CredentialsFromAdminAccess.java b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/functions/CredentialsFromAdminAccess.java index b5055796f8..46ffcd2b77 100644 --- a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/functions/CredentialsFromAdminAccess.java +++ b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/functions/CredentialsFromAdminAccess.java @@ -28,6 +28,7 @@ import org.jclouds.scriptbuilder.domain.StatementVisitor; import org.jclouds.scriptbuilder.statements.login.AdminAccess; import com.google.common.base.Function; +import com.google.common.util.concurrent.Atomics; /** * @@ -40,7 +41,7 @@ public enum CredentialsFromAdminAccess implements Function credsHolder = new AtomicReference(); + final AtomicReference credsHolder = Atomics.newReference(); AcceptsStatementVisitor.class.cast(input).accept(new StatementVisitor() { @Override