Router: Put the GarlicMessageParser in the RouterContext

to reduce object churn, we only need one
Add DeliveryInstructions.create() to return immmutable
local instructions, to reduce object churn
Minor cleanups
This commit is contained in:
zzz
2015-05-03 17:00:22 +00:00
parent 1eba6c5167
commit 707bfbbf8b
5 changed files with 47 additions and 17 deletions

View File

@@ -63,6 +63,19 @@ public class DeliveryInstructions extends DataStructureImpl {
*/
public static final DeliveryInstructions LOCAL = new LocalInstructions();
/**
* Returns immutable local instructions, or new
*
* @since 0.9.20
*/
public static DeliveryInstructions create(byte[] data, int offset) throws DataFormatException {
if (data[offset] == 0)
return LOCAL;
DeliveryInstructions rv = new DeliveryInstructions();
rv.readBytes(data, offset);
return rv;
}
public DeliveryInstructions() {
_deliveryMode = -1;
}

View File

@@ -89,8 +89,8 @@ public class GarlicClove extends DataStructureImpl {
*/
public int readBytes(byte source[], int offset) throws DataFormatException {
int cur = offset;
_instructions = new DeliveryInstructions();
cur += _instructions.readBytes(source, cur);
_instructions = DeliveryInstructions.create(source, offset);
cur += _instructions.getSize();
//if (_log.shouldLog(Log.DEBUG))
// _log.debug("Read instructions: " + _instructions);
try {