Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial commit continued..

  • Loading branch information...
commit 3d2c306898630be881b9ffa3c986ac78dfb085d4 1 parent a01ee4a
@dustismo authored
Showing with 72 additions and 0 deletions.
  1. BIN  lib/commons-logging-1.1.1.jar
  2. +72 −0 src/Example.java
View
BIN  lib/commons-logging-1.1.1.jar
Binary file not shown
View
72 src/Example.java
@@ -0,0 +1,72 @@
+/**
+ *
+ */
+
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import com.trendrr.beanstalk.BeanstalkClient;
+import com.trendrr.beanstalk.BeanstalkException;
+import com.trendrr.beanstalk.BeanstalkJob;
+import com.trendrr.beanstalk.BeanstalkPool;
+
+
+
+/**
+ * @author Dustin Norlander
+ * @created Nov 15, 2010
+ *
+ */
+public class Example {
+
+ protected static Log log = LogFactory.getLog(Example.class);
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ //Example usage for a
+
+ try {
+ clientExample();
+ } catch (BeanstalkException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+
+
+ }
+
+ /**
+ * Example for using an unpooled client
+ * @throws BeanstalkException
+ */
+ public static void clientExample() throws BeanstalkException {
+ BeanstalkClient client = new BeanstalkClient("localhost", 8010, "example");
+ log.info("Putting a job");
+ client.put(1l, 0, 5000, "this is some data".getBytes());
+ BeanstalkJob job = client.reserve(60);
+ log.info("GOt job: " + job);
+ client.deleteJob(job);
+ client.close(); //closes the connection
+ }
+
+
+ public static void pooledExample() throws BeanstalkException {
+ BeanstalkPool pool = new BeanstalkPool("localhost", 8010,
+ 30, //poolsize
+ "example" //tube to use
+ );
+
+ BeanstalkClient client = pool.getClient();
+
+ log.info("Putting a job");
+ client.put(1l, 0, 5000, "this is some data".getBytes());
+ BeanstalkJob job = client.reserve(60);
+ log.info("GOt job: " + job);
+ client.deleteJob(job);
+ client.close(); //returns the connection to the pool
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.