Handle reconnection

java

#1

Hey, I’m struggling to handle reconnections with HBC. Where do I get the status code ? And when I have the status code, depending of the time I have to wait, Do I just re-call : hosebirdClient.connect();

Here is what I got at the moment (it’s similar to the example):

@Asynchronous
@Override
public void makeLatestsTweets() {

	msgList = new LinkedList<Tweet>();

	BlockingQueue<String> msgQueue = new LinkedBlockingQueue<String>(100);
	BlockingQueue<Event> eventQueue = new LinkedBlockingQueue<Event>(100);

	Hosts hosebirdHosts = new HttpHosts(Constants.SITESTREAM_HOST);

	StatusesFilterEndpoint hosebirdEndpoint = new StatusesFilterEndpoint();

	userIds = addFollowings();

	hosebirdEndpoint.followings(userIds);

	Authentication hosebirdAuth = new OAuth1(CONSUMER_KEY, CONSUMER_SECRET,
			TOKEN, SECRET);

	ClientBuilder builder = new ClientBuilder().hosts(hosebirdHosts)
			.authentication(hosebirdAuth).endpoint(hosebirdEndpoint)
			.processor(new StringDelimitedProcessor(msgQueue))
			.eventMessageQueue(eventQueue);

	Client hosebirdClient = builder.build();
	hosebirdClient.connect();
	System.out.println("before starting loop");

	while (!hosebirdClient.isDone()) {
		try {
			System.out.println("queueu size: " + msgQueue.size());
			String msg = msgQueue.take();
			System.out.println(msg);
			List<Event> listEvents = new ArrayList<Event>();
			eventQueue.drainTo(listEvents);
			Tweet tweet = format(msg);
			if (tweet != null) {
				msgList.addFirst(tweet);
				if (msgList.size() > tweetListSize) {
					msgList.removeLast();
				}
				caller.setMsgList(msgList);
			}
		} catch (InterruptedException e) {
			hosebirdClient.stop();
			e.printStackTrace();
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}
}