Skip to content

Commit

Permalink
[EJBCLIENT-175] Add getUri() method to Affinity hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlloyd committed Nov 29, 2016
1 parent 44c4a72 commit c10df57
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
25 changes: 25 additions & 0 deletions src/main/java/org/jboss/ejb/client/Affinity.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.net.URI;
import java.net.URISyntaxException;

/**
* The affinity specification for an EJB proxy.
Expand Down Expand Up @@ -74,6 +75,13 @@ public static Affinity forUri(URI uri) {
}
}

/**
* Get the associated URI.
*
* @return the associated URI (not {@code null})
*/
public abstract URI getUri();

public boolean equals(Object other) {
return other instanceof Affinity && equals((Affinity) other);
}
Expand All @@ -97,6 +105,10 @@ public int hashCode() {
return -1;
}

public URI getUri() {
return null;
}

public boolean equals(final Object other) {
return other == this;
}
Expand All @@ -117,11 +129,24 @@ public String toString() {
static class LocalAffinity extends Affinity {

private static final long serialVersionUID = -2052559528672779420L;
private static final URI uri;

static {
try {
uri = new URI("local", "-", null);
} catch (URISyntaxException e) {
throw new IllegalStateException(e);
}
}

public int hashCode() {
return -1;
}

public URI getUri() {
return uri;
}

public boolean equals(final Object other) {
return other == this;
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/jboss/ejb/client/ClusterAffinity.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

package org.jboss.ejb.client;

import java.net.URI;
import java.net.URISyntaxException;

/**
* A cluster affinity specification.
*
Expand Down Expand Up @@ -55,6 +58,14 @@ public String toString() {
return String.format("Cluster \"%s\"", clusterName);
}

public URI getUri() {
try {
return new URI("cluster", clusterName, null);
} catch (URISyntaxException e) {
throw new IllegalStateException(e);
}
}

public boolean equals(final Object other) {
return other instanceof ClusterAffinity && equals((ClusterAffinity) other);
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/jboss/ejb/client/NodeAffinity.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

package org.jboss.ejb.client;

import java.net.URI;
import java.net.URISyntaxException;

/**
* A single node affinity specification.
*
Expand Down Expand Up @@ -55,6 +58,14 @@ public String toString() {
return String.format("Node \"%s\"", nodeName);
}

public URI getUri() {
try {
return new URI("node", nodeName, null);
} catch (URISyntaxException e) {
throw new IllegalStateException(e);
}
}

public boolean equals(final Object other) {
return other instanceof NodeAffinity && equals((NodeAffinity) other);
}
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/org/jboss/ejb/client/URIAffinity.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ public final class URIAffinity extends Affinity {
this.uri = uri;
}

/**
* Get the associated URI.
*
* @return the associated URI (not {@code null})
*/
public URI getUri() {
return uri;
}
Expand Down

0 comments on commit c10df57

Please sign in to comment.