Permalink
Browse files

Added support for delay and expires_in parameters

  • Loading branch information...
1 parent ca874ff commit 0898536879f3dc950d636fd173c758cd8fed443f @thejo committed Apr 23, 2012
Showing with 50 additions and 2 deletions.
  1. +2 −0 .gitignore
  2. +36 −0 src/main/java/io/iron/ironmq/Message.java
  3. +12 −2 src/main/java/io/iron/ironmq/Queue.java
View
@@ -1,2 +1,4 @@
reports
target
+.idea
+*.iml
@@ -9,6 +9,10 @@
private String id;
private String body;
private long timeout;
+ private long delay;
+ private long expires_in;
edsrzf
edsrzf Apr 23, 2012

I would rather conform to Java conventions than our API conventions. Please rename this to expiresIn.

thejo
thejo Apr 23, 2012 Owner

The JSON serializer will use "expiresIn" as the parameter, but your API expects "expires_in". That's why I broke Java convention and named the variable expires_in. Does your REST API accept expiresIn as the parameter? I can change it if it does.

edsrzf
edsrzf Apr 23, 2012

Ah, I see, that would be invalid. I suppose it's alright to keep this name for the private variable but change the mutator and accessor. I'll probably have to rework how serialization is done at some point anyway.

thejo
thejo Apr 23, 2012 Owner

That was how I had implemented it. It looks like the getter and setter names are used in the serialization. I had to rename them to get the correct JSON format. You can try it.

edsrzf
edsrzf Apr 23, 2012

Ok, I'll have a play with it. What a hassle (but not your fault at all).

+
+ public static final long DEFAULT_EXPIRES_IN = 604800;
public Message() {}
@@ -49,6 +53,38 @@ public Message() {}
public void setTimeout(long timeout) { this.timeout = timeout; }
/**
+ * Returns the Message's delay.
+ */
+ public long getDelay() {
+ return delay;
+ }
+
+ /**
+ * Sets the number of seconds after which the Message will be available
+ *
+ * @param delay The new delay
+ */
+ public void setDelay(long delay) {
+ this.delay = delay;
+ }
+
+ /**
+ * Returns the number of seconds in which this message will be removed from the queue
+ */
+ public long getExpires_in() {
edsrzf
edsrzf Apr 23, 2012

As above, please rename this to getExpiresIn

+ return expires_in;
+ }
+
+ /**
+ * Sets the number of seconds after which the message is deleted from the queue.
+ *
+ * @param expires_in The new expiry value
+ */
+ public void setExpires_in(long expires_in) {
edsrzf
edsrzf Apr 23, 2012

Please rename to setExpiresIn and the argument to expiresIn

+ this.expires_in = expires_in;
+ }
+
+ /**
* Returns a string representation of the Message.
*/
public String toString() { return body; }
@@ -82,7 +82,15 @@ public void deleteMessage(Message msg) throws IOException {
* @throws IOException If there is an error accessing the IronMQ server.
*/
public void push(String msg) throws IOException {
- push(msg, 0);
+ push(msg, 0, 0, Message.DEFAULT_EXPIRES_IN);
+ }
+
+ public void push(String msg, long timeout) throws IOException {
+ push(msg, timeout, 0, Message.DEFAULT_EXPIRES_IN);
+ }
+
+ public void push(String msg, long timeout, long delay) throws IOException {
+ push(msg, timeout, delay, Message.DEFAULT_EXPIRES_IN);
}
/**
@@ -94,10 +102,12 @@ public void push(String msg) throws IOException {
* @throws HTTPException If the IronMQ service returns a status other than 200 OK.
* @throws IOException If there is an error accessing the IronMQ server.
*/
- public void push(String msg, long timeout) throws IOException {
+ public void push(String msg, long timeout, long delay, long expiresIn) throws IOException {
Message message = new Message();
message.setBody(msg);
message.setTimeout(timeout);
+ message.setDelay(delay);
+ message.setExpires_in(expiresIn);
JSON jsonMsg = JSONSerializer.toJSON(message);
JSONArray array = new JSONArray();

2 comments on commit 0898536

edsrzf commented on 0898536 Apr 23, 2012

Thanks! This looks pretty good overall.

I made some comments inline. You can address them yourself or I can just fix them if you like. Either way's fine with me.

Owner

Can you confirm that using "expiresIn" in the JSON POSTed to your REST API valid.

Please sign in to comment.