Example usage for twitter4j StatusListener onStatus

List of usage examples for twitter4j StatusListener onStatus

Introduction

In this page you can find the example usage for twitter4j StatusListener onStatus.

Prototype

void onStatus(Status status);

Source Link

Usage

From source file:com.finders.twitter.commands.TwitterRunnerOffline.java

License:Apache License

/**
 * Feed events from the stream to the engine
 * @param ksession//from   w w  w  . jav a  2 s.  c o  m
 * @param ep
 */
private void feedEvents(final KieSession ksession, final EntryPoint ep) {
    try {
        StatusListener listener = new TwitterStatusListener(ep);
        ObjectInputStream in = new ObjectInputStream(getClass().getResourceAsStream("/twitterstream.dump"));
        SessionPseudoClock clock = ksession.getSessionClock();

        for (int i = 0;; i++) {
            try {
                // Read an event
                Status st = (Status) in.readObject();
                // Using the pseudo clock, advance the clock
                clock.advanceTime(st.getCreatedAt().getTime() - clock.getCurrentTime(), TimeUnit.MILLISECONDS);
                // call the listener
                listener.onStatus(st);
                if (this.dumpListener != null) {
                    this.dumpListener.onStatus(st);
                }
                ksession.getEntryPoint("twitter").insert(st);
            } catch (IOException ioe) {
                break;
            }
        }
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.drools.examples.twittercbr.guvnor.TwitterCBRGuvnor.java

License:Apache License

/**
 * Feed events from the stream to the engine
 * @param ksession//from  www.  j a va  2 s .c om
 * @param ep
 */
private static void feedEvents(final StatefulKnowledgeSession ksession, final WorkingMemoryEntryPoint ep) {
    try {
        StatusListener listener = new TwitterStatusListener(ep);
        ObjectInputStream in = new ObjectInputStream(
                new FileInputStream("src/main/resources/twitterstream.dump"));
        SessionPseudoClock clock = ksession.getSessionClock();

        for (int i = 0;; i++) {
            try {
                // Read an event
                Status st = (Status) in.readObject();
                // Using the pseudo clock, advance the clock
                clock.advanceTime(st.getCreatedAt().getTime() - clock.getCurrentTime(), TimeUnit.MILLISECONDS);
                // call the listener
                listener.onStatus(st);
            } catch (IOException ioe) {
                break;
            }
        }
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}