1

我无法弄清楚如何处理与 hbc twitter api 的断开连接。医生说我需要根据遇到的错误类型减慢重新连接尝试的速度。我从哪里获得遇到的错误类型?是在里面msgQueue还是在eventQueue 哪里?

@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();
    while (!hosebirdClient.isDone()) {
        try {
            String msg = msgQueue.take();
            Tweet tweet = format(msg);
            if (tweet != null) {
                System.out.println(tweet.getTweetsContent());
                msgList.addFirst(tweet);
                if (msgList.size() > tweetListSize) {
                    msgList.removeLast();
                }
                caller.setMsgList(msgList);
            }
        } catch (InterruptedException e) {
            hosebirdClient.stop();
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
4

0 回答 0