List of usage examples for twitter4j.util.function Consumer Consumer
Consumer
From source file:monitoring.tools.TwitterAPI.java
License:Apache License
private void resetStream() { //logger.debug("Initialising kafka producer..."); //kafka.initProducer(confParams.getKafkaEndpoint()); logger.debug("Initialising proxy..."); kafka.initProxy(confParams.getKafkaEndpoint()); logger.debug("Initialising streaming..."); firstConnection = true;/*from www.j a va 2s . c o m*/ tweetInfo = new ArrayList<>(); stream = new TwitterStreamFactory().getInstance(); timer = new Timer(); stream.onStatus(new Consumer<Status>() { @Override public void accept(Status arg0) { if (confParams.getAccounts() != null && !confParams.getAccounts().isEmpty()) { if (confParams.getAccounts().contains(arg0.getUser().getScreenName())) { tweetInfo.add(arg0); } } else tweetInfo.add(arg0); } }); stream.addConnectionLifeCycleListener(new ConnectionLifeCycleListener() { @Override public void onCleanUp() { } @Override public void onConnect() { logger.debug("Connection established successfully"); timer = new Timer(); timer.schedule(new TimerTask() { public void run() { if (firstConnection) { firstConnection = false; } else { generateData((new Timestamp((new Date()).getTime()).toString())); } } }, 0, Integer.parseInt(confParams.getTimeSlot()) * 1000); } @Override public void onDisconnect() { logger.debug("Connection closed"); } }); FilterQuery filterQuery = new FilterQuery(); if (this.confParams.getKeywordExpression() != null) filterQuery.track(Utils.generateKeywordExp(this.confParams.getKeywordExpression())); stream.filter(filterQuery); }