Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EJBCLIENT-175] Add getUri() method to Affinity hierarchy #171

Merged
merged 1 commit into from
Nov 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not super happy about this. But Java doesn't support conforming "empty" URIs with only a scheme part. Still thinking of a way to sling this weakness into an advantage, somehow.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't like this; trying to think of a better way, but if anyone has a suggestion or idea please speak up.

} 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