public abstract class MultipleParcelsHandler
extends android.os.Handler
Message-Sender:
MessengerService
MessengerRunner
Message-Receiver:
MessengerHandler
MessengerHandler
MessengerService
,
MessengerRunner
,
MessengerHandler
,
MessengerHandler
Modifier and Type | Class and Description |
---|---|
protected class |
MultipleParcelsHandler.ParcelBuffer |
protected class |
MultipleParcelsHandler.SmallParcel
This class is used to wrap a small parcel of a whole message.
|
Modifier and Type | Field and Description |
---|---|
static int |
INITIAL_MESSAGE_CACHE_SIZE |
static int |
INITIAL_PARCEL_CACHE_SIZE |
java.lang.String |
TAG |
static int |
TIMEOUT_WAIT_FOR_PARCEL_ACKNOWLEDGMENT
time to wait for acknowledgment of parcel in milliseconds
|
Constructor and Description |
---|
MultipleParcelsHandler(android.os.Looper looper,
MultipleParcelListener multipleParcelListener) |
MultipleParcelsHandler(MultipleParcelListener multipleParcelListener) |
Modifier and Type | Method and Description |
---|---|
boolean |
assembleSmallParcels(android.os.Message msg)
This method will accumulate small parcels of one message, store them into
a cache for future assembly. Message.obj will hold the final result of message: If the message is not divided into parcels, this method will do no thing. If the message is divided into parcels, this method will store them into a cache messageReceivedCache and assemble them and assign it to parameter msg.obj when the last parcel arrives. |
protected void |
clearParcelMessage(java.lang.String messageID)
Clear the cache
messageSendedCache |
protected void |
clearParcelMessage(java.lang.String messageID,
int index)
Clear one parcel of a message from the cache
messageSendedCache |
protected boolean |
containMessageWithoutAck(java.lang.String messageID)
It is used to test if the cache
messageSendedCache still contains acertain message indicated by parameter messageID. |
protected void |
debug(java.lang.String message) |
protected java.util.List<android.os.Message> |
divideMessageIntoSmallPieces(android.os.Message msg,
char[] buffer)
Divide message's content into small parcels if the message content size is too large.
If the content size is bigger than MessageUtil.MAX_TRANSFER_BYTE_SIZE , it willbe divided into small parcels, wrapped to a Message object and put into a List to return. If the content size is smaller than MessageUtil.MAX_TRANSFER_BYTE_SIZE , it willbe set to the original Message object and put into a List to return. |
protected java.util.List<android.os.Message> |
divideMessageIntoSmallPieces(android.os.Message msg,
java.util.Properties props)
Divide message's content into small parcels if the message content size is too large.
If the content size is bigger than MessageUtil.MAX_TRANSFER_BYTE_SIZE , it willbe divided into small parcels, wrapped to a Message object and put into a List to return. If the content size is smaller than MessageUtil.MAX_TRANSFER_BYTE_SIZE , it willbe set to the original Message object and put into a List to return. |
protected java.util.List<android.os.Message> |
divideMessageIntoSmallPieces(android.os.Message msg,
java.lang.String message)
Divide message's content into small parcels if the message content size is too large.
If the content size is bigger than MessageUtil.MAX_TRANSFER_BYTE_SIZE , it willbe divided into small parcels, wrapped to a Message object and put into a List to return. If the content size is smaller than MessageUtil.MAX_TRANSFER_BYTE_SIZE , it willbe set to the original Message object and put into a List to return. |
protected android.os.Message[] |
getParcelMessage(java.lang.String messageID)
|
protected android.os.Message |
getParcelMessage(java.lang.String messageID,
int index)
According to messageId and index to get one parcel of a whole message from
the cache messageSendedCache . |
protected int |
getTotalNumberOfParcels(int dataLength,
int parcelLength)
Calculate the total number of parcels the message will be divided.
|
protected java.lang.String |
getUniqueKey()
Routine is used to create a unique ID String key that can be used by "message-sender"
to identify different small parcels of the same message.
This method is thread-safe: it guarantees that multiple threads can get unique ID. |
void |
handleMessage(android.os.Message msg)
Override method from
Handler
We will handle the small parcels of a whole message. |
protected abstract void |
handleWholeMessage(android.os.Message msg)
The subclass of this class must implement this method to handle message.
|
protected void |
sendAcknowledgment(java.lang.String messageID) |
protected void |
sendAcknowledgment(java.lang.String messageID,
int index) |
boolean |
sendMessageAsMultipleParcels(android.os.Messenger mService,
android.os.Message msg,
java.lang.Object object)
If the messag's size is bigger than
MessageUtil.MAX_TRANSFER_BYTE_SIZE ,Send the message as multiple parcels and wait for acknowledgment of the each parcel, if no acknowledgment arrive within timeout 5000, all the parcels in cache messageSendedCache of a message will be re-sent out.At the message-receiver side, the parcels will be assembled by method assembleSmallParcels(Message) |
boolean |
sendMessageOfLostParcel(android.os.Messenger mService,
java.lang.String messageID)
According to the messageID, we will get the message from cache
messageSendedCache and send it out. We should set the field MessageUtil.BUNDLE_SMALL_RESENT_PARCEL to true,so that 'message-receiver' will know it is a message being resent by 'sender' |
boolean |
sendMessageOfLostParcel(android.os.Messenger mService,
java.lang.String messageID,
int index)
According to the messageID and index, we will get the message from cache
messageSendedCache and send it out. We should set the field MessageUtil.BUNDLE_SMALL_RESENT_PARCEL to true,so that 'message-receiver' will know it is a message being resent by 'sender' |
protected java.lang.String |
storeParcelMessage(android.os.Message parcel)
Store parcel (part of a message) into a cache according to the message ID.
If the parcel is not a part of a whole message, it will not be stored in the cache We use MessageUtil.isSmallParcelOfWholeMessage(Bundle) to test if thisparcel is a part of message. |
dispatchMessage, dump, getLooper, getMessageName, hasMessages, hasMessages, obtainMessage, obtainMessage, obtainMessage, obtainMessage, obtainMessage, post, postAtFrontOfQueue, postAtTime, postAtTime, postDelayed, removeCallbacks, removeCallbacks, removeCallbacksAndMessages, removeMessages, removeMessages, sendEmptyMessage, sendEmptyMessageAtTime, sendEmptyMessageDelayed, sendMessage, sendMessageAtFrontOfQueue, sendMessageAtTime, sendMessageDelayed, toString
public java.lang.String TAG
public static final int INITIAL_MESSAGE_CACHE_SIZE
public static final int INITIAL_PARCEL_CACHE_SIZE
public static final int TIMEOUT_WAIT_FOR_PARCEL_ACKNOWLEDGMENT
public MultipleParcelsHandler(android.os.Looper looper, MultipleParcelListener multipleParcelListener)
public MultipleParcelsHandler(MultipleParcelListener multipleParcelListener)
protected void debug(java.lang.String message)
public boolean assembleSmallParcels(android.os.Message msg) throws java.lang.Exception
messageReceivedCache
and assemble them and assign it to messageReceivedCache
, an acknowledgmentsendMessageAsMultipleParcels(Messenger, Message, Object)
msg
- Messagejava.lang.Exception
sendMessageAsMultipleParcels(Messenger, Message, Object)
protected void sendAcknowledgment(java.lang.String messageID)
protected void sendAcknowledgment(java.lang.String messageID, int index)
protected abstract void handleWholeMessage(android.os.Message msg)
protected java.lang.String getUniqueKey()
protected java.lang.String storeParcelMessage(android.os.Message parcel)
MessageUtil.isSmallParcelOfWholeMessage(Bundle)
to test if thisparcel,
- Message, one parcel of a whole message,
it should contain a data(ID,index,totalNumber)protected void clearParcelMessage(java.lang.String messageID)
messageSendedCache
protected void clearParcelMessage(java.lang.String messageID, int index)
messageSendedCache
protected android.os.Message[] getParcelMessage(java.lang.String messageID)
messageID,
- String, represent a messageprotected android.os.Message getParcelMessage(java.lang.String messageID, int index)
messageSendedCache
.messageID,
- String, represent a message.index,
- int, the index of the parcel.protected boolean containMessageWithoutAck(java.lang.String messageID)
messageSendedCache
still contains aprotected int getTotalNumberOfParcels(int dataLength, int parcelLength)
protected java.util.List<android.os.Message> divideMessageIntoSmallPieces(android.os.Message msg, java.util.Properties props) throws java.lang.Exception
MessageUtil.MAX_TRANSFER_BYTE_SIZE
, it willMessageUtil.MAX_TRANSFER_BYTE_SIZE
, it willmsg
- Message, the original message to send. It contains 'what' and 'replyTo'.props
- Properties, the real content to send through Message.java.lang.Exception
MessageUtil
protected java.util.List<android.os.Message> divideMessageIntoSmallPieces(android.os.Message msg, char[] buffer) throws java.lang.Exception
MessageUtil.MAX_TRANSFER_BYTE_SIZE
, it willMessageUtil.MAX_TRANSFER_BYTE_SIZE
, it willmsg
- Message, the original message to send. It contains 'what' and 'replyTo'.buffer
- char[], the real content to send through Message.java.lang.Exception
MessageUtil
protected java.util.List<android.os.Message> divideMessageIntoSmallPieces(android.os.Message msg, java.lang.String message) throws java.lang.Exception
MessageUtil.MAX_TRANSFER_BYTE_SIZE
, it willMessageUtil.MAX_TRANSFER_BYTE_SIZE
, it willmsg
- Message, the original message to send. It contains 'what' and 'replyTo'.message
- String, the real content to send through Message.java.lang.Exception
MessageUtil
public boolean sendMessageAsMultipleParcels(android.os.Messenger mService, android.os.Message msg, java.lang.Object object)
MessageUtil.MAX_TRANSFER_BYTE_SIZE
,messageSendedCache
of a message will be re-sent out.assembleSmallParcels(Message)
msg,
- Message, a wrapper for the object.message,
- Object, the object to send#sendServiceResult(Properties)
,
#sendServiceResult(MessageResult)
,
assembleSmallParcels(Message)
public boolean sendMessageOfLostParcel(android.os.Messenger mService, java.lang.String messageID)
messageSendedCache
MessageUtil.BUNDLE_SMALL_RESENT_PARCEL
to true,public boolean sendMessageOfLostParcel(android.os.Messenger mService, java.lang.String messageID, int index)
messageSendedCache
MessageUtil.BUNDLE_SMALL_RESENT_PARCEL
to true,getParcelMessage(String, int)
public void handleMessage(android.os.Message msg)
Handler
We will handle the small parcels of a whole message. Make sure no parcels
are lost and assemble them in order.handleMessage
in class android.os.Handler
Copyright © SAS Institute. All Rights Reserved.