From bf3a2ed7a87bae9aafdd64d210fc7ec17f8984c5 Mon Sep 17 00:00:00 2001 From: Everett Toews Date: Tue, 22 Jan 2013 20:10:28 -0600 Subject: [PATCH] These Parsers are unnecessary when the domain objects have ConstructorProperties. --- .../domain/ConnectionThrottle.java | 7 +- .../features/ConnectionAsyncApi.java | 4 +- .../features/HealthMonitorAsyncApi.java | 5 +- .../functions/ParseConnectionThrottle.java | 66 ------------------- .../functions/ParseHealthMonitor.java | 65 ------------------ 5 files changed, 10 insertions(+), 137 deletions(-) delete mode 100644 apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/functions/ParseConnectionThrottle.java delete mode 100644 apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/functions/ParseHealthMonitor.java diff --git a/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/domain/ConnectionThrottle.java b/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/domain/ConnectionThrottle.java index b6290ae5e7..cd6c0cdd4a 100644 --- a/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/domain/ConnectionThrottle.java +++ b/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/domain/ConnectionThrottle.java @@ -20,6 +20,8 @@ package org.jclouds.rackspace.cloudloadbalancers.domain; import static com.google.common.base.Preconditions.checkArgument; +import java.beans.ConstructorProperties; + import com.google.common.base.Objects; import com.google.common.base.Objects.ToStringHelper; @@ -37,7 +39,10 @@ public class ConnectionThrottle { private final int maxConnectionRate; private final int rateInterval; - protected ConnectionThrottle(int maxConnections, int minConnections, int maxConnectionRate, int rateInterval) { + @ConstructorProperties({ + "maxConnections", "minConnections", "maxConnectionRate", "rateInterval" + }) + protected ConnectionThrottle(Integer maxConnections, Integer minConnections, Integer maxConnectionRate, Integer rateInterval) { this.maxConnections = maxConnections; this.minConnections = minConnections; this.maxConnectionRate = maxConnectionRate; diff --git a/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/features/ConnectionAsyncApi.java b/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/features/ConnectionAsyncApi.java index 7b218fc43a..c940ff2786 100644 --- a/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/features/ConnectionAsyncApi.java +++ b/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/features/ConnectionAsyncApi.java @@ -33,12 +33,12 @@ import org.jclouds.Fallbacks.NullOnNotFoundOr404; import org.jclouds.Fallbacks.VoidOnNotFoundOr404; import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; import org.jclouds.rackspace.cloudloadbalancers.domain.ConnectionThrottle; -import org.jclouds.rackspace.cloudloadbalancers.functions.ParseConnectionThrottle; import org.jclouds.rackspace.cloudloadbalancers.functions.ParseNestedBoolean; import org.jclouds.rest.annotations.Fallback; import org.jclouds.rest.annotations.Payload; import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.ResponseParser; +import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.WrapWith; import com.google.common.util.concurrent.ListenableFuture; @@ -70,7 +70,7 @@ public interface ConnectionAsyncApi { @Named("connectionthrottle:get") @GET @Consumes(MediaType.APPLICATION_JSON) - @ResponseParser(ParseConnectionThrottle.class) + @SelectJson("connectionThrottle") @Fallback(NullOnNotFoundOr404.class) @Path("/connectionthrottle") ListenableFuture getConnectionThrottle(); diff --git a/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/features/HealthMonitorAsyncApi.java b/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/features/HealthMonitorAsyncApi.java index 59ba880702..4544f143ed 100644 --- a/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/features/HealthMonitorAsyncApi.java +++ b/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/features/HealthMonitorAsyncApi.java @@ -31,10 +31,9 @@ import org.jclouds.Fallbacks.NullOnNotFoundOr404; import org.jclouds.Fallbacks.VoidOnNotFoundOr404; import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest; import org.jclouds.rackspace.cloudloadbalancers.domain.HealthMonitor; -import org.jclouds.rackspace.cloudloadbalancers.functions.ParseHealthMonitor; import org.jclouds.rest.annotations.Fallback; import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.annotations.ResponseParser; +import org.jclouds.rest.annotations.SelectJson; import org.jclouds.rest.annotations.WrapWith; import com.google.common.util.concurrent.ListenableFuture; @@ -65,7 +64,7 @@ public interface HealthMonitorAsyncApi { @Named("healthmonitor:get") @GET @Consumes(MediaType.APPLICATION_JSON) - @ResponseParser(ParseHealthMonitor.class) + @SelectJson("healthMonitor") @Fallback(NullOnNotFoundOr404.class) @Path("/healthmonitor") ListenableFuture get(); diff --git a/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/functions/ParseConnectionThrottle.java b/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/functions/ParseConnectionThrottle.java deleted file mode 100644 index 7850bde545..0000000000 --- a/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/functions/ParseConnectionThrottle.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.rackspace.cloudloadbalancers.functions; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Map; - -import javax.inject.Inject; - -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.HttpResponseException; -import org.jclouds.http.functions.ParseJson; -import org.jclouds.rackspace.cloudloadbalancers.domain.ConnectionThrottle; -import org.jclouds.rest.InvocationContext; - -import com.google.common.base.Function; -import com.google.common.collect.Iterables; - -/** - * @author Everett Toews - */ -public class ParseConnectionThrottle implements - Function, InvocationContext { - - private final ParseJson> json; - - @Inject - ParseConnectionThrottle(ParseJson> json) { - this.json = checkNotNull(json, "json"); - } - - @Override - public ConnectionThrottle apply(HttpResponse response) { - Map map = json.apply(response); - - if (map == null || map.size() == 0) - throw new HttpResponseException("Unexpected connection throttle format returned.", null, response); - - ConnectionThrottle connectionThrottle = Iterables.get(map.values(), 0); - - return connectionThrottle.isValid() ? connectionThrottle : null; - } - - @Override - public ParseConnectionThrottle setContext(HttpRequest request) { - return this; - } -} diff --git a/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/functions/ParseHealthMonitor.java b/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/functions/ParseHealthMonitor.java deleted file mode 100644 index 0b9b5e03a3..0000000000 --- a/apis/rackspace-cloudloadbalancers/src/main/java/org/jclouds/rackspace/cloudloadbalancers/functions/ParseHealthMonitor.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.jclouds.rackspace.cloudloadbalancers.functions; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Map; - -import javax.inject.Inject; - -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.functions.ParseJson; -import org.jclouds.rackspace.cloudloadbalancers.domain.HealthMonitor; -import org.jclouds.rest.InvocationContext; - -import com.google.common.base.Function; -import com.google.common.collect.Iterables; - -/** - * @author Everett Toews - */ -public class ParseHealthMonitor implements - Function, InvocationContext { - - private final ParseJson> json; - - @Inject - ParseHealthMonitor(ParseJson> json) { - this.json = checkNotNull(json, "json"); - } - - @Override - public HealthMonitor apply(HttpResponse response) { - Map map = json.apply(response); - - if (map == null || map.size() == 0) - return null; - - HealthMonitor healthMonitor = Iterables.get(map.values(), 0); - - return healthMonitor.isValid() ? healthMonitor : null; - } - - @Override - public ParseHealthMonitor setContext(HttpRequest request) { - return this; - } -}