public class AsyncChannel extends Object
An asynchronous channel between two handlers.
The handlers maybe in the same process or in another process. There are two protocol styles that can be used with an AysncChannel. The first is a simple request/reply protocol where the server does not need to know which client is issuing the request.
In a simple request/reply protocol the client/source sends requests to the server/destination. And the server uses the replyToMessage methods. In this usage model there is no need for the destination to use the connect methods. The typical sequence of operations is:
comm-loop:
comm-loop
until donedisconnect()
A second usage model is where the server/destination needs to know which client it's connected too. For example the server needs to send unsolicited messages back to the client. Or the server keeps different state for each client. In this model the server will also use the connect methods. The typical sequence of operation is:
comm-loop:
comm-loop
until donedisconnect()
Modifier and Type | Field and Description |
---|---|
static int |
CMD_CHANNEL_DISCONNECT
Command sent when one side or the other wishes to disconnect.
|
static int |
CMD_CHANNEL_DISCONNECTED
Command sent when the channel becomes disconnected.
|
static int |
CMD_CHANNEL_FULL_CONNECTION
Command typically sent when after receiving the CMD_CHANNEL_HALF_CONNECTED.
|
static int |
CMD_CHANNEL_FULLY_CONNECTED
Command typically sent after the destination receives a CMD_CHANNEL_FULL_CONNECTION.
|
static int |
CMD_CHANNEL_HALF_CONNECTED
Command sent when the channel is half connected.
|
static int |
STATUS_BINDING_UNSUCCESSFUL
Error attempting to bind on a connect
|
static int |
STATUS_FULL_CONNECTION_REFUSED_ALREADY_CONNECTED
CMD_FULLY_CONNECTED refused because a connection already exists
|
static int |
STATUS_REMOTE_DISCONNECTION
Error indicating abnormal termination of destination messenger
|
static int |
STATUS_SEND_UNSUCCESSFUL
Error attempting to send a message
|
static int |
STATUS_SUCCESSFUL
Successful status always 0, !
|
Constructor and Description |
---|
AsyncChannel()
AsyncChannel constructor
|
Modifier and Type | Method and Description |
---|---|
protected static String |
cmdToString(int cmd) |
void |
connect(AsyncService srcAsyncService,
Messenger dstMessenger)
Connect service and messenger.
|
void |
connect(Context srcContext,
Handler srcHandler,
Class<?> klass)
Connect handler to a class
Sends a CMD_CHANNEL_HALF_CONNECTED message to srcHandler when complete.
|
void |
connect(Context srcContext,
Handler srcHandler,
Handler dstHandler)
Connect two local Handlers.
|
void |
connect(Context srcContext,
Handler srcHandler,
Messenger dstMessenger)
Connect handler and messenger.
|
void |
connect(Context srcContext,
Handler srcHandler,
String dstPackageName,
String dstClassName)
Connect handler to named package/class.
|
void |
connected(Context srcContext,
Handler srcHandler,
Messenger dstMessenger)
Connect handler to messenger.
|
int |
connectSrcHandlerToPackageSync(Context srcContext,
Handler srcHandler,
String dstPackageName,
String dstClassName)
Connect handler to named package/class synchronously.
|
int |
connectSync(Context srcContext,
Handler srcHandler,
Handler dstHandler)
connect two local Handlers synchronously.
|
int |
connectSync(Context srcContext,
Handler srcHandler,
Messenger dstMessenger)
Connect a handler to Messenger synchronously.
|
void |
disconnect()
Disconnect
|
void |
disconnected()
To close the connection call when handler receives CMD_CHANNEL_DISCONNECTED
|
int |
fullyConnectSync(Context srcContext,
Handler srcHandler,
Handler dstHandler)
Fully connect two local Handlers synchronously.
|
void |
replyToMessage(Message srcMsg,
int what)
Reply to srcMsg
|
void |
replyToMessage(Message srcMsg,
int what,
int arg1)
Reply to srcMsg
|
void |
replyToMessage(Message srcMsg,
int what,
int arg1,
int arg2)
Reply to srcMsg
|
void |
replyToMessage(Message srcMsg,
int what,
int arg1,
int arg2,
Object obj)
Reply to srcMsg
|
void |
replyToMessage(Message srcMsg,
int what,
Object obj)
Reply to srcMsg
|
void |
replyToMessage(Message srcMsg,
Message dstMsg)
Reply to srcMsg sending dstMsg
|
void |
sendMessage(int what)
Send a message to the destination handler
|
void |
sendMessage(int what,
int arg1)
Send a message to the destination handler
|
void |
sendMessage(int what,
int arg1,
int arg2)
Send a message to the destination handler
|
void |
sendMessage(int what,
int arg1,
int arg2,
Object obj)
Send a message to the destination handler
|
void |
sendMessage(int what,
Object obj)
Send a message to the destination handler
|
void |
sendMessage(Message msg)
Send a message to the destination handler.
|
Message |
sendMessageSynchronously(int what)
Send the Message synchronously.
|
Message |
sendMessageSynchronously(int what,
int arg1)
Send the Message synchronously.
|
Message |
sendMessageSynchronously(int what,
int arg1,
int arg2)
Send the Message synchronously.
|
Message |
sendMessageSynchronously(int what,
int arg1,
int arg2,
Object obj)
Send the Message synchronously.
|
Message |
sendMessageSynchronously(int what,
Object obj)
Send the Message synchronously.
|
Message |
sendMessageSynchronously(Message msg)
Send the Message synchronously.
|
public static final int CMD_CHANNEL_HALF_CONNECTED
public static final int CMD_CHANNEL_FULL_CONNECTION
public static final int CMD_CHANNEL_FULLY_CONNECTED
disconnect()
would typically be called.public static final int CMD_CHANNEL_DISCONNECT
disconnect()
to close its side of the channel and it will receive a CMD_CHANNEL_DISCONNECTED
when the channel is closed.
msg.replyTo = messenger that is disconnectingpublic static final int CMD_CHANNEL_DISCONNECTED
public static final int STATUS_SUCCESSFUL
public static final int STATUS_BINDING_UNSUCCESSFUL
public static final int STATUS_SEND_UNSUCCESSFUL
public static final int STATUS_FULL_CONNECTION_REFUSED_ALREADY_CONNECTED
public static final int STATUS_REMOTE_DISCONNECTION
protected static String cmdToString(int cmd)
public int connectSrcHandlerToPackageSync(Context srcContext, Handler srcHandler, String dstPackageName, String dstClassName)
srcContext
- is the context of the sourcesrcHandler
- is the hander to receive CONNECTED & DISCONNECTED
messagesdstPackageName
- is the destination package namedstClassName
- is the fully qualified class name (i.e. contains
package name)public int connectSync(Context srcContext, Handler srcHandler, Messenger dstMessenger)
srcContext
- is the context of the sourcesrcHandler
- is the hander to receive CONNECTED & DISCONNECTED
messagesdstMessenger
- is the hander to send messages to.public int connectSync(Context srcContext, Handler srcHandler, Handler dstHandler)
srcContext
- is the context of the sourcesrcHandler
- is the hander to receive CONNECTED & DISCONNECTED
messagesdstHandler
- is the hander to send messages to.public int fullyConnectSync(Context srcContext, Handler srcHandler, Handler dstHandler)
srcContext
- is the context of the sourcesrcHandler
- is the hander to receive CONNECTED & DISCONNECTED
messagesdstHandler
- is the hander to send messages to.public void connect(Context srcContext, Handler srcHandler, String dstPackageName, String dstClassName)
srcContext
- is the context of the sourcesrcHandler
- is the hander to receive CONNECTED & DISCONNECTED
messagesdstPackageName
- is the destination package namedstClassName
- is the fully qualified class name (i.e. contains
package name)public void connect(Context srcContext, Handler srcHandler, Class<?> klass)
srcContext
- srcHandler
- klass
- is the class to send messages to.public void connect(Context srcContext, Handler srcHandler, Messenger dstMessenger)
srcContext
- srcHandler
- dstMessenger
- public void connected(Context srcContext, Handler srcHandler, Messenger dstMessenger)
srcContext
- srcHandler
- dstMessenger
- public void connect(Context srcContext, Handler srcHandler, Handler dstHandler)
srcContext
- is the context of the sourcesrcHandler
- is the hander to receive CONNECTED & DISCONNECTED
messagesdstHandler
- is the hander to send messages to.public void connect(AsyncService srcAsyncService, Messenger dstMessenger)
srcAsyncService
- dstMessenger
- public void disconnected()
public void disconnect()
public void sendMessage(Message msg)
msg
- public void sendMessage(int what)
what
- public void sendMessage(int what, int arg1)
what
- arg1
- public void sendMessage(int what, int arg1, int arg2)
what
- arg1
- arg2
- public void sendMessage(int what, int arg1, int arg2, Object obj)
what
- arg1
- arg2
- obj
- public void sendMessage(int what, Object obj)
what
- obj
- public void replyToMessage(Message srcMsg, Message dstMsg)
srcMsg
- dstMsg
- public void replyToMessage(Message srcMsg, int what)
srcMsg
- what
- public void replyToMessage(Message srcMsg, int what, int arg1)
srcMsg
- what
- arg1
- public void replyToMessage(Message srcMsg, int what, int arg1, int arg2)
srcMsg
- what
- arg1
- arg2
- public void replyToMessage(Message srcMsg, int what, int arg1, int arg2, Object obj)
srcMsg
- what
- arg1
- arg2
- obj
- public void replyToMessage(Message srcMsg, int what, Object obj)
srcMsg
- what
- obj
- public Message sendMessageSynchronously(Message msg)
msg
- to sendpublic Message sendMessageSynchronously(int what)
what
- public Message sendMessageSynchronously(int what, int arg1)
what
- arg1
- public Message sendMessageSynchronously(int what, int arg1, int arg2)
what
- arg1
- arg2
- public Message sendMessageSynchronously(int what, int arg1, int arg2, Object obj)
what
- arg1
- arg2
- obj
-