@Override public void run() { while (provider.isRunning()) { ResponseList<Post> postResponseList; try { postResponseList = client.getFeed(id); Set<Post> update = Sets.newHashSet(postResponseList); Set<Post> repeats = Sets.intersection(priorPollResult, Sets.newHashSet(update)); Set<Post> entrySet = Sets.difference(update, repeats); LOGGER.debug( this.id + " response: " + update.size() + " previous: " + repeats.size() + " new: " + entrySet.size()); for (Post item : entrySet) { String json = DataObjectFactory.getRawJSON(item); org.apache.streams.facebook.Post post = mapper.readValue(json, org.apache.streams.facebook.Post.class); try { lock.readLock().lock(); ComponentUtils.offerUntilSuccess(new StreamsDatum(post), providerQueue); countersCurrent.incrementAttempt(); } finally { lock.readLock().unlock(); } } priorPollResult = update; } catch (Exception e) { e.printStackTrace(); } finally { try { Thread.sleep(configuration.getPollIntervalMillis()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } } }
@Override public void startStream() { client = getFacebookClient(); if (configuration.getInfo() != null && configuration.getInfo().size() > 0) { for (String id : configuration.getInfo()) { executor.submit(new FacebookFeedPollingTask(this, id)); } running.set(true); } else { try { String id = client.getMe().getId(); executor.submit(new FacebookFeedPollingTask(this, id)); running.set(true); } catch (FacebookException e) { LOGGER.error(e.getMessage()); running.set(false); } } }