Example usage for twitter4j SiteStreamsAdapter SiteStreamsAdapter

List of usage examples for twitter4j SiteStreamsAdapter SiteStreamsAdapter

Introduction

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

Prototype

SiteStreamsAdapter

Source Link

Usage

From source file:org.mule.twitter.TwitterConnector.java

License:Open Source License

/**
 * Asynchronously retrieves statutes for a set of supplied user's ids.
 * Site Streams are a beta service, so refer always to latest twitter documentation about them.
 * <p/>/*from  w w  w.  j  ava2 s.co  m*/
 * Only one Twitter stream can be consumed using the same credentials. As a consequence,
 * only one twitter stream can be consumed per connector instance.
 * <p/>
 * {@sample.xml ../../../doc/twitter-connector.xml.sample twitter:siteStream}
 *
 * @param userIds        ids of users to include in the stream
 * @param withFollowings withFollowings whether to receive status updates from people following
 * @param callback_      the {@link SourceCallback} used to dispatch messages when a response is received
 */
@Source
public void siteStream(@Placement(group = "User Ids to Follow") List<String> userIds,
        @Optional @Default("false") boolean withFollowings, final SourceCallback callback_) {
    initStream();
    final SoftCallback callback = new SoftCallback(callback_);
    stream.addListener(new SiteStreamsAdapter() {

        @Override
        public void onException(Exception ex) {
            logger.warn("An exception occured while processing site stream", ex);
        }

        @Override
        public void onStatus(long forUser, Status status) {
            try {
                callback.process(status);
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }

    });
    stream.site(withFollowings, toLongArray(userIds));
}