Permalink
Browse files

Made Address implement Externalizable, added implementations (https:/…

  • Loading branch information...
1 parent 23667ce commit 19ba8f6889c656d945a1700ec9ed5cf56ca56b6c Bela Ban committed Jan 25, 2012
@@ -4,6 +4,8 @@
import org.jgroups.util.Streamable;
import org.jgroups.util.UUID;
+import java.io.Externalizable;
+
/**
* Address identifies cluster member. For example, whenever a unicast message is sent in a cluster
* an Address of a cluster member message recipient needs to be specified. Similarly a cluster
@@ -16,7 +18,7 @@
* @see PhysicalAddress
* @see UUID
*/
-public interface Address extends Streamable, Comparable<Address> {
+public interface Address extends Streamable, Comparable<Address>, Externalizable {
// flags used for marshalling
public static final byte NULL = 1 << 0;
public static final byte UUID_ADDR = 1 << 1;
@@ -21,7 +21,7 @@
* @author Bela Ban
*/
public class IpAddress implements PhysicalAddress {
-
+ private static final long serialVersionUID=5877146630213185651L;
private InetAddress ip_addr;
private int port;
protected static final Log log=LogFactory.getLog(IpAddress.class);
@@ -174,7 +174,23 @@ public String toString() {
}
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ try {
+ readFrom(in);
+ }
+ catch(Exception e) {
+ throw new IOException(e);
+ }
+ }
+ public void writeExternal(ObjectOutput out) throws IOException {
+ try {
+ writeTo(out);
+ }
+ catch(Exception e) {
+ throw new IOException(e);
+ }
+ }
public void writeTo(DataOutput out) throws Exception {
if(ip_addr != null) {
@@ -12,6 +12,7 @@
* @author Bela Ban
*/
public class AdditionalDataUUID extends UUID {
+ private static final long serialVersionUID=4583682459482601554L;
protected byte[] payload;
public AdditionalDataUUID() {
@@ -50,6 +51,26 @@ public int size() {
return retval;
}
+ public void writeExternal(ObjectOutput out) throws IOException {
+ super.writeExternal(out);
+ try {
+ Util.writeByteBuffer(payload, out);
+ }
+ catch(Exception e) {
+ throw new IOException(e);
+ }
+ }
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ super.readExternal(in);
+ try {
+ payload=Util.readByteBuffer(in);
+ }
+ catch(Exception e) {
+ throw new IOException(e);
+ }
+ }
+
public void writeTo(DataOutput out) throws Exception {
super.writeTo(out);
Util.writeByteBuffer(payload, out);
@@ -12,6 +12,7 @@
* @author Bela Ban
*/
public class PayloadUUID extends UUID {
+ private static final long serialVersionUID=-7383508979230850669L;
protected String payload;
public PayloadUUID() {
@@ -57,6 +58,26 @@ public int size() {
return retval;
}
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ super.readExternal(in);
+ try {
+ payload=Util.readString(in);
+ }
+ catch(Exception e) {
+ throw new IOException(e);
+ }
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ super.writeExternal(out);
+ try {
+ Util.writeString(payload, out);
+ }
+ catch(Exception e) {
+ throw new IOException(e);
+ }
+ }
+
public void writeTo(DataOutput out) throws Exception {
super.writeTo(out);
Util.writeString(payload, out);
@@ -9,7 +9,8 @@
* @author Bela Ban
*/
public class SingletonAddress implements Address {
- protected final String cluster_name;
+ private static final long serialVersionUID=7295848950180741550L;
+ protected final String cluster_name;
protected final Address addr;
public SingletonAddress(String cluster_name, Address addr) {
@@ -36,6 +37,14 @@ public int size() {
return 0;
}
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
public void writeTo(DataOutput out) throws Exception {
throw new UnsupportedOperationException();
}
@@ -13,6 +13,7 @@
* @author Bela Ban
*/
public class TopologyUUID extends UUID {
+ private static final long serialVersionUID=-9174743372383447193L;
protected String site_id;
protected String rack_id;
protected String machine_id;
@@ -102,6 +103,29 @@ public void readFrom(DataInput in) throws Exception {
machine_id=Util.readString(in);
}
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ super.readExternal(in);
+ try {
+ site_id=Util.readString(in);
+ rack_id=Util.readString(in);
+ machine_id=Util.readString(in);
+ }
+ catch(Exception e) {
+ throw new IOException(e);
+ }
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ super.writeExternal(out);
+ try {
+ Util.writeString(site_id, out);
+ Util.writeString(rack_id, out);
+ Util.writeString(machine_id, out);
+ }
+ catch(Exception e) {
+ throw new IOException(e);
+ }
+ }
public String toString() {
if(print_uuids)
@@ -16,7 +16,7 @@
*
* @author Bela Ban
*/
-public class UUID implements Address, Streamable, Comparable<Address>, Externalizable {
+public class UUID implements Address, Comparable<Address> {
private static final long serialVersionUID=-6194072960039354716L;
protected long mostSigBits;
protected long leastSigBits;
@@ -264,6 +264,12 @@ public int size() {
return 0;
}
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ }
+
public void writeTo(DataOutput out) throws Exception {
;
}
@@ -494,6 +494,12 @@ public boolean equals(Object obj) {
return address.name.equals(this.name);
}
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ }
+
public void writeTo(DataOutput out) throws Exception {
}

0 comments on commit 19ba8f6

Please sign in to comment.