Example usage for twitter4j StatusStream close

List of usage examples for twitter4j StatusStream close

Introduction

In this page you can find the example usage for twitter4j StatusStream close.

Prototype

void close() throws IOException;

Source Link

Usage

From source file:mx.bigdata.t4j.TwitterStreamConsumerImpl.java

License:Apache License

/**
 * Connects to twitter and handles tweets until it gets an
 * exception or is interrupted.//from   www  .  ja v  a 2 s. c o m
 */
private void connectAndProcess() throws InterruptedException, IOException, TwitterException {
    StatusStream stream = provider.getStream();
    try {
        processStream(stream.getInputStream());
    } finally {
        stream.close();
    }
}

From source file:org.seasr.meandre.apps.twitter.TwitterToTuple.java

public void run() {
    try {//from ww  w.jav  a 2  s  . c o m
        Thread.currentThread().sleep(5000);
        console.info("Start Twitter reader");

        /*
        Twitter tweet = new Twitter("seasrSalad" , "0penNlp");
        Status status = tweet.updateStatus("Hello world2 {\"name\":\"mike\"}");
        User me = status.getUser();
        console.info("user is " + me.getId());
        */

        // twitterStream = new TwitterStream("seasrSalad", "0penNlp", this);

        // this will force an exception if invalid
        TwitterStream tsTmp = new TwitterStreamFactory().getInstance(userName, passwd);
        StatusStream tmp = tsTmp.getSampleStream();
        tmp.close();
        tsTmp.cleanup();

        // if we got this far, we are good to go
        twitterStream = new TwitterStreamFactory().getInstance(userName, passwd);
        twitterStream.setStatusListener(this);

        // for a continuous unfiltered stream:
        twitterStream.sample();

        /*
        int count = 0; // last 100 messages, NOT supported
        int[] follow = new int[0]; // don't follow any specific users
        String[] tags = new String[]{"#apple", "Balloon Boy"};
        twitterStream.filter(count, follow, tags);
        */

        // black forever
        waitForStatus();

    } catch (Exception e) {
        console.info("unable to read twitter " + e.toString());
    } finally {
        if (twitterStream != null)
            twitterStream.cleanup();
    }

    console.info("Stop Twitter service");

    noExceptions = false;
    synchronized (buffer) {
        buffer.notifyAll();
    }

}