Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

implemented simplistic new address based on short (IdAddress)

  • Loading branch information...
commit f0d2de4e9bf6b989f0605c3b7a7fbacb2577a858 1 parent 28e304a
@belaban authored
View
1  conf/jg-magic-map.xml
@@ -49,4 +49,5 @@
<class id="78" name="org.jgroups.protocols.STOMP$StompHeader"/>
<class id="79" name="org.jgroups.util.ProxyAddress"/>
<class id="80" name="org.jgroups.protocols.PrioHeader"/>
+ <class id="81" name="org.jgroups.util.IdAddress"/>
</magic-number-class-mapping>
View
1  src/org/jgroups/Address.java
@@ -18,6 +18,7 @@
public static final byte UUID_ADDR = 1 << 1;
public static final byte IP_ADDR = 1 << 2;
public static final byte PROXY_ADDR = 1 << 3;
+ public static final byte ID_ADDR = 1 << 4;
/**
View
5 src/org/jgroups/JChannel.java
@@ -1786,7 +1786,10 @@ private void startStack(String cluster_name) throws ChannelException {
*/
protected void setAddress() {
Address old_addr=local_addr;
- local_addr=UUID.randomUUID();
+ // local_addr=UUID.randomUUID();
+
+ short id=(short)Util.random(Short.MAX_VALUE);
+ local_addr=new IdAddress(id);
byte[] buf=(byte[])additional_data.get("additional_data");
if(buf != null)
View
2  src/org/jgroups/protocols/Discovery.java
@@ -358,7 +358,7 @@ public Object up(Event evt) {
if(logical_addr != null && physical_addr != null)
down(new Event(Event.SET_PHYSICAL_ADDRESS, new Tuple<Address,PhysicalAddress>(logical_addr, physical_addr)));
if(logical_addr != null && data.getLogicalName() != null)
- UUID.add((UUID)logical_addr, data.getLogicalName());
+ UUID.add(logical_addr, data.getLogicalName());
if(log.isTraceEnabled())
log.trace("received GET_MBRS_RSP from " + response_sender + ": " + data);
View
106 src/org/jgroups/util/IdAddress.java
@@ -0,0 +1,106 @@
+package org.jgroups.util;
+
+import org.jgroups.Address;
+import org.jgroups.Global;
+
+import java.io.*;
+
+/** Logical address which is unique over space and time.
+ * <br/>
+ * Copied from java.util.UUID, but unneeded fields from the latter have been removed. UUIDs needs to
+ * have a small memory footprint.
+ * @author Bela Ban
+ */
+public class IdAddress implements Address, Streamable, Comparable<Address> {
+ private static final long serialVersionUID=-28777882492099481L;
+
+ short id;
+
+
+
+
+ public IdAddress() {
+ }
+
+
+ public IdAddress(short id) {
+ this.id=id;
+ }
+
+
+ public String toString() {
+ return String.valueOf(id);
+ }
+
+
+ /**
+ * Returns a hash code for this {@code UUID}.
+ * @return A hash code value for this {@code UUID}
+ */
+ public int hashCode() {
+ return id;
+ }
+
+ /**
+ * Compares this object to the specified object. The result is {@code
+ * true} if and only if the argument is not {@code null}, is a {@code UUID}
+ * object, has the same variant, and contains the same value, bit for bit,
+ * as this {@code UUID}.
+ * @param obj The object to be compared
+ * @return {@code true} if the objects are the same; {@code false} otherwise
+ */
+ public boolean equals(Object obj) {
+ if(!(obj instanceof IdAddress))
+ return false;
+ IdAddress tmp = (IdAddress)obj;
+ return this == tmp || id == tmp.id;
+ }
+
+
+ /**
+ * Compares this UUID with the specified UUID.
+ * <p> The first of two UUIDs is greater than the second if the most
+ * significant field in which the UUIDs differ is greater for the first UUID.
+ * @param other {@code UUID} to which this {@code UUID} is to be compared
+ * @return -1, 0 or 1 as this {@code UUID} is less than, equal to, or greater than {@code val}
+ */
+ public int compareTo(Address other) {
+ IdAddress val=(IdAddress)other;
+ if(this == val)
+ return 0;
+ return id < val.id? -1 : id > val.id? 1 : 0;
+ }
+
+
+
+ public void writeTo(DataOutputStream out) throws IOException {
+ out.writeShort(id);
+ }
+
+ public void readFrom(DataInputStream in) throws IOException, IllegalAccessException, InstantiationException {
+ id=in.readShort();
+ }
+
+ public boolean isMulticastAddress() {
+ return false;
+ }
+
+ public int size() {
+ return Global.SHORT_SIZE;
+ }
+
+ public Object clone() throws CloneNotSupportedException {
+ return new IdAddress(id);
+ }
+
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeShort(id);
+ }
+
+
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ id=in.readShort();
+ }
+
+
+}
View
7 src/org/jgroups/util/Util.java
@@ -836,6 +836,9 @@ else if(addr instanceof IpAddress) {
else if(addr instanceof ProxyAddress) {
flags=Util.setFlag(flags, Address.PROXY_ADDR);
}
+ else if(addr instanceof IdAddress) {
+ flags=Util.setFlag(flags, Address.ID_ADDR);
+ }
else {
streamable_addr=false;
}
@@ -865,6 +868,10 @@ else if(Util.isFlagSet(flags, Address.PROXY_ADDR)) {
addr=new ProxyAddress();
addr.readFrom(in);
}
+ else if(Util.isFlagSet(flags, Address.ID_ADDR)) {
+ addr=new IdAddress();
+ addr.readFrom(in);
+ }
else {
addr=readOtherAddress(in);
}
Please sign in to comment.
Something went wrong with that request. Please try again.