Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds basic multi-threading support to the TwitIE calls #7

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import java.util.List;
import java.util.Set;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicBoolean;

import javax.transaction.Transactional;

import org.elasticsearch.action.update.UpdateRequest;
Expand Down Expand Up @@ -164,13 +167,13 @@ public Date findWhereIndexingStopped(CollectRequest request) {
public void indexWordsObj(List<TwintModel> tms) throws IOException {
List<UpdateQuery> updateQueries = new LinkedList<UpdateQuery>();

int i = 0;
boolean allNull = true;
AtomicInteger i = new AtomicInteger();
AtomicBoolean allNull = new AtomicBoolean(true);
Logger.info("call Twittie WS for {} extracted tweets", tms.size());
for (TwintModel tm : tms) {
tms.parallelStream().forEach((tm) -> {

try {
allNull = false;
allNull.set(false);
// Logger.debug("Builtin wit : " + i++ + "/" + tms.size());
List<WordsInTweet> wit = twintModelAdapter.buildWit(tm.getTweet(), tm.getSearch());

Expand All @@ -186,15 +189,15 @@ public void indexWordsObj(List<TwintModel> tms) throws IOException {
updateQuery.setUpdateRequest(updateRequest);
updateQueries.add(updateQuery);

i++;
i.incrementAndGet();
} catch (Exception e) {
Logger.error("Error processing this tweet: {} with error : {}", tm.getId(), e.getMessage());
// e.printStackTrace();
}
}
});

Logger.debug("{}/{} process tweets ", i, tms.size());
if (!allNull)
Logger.debug("{}/{} process tweets ", i.intValue(), tms.size());
if (!allNull.get())
esOperation.bulkUpdate(updateQueries, BulkOptions.defaultOptions());

}
Expand Down