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).
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
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; |
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
public interface IMessageListener { | |
void messageReceived(String messageBody); | |
} |
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
import android.os.Handler; | |
import org.jeromq.ZMQ; | |
public class ZeroMQServer implements Runnable { | |
private final Handler uiThreadHandler; | |
public ZeroMQServer(Handler uiThreadHandler) { | |
this.uiThreadHandler = uiThreadHandler; | |
} |
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
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; |
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
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; |
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
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; |
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
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() {} |
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
@@ -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 |
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
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(); | |
} |
OlderNewer