Reputation: 13
Twitter has released a Java client library and included the following example code for using it:
// Connect to the filter endpoint, tracking the term "twitterapi"
Hosts host = new BasicHost(Constants.STREAM_HOST);
StreamingEndpoint endpoint = new StatusesFilterEndpoint();
endpoint.trackTerms(Lists.newArrayList("twitterapi"));
// Drop in the oauth credentials for your app, available on dev.twitter.com
Authentication auth = new OAuth1("consumerKey", "consumerSecret",
"token", "tokenSecret");
// Initialize a queue to collect messages from the stream
BlockingQueue<String> messages = new LinkedBlockingQueue<String>(100000);
// Build a client and read messages until the connection closes.
ClientBuilder builder = new ClientBuilder()
.name("FooBarBaz-StreamingClient")
.hosts(host)
.authentication(auth)
.endpoint(endpoint)
.processor(new StringDelimitedProcessor(messages));
Client client = builder.build;
client.connect();
while (!client.isDone()) {
String message = messages.take();
// Do something with message
}
Release announcement at: https://dev.twitter.com/blog/the-hosebird-client-streaming-library
What do the angled brackets mean?
Upvotes: 1
Views: 189
Reputation: 12524
One of the superinterfaces of BlockingQueue<String>
is Collection.
That means it implements the functionality of java.util.Collection
and it gives you the possibility to use generics and make the collection cast-save!
With the generic:
BlockingQueue<String>
you only have the possibility to work with String inside of BlockingQueue. Try adding another value and your IDE will inform you about the mismatch. That is a great benefit because the check is not done during the runtime of your application.
Upvotes: 3