SitestreamEndpoint endpoint = new SitestreamEndpoint(followings);
Authentication auth = new OAuth1(consumerKey, consumerSecret, token, tokenSecret);
// Create a new BasicClient. By default gzip is enabled.
BasicClient client = new ClientBuilder()
.hosts(Constants.SITESTREAM_HOST)
.endpoint(endpoint)
.authentication(auth)
.processor(new StringDelimitedProcessor(queue))
.build();
// Create an executor service which will spawn threads to do the actual work of parsing the incoming messages and
// calling the listeners on each message
int numProcessingThreads = 4;
ExecutorService service = Executors.newFixedThreadPool(numProcessingThreads);
// Wrap our BasicClient with the twitter4j client
Twitter4jSitestreamClient t4jClient = new Twitter4jSitestreamClient(
client, queue, Lists.newArrayList(listener), service);
// Establish a connection
t4jClient.connect();
for (int threads = 0; threads < numProcessingThreads; threads++) {
// This must be called once per processing thread
t4jClient.process();
}
Thread.sleep(5000);
// Create a sitestream controller to issue controlstream requests
SitestreamController controller = new SitestreamController(auth);
controller.getFriends(t4jClient.getStreamId(), 12345L);
controller.addUser(t4jClient.getStreamId(), 987765L);
client.stop();
}