Skip to content

Commit

Permalink
Made Address implement Externalizable, added implementations (https:/…
Browse files Browse the repository at this point in the history
  • Loading branch information
belaban committed Jan 25, 2012
1 parent 616d675 commit 7328ff6
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/org/jgroups/Address.java
Expand Up @@ -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
Expand All @@ -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;
Expand Down
18 changes: 17 additions & 1 deletion src/org/jgroups/stack/IpAddress.java
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
23 changes: 22 additions & 1 deletion src/org/jgroups/util/AdditionalDataUUID.java
Expand Up @@ -12,7 +12,8 @@
* @author Bela Ban
*/
public class AdditionalDataUUID extends UUID {
protected byte[] payload;
private static final long serialVersionUID = 4583682459482601554L;
protected byte[] payload;

public AdditionalDataUUID() {
}
Expand Down Expand Up @@ -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);
Expand Down
21 changes: 21 additions & 0 deletions src/org/jgroups/util/PayloadUUID.java
Expand Up @@ -12,6 +12,7 @@
* @author Bela Ban
*/
public class PayloadUUID extends UUID {
private static final long serialVersionUID = -7920418038143502913L;
protected String payload;

public PayloadUUID() {
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 10 additions & 1 deletion src/org/jgroups/util/SingletonAddress.java
Expand Up @@ -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) {
Expand All @@ -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();
}
Expand Down
24 changes: 24 additions & 0 deletions src/org/jgroups/util/TopologyUUID.java
Expand Up @@ -13,6 +13,7 @@
* @author Bela Ban
*/
public class TopologyUUID extends UUID {
private static final long serialVersionUID = -3724100022170135811L;
protected String site_id;
protected String rack_id;
protected String machine_id;
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/org/jgroups/util/UUID.java
Expand Up @@ -16,8 +16,8 @@
*
* @author Bela Ban
*/
public class UUID implements Address, Streamable, Comparable<Address>, Externalizable {
private static final long serialVersionUID = -6194072960039354716L;
public class UUID implements Address {
private static final long serialVersionUID = 8610088016866299124L;
protected long mostSigBits;
protected long leastSigBits;

Expand Down
Expand Up @@ -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 {
;
}
Expand Down
Expand Up @@ -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 {
}

Expand Down

0 comments on commit 7328ff6

Please sign in to comment.