Created
December 16, 2010 18:57
-
-
Save ckundo/743797 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
package earthquake_detector; | |
import java.io.IOException; | |
import java.util.Map; | |
import com.buglabs.bug.accelerometer.pub.AccelerometerSample; | |
import com.buglabs.bug.accelerometer.pub.IAccelerometerSampleProvider; | |
import com.buglabs.bug.swarm.connector.pub.IReplicatedModel; | |
import com.buglabs.bug.swarm.connector.pub.IReplicationPolicy; | |
import com.buglabs.bug.swarm.connector.pub.ISwarmConnector; | |
import com.buglabs.application.ServiceTrackerHelper; | |
/** | |
* Read accelerometer data and send to Swarm server. | |
* | |
*/ | |
public class Monitor implements ServiceTrackerHelper.ManagedRunnable { | |
@Override | |
public void run(Map services) { | |
ISwarmConnector connector = (ISwarmConnector) services.get(ISwarmConnector.class.getName()); | |
IAccelerometerSampleProvider accel = (IAccelerometerSampleProvider) services.get(IAccelerometerSampleProvider.class.getName()); | |
try { | |
IReplicatedModel model = connector.getModel("EarthquakeDB", IReplicationPolicy.POLICY_PUSH, new AccelerometerSampleFilter()); | |
while (!Thread.interrupted()) { | |
Thread.sleep(1000); | |
AccelerometerSample sample = accel.readSample(); | |
model.put("x", sample.getAccelerationX()); | |
model.put("y", sample.getAccelerationY()); | |
model.put("z", sample.getAccelerationZ()); | |
} | |
} catch (IOException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} catch (InterruptedException e) { | |
} | |
} | |
@Override | |
public void shutdown() { | |
// TODO Auto-generated method stub | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment