Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add listTubes method

  • Loading branch information...
commit a8d6bd06f3c6cedcb2ac8b71232659894182b6ad 1 parent 4f5a378
@uwemaurer authored
Showing with 32 additions and 4 deletions.
  1. +32 −4 src/com/trendrr/beanstalk/BeanstalkClient.java
View
36 src/com/trendrr/beanstalk/BeanstalkClient.java
@@ -3,12 +3,13 @@
*/
package com.trendrr.beanstalk;
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import java.io.ByteArrayOutputStream;
-import java.util.Date;
-
//import com.trendrr.common.DynMap;
/**
@@ -134,7 +135,34 @@ public void ignoreTube(String tube) throws BeanstalkException{
public String tubeStats() throws BeanstalkException {
return this.tubeStats(this.tube);
}
-
+
+ public List<String> listTubes() throws BeanstalkException {
+ try {
+ this.init();
+ String command = "list-tubes\r\n";
+ con.write(command);
+ String line = con.readControlResponse();
+ if (!line.startsWith("OK")) {
+ throw new BeanstalkException(line);
+ }
+ int numBytes = Integer.parseInt(line.split(" ")[1]);
+ String response = new String(con.readBytes(numBytes));
+ // log.info(response);
+ String lines[] = response.split("\\n");
+ List<String> result = new ArrayList<String>();
+ // remove "- "
+ for (String tube : lines) {
+ if (tube.startsWith("- ")) {
+ result.add(tube.substring(2));
+ }
+ }
+ return result;
+ } catch (BeanstalkDisconnectedException x) {
+ this.reap = true; // reap that shit..
+ throw x;
+ }
+ }
+
public String tubeStats(String tube) throws BeanstalkException {
try {
this.init();
Please sign in to comment.
Something went wrong with that request. Please try again.