List of usage examples for twitter4j FilterQuery toString
@Override
public String toString()
From source file:com.telefonica.iot.cygnus.sources.TwitterSource.java
License:Open Source License
@Override public synchronized void start() { LOGGER.info("Starting twitter source {} ...", this); documentCount = 0;/*w w w .jav a 2 s .co m*/ startTime = System.currentTimeMillis(); exceptionCount = 0; totalTextIndexed = 0; skippedDocs = 0; batchEndTime = System.currentTimeMillis() + maxBatchDurationMillis; final ChannelProcessor channel = getChannelProcessor(); StatusListener listener = new StatusListener() { public void onStatus(Status status) { String jsonTweet = getStringJSONTweet(status); Event event = EventBuilder.withBody(jsonTweet, Charset.forName("UTF8")); eventBatch.add(event); if (eventBatch.size() >= maxBatchSize || System.currentTimeMillis() >= batchEndTime) { batchEndTime = System.currentTimeMillis() + maxBatchDurationMillis; channel.processEventBatch(eventBatch); // send batch of events (one per tweet) to the flume sink eventBatch.clear(); } documentCount++; if ((documentCount % REPORT_INTERVAL) == 0) { LOGGER.info(String.format("Processed %s docs", numFormatter.format(documentCount))); } if ((documentCount % STATS_INTERVAL) == 0) { logStats(); } } // This listener will ignore everything except for new tweets public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { } public void onTrackLimitationNotice(int numberOfLimitedStatuses) { } public void onScrubGeo(long userId, long upToStatusId) { } public void onStallWarning(StallWarning warning) { } public void onException(Exception e) { LOGGER.error("Exception while streaming tweets", e); } }; twitterStream.addListener(listener); if (haveFilters) { FilterQuery filterQuery = new FilterQuery(); if (haveCoordinateFilter) { filterQuery.locations(boundingBox); LOGGER.info("Coordinates added to filter query: {}", boundingBox[0][0] + " " + boundingBox[0][1] + " " + boundingBox[1][0] + " " + boundingBox[1][1]); } if (haveKeywordFilter) { filterQuery.track(splitKeywords); LOGGER.info("Keywords added to filter query: {}", Arrays.toString(splitKeywords)); } twitterStream.filter(filterQuery); LOGGER.info("Filter Query created: {}", filterQuery.toString()); } LOGGER.info("Twitter source {} started.", getName()); super.start(); }