JCLOUDS-150. De-async SQS.

This commit is contained in:
Andrew Bayer 2013-07-02 19:03:59 -07:00
parent 91d6736c22
commit e6765cc5db
12 changed files with 354 additions and 729 deletions

View File

@ -36,7 +36,6 @@ import com.google.inject.Provides;
* <p/> * <p/>
* *
* @author Adrian Cole * @author Adrian Cole
* @see SQSAsyncApi
*/ */
@Beta @Beta
public interface SQSApi extends Closeable { public interface SQSApi extends Closeable {

View File

@ -25,8 +25,8 @@ import java.net.URI;
import java.util.Properties; import java.util.Properties;
import org.jclouds.apis.ApiMetadata; import org.jclouds.apis.ApiMetadata;
import org.jclouds.rest.internal.BaseRestApiMetadata; import org.jclouds.rest.internal.BaseHttpApiMetadata;
import org.jclouds.sqs.config.SQSRestClientModule; import org.jclouds.sqs.config.SQSHttpApiModule;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.TypeToken; import com.google.common.reflect.TypeToken;
@ -37,33 +37,23 @@ import com.google.inject.Module;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class SQSApiMetadata extends BaseRestApiMetadata { public class SQSApiMetadata extends BaseHttpApiMetadata {
/**
* @deprecated please use {@code org.jclouds.ContextBuilder#buildApi(SQSApi.class)} as
* {@link SQSAsyncApi} interface will be removed in jclouds 1.7.
*/
@Deprecated
public static final TypeToken<org.jclouds.rest.RestContext<SQSApi, SQSAsyncApi>> CONTEXT_TOKEN = new TypeToken<org.jclouds.rest.RestContext<SQSApi, SQSAsyncApi>>() {
private static final long serialVersionUID = 1L;
};
@Override @Override
public Builder toBuilder() { public Builder<?> toBuilder() {
return new Builder(getApi(), getAsyncApi()).fromApiMetadata(this); return new ConcreteBuilder().fromApiMetadata(this);
} }
@SuppressWarnings("deprecation")
public SQSApiMetadata() { public SQSApiMetadata() {
this(new Builder(SQSApi.class, SQSAsyncApi.class)); this(new ConcreteBuilder());
} }
protected SQSApiMetadata(Builder builder) { protected SQSApiMetadata(Builder<?> builder) {
super(builder); super(builder);
} }
public static Properties defaultProperties() { public static Properties defaultProperties() {
Properties properties = BaseRestApiMetadata.defaultProperties(); Properties properties = BaseHttpApiMetadata.defaultProperties();
properties.setProperty(CREATE_QUEUE_MAX_RETRIES, "60"); properties.setProperty(CREATE_QUEUE_MAX_RETRIES, "60");
properties.setProperty(CREATE_QUEUE_RETRY_INTERVAL, "1000"); properties.setProperty(CREATE_QUEUE_RETRY_INTERVAL, "1000");
properties.setProperty(PROPERTY_AUTH_TAG, "AWS"); properties.setProperty(PROPERTY_AUTH_TAG, "AWS");
@ -71,10 +61,9 @@ public class SQSApiMetadata extends BaseRestApiMetadata {
return properties; return properties;
} }
public static class Builder extends BaseRestApiMetadata.Builder<Builder> { public abstract static class Builder<T extends Builder<T>> extends BaseHttpApiMetadata.Builder<SQSApi, T> {
protected Builder(Class<?> api, Class<?> asyncApi) { protected Builder() {
super(api, asyncApi);
id("sqs") id("sqs")
.name("Amazon Simple Queue Service API") .name("Amazon Simple Queue Service API")
.identityName("Access Key ID") .identityName("Access Key ID")
@ -83,16 +72,18 @@ public class SQSApiMetadata extends BaseRestApiMetadata {
.defaultProperties(SQSApiMetadata.defaultProperties()) .defaultProperties(SQSApiMetadata.defaultProperties())
.defaultEndpoint("https://sqs.us-east-1.amazonaws.com") .defaultEndpoint("https://sqs.us-east-1.amazonaws.com")
.documentation(URI.create("http://docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference")) .documentation(URI.create("http://docs.amazonwebservices.com/AWSSimpleQueueService/latest/APIReference"))
.defaultModules(ImmutableSet.<Class<? extends Module>>of(SQSRestClientModule.class)); .defaultModules(ImmutableSet.<Class<? extends Module>>of(SQSHttpApiModule.class));
} }
@Override @Override
public SQSApiMetadata build() { public SQSApiMetadata build() {
return new SQSApiMetadata(this); return new SQSApiMetadata(this);
} }
}
private static class ConcreteBuilder extends Builder<ConcreteBuilder> {
@Override @Override
protected Builder self() { protected ConcreteBuilder self() {
return this; return this;
} }
} }

View File

@ -1,84 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.sqs;
import java.io.Closeable;
import java.net.URI;
import java.util.Set;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.javax.annotation.Nullable;
import org.jclouds.location.Region;
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
import org.jclouds.rest.annotations.Delegate;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.sqs.features.MessageAsyncApi;
import org.jclouds.sqs.features.PermissionAsyncApi;
import org.jclouds.sqs.features.QueueAsyncApi;
import com.google.common.annotations.Beta;
import com.google.inject.Provides;
/**
* Provides access to SQS via REST API.
* <p/>
*
* @see <a
* href="http://docs.amazonwebservices.com/AWSSimpleQueueService/2011-10-01/APIReference/Welcome.html">SQS
* documentation</a>
* @author Adrian Cole
* @deprecated please use {@code org.jclouds.ContextBuilder#buildApi(SQSApi.class)} as
* {@link SQSAsyncApi} interface will be removed in jclouds 1.7.
*/
@Deprecated
@Beta
@RequestFilters(FormSigner.class)
@VirtualHost
public interface SQSAsyncApi extends Closeable {
/**
*
* @return the Region codes configured
*/
@Provides
@Region
Set<String> getConfiguredRegions();
/**
* Provides asynchronous access to Queue features.
*/
@Delegate
QueueAsyncApi getQueueApi();
@Delegate
QueueAsyncApi getQueueApiForRegion(
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region);
/**
* Provides asynchronous access to Message features.
*/
@Delegate
MessageAsyncApi getMessageApiForQueue(@EndpointParam URI queue);
/**
* Provides asynchronous access to Permission features.
*/
@Delegate
PermissionAsyncApi getPermissionApiForQueue(@EndpointParam URI queue);
}

View File

@ -21,22 +21,18 @@ import static org.jclouds.reflect.Reflection2.typeToken;
import java.util.Map; import java.util.Map;
import org.jclouds.aws.config.FormSigningRestClientModule; import org.jclouds.aws.config.FormSigningHttpApiModule;
import org.jclouds.aws.handlers.AWSServerErrorRetryHandler; import org.jclouds.aws.handlers.AWSServerErrorRetryHandler;
import org.jclouds.http.HttpErrorHandler; import org.jclouds.http.HttpErrorHandler;
import org.jclouds.http.HttpRetryHandler; import org.jclouds.http.HttpRetryHandler;
import org.jclouds.http.annotation.ClientError; import org.jclouds.http.annotation.ClientError;
import org.jclouds.http.annotation.Redirection; import org.jclouds.http.annotation.Redirection;
import org.jclouds.http.annotation.ServerError; import org.jclouds.http.annotation.ServerError;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresHttpApi;
import org.jclouds.sqs.SQSApi; import org.jclouds.sqs.SQSApi;
import org.jclouds.sqs.SQSAsyncApi;
import org.jclouds.sqs.features.MessageApi; import org.jclouds.sqs.features.MessageApi;
import org.jclouds.sqs.features.MessageAsyncApi;
import org.jclouds.sqs.features.PermissionApi; import org.jclouds.sqs.features.PermissionApi;
import org.jclouds.sqs.features.PermissionAsyncApi;
import org.jclouds.sqs.features.QueueApi; import org.jclouds.sqs.features.QueueApi;
import org.jclouds.sqs.features.QueueAsyncApi;
import org.jclouds.sqs.handlers.ParseSQSErrorFromXmlContent; import org.jclouds.sqs.handlers.ParseSQSErrorFromXmlContent;
import org.jclouds.sqs.handlers.SQSErrorRetryHandler; import org.jclouds.sqs.handlers.SQSErrorRetryHandler;
@ -47,16 +43,11 @@ import com.google.common.collect.ImmutableMap;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@ConfiguresRestClient @ConfiguresHttpApi
public class SQSRestClientModule extends FormSigningRestClientModule<SQSApi, SQSAsyncApi> { public class SQSHttpApiModule extends FormSigningHttpApiModule<SQSApi> {
public static final Map<Class<?>, Class<?>> DELEGATE_MAP = ImmutableMap.<Class<?>, Class<?>> builder()//
.put(QueueApi.class, QueueAsyncApi.class)
.put(MessageApi.class, MessageAsyncApi.class)
.put(PermissionApi.class, PermissionAsyncApi.class)
.build();
public SQSRestClientModule() { public SQSHttpApiModule() {
super(typeToken(SQSApi.class), typeToken(SQSAsyncApi.class), DELEGATE_MAP); super(SQSApi.class);
} }
@Override @Override

View File

@ -16,12 +16,43 @@
*/ */
package org.jclouds.sqs.features; package org.jclouds.sqs.features;
import static org.jclouds.sqs.reference.SQSParameters.ACTION;
import static org.jclouds.sqs.reference.SQSParameters.VERSION;
import java.util.Map; import java.util.Map;
import javax.inject.Named;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.jclouds.Constants;
import org.jclouds.Fallbacks.VoidOnNotFoundOr404;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.FormParams;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.sqs.binders.BindChangeMessageVisibilityBatchRequestEntryToIndexedFormParams;
import org.jclouds.sqs.binders.BindDeleteMessageBatchRequestEntryToIndexedFormParams;
import org.jclouds.sqs.binders.BindSendMessageBatchRequestEntryToIndexedFormParams;
import org.jclouds.sqs.binders.BindSendMessageBatchRequestEntryWithDelaysToIndexedFormParams;
import org.jclouds.sqs.domain.BatchResult; import org.jclouds.sqs.domain.BatchResult;
import org.jclouds.sqs.domain.Message; import org.jclouds.sqs.domain.Message;
import org.jclouds.sqs.domain.MessageIdAndMD5; import org.jclouds.sqs.domain.MessageIdAndMD5;
import org.jclouds.sqs.options.ReceiveMessageOptions; import org.jclouds.sqs.options.ReceiveMessageOptions;
import org.jclouds.sqs.options.SendMessageOptions; import org.jclouds.sqs.options.SendMessageOptions;
import org.jclouds.sqs.xml.ChangeMessageVisibilityBatchResponseHandler;
import org.jclouds.sqs.xml.DeleteMessageBatchResponseHandler;
import org.jclouds.sqs.xml.MessageHandler;
import org.jclouds.sqs.xml.ReceiveMessageResponseHandler;
import org.jclouds.sqs.xml.RegexMessageIdAndMD5Handler;
import org.jclouds.sqs.xml.SendMessageBatchResponseHandler;
import com.google.common.collect.FluentIterable; import com.google.common.collect.FluentIterable;
import com.google.common.collect.Table; import com.google.common.collect.Table;
@ -30,9 +61,11 @@ import com.google.common.collect.Table;
* Provides access to SQS via their REST API. * Provides access to SQS via their REST API.
* <p/> * <p/>
* *
* @see MessageAsyncApi
* @author Adrian Cole * @author Adrian Cole
*/ */
@RequestFilters(FormSigner.class)
@FormParams(keys = VERSION, values = "{" + Constants.PROPERTY_API_VERSION + "}")
@VirtualHost
public interface MessageApi { public interface MessageApi {
/** /**
@ -67,7 +100,12 @@ public interface MessageApi {
* The receipt handle associated with the message you want to * The receipt handle associated with the message you want to
* delete. * delete.
*/ */
void delete(String receiptHandle); @Named("DeleteMessage")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "DeleteMessage")
@Fallback(VoidOnNotFoundOr404.class)
void delete(@FormParam("ReceiptHandle") String receiptHandle);
/** /**
* Currently, you can send up to 10 {@link #delete} requests. * Currently, you can send up to 10 {@link #delete} requests.
@ -91,7 +129,13 @@ public interface MessageApi {
* @return result that contains success or errors of the operation * @return result that contains success or errors of the operation
* @see #delete(String) * @see #delete(String)
*/ */
BatchResult<String> delete(Map<String, String> idReceiptHandle); @Named("DeleteMessageBatch")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "DeleteMessageBatch")
@XMLResponseParser(DeleteMessageBatchResponseHandler.class)
BatchResult<String> delete(
@BinderParam(BindDeleteMessageBatchRequestEntryToIndexedFormParams.class) Map<String, String> idReceiptHandle);
/** /**
* Same as {@link #delete(Map)}, except that we generate numeric ids starting * Same as {@link #delete(Map)}, except that we generate numeric ids starting
@ -101,7 +145,13 @@ public interface MessageApi {
* receipt handles to delete * receipt handles to delete
* @see #delete(Map) * @see #delete(Map)
*/ */
BatchResult<String> delete(Iterable<String> receiptHandles); @Named("DeleteMessageBatch")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "DeleteMessageBatch")
@XMLResponseParser(DeleteMessageBatchResponseHandler.class)
BatchResult<String> delete(
@BinderParam(BindDeleteMessageBatchRequestEntryToIndexedFormParams.class) Iterable<String> receiptHandles);
/** /**
* The ChangeMessageVisibility action changes the visibility timeout of a * The ChangeMessageVisibility action changes the visibility timeout of a
@ -143,7 +193,12 @@ public interface MessageApi {
* The new value for the message's visibility timeout (in seconds) * The new value for the message's visibility timeout (in seconds)
* from 0 to 43200 (maximum 12 hours) * from 0 to 43200 (maximum 12 hours)
*/ */
void changeVisibility(String receiptHandle, int visibilityTimeout); @Named("ChangeMessageVisibility")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ChangeMessageVisibility")
void changeVisibility(@FormParam("ReceiptHandle") String receiptHandle,
@FormParam("VisibilityTimeout") int visibilityTimeout);
/** /**
* Currently, you can send up to 10 {@link #changeVisibility} requests. * Currently, you can send up to 10 {@link #changeVisibility} requests.
@ -168,7 +223,13 @@ public interface MessageApi {
* @return result that contains success or errors of the operation * @return result that contains success or errors of the operation
* @see #changeVisibility(String, int) * @see #changeVisibility(String, int)
*/ */
BatchResult<String> changeVisibility(Table<String, String, Integer> idReceiptHandleVisibilityTimeout); @Named("ChangeMessageVisibilityBatch")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ChangeMessageVisibilityBatch")
@XMLResponseParser(ChangeMessageVisibilityBatchResponseHandler.class)
BatchResult<String> changeVisibility(
@BinderParam(BindChangeMessageVisibilityBatchRequestEntryToIndexedFormParams.class) Table<String, String, Integer> idReceiptHandleVisibilityTimeout);
/** /**
* Same as {@link #changeVisibility(Table)}, except that we generate numeric * Same as {@link #changeVisibility(Table)}, except that we generate numeric
@ -178,7 +239,13 @@ public interface MessageApi {
* receipt handle to visibility timeout * receipt handle to visibility timeout
* @see #changeVisibility(Table) * @see #changeVisibility(Table)
*/ */
BatchResult<? extends MessageIdAndMD5> changeVisibility(Map<String, Integer> receiptHandleVisibilityTimeout); @Named("ChangeMessageVisibilityBatch")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ChangeMessageVisibilityBatch")
@XMLResponseParser(ChangeMessageVisibilityBatchResponseHandler.class)
BatchResult<MessageIdAndMD5> changeVisibility(
@BinderParam(BindChangeMessageVisibilityBatchRequestEntryToIndexedFormParams.class) Map<String, Integer> receiptHandleVisibilityTimeout);
/** /**
* Currently, you can send up to 10 {@link #changeVisibility} requests. * Currently, you can send up to 10 {@link #changeVisibility} requests.
@ -204,7 +271,15 @@ public interface MessageApi {
* @return result that contains success or errors of the operation * @return result that contains success or errors of the operation
* @see #changeVisibility(String, int) * @see #changeVisibility(String, int)
*/ */
BatchResult<String> changeVisibility(Map<String, String> idReceiptHandle, int visibilityTimeout); @Named("ChangeMessageVisibilityBatch")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ChangeMessageVisibilityBatch")
@MapBinder(BindChangeMessageVisibilityBatchRequestEntryToIndexedFormParams.class)
@XMLResponseParser(ChangeMessageVisibilityBatchResponseHandler.class)
BatchResult<String> changeVisibility(
@PayloadParam("idReceiptHandle") Map<String, String> idReceiptHandle,
@PayloadParam("visibilityTimeout") int visibilityTimeout);
/** /**
* Same as {@link #changeVisibility(Map, int)}, except that we generate * Same as {@link #changeVisibility(Map, int)}, except that we generate
@ -214,7 +289,15 @@ public interface MessageApi {
* receipt handles to change visibility * receipt handles to change visibility
* @see #changeVisibility(Map, int) * @see #changeVisibility(Map, int)
*/ */
BatchResult<String> changeVisibility(Iterable<String> receiptHandles, int visibilityTimeout); @Named("ChangeMessageVisibilityBatch")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ChangeMessageVisibilityBatch")
@MapBinder(BindChangeMessageVisibilityBatchRequestEntryToIndexedFormParams.class)
@XMLResponseParser(ChangeMessageVisibilityBatchResponseHandler.class)
BatchResult<String> changeVisibility(
@PayloadParam("receiptHandles") Iterable<String> receiptHandles,
@PayloadParam("visibilityTimeout") int visibilityTimeout);
/** /**
* The SendMessage action delivers a message to the specified queue. The * The SendMessage action delivers a message to the specified queue. The
@ -238,7 +321,27 @@ public interface MessageApi {
* characters, see the preceding important note. * characters, see the preceding important note.
* @return id of the message and md5 of the content sent * @return id of the message and md5 of the content sent
*/ */
MessageIdAndMD5 send(String message); @Named("SendMessage")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "SendMessage")
@ResponseParser(RegexMessageIdAndMD5Handler.class)
MessageIdAndMD5 send(@FormParam("MessageBody") String message);
/**
* same as {@link #sendMessage(URI, String)} except you can control options
* such as delay seconds.
*
* @param options
* options such as delay seconds
* @see #sendMessage(URI, String)
*/
@Named("SendMessage")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "SendMessage")
@ResponseParser(RegexMessageIdAndMD5Handler.class)
MessageIdAndMD5 send(@FormParam("MessageBody") String message, SendMessageOptions options);
/** /**
* Same as {@link #send(Map)} except you can set a delay for each message in * Same as {@link #send(Map)} except you can set a delay for each message in
@ -264,7 +367,14 @@ public interface MessageApi {
* @return result that contains success or errors of the operation * @return result that contains success or errors of the operation
* @see #send(String, SendMessageOptions) * @see #send(String, SendMessageOptions)
*/ */
BatchResult<? extends MessageIdAndMD5> sendWithDelays(Table<String, String, Integer> idMessageBodyDelaySeconds); @Named("SendMessageBatch")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "SendMessageBatch")
@ResponseParser(RegexMessageIdAndMD5Handler.class)
@XMLResponseParser(SendMessageBatchResponseHandler.class)
BatchResult<? extends MessageIdAndMD5> sendWithDelays(
@BinderParam(BindSendMessageBatchRequestEntryWithDelaysToIndexedFormParams.class) Table<String, String, Integer> idMessageBodyDelaySeconds);
/** /**
* Same as {@link #sendWithDelays(Table)}, except that we generate numeric * Same as {@link #sendWithDelays(Table)}, except that we generate numeric
@ -274,7 +384,14 @@ public interface MessageApi {
* message body to the delay desired * message body to the delay desired
* @see #sendWithDelays(Table) * @see #sendWithDelays(Table)
*/ */
BatchResult<? extends MessageIdAndMD5> sendWithDelays(Map<String, Integer> messageBodyDelaySeconds); @Named("SendMessageBatch")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "SendMessageBatch")
@ResponseParser(RegexMessageIdAndMD5Handler.class)
@XMLResponseParser(SendMessageBatchResponseHandler.class)
BatchResult<? extends MessageIdAndMD5> sendWithDelays(
@BinderParam(BindSendMessageBatchRequestEntryWithDelaysToIndexedFormParams.class) Map<String, Integer> messageBodyDelaySeconds);
/** /**
* Same as {@link #send(Map)} except you set a delay for all messages in the * Same as {@link #send(Map)} except you set a delay for all messages in the
@ -287,7 +404,15 @@ public interface MessageApi {
* *
* @see #send(String, SendMessageOptions) * @see #send(String, SendMessageOptions)
*/ */
BatchResult<? extends MessageIdAndMD5> sendWithDelay(Map<String, String> idMessageBody, int delaySeconds); @Named("SendMessageBatch")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "SendMessageBatch")
@MapBinder(BindSendMessageBatchRequestEntryWithDelaysToIndexedFormParams.class)
@XMLResponseParser(SendMessageBatchResponseHandler.class)
BatchResult<? extends MessageIdAndMD5> sendWithDelay(
@PayloadParam("idMessageBody") Map<String, String> idMessageBody,
@PayloadParam("delaySeconds") int delaySeconds);
/** /**
* Same as {@link #sendWithDelay(Map, int)}, except that we generate numeric * Same as {@link #sendWithDelay(Map, int)}, except that we generate numeric
@ -297,7 +422,14 @@ public interface MessageApi {
* message bodies to send * message bodies to send
* @see #sendWithDelay(Map, int) * @see #sendWithDelay(Map, int)
*/ */
BatchResult<? extends MessageIdAndMD5> sendWithDelay(Iterable<String> messageBodies, int delaySeconds); @Named("SendMessageBatch")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "SendMessageBatch")
@MapBinder(BindSendMessageBatchRequestEntryWithDelaysToIndexedFormParams.class)
@XMLResponseParser(SendMessageBatchResponseHandler.class)
BatchResult<? extends MessageIdAndMD5> sendWithDelay(
@PayloadParam("messageBodies") Iterable<String> messageBodies, @PayloadParam("delaySeconds") int delaySeconds);
/** /**
* The SendMessageBatch action delivers up to ten messages to the specified * The SendMessageBatch action delivers up to ten messages to the specified
@ -329,7 +461,13 @@ public interface MessageApi {
* @return result that contains success or errors of the operation * @return result that contains success or errors of the operation
* @see #send(String) * @see #send(String)
*/ */
BatchResult<? extends MessageIdAndMD5> send(Map<String, String> idMessageBody); @Named("SendMessageBatch")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "SendMessageBatch")
@XMLResponseParser(SendMessageBatchResponseHandler.class)
BatchResult<? extends MessageIdAndMD5> send(
@BinderParam(BindSendMessageBatchRequestEntryToIndexedFormParams.class) Map<String, String> idMessageBody);
/** /**
* Same as {@link #send(Map)}, except that we generate numeric ids starting * Same as {@link #send(Map)}, except that we generate numeric ids starting
@ -339,17 +477,13 @@ public interface MessageApi {
* message bodies to send * message bodies to send
* @see #send(Map) * @see #send(Map)
*/ */
BatchResult<? extends MessageIdAndMD5> send(Iterable<String> messageBodies); @Named("SendMessageBatch")
@POST
/** @Path("/")
* same as {@link #sendMessage(URI, String)} except you can control options @FormParams(keys = ACTION, values = "SendMessageBatch")
* such as delay seconds. @XMLResponseParser(SendMessageBatchResponseHandler.class)
* BatchResult<? extends MessageIdAndMD5> send(
* @param options @BinderParam(BindSendMessageBatchRequestEntryToIndexedFormParams.class) Iterable<String> messageBodies);
* options such as delay seconds
* @see #sendMessage(URI, String)
*/
MessageIdAndMD5 send(String message, SendMessageOptions options);
/** /**
* The ReceiveMessage action retrieves one or more messages from the * The ReceiveMessage action retrieves one or more messages from the
@ -373,6 +507,11 @@ public interface MessageApi {
* from where you are receiving messages * from where you are receiving messages
* @return message including the receipt handle you can use to delete it * @return message including the receipt handle you can use to delete it
*/ */
@Named("ReceiveMessage")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ReceiveMessage")
@XMLResponseParser(MessageHandler.class)
Message receive(); Message receive();
/** /**
@ -386,6 +525,11 @@ public interface MessageApi {
* options such as VisibilityTimeout * options such as VisibilityTimeout
* @see #receive(URI) * @see #receive(URI)
*/ */
@Named("ReceiveMessage")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ReceiveMessage")
@XMLResponseParser(MessageHandler.class)
Message receive(ReceiveMessageOptions options); Message receive(ReceiveMessageOptions options);
/** /**
@ -395,7 +539,12 @@ public interface MessageApi {
* maximum messages to receive, current limit is 10 * maximum messages to receive, current limit is 10
* @see #receive(URI) * @see #receive(URI)
*/ */
FluentIterable<Message> receive(int max); @Named("ReceiveMessage")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ReceiveMessage")
@XMLResponseParser(ReceiveMessageResponseHandler.class)
FluentIterable<Message> receive(@FormParam("MaxNumberOfMessages") int max);
/** /**
* same as {@link #receive(URI, int)} except you can provide options like * same as {@link #receive(URI, int)} except you can provide options like
@ -408,5 +557,12 @@ public interface MessageApi {
* options such as VisibilityTimeout * options such as VisibilityTimeout
* @see #receive(URI, int) * @see #receive(URI, int)
*/ */
FluentIterable<Message> receive(int max, ReceiveMessageOptions options); @Named("ReceiveMessage")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ReceiveMessage")
@XMLResponseParser(ReceiveMessageResponseHandler.class)
FluentIterable<Message> receive(@FormParam("MaxNumberOfMessages") int max,
ReceiveMessageOptions options);
} }

View File

@ -1,294 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.sqs.features;
import static org.jclouds.sqs.reference.SQSParameters.ACTION;
import static org.jclouds.sqs.reference.SQSParameters.VERSION;
import java.util.Map;
import javax.inject.Named;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.jclouds.Constants;
import org.jclouds.Fallbacks.VoidOnNotFoundOr404;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.FormParams;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.PayloadParam;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.sqs.binders.BindChangeMessageVisibilityBatchRequestEntryToIndexedFormParams;
import org.jclouds.sqs.binders.BindDeleteMessageBatchRequestEntryToIndexedFormParams;
import org.jclouds.sqs.binders.BindSendMessageBatchRequestEntryToIndexedFormParams;
import org.jclouds.sqs.binders.BindSendMessageBatchRequestEntryWithDelaysToIndexedFormParams;
import org.jclouds.sqs.domain.BatchResult;
import org.jclouds.sqs.domain.Message;
import org.jclouds.sqs.domain.MessageIdAndMD5;
import org.jclouds.sqs.options.ReceiveMessageOptions;
import org.jclouds.sqs.options.SendMessageOptions;
import org.jclouds.sqs.xml.ChangeMessageVisibilityBatchResponseHandler;
import org.jclouds.sqs.xml.DeleteMessageBatchResponseHandler;
import org.jclouds.sqs.xml.MessageHandler;
import org.jclouds.sqs.xml.ReceiveMessageResponseHandler;
import org.jclouds.sqs.xml.RegexMessageIdAndMD5Handler;
import org.jclouds.sqs.xml.SendMessageBatchResponseHandler;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Table;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides access to SQS via their REST API.
* <p/>
*
* @author Adrian Cole
*/
@RequestFilters(FormSigner.class)
@FormParams(keys = VERSION, values = "{" + Constants.PROPERTY_API_VERSION + "}")
@VirtualHost
public interface MessageAsyncApi {
/**
* @see MessageApi#delete(String)
*/
@Named("DeleteMessage")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "DeleteMessage")
@Fallback(VoidOnNotFoundOr404.class)
ListenableFuture<Void> delete(@FormParam("ReceiptHandle") String receiptHandle);
/**
* @see MessageApi#delete(Map)
*/
@Named("DeleteMessageBatch")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "DeleteMessageBatch")
@XMLResponseParser(DeleteMessageBatchResponseHandler.class)
ListenableFuture<? extends BatchResult<String>> delete(
@BinderParam(BindDeleteMessageBatchRequestEntryToIndexedFormParams.class) Map<String, String> idReceiptHandle);
/**
* @see MessageApi#delete(Iterable)
*/
@Named("DeleteMessageBatch")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "DeleteMessageBatch")
@XMLResponseParser(DeleteMessageBatchResponseHandler.class)
ListenableFuture<? extends BatchResult<String>> delete(
@BinderParam(BindDeleteMessageBatchRequestEntryToIndexedFormParams.class) Iterable<String> receiptHandles);
/**
* @see MessageApi#changeVisibility(String, int)
*/
@Named("ChangeMessageVisibility")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ChangeMessageVisibility")
ListenableFuture<Void> changeVisibility(@FormParam("ReceiptHandle") String receiptHandle,
@FormParam("VisibilityTimeout") int visibilityTimeout);
/**
* @see MessageApi#changeVisibility(Table)
*/
@Named("ChangeMessageVisibilityBatch")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ChangeMessageVisibilityBatch")
@XMLResponseParser(ChangeMessageVisibilityBatchResponseHandler.class)
ListenableFuture<? extends BatchResult<String>> changeVisibility(
@BinderParam(BindChangeMessageVisibilityBatchRequestEntryToIndexedFormParams.class) Table<String, String, Integer> idReceiptHandleVisibilityTimeout);
/**
* @see MessageApi#changeVisibility(Map)
*/
@Named("ChangeMessageVisibilityBatch")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ChangeMessageVisibilityBatch")
@XMLResponseParser(ChangeMessageVisibilityBatchResponseHandler.class)
ListenableFuture<? extends BatchResult<String>> changeVisibility(
@BinderParam(BindChangeMessageVisibilityBatchRequestEntryToIndexedFormParams.class) Map<String, Integer> receiptHandleVisibilityTimeout);
/**
* @see MessageApi#changeVisibility(Map, int)
*/
@Named("ChangeMessageVisibilityBatch")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ChangeMessageVisibilityBatch")
@MapBinder(BindChangeMessageVisibilityBatchRequestEntryToIndexedFormParams.class)
@XMLResponseParser(ChangeMessageVisibilityBatchResponseHandler.class)
ListenableFuture<? extends BatchResult<String>> changeVisibility(
@PayloadParam("idReceiptHandle") Map<String, String> idReceiptHandle,
@PayloadParam("visibilityTimeout") int visibilityTimeout);
/**
* @see MessageApi#changeVisibility(Iterable, int)
*/
@Named("ChangeMessageVisibilityBatch")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ChangeMessageVisibilityBatch")
@MapBinder(BindChangeMessageVisibilityBatchRequestEntryToIndexedFormParams.class)
@XMLResponseParser(ChangeMessageVisibilityBatchResponseHandler.class)
ListenableFuture<? extends BatchResult<String>> changeVisibility(
@PayloadParam("receiptHandles") Iterable<String> receiptHandles,
@PayloadParam("visibilityTimeout") int visibilityTimeout);
/**
* @see MessageApi#send(String)
*/
@Named("SendMessage")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "SendMessage")
@ResponseParser(RegexMessageIdAndMD5Handler.class)
ListenableFuture<? extends MessageIdAndMD5> send(@FormParam("MessageBody") String message);
/**
* @see MessageApi#send(String, SendMessageOptions)
*/
@Named("SendMessage")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "SendMessage")
@ResponseParser(RegexMessageIdAndMD5Handler.class)
ListenableFuture<? extends MessageIdAndMD5> send(@FormParam("MessageBody") String message, SendMessageOptions options);
/**
* @see MessageApi#sendWithDelays(Table)
*/
@Named("SendMessageBatch")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "SendMessageBatch")
@ResponseParser(RegexMessageIdAndMD5Handler.class)
@XMLResponseParser(SendMessageBatchResponseHandler.class)
ListenableFuture<? extends BatchResult<? extends MessageIdAndMD5>> sendWithDelays(
@BinderParam(BindSendMessageBatchRequestEntryWithDelaysToIndexedFormParams.class) Table<String, String, Integer> idMessageBodyDelaySeconds);
/**
* @see MessageApi#sendWithDelays(Map)
*/
@Named("SendMessageBatch")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "SendMessageBatch")
@ResponseParser(RegexMessageIdAndMD5Handler.class)
@XMLResponseParser(SendMessageBatchResponseHandler.class)
ListenableFuture<? extends BatchResult<? extends MessageIdAndMD5>> sendWithDelays(
@BinderParam(BindSendMessageBatchRequestEntryWithDelaysToIndexedFormParams.class) Map<String, Integer> messageBodyDelaySeconds);
/**
* @see MessageApi#sendWithDelay(Map, int)
*/
@Named("SendMessageBatch")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "SendMessageBatch")
@MapBinder(BindSendMessageBatchRequestEntryWithDelaysToIndexedFormParams.class)
@XMLResponseParser(SendMessageBatchResponseHandler.class)
ListenableFuture<? extends BatchResult<? extends MessageIdAndMD5>> sendWithDelay(
@PayloadParam("idMessageBody") Map<String, String> idMessageBody,
@PayloadParam("delaySeconds") int delaySeconds);
/**
* @see MessageApi#sendWithDelay(Iterable, int)
*/
@Named("SendMessageBatch")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "SendMessageBatch")
@MapBinder(BindSendMessageBatchRequestEntryWithDelaysToIndexedFormParams.class)
@XMLResponseParser(SendMessageBatchResponseHandler.class)
ListenableFuture<? extends BatchResult<? extends MessageIdAndMD5>> sendWithDelay(
@PayloadParam("messageBodies") Iterable<String> messageBodies, @PayloadParam("delaySeconds") int delaySeconds);
/**
* @see MessageApi#send(Map)
*/
@Named("SendMessageBatch")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "SendMessageBatch")
@XMLResponseParser(SendMessageBatchResponseHandler.class)
ListenableFuture<? extends BatchResult<? extends MessageIdAndMD5>> send(
@BinderParam(BindSendMessageBatchRequestEntryToIndexedFormParams.class) Map<String, String> idMessageBody);
/**
* @see MessageApi#send(Iterable)
*/
@Named("SendMessageBatch")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "SendMessageBatch")
@XMLResponseParser(SendMessageBatchResponseHandler.class)
ListenableFuture<? extends BatchResult<? extends MessageIdAndMD5>> send(
@BinderParam(BindSendMessageBatchRequestEntryToIndexedFormParams.class) Iterable<String> messageBodies);
/**
* @see MessageApi#receive()
*/
@Named("ReceiveMessage")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ReceiveMessage")
@XMLResponseParser(MessageHandler.class)
ListenableFuture<Message> receive();
/**
* @see MessageApi#receive(ReceiveMessageOptions)
*/
@Named("ReceiveMessage")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ReceiveMessage")
@XMLResponseParser(MessageHandler.class)
ListenableFuture<? extends Message> receive(ReceiveMessageOptions options);
/**
* @see MessageApi#receive(int)
*/
@Named("ReceiveMessage")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ReceiveMessage")
@XMLResponseParser(ReceiveMessageResponseHandler.class)
ListenableFuture<? extends FluentIterable<? extends Message>> receive(@FormParam("MaxNumberOfMessages") int max);
/**
* @see MessageApi#receive(int, ReceiveMessageOptions)
*/
@Named("ReceiveMessage")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ReceiveMessage")
@XMLResponseParser(ReceiveMessageResponseHandler.class)
ListenableFuture<? extends FluentIterable<? extends Message>> receive(@FormParam("MaxNumberOfMessages") int max,
ReceiveMessageOptions options);
}

View File

@ -16,15 +16,30 @@
*/ */
package org.jclouds.sqs.features; package org.jclouds.sqs.features;
import static org.jclouds.sqs.reference.SQSParameters.ACTION;
import static org.jclouds.sqs.reference.SQSParameters.VERSION;
import javax.inject.Named;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.jclouds.Constants;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.rest.annotations.FormParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.sqs.domain.Action; import org.jclouds.sqs.domain.Action;
/** /**
* Provides access to SQS via their REST API. * Provides access to SQS via their REST API.
* <p/> * <p/>
* *
* @see PermissionAsyncApi
* @author Adrian Cole * @author Adrian Cole
*/ */
@RequestFilters(FormSigner.class)
@FormParams(keys = VERSION, values = "{" + Constants.PROPERTY_API_VERSION + "}")
@VirtualHost
public interface PermissionApi { public interface PermissionApi {
/** /**
@ -62,7 +77,12 @@ public interface PermissionApi {
* Constraints: Valid 12-digit AWS account number, without hyphens * Constraints: Valid 12-digit AWS account number, without hyphens
* *
*/ */
void addPermissionToAccount(String label, Action permission, String accountId); @Named("AddPermission")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "AddPermission")
void addPermissionToAccount(@FormParam("Label") String label,
@FormParam("ActionName.1") Action permission, @FormParam("AWSAccountId.1") String accountId);
/** /**
* The RemovePermission action revokes any permissions in the queue policy * The RemovePermission action revokes any permissions in the queue policy
@ -76,6 +96,10 @@ public interface PermissionApi {
* The identification of the permission you want to remove. This is * The identification of the permission you want to remove. This is
* the label you added in AddPermission. example: AliceSendMessage * the label you added in AddPermission. example: AliceSendMessage
*/ */
void remove(String label); @Named("RemovePermission")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "RemovePermission")
void remove(@FormParam("Label") String label);
} }

View File

@ -1,66 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.sqs.features;
import static org.jclouds.sqs.reference.SQSParameters.ACTION;
import static org.jclouds.sqs.reference.SQSParameters.VERSION;
import javax.inject.Named;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.jclouds.Constants;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.rest.annotations.FormParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.sqs.domain.Action;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides access to SQS via their REST API.
* <p/>
*
* @author Adrian Cole
*/
@RequestFilters(FormSigner.class)
@FormParams(keys = VERSION, values = "{" + Constants.PROPERTY_API_VERSION + "}")
@VirtualHost
public interface PermissionAsyncApi {
/**
* @see PermissionApi#addPermissionToAccount
*/
@Named("AddPermission")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "AddPermission")
ListenableFuture<Void> addPermissionToAccount(@FormParam("Label") String label,
@FormParam("ActionName.1") Action permission, @FormParam("AWSAccountId.1") String accountId);
/**
* @see PermissionApi#remove
*/
@Named("RemovePermission")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "RemovePermission")
ListenableFuture<Void> remove(@FormParam("Label") String label);
}

View File

@ -16,11 +16,39 @@
*/ */
package org.jclouds.sqs.features; package org.jclouds.sqs.features;
import static org.jclouds.sqs.reference.SQSParameters.ACTION;
import static org.jclouds.sqs.reference.SQSParameters.VERSION;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import javax.inject.Named;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.jclouds.Constants;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.Fallbacks.VoidOnNotFoundOr404;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.FormParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.Transform;
import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.sqs.binders.BindAttributeNamesToIndexedFormParams;
import org.jclouds.sqs.domain.QueueAttributes; import org.jclouds.sqs.domain.QueueAttributes;
import org.jclouds.sqs.functions.MapToQueueAttributes;
import org.jclouds.sqs.options.CreateQueueOptions; import org.jclouds.sqs.options.CreateQueueOptions;
import org.jclouds.sqs.options.ListQueuesOptions; import org.jclouds.sqs.options.ListQueuesOptions;
import org.jclouds.sqs.xml.AttributesHandler;
import org.jclouds.sqs.xml.RegexListQueuesResponseHandler;
import org.jclouds.sqs.xml.RegexQueueHandler;
import org.jclouds.sqs.xml.ValueHandler;
import com.google.common.collect.FluentIterable; import com.google.common.collect.FluentIterable;
@ -28,9 +56,11 @@ import com.google.common.collect.FluentIterable;
* Provides access to SQS via their REST API. * Provides access to SQS via their REST API.
* <p/> * <p/>
* *
* @see QueueAsyncApi
* @author Adrian Cole * @author Adrian Cole
*/ */
@RequestFilters(FormSigner.class)
@FormParams(keys = VERSION, values = "{" + Constants.PROPERTY_API_VERSION + "}")
@VirtualHost
public interface QueueApi { public interface QueueApi {
/** /**
@ -48,8 +78,18 @@ public interface QueueApi {
* "http://docs.amazonwebservices.com/AWSSimpleQueueService/2011-10-01/APIReference/Query_QueryListQueues.html" * "http://docs.amazonwebservices.com/AWSSimpleQueueService/2011-10-01/APIReference/Query_QueryListQueues.html"
* /> * />
*/ */
@Named("ListQueues")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ListQueues")
@ResponseParser(RegexListQueuesResponseHandler.class)
FluentIterable<URI> list(); FluentIterable<URI> list();
@Named("ListQueues")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ListQueues")
@ResponseParser(RegexListQueuesResponseHandler.class)
FluentIterable<URI> list(ListQueuesOptions options); FluentIterable<URI> list(ListQueuesOptions options);
/** /**
@ -61,7 +101,13 @@ public interface QueueApi {
* The name of an existing queue. * The name of an existing queue.
* @return uri of the queue or null if not found * @return uri of the queue or null if not found
*/ */
URI get(String queueName); @Named("GetQueueUrl")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "GetQueueUrl")
@ResponseParser(RegexQueueHandler.class)
@Fallback(NullOnNotFoundOr404.class)
URI get(@FormParam("QueueName") String queueName);
/** /**
* like {@link #get(String)}, except specifying the owner of the queue. * like {@link #get(String)}, except specifying the owner of the queue.
@ -73,7 +119,14 @@ public interface QueueApi {
* @param accountId * @param accountId
* @return The AWS account ID of the account that created the queue. * @return The AWS account ID of the account that created the queue.
*/ */
URI getInAccount(String queueName, String accountId); @Named("GetQueueUrl")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "GetQueueUrl")
@ResponseParser(RegexQueueHandler.class)
@Fallback(NullOnNotFoundOr404.class)
URI getInAccount(@FormParam("QueueName") String queueName,
@FormParam("QueueOwnerAWSAccountId") String accountId);
/** /**
* The CreateQueue action creates a new queue. * The CreateQueue action creates a new queue.
@ -104,7 +157,12 @@ public interface QueueApi {
* characters; alphanumeric characters, hyphens (-), and * characters; alphanumeric characters, hyphens (-), and
* underscores (_) are allowed. * underscores (_) are allowed.
*/ */
URI create(String queueName); @Named("CreateQueue")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "CreateQueue")
@ResponseParser(RegexQueueHandler.class)
URI create(@FormParam("QueueName") String queueName);
/** /**
* same as {@link #create(String, String)} except you can * same as {@link #create(String, String)} except you can
@ -114,7 +172,12 @@ public interface QueueApi {
* options such as delay seconds * options such as delay seconds
* @see #create(String, String) * @see #create(String, String)
*/ */
URI create(String queueName, CreateQueueOptions options); @Named("CreateQueue")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "CreateQueue")
@ResponseParser(RegexQueueHandler.class)
URI create(@FormParam("QueueName") String queueName, CreateQueueOptions options);
/** /**
* The DeleteQueue action deletes the queue specified by the queue URL, * The DeleteQueue action deletes the queue specified by the queue URL,
@ -140,7 +203,12 @@ public interface QueueApi {
* @param queue * @param queue
* queue you want to delete * queue you want to delete
*/ */
void delete(URI queue); @Named("DeleteQueue")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "DeleteQueue")
@Fallback(VoidOnNotFoundOr404.class)
void delete(@EndpointParam URI queue);
/** /**
* returns all attributes of a queue. * returns all attributes of a queue.
@ -148,7 +216,41 @@ public interface QueueApi {
* @param queue * @param queue
* queue to get the attributes of * queue to get the attributes of
*/ */
QueueAttributes getAttributes(URI queue); @Named("GetQueueAttributes")
@POST
@Path("/")
@FormParams(keys = { ACTION, "AttributeName.1" }, values = { "GetQueueAttributes", "All" })
@Transform(MapToQueueAttributes.class)
@Fallback(NullOnNotFoundOr404.class)
@XMLResponseParser(AttributesHandler.class)
QueueAttributes getAttributes(@EndpointParam URI queue);
/**
* returns an attribute of a queue.
*
* @param queue
* queue to get the attributes of
*/
@Named("GetQueueAttributes")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "GetQueueAttributes")
@XMLResponseParser(AttributesHandler.class)
Map<String, String> getAttributes(@EndpointParam URI queue,
@BinderParam(BindAttributeNamesToIndexedFormParams.class) Iterable<String> attributeNames);
/**
* returns an attribute of a queue.
*
* @param queue
* queue to get the attributes of
*/
@Named("GetQueueAttributes")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "GetQueueAttributes")
@XMLResponseParser(ValueHandler.class)
String getAttribute(@EndpointParam URI queue, @FormParam("AttributeName.1") String attributeName);
/** /**
* The SetQueueAttributes action sets one attribute of a queue per request. * The SetQueueAttributes action sets one attribute of a queue per request.
@ -205,22 +307,11 @@ public interface QueueApi {
* DelaySeconds - An integer from 0 to 900 (15 minutes). The * DelaySeconds - An integer from 0 to 900 (15 minutes). The
* default for this attribute is 0. * default for this attribute is 0.
*/ */
void setAttribute(URI queue, String name, String value); @Named("SetQueueAttributes")
@POST
/** @Path("/")
* returns some attributes of a queue. @FormParams(keys = ACTION, values = "SetQueueAttributes")
* void setAttribute(@EndpointParam URI queue, @FormParam("Attribute.Name") String name,
* @param queue @FormParam("Attribute.Value") String value);
* queue to get the attributes of
*/
Map<String, String> getAttributes(URI queue, Iterable<String> attributeNames);
/**
* returns an attribute of a queue.
*
* @param queue
* queue to get the attributes of
*/
String getAttribute(URI queue, String attributeName);
} }

View File

@ -1,183 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.sqs.features;
import static org.jclouds.sqs.reference.SQSParameters.ACTION;
import static org.jclouds.sqs.reference.SQSParameters.VERSION;
import java.net.URI;
import java.util.Map;
import javax.inject.Named;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import org.jclouds.Constants;
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
import org.jclouds.Fallbacks.VoidOnNotFoundOr404;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.EndpointParam;
import org.jclouds.rest.annotations.Fallback;
import org.jclouds.rest.annotations.FormParams;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.ResponseParser;
import org.jclouds.rest.annotations.Transform;
import org.jclouds.rest.annotations.VirtualHost;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.sqs.binders.BindAttributeNamesToIndexedFormParams;
import org.jclouds.sqs.domain.QueueAttributes;
import org.jclouds.sqs.functions.MapToQueueAttributes;
import org.jclouds.sqs.options.CreateQueueOptions;
import org.jclouds.sqs.options.ListQueuesOptions;
import org.jclouds.sqs.xml.AttributesHandler;
import org.jclouds.sqs.xml.RegexListQueuesResponseHandler;
import org.jclouds.sqs.xml.RegexQueueHandler;
import org.jclouds.sqs.xml.ValueHandler;
import com.google.common.collect.FluentIterable;
import com.google.common.util.concurrent.ListenableFuture;
/**
* Provides access to SQS via their REST API.
* <p/>
*
* @author Adrian Cole
*/
@RequestFilters(FormSigner.class)
@FormParams(keys = VERSION, values = "{" + Constants.PROPERTY_API_VERSION + "}")
@VirtualHost
public interface QueueAsyncApi {
/**
* @see QueueApi#list
*/
@Named("ListQueues")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ListQueues")
@ResponseParser(RegexListQueuesResponseHandler.class)
ListenableFuture<FluentIterable<URI>> list();
/**
* @see QueueApi#list(ListQueuesOptions)
*/
@Named("ListQueues")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "ListQueues")
@ResponseParser(RegexListQueuesResponseHandler.class)
ListenableFuture<FluentIterable<URI>> list(ListQueuesOptions options);
/**
* @see QueueApi#get(String)
*/
@Named("GetQueueUrl")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "GetQueueUrl")
@ResponseParser(RegexQueueHandler.class)
@Fallback(NullOnNotFoundOr404.class)
ListenableFuture<URI> get(@FormParam("QueueName") String queueName);
/**
* @see QueueApi#getInAccount
*/
@Named("GetQueueUrl")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "GetQueueUrl")
@ResponseParser(RegexQueueHandler.class)
@Fallback(NullOnNotFoundOr404.class)
ListenableFuture<URI> getInAccount(@FormParam("QueueName") String queueName,
@FormParam("QueueOwnerAWSAccountId") String accountId);
/**
* @see QueueApi#create
*/
@Named("CreateQueue")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "CreateQueue")
@ResponseParser(RegexQueueHandler.class)
ListenableFuture<URI> create(@FormParam("QueueName") String queueName);
/**
* @see QueueApi#create
*/
@Named("CreateQueue")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "CreateQueue")
@ResponseParser(RegexQueueHandler.class)
ListenableFuture<URI> create(@FormParam("QueueName") String queueName, CreateQueueOptions options);
/**
* @see QueueApi#delete
*/
@Named("DeleteQueue")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "DeleteQueue")
@Fallback(VoidOnNotFoundOr404.class)
ListenableFuture<Void> delete(@EndpointParam URI queue);
/**
* @see QueueApi#getAttributes(URI)
*/
@Named("GetQueueAttributes")
@POST
@Path("/")
@FormParams(keys = { ACTION, "AttributeName.1" }, values = { "GetQueueAttributes", "All" })
@Transform(MapToQueueAttributes.class)
@Fallback(NullOnNotFoundOr404.class)
@XMLResponseParser(AttributesHandler.class)
ListenableFuture<? extends QueueAttributes> getAttributes(@EndpointParam URI queue);
/**
* @see QueueApi#getAttributes(URI, Iterable)
*/
@Named("GetQueueAttributes")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "GetQueueAttributes")
@XMLResponseParser(AttributesHandler.class)
ListenableFuture<Map<String, String>> getAttributes(@EndpointParam URI queue,
@BinderParam(BindAttributeNamesToIndexedFormParams.class) Iterable<String> attributeNames);
/**
* @see QueueApi#getAttribute
*/
@Named("GetQueueAttributes")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "GetQueueAttributes")
@XMLResponseParser(ValueHandler.class)
ListenableFuture<String> getAttribute(@EndpointParam URI queue, @FormParam("AttributeName.1") String attributeName);
/**
* @see QueueApi#setAttribute
*/
@Named("SetQueueAttributes")
@POST
@Path("/")
@FormParams(keys = ACTION, values = "SetQueueAttributes")
ListenableFuture<Void> setAttribute(@EndpointParam URI queue, @FormParam("Attribute.Name") String name,
@FormParam("Attribute.Value") String value);
}

View File

@ -17,7 +17,7 @@
package org.jclouds.sqs; package org.jclouds.sqs;
import org.jclouds.View; import org.jclouds.View;
import org.jclouds.rest.internal.BaseRestApiMetadataTest; import org.jclouds.rest.internal.BaseHttpApiMetadataTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
@ -28,7 +28,7 @@ import com.google.common.reflect.TypeToken;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "unit", testName = "SQSApiMetadataTest") @Test(groups = "unit", testName = "SQSApiMetadataTest")
public class SQSApiMetadataTest extends BaseRestApiMetadataTest { public class SQSApiMetadataTest extends BaseHttpApiMetadataTest {
// no queue abstraction, yet // no queue abstraction, yet
public SQSApiMetadataTest() { public SQSApiMetadataTest() {

View File

@ -19,9 +19,9 @@ package org.jclouds.sqs.internal;
import java.net.URI; import java.net.URI;
import org.jclouds.date.DateService; import org.jclouds.date.DateService;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresHttpApi;
import org.jclouds.rest.internal.BaseRestApiExpectTest; import org.jclouds.rest.internal.BaseRestApiExpectTest;
import org.jclouds.sqs.config.SQSRestClientModule; import org.jclouds.sqs.config.SQSHttpApiModule;
import com.google.inject.Module; import com.google.inject.Module;
@ -36,8 +36,8 @@ public class BaseSQSExpectTest<T> extends BaseRestApiExpectTest<T> {
provider = "sqs"; provider = "sqs";
} }
@ConfiguresRestClient @ConfiguresHttpApi
private static final class TestSQSRestClientModule extends SQSRestClientModule { private static final class TestSQSHttpApiModule extends SQSHttpApiModule {
@Override @Override
protected String provideTimeStamp(final DateService dateService) { protected String provideTimeStamp(final DateService dateService) {
@ -47,6 +47,6 @@ public class BaseSQSExpectTest<T> extends BaseRestApiExpectTest<T> {
@Override @Override
protected Module createModule() { protected Module createModule() {
return new TestSQSRestClientModule(); return new TestSQSHttpApiModule();
} }
} }