Skip to content

Instantly share code, notes, and snippets.



Created Mar 24, 2011
What would you like to do?
package com.urbanairship.octobot;
import com.surftools.BeanstalkClientImpl.ClientImpl;
import org.apache.log4j.Logger;
// This class handles all interfacing with a Beanstalk in Octobot.
// It is responsible for connection initialization and management.
public class Beanstalk {
private static final Logger logger = Logger.getLogger("Beanstalk");
private static final String host = Settings.get("Beanstalk", "host");
private static final Integer port = Settings.getAsInt("Beanstalk", "port");
public static ClientImpl getBeanstalkChannel(String host, Integer port, String tube) {
int attempts = 0;
ClientImpl client = null;"Opening connection to Beanstalk tube: '" + tube + "'...");
while (true) {
logger.debug("Attempt #" + attempts);
try {
client = new ClientImpl(host, port);
client.useTube(tube);;"Connected to Beanstalk");
} catch (Exception e) {
logger.error("Unable to connect to Beanstalk. Retrying in 5 seconds", e);
try { Thread.sleep(1000 * 5); }
catch (InterruptedException ex) { }
return client;
public static ClientImpl getBeanstalkChannel(String tube) {
return getBeanstalkChannel(host, port, tube);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment