Permalink
Browse files

additional flag PROXY_ADDR for faster marshalling

  • Loading branch information...
1 parent 20f804f commit 771bef138ef2f464f089f0cb6e7470c49c8070da @belaban committed Nov 18, 2010
View
8 src/org/jgroups/Address.java
@@ -14,9 +14,11 @@
*/
public interface Address extends Externalizable, Streamable, Comparable<Address>, Cloneable { // todo: remove Externalizable
// flags used for marshalling
- public static final byte NULL = 1 << 0;
- public static final byte UUID_ADDR = 1 << 1;
- public static final byte IP_ADDR = 1 << 2;
+ public static final byte NULL = 1 << 0;
+ public static final byte UUID_ADDR = 1 << 1;
+ public static final byte IP_ADDR = 1 << 2;
+ public static final byte PROXY_ADDR = 1 << 3;
+
/**
* Checks whether this is an address that represents multiple destinations;
View
9 src/org/jgroups/util/Util.java
@@ -833,6 +833,9 @@ public static void writeAddress(Address addr, DataOutputStream out) throws IOExc
else if(addr instanceof IpAddress) {
flags=Util.setFlag(flags, Address.IP_ADDR);
}
+ else if(addr instanceof ProxyAddress) {
+ flags=Util.setFlag(flags, Address.PROXY_ADDR);
+ }
else {
streamable_addr=false;
}
@@ -858,6 +861,10 @@ else if(Util.isFlagSet(flags, Address.IP_ADDR)) {
addr=new IpAddress();
addr.readFrom(in);
}
+ else if(Util.isFlagSet(flags, Address.PROXY_ADDR)) {
+ addr=new ProxyAddress();
+ addr.readFrom(in);
+ }
else {
addr=readOtherAddress(in);
}
@@ -867,7 +874,7 @@ else if(Util.isFlagSet(flags, Address.IP_ADDR)) {
public static int size(Address addr) {
int retval=Global.BYTE_SIZE; // flags
if(addr != null) {
- if(addr instanceof UUID || addr instanceof IpAddress)
+ if(addr instanceof UUID || addr instanceof IpAddress || addr instanceof ProxyAddress)
retval+=addr.size();
else {
retval+=Global.SHORT_SIZE; // magic number
View
24 tests/junit-functional/org/jgroups/tests/SizeTest.java
@@ -519,6 +519,9 @@ public static void testStompHeader() throws Exception {
public static void testRelayHeader() throws Exception {
RELAY.RelayHeader hdr=new RELAY.RelayHeader(RELAY.RelayHeader.Type.DISSEMINATE);
_testSize(hdr);
+
+ hdr=new RELAY.RelayHeader(RELAY.RelayHeader.Type.DISSEMINATE, Util.createRandomAddress("A"));
+ _testSize(hdr);
}
public static void testStateHeader() throws Exception {
@@ -581,27 +584,36 @@ public static void testIpAddress3() throws Exception {
}
+
public static void testIpAddressWithAdditionalData() throws Exception {
IpAddress addr=new IpAddress(5555, false);
addr.setAdditionalData("bela".getBytes());
_testSize(addr);
}
+ public static void testProxyAddress() throws Exception {
+ ProxyAddress addr=new ProxyAddress(Util.createRandomAddress("A"), Util.createRandomAddress("B"));
+ _testSize(addr);
+ }
+
public static void testWriteAddress() throws IOException, IllegalAccessException, InstantiationException {
- UUID uuid=UUID.randomUUID();
+ Address uuid=UUID.randomUUID();
_testWriteAddress(uuid);
- uuid.setAdditionalData("Bela Ban".getBytes());
+ ((UUID)uuid).setAdditionalData("Bela Ban".getBytes());
_testWriteAddress(uuid);
- IpAddress addr=new IpAddress(7500);
+ Address addr=new IpAddress(7500);
_testWriteAddress(addr);
addr=new IpAddress("127.0.0.1", 5678);
_testWriteAddress(addr);
- addr.setAdditionalData("Bela Ban".getBytes());
+ ((IpAddress)addr).setAdditionalData("Bela Ban".getBytes());
+ _testWriteAddress(addr);
+
+ addr=new ProxyAddress(Util.createRandomAddress("A"), Util.createRandomAddress("B"));
_testWriteAddress(addr);
}
@@ -771,11 +783,11 @@ private static void _testSize(Header hdr) throws Exception {
- private static void _testSize(Address addr) throws Exception {
+ private static void _testSize(Address addr) throws Exception {
long size=addr.size();
byte[] serialized_form=Util.streamableToByteBuffer(addr);
System.out.println("size=" + size + ", serialized size=" + serialized_form.length);
- Assert.assertEquals(serialized_form.length, size);
+ Assert.assertEquals(serialized_form.length, size);
}

0 comments on commit 771bef1

Please sign in to comment.