Skip to content

Instantly share code, notes, and snippets.

View moea's full-sized avatar

Moe Aboulkheir moea

  • Nervous Systems, Ltd.
  • London
View GitHub Profile
import android.os.Handler;
import android.os.Message;
public class MessageListenerHandler extends Handler {
private final IMessageListener messageListener;
private final String payloadKey;
public MessageListenerHandler(IMessageListener messageListener, String payloadKey) {
this.messageListener = messageListener;
this.payloadKey = payloadKey;
public interface IMessageListener {
void messageReceived(String messageBody);
}
import android.os.Handler;
import org.jeromq.ZMQ;
public class ZeroMQServer implements Runnable {
private final Handler uiThreadHandler;
public ZeroMQServer(Handler uiThreadHandler) {
this.uiThreadHandler = uiThreadHandler;
}
import android.os.AsyncTask;
import android.os.Handler;
import org.jeromq.ZMQ;
public class ZeroMQMessageTask extends AsyncTask<String, Void, String> {
private final Handler uiThreadHandler;
public ZeroMQMessageTask(Handler uiThreadHandler) {
this.uiThreadHandler = uiThreadHandler;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

Minimal Android ZeroMQ Client/Server Example

While researching possible technologies for implementing a publish/subscribe-based task distribution system for long-running, semi-autonomous/intelligent agents (with Android as a supported platform), ZeroMQ emerged as a sensible choice for handling message transportation, given the exploding complexity of AMQP (Pieter Hintjens' August 2008 steering comittee missive sums up my misgivings).

package com.novoda.example.MemoryLeaker;
import android.app.Activity;
import android.os.Bundle;
import android.os.Debug;
import android.view.View;
import android.widget.TextView;
import java.io.File;
import java.io.IOException;
package com.novoda.example.MemoryLeaker;
import java.util.HashSet;
import java.util.Set;
public class ToyMessageBus {
private static ToyMessageBus instance;
private final Set<Object> listeners = new HashSet<Object>();
private ToyMessageBus() {}
@@ -15,6 +15,8 @@ public class LeakingActivity extends Activity
private static final int BYTES_TO_ALLOCATE = BYTES_IN_A_MEGABYTE;
private static final String HPROF_DUMP_BASENAME = "LeakingActivity.hprof";
+ private final ToyMessageBus messageBus = ToyMessageBus.getInstance();
+
private byte[] byteArray;
private TextView heapSizeTextView;
@@ -65,5 +67,6 @@ public class LeakingActivity extends Activity
findViewById(R.id.btn_dump_heap).setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
File destination = new File(getApplicationInfo().dataDir, "MyApp.dalvik-hprof");
try {
Debug.dumpHprofData(destination.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
}