Created
March 24, 2011 03:15
-
-
Save ddaugher/884489 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
logger.info("Opening connection to Beanstalk tube: '" + tube + "'..."); | |
while (true) { | |
attempts++; | |
logger.debug("Attempt #" + attempts); | |
try { | |
client = new ClientImpl(host, port); | |
client.useTube(tube); | |
client.watch(tube); | |
logger.info("Connected to Beanstalk"); | |
break; | |
} 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