Skip to content
Permalink
Browse files
Code and comment clean up for the Claim API.
  • Loading branch information
Everett Toews committed Dec 14, 2013
1 parent e219faf commit 01222c9868af76db321e034a8c7b50d99e0de06e
Showing 3 changed files with 20 additions and 14 deletions.
@@ -75,11 +75,11 @@ public interface ClaimApi {
* claim itself, plus the specified grace period. If a claimed message would normally live longer than the grace
* period, its expiration is not adjusted.
*
* @param ttl The ttl attribute specifies how long the server waits before releasing the claim. The ttl value
* @param ttl The TTL attribute specifies how long the server waits before releasing the claim. The ttl value
* must be between 60 and 43200 seconds (12 hours). You must include a value for this attribute in
* your request.
* @param grace The grace attribute specifies the message grace period in seconds. The value of grace value must
* be between 60 and 43200 seconds (12 hours). You must include a value for thia attribute in your
* @param grace The grace value specifies the message grace period in seconds. The value of grace value must
* be between 60 and 43200 seconds (12 hours). You must include a value for this attribute in your
* request.
* @param limit Specifies the number of messages to return, up to 20 messages.
*/
@@ -127,7 +127,7 @@ List<Message> claim(@PayloadParam("ttl") int ttl,
// @PayloadParam("ttl") int ttl);

/**
* This operation immediately releases a claim, making any remaining, undeleted) messages that are associated with
* This operation immediately releases a claim, making any remaining, undeleted messages that are associated with
* the claim available to other workers. This operation is useful when a worker is performing a graceful shutdown,
* fails to process one or more messages, or is taking longer than expected to process messages, and wants to make
* the remainder of the messages available to other workers.
@@ -17,6 +17,7 @@
package org.jclouds.openstack.marconi.v1.functions;

import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import org.jclouds.http.HttpResponse;
import org.jclouds.http.functions.ParseJson;
import org.jclouds.openstack.marconi.v1.domain.Claim;
@@ -28,7 +29,6 @@

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Lists.newArrayList;
import static org.jclouds.openstack.marconi.v1.functions.ParseMessagesToStream.MessageWithHref;
import static org.jclouds.openstack.marconi.v1.functions.ParseMessagesToStream.TO_ID_FROM_HREF;
import static org.jclouds.openstack.marconi.v1.functions.ParseMessagesToStream.TO_MESSAGE;
@@ -41,7 +41,7 @@ public class ParseClaim implements Function<HttpResponse, Claim> {
protected static final Function<ClaimWithHref, Claim> TO_CLAIM = new Function<ClaimWithHref, Claim>() {
@Override
public Claim apply(ClaimWithHref claimWithHref) {
List<Message> messages = newArrayList(transform(claimWithHref.messagesWithHref, TO_MESSAGE));
List<Message> messages = ImmutableList.copyOf(transform(claimWithHref.messagesWithHref, TO_MESSAGE));
String claimId = TO_ID_FROM_HREF.apply(claimWithHref.getId());

return claimWithHref.toBuilder()
@@ -28,6 +28,8 @@

import javax.inject.Inject;
import java.beans.ConstructorProperties;
import java.net.URI;
import java.net.URISyntaxException;

import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.collect.Iterables.getOnlyElement;
@@ -66,7 +68,7 @@ private static String getIdFromHref(String rawMessageHref) {
int indexOfQuestionMark = rawMessageHref.indexOf('?');
int lastIndexOfSlash = rawMessageHref.lastIndexOf('/') + 1;

if (indexOfQuestionMark > 0) {
if (indexOfQuestionMark > lastIndexOfSlash) {
return rawMessageHref.substring(lastIndexOfSlash, indexOfQuestionMark);
}
else {
@@ -75,14 +77,18 @@ private static String getIdFromHref(String rawMessageHref) {
}

private static String getClaimIdFromHref(String rawMessageHref) {
int indexOfQuestionMark = rawMessageHref.indexOf('?') + 1;

if (indexOfQuestionMark > 0) {
Multimap<String, String> queryParams = queryParser().apply(rawMessageHref.substring(indexOfQuestionMark));

return getOnlyElement(queryParams.get("claim_id"), null);
try {
String query = new URI(rawMessageHref).getQuery();

if (query != null) {
Multimap<String, String> queryParams = queryParser().apply(query);
return getOnlyElement(queryParams.get("claim_id"), null);
}
else {
return null;
}
}
else {
catch (URISyntaxException e) {
return null;
}
}

0 comments on commit 01222c9

Please sign in to comment.