Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

SOCIAL-483: Add support for non-Tweet stream events #99

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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 @@ -15,6 +15,8 @@
*/
package org.springframework.social.twitter.api;

import java.util.Map;

/**
* Listener interface for clients consuming data from a Twitter stream.
* @author Craig Walls
Expand Down Expand Up @@ -44,5 +46,6 @@ public interface StreamListener {
* @param warningEvent a warning event
*/
void onWarning(StreamWarningEvent warningEvent);


void onEvent(Map event);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -68,6 +69,8 @@ public void run() {
handleDelete(line);
} else if (line.startsWith("{\"warning")) {
handleWarning(line);
} else {
handleEvent(line);
}
} catch (IOException e) {
// TODO: Should only happen if Jackson doesn't know how to map the line
Expand Down Expand Up @@ -123,5 +126,16 @@ public void run() {
}));
}
}

private void handleEvent(String line) throws IOException {
final Map event = objectMapper.readValue(line, Map.class);
for (final StreamListener listener : listeners) {
Future<?> result = pool.submit((new Runnable() {
public void run() {
listener.onEvent(event);
}
}));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.junit.Ignore;
import org.junit.Test;
Expand Down Expand Up @@ -114,6 +115,11 @@ public void onWarning(StreamWarningEvent warningEvent) {
messageReceived();
}

@Override
public void onEvent(Map event) {
messageReceived();
}

private void messageReceived() {
stopAfter--;
if(stopAfter == 0) {
Expand Down