diff options
author | Peter Wu <peter@lekensteyn.nl> | 2014-04-30 13:57:39 +0200 |
---|---|---|
committer | Peter Wu <peter@lekensteyn.nl> | 2014-04-30 13:57:39 +0200 |
commit | 7ed1ad840e57ebe84772a60cdde29cadc7506db2 (patch) | |
tree | 04c553c9f25f850fab22a67834d5df760293a105 | |
parent | b47e834f62684fc0d1af4470ba10f6f5d26926c8 (diff) | |
download | TwitterDataAnalytics-7ed1ad840e57ebe84772a60cdde29cadc7506db2.tar.gz |
Stream interface
-rw-r--r-- | src/main/StreamCommand.java | 45 | ||||
-rw-r--r-- | src/mining/OAuthStream.java | 26 | ||||
-rw-r--r-- | src/mining/Stream.java | 29 | ||||
-rw-r--r-- | src/provider/ExceptionListener.java | 14 |
4 files changed, 35 insertions, 79 deletions
diff --git a/src/main/StreamCommand.java b/src/main/StreamCommand.java deleted file mode 100644 index f0f38fe..0000000 --- a/src/main/StreamCommand.java +++ /dev/null @@ -1,45 +0,0 @@ -package main; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import mining.OAuthStream; -import mining.Stream; -import mining.StreamListener; -import mining.TwitterApi; -import org.json.JSONObject; - -/** - * A command that reads a stream from a stream listener and writes the data to a - * file. - * - * @author Maurice Laveaux - */ -public class StreamCommand implements StreamListener { - - /** - * A private reference for the stream. - */ - private final Stream m_stream; - - public StreamCommand(final TwitterApi api) { - - m_stream = new OAuthStream(); - } - - @Override - public void notify(JSONObject data) { - try { - // TODO: add the results to the main database. - // For now write to a file - File file = new File("database.txt"); - - FileWriter writer = new FileWriter(file, true); - - writer.write("\n\r" + data.toString()); - writer.flush(); - } catch (IOException ex) { - throw new RuntimeException(ex); - } - } -} diff --git a/src/mining/OAuthStream.java b/src/mining/OAuthStream.java deleted file mode 100644 index 3cddb57..0000000 --- a/src/mining/OAuthStream.java +++ /dev/null @@ -1,26 +0,0 @@ - -package mining; - -/** - * An implementation of a Stream using the OAuthentication method. - * @author Maurice Laveaux - */ -public class OAuthStream implements Stream { - - @Override - public void open() { - - } - - @Override - public void setListener(StreamListener listener) { - - } - - @Override - public boolean isValid() { - - return false; - } - -} diff --git a/src/mining/Stream.java b/src/mining/Stream.java index 283b4ea..456a405 100644 --- a/src/mining/Stream.java +++ b/src/mining/Stream.java @@ -1,23 +1,36 @@ package mining; +import java.io.IOException; + /** - * interface for all streaming classes. - * - * @author Maurice Laveaux + * Provides access to a stream. The implementor is supposed to provide means + * that allows a client to be notified of new tweets. */ public interface Stream { /** - * Open the connection to the server. + * Add the keyword (or phrase) to the list of keywords to be watched in a + * stream. + * + * @param keyword + */ + public void watchKeyword(String keyword); + + /** + * Removes the keyword (or phrase) from the list of keywords to watch for in + * a stream. + * + * @param keyword */ - public void open(); + public void unwatchKeyword(String keyword); /** - * Set a single listener for this stream. + * Starts streaming tweets. If a connection is already open, then it may be + * re-opened to use new keywords. * - * @param listener The object that is listening. + * @throws IOException on failure to open a streaming connection. */ - public void setListener(StreamListener listener); + public void commit() throws IOException; /** * Test whether the stream is ready for streaming diff --git a/src/provider/ExceptionListener.java b/src/provider/ExceptionListener.java new file mode 100644 index 0000000..bc4860e --- /dev/null +++ b/src/provider/ExceptionListener.java @@ -0,0 +1,14 @@ +package provider; + +/** + * Notifies whenever an unexpected, fatal exception occurred. + */ +public interface ExceptionListener { + + /** + * Callback for fatal errors. + * + * @param ex Exception that occurred. + */ + public void exceptionGenerated(Exception ex); +} |