com.twitter.processing

class TweetStream

[source: com/twitter/processing/TweetStream.scala]

class TweetStream(parent : processing.core.PApplet, host : java.lang.String, port : Int, path : java.lang.String, username : java.lang.String, password : java.lang.String)
extends Log
Provides a Processing interface to the Twitter streaming API. Note that this interface will ONLY work with JSON formatted streams.
Examples
ample SimpleStream
Author
Mark McBride
Type Summary
type T
A structural type that defines a tweet(status: Status) method. If our parent conforms to this type we can call back to it
Value Summary
val VERSION : java.lang.String
the version of the library
var callbackApplet : <refinement>
We'll attempt to cast parent and set callbackApplet. If it stays null we don't callback. Note that this makes initializing a TweetStream object sorta pointless.
var client : org.apache.http.impl.client.DefaultHttpClient
an Apache commons http client to use for communication
var connectTimeMs : Long
how long we've spent connecting
var connectTimeoutMs : Int
how long to wait for a connection
val delimitedLength : Boolean
whether we're using delimited length mode
var delimitedReadStall : Int
how many times we've stalled trying to read length delimited content
var disconnectTimeMs : Long
how long we've spent disconnecting
var halt : Boolean
set when we want processing to terminate
var idleProbe : Int
how many idle probes we've received from the server. These are empty lines sent to keep the stream open.
var lastReceivedMs : Long
the time at which we last received a tweet
val maxReconnectTries : Int
how many times we'll try to reconnect when network hiccups occur
val name : java.lang.String
the full URI of the request
var readLoopTimeMs : Long
how long we've spent in a read loop
var reader : java.io.BufferedReader
the reader for the stream for our connection
var socketTimeoutMs : Int
how long to wait for more input on the stream
var stream : java.io.InputStream
the content stream from our connection
Method Summary
def connect : Boolean
Establish a connection. This tries only once (reconnect wraps this in retry logic) Returns true if a connection was established, false otherwise. Note that this also initializes the stream and reader fields, used by readLoop
def deliver (tweet : java.lang.String) : Unit
If your callback is set, call tweet() on it. Otherwise noop
def disconnect : Unit
Dissconnect from our source
def go : Unit
Connect to the streaming API and start received tweets. Under the covers this calls setup, then forks a thread that calls runLoop.
def readLine : java.lang.String
Read a line of input from the stream. This line should either be a blank line (idle probe) or a full tweet readLine will block until more data arrives. Not interruptable.
def readLoop : Unit
Read tweets until either halt is set or we get an exception
def reconnect : Unit
Try up to maxRecconnectTries times to connect, with exponentially increasing backoff times (tries*tries*1000 ms)
def runLoop : Unit
while halt isn't set, perform the following
  1. call reconnect (establishing a connection)
  2. call readLoop (read tweets)
if an exception is caught, try to repeat
def setup : Unit
Set up our HTTP connection parameters, and try to cast our parent to a callbackable form.
def stop : Unit
Stop our read loop, don't process anything else.
Methods inherited from Log
debug, trace, info, warning, error
Methods inherited from AnyRef
getClass, hashCode, equals, clone, toString, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Type Details
type T
A structural type that defines a tweet(status: Status) method. If our parent conforms to this type we can call back to it

Value Details
val VERSION : java.lang.String
the version of the library

val name : java.lang.String
the full URI of the request

var callbackApplet : <refinement>
We'll attempt to cast parent and set callbackApplet. If it stays null we don't callback. Note that this makes initializing a TweetStream object sorta pointless.

var connectTimeMs : Long
how long we've spent connecting

var readLoopTimeMs : Long
how long we've spent in a read loop

var disconnectTimeMs : Long
how long we've spent disconnecting

var idleProbe : Int
how many idle probes we've received from the server. These are empty lines sent to keep the stream open.

var delimitedReadStall : Int
how many times we've stalled trying to read length delimited content

var lastReceivedMs : Long
the time at which we last received a tweet

var connectTimeoutMs : Int
how long to wait for a connection

var socketTimeoutMs : Int
how long to wait for more input on the stream

var client : org.apache.http.impl.client.DefaultHttpClient
an Apache commons http client to use for communication

var stream : java.io.InputStream
the content stream from our connection

var reader : java.io.BufferedReader
the reader for the stream for our connection

var halt : Boolean
set when we want processing to terminate

val delimitedLength : Boolean
whether we're using delimited length mode

val maxReconnectTries : Int
how many times we'll try to reconnect when network hiccups occur

Method Details
def go : Unit
Connect to the streaming API and start received tweets. Under the covers this calls setup, then forks a thread that calls runLoop.

def setup : Unit
Set up our HTTP connection parameters, and try to cast our parent to a callbackable form.

def runLoop : Unit
while halt isn't set, perform the following
  1. call reconnect (establishing a connection)
  2. call readLoop (read tweets)
if an exception is caught, try to repeat

def reconnect : Unit
Try up to maxRecconnectTries times to connect, with exponentially increasing backoff times (tries*tries*1000 ms)

def connect : Boolean
Establish a connection. This tries only once (reconnect wraps this in retry logic) Returns true if a connection was established, false otherwise. Note that this also initializes the stream and reader fields, used by readLoop

def readLoop : Unit
Read tweets until either halt is set or we get an exception

def deliver(tweet : java.lang.String) : Unit
If your callback is set, call tweet() on it. Otherwise noop

def readLine : java.lang.String
Read a line of input from the stream. This line should either be a blank line (idle probe) or a full tweet readLine will block until more data arrives. Not interruptable.

def stop : Unit
Stop our read loop, don't process anything else.

def disconnect : Unit
Dissconnect from our source


processing library Tweet Stream by Mark McBride. (c) 2009