This repository has been archived by the owner on Aug 13, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Deacon wrapper class (again) that isolates Android-specific cod…
…e in order to enable standalone testing of Deacon without and Android instance
- Loading branch information
Showing
2 changed files
with
59 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.deacon; | ||
|
||
import java.io.IOException; | ||
import java.net.UnknownHostException; | ||
|
||
import android.os.Handler; | ||
import android.os.Message; | ||
import android.util.Log; | ||
|
||
/** | ||
* @author dave | ||
* | ||
* Deacon class | ||
* A thin wrapper around DeaconService which | ||
* | ||
*/ | ||
public class Deacon extends DeaconService { | ||
|
||
private Handler handler = new Handler() { | ||
@Override | ||
public void handleMessage(final Message msg) { | ||
parse((String)msg.obj); | ||
} | ||
}; | ||
|
||
/** | ||
* @param host The Meteor server to which this client should connect | ||
* @param port The client port that the Meteor server is listening on (default is usually 4670) | ||
* @throws UnknownHostException | ||
* @throws IOException | ||
*/ | ||
public Deacon(String host, int port) throws UnknownHostException, IOException { | ||
super(host, port); | ||
} | ||
|
||
/** | ||
* Android-wrapped version of socketLine; called whenever a line is received from the Meteor server | ||
* This version implements Android thread-safe message passing rather than calling parse() directly (from the deaconThread) | ||
*/ | ||
@Override | ||
protected void socketLine(String line) { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
Message msg = Message.obtain(handler, 0, line); | ||
msg.sendToTarget(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 comment
on commit 117f758
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit implements a thin wrapper around DeaconService, that isolates the Android specific code. It maintains our flexibiltiy to test Deacon standalone (by instantiating DeaconService directly) or within the bounds of an Android app (by instantiating the Deacon wrapper subclass). If everybody likes the way this came out, I will merge the uses-header branch into the master branch.
Not sure why, but Java refused to let me override this method when it was declared 'private' in both the super and sub classes.