[jboss-svn-commits] JBoss Common SVN: r4195 - invokablecontainer/trunk/api/src/main/java/org/jboss/invokable.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Mar 29 10:43:52 EDT 2010
Author: david.lloyd at jboss.com
Date: 2010-03-29 10:43:51 -0400 (Mon, 29 Mar 2010)
New Revision: 4195
Added:
invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/DispatcherIdentifier.java
invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/ForwardedInvocationDispatcher.java
invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/RemoteDispatcherLocation.java
Removed:
invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/DispatcherLocation.java
Modified:
invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/ExportedInvocationDispatcher.java
invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/NodeInvocationContext.java
invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/NodeLocation.java
invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/ServerInvocationContext.java
Log:
Point commit
Added: invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/DispatcherIdentifier.java
===================================================================
--- invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/DispatcherIdentifier.java (rev 0)
+++ invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/DispatcherIdentifier.java 2010-03-29 14:43:51 UTC (rev 4195)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.invokable;
+
+import java.io.IOException;
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
+
+/**
+ * A unique identifier for a dispatcher within a single node.
+ */
+public final class DispatcherIdentifier implements Serializable {
+
+ private static final long serialVersionUID = -1228682891715016792L;
+
+ private final String contextName;
+ private final String dispatcherName;
+ private transient final int hashCode;
+
+ private static final FieldSetter<DispatcherIdentifier> hashCodeSetter = FieldSetter.forField(DispatcherIdentifier.class, "hashCode");
+
+ public DispatcherIdentifier(final String contextName, final String dispatcherName) {
+ if (contextName == null) {
+ throw new IllegalArgumentException("contextName is null");
+ }
+ if (dispatcherName == null) {
+ throw new IllegalArgumentException("dispatcherName is null");
+ }
+ this.contextName = contextName;
+ this.dispatcherName = dispatcherName;
+ hashCode = hashCode(contextName, dispatcherName);
+ }
+
+ public String getContextName() {
+ return contextName;
+ }
+
+ public String getDispatcherName() {
+ return dispatcherName;
+ }
+
+ private static int hashCode(String contextName, String dispatcherName) {
+ return contextName.hashCode() * 31 + dispatcherName.hashCode();
+ }
+
+ public boolean equals(final Object obj) {
+ return obj instanceof DispatcherIdentifier && equals((DispatcherIdentifier) obj);
+ }
+
+ public boolean equals(final DispatcherIdentifier other) {
+ return other == this || other != null && hashCode == other.hashCode && contextName.equals(other.contextName) && dispatcherName.equals(other.dispatcherName);
+ }
+
+ public int hashCode() {
+ return hashCode;
+ }
+
+ private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
+ ois.defaultReadObject();
+ if (contextName == null) {
+ throw new InvalidObjectException("contextName is null");
+ }
+ if (dispatcherName == null) {
+ throw new InvalidObjectException("dispatcherName is null");
+ }
+ hashCodeSetter.setInt(this, hashCode(contextName, dispatcherName));
+ }
+
+ public String toString() {
+ return String.format("Dispatcher identifier {context=\"%s\", name=\"%s\"}", contextName, dispatcherName);
+ }
+}
Deleted: invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/DispatcherLocation.java
===================================================================
--- invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/DispatcherLocation.java 2010-03-27 20:27:37 UTC (rev 4194)
+++ invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/DispatcherLocation.java 2010-03-29 14:43:51 UTC (rev 4195)
@@ -1,95 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, JBoss Inc., and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.invokable;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.Serializable;
-
-public final class DispatcherLocation implements Serializable {
-
- private static final long serialVersionUID = -8104174497055191121L;
-
- private static final FieldSetter<DispatcherLocation> hashCodeSetter = FieldSetter.forField(DispatcherLocation.class, "hashCode");
-
- private final NodeLocation nodeLocation;
- private final String contextName;
- private final String dispatcherName;
- private transient final int hashCode;
-
- public DispatcherLocation(final NodeLocation nodeLocation, final String contextName, final String dispatcherName) {
- if (nodeLocation == null) {
- throw new IllegalArgumentException("nodeLocation is null");
- }
- if (contextName == null) {
- throw new IllegalArgumentException("contextName is null");
- }
- if (dispatcherName == null) {
- throw new IllegalArgumentException("dispatcherName is null");
- }
- this.nodeLocation = nodeLocation;
- this.contextName = contextName;
- this.dispatcherName = dispatcherName;
- hashCode = hashCode(nodeLocation, contextName, dispatcherName);
- }
-
- private static int hashCode(final NodeLocation nodeLocation, final String contextName, final String dispatcherName) {
- return (nodeLocation.hashCode() * 31 + contextName.hashCode()) * 31 + dispatcherName.hashCode();
- }
-
- public NodeLocation getNodeLocation() {
- return nodeLocation;
- }
-
- public String getContextName() {
- return contextName;
- }
-
- public String getDispatcherName() {
- return dispatcherName;
- }
-
- public boolean equals(final Object obj) {
- return obj instanceof DispatcherLocation && equals((DispatcherLocation) obj);
- }
-
- public boolean equals(final DispatcherLocation other) {
- return this == other || other != null
- && nodeLocation.equals(other.nodeLocation)
- && contextName.equals(other.contextName)
- && dispatcherName.equals(other.dispatcherName);
- }
-
- public int hashCode() {
- return hashCode;
- }
-
- private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
- ois.defaultReadObject();
- hashCodeSetter.setInt(this, hashCode(nodeLocation, contextName, dispatcherName));
- }
-
- public String toString() {
- return String.format("Dispatcher location {nodeLocation=\"%s\", contextName=\"%s\", dispatcherName=\"%s\"}", nodeLocation, contextName, dispatcherName);
- }
-}
Modified: invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/ExportedInvocationDispatcher.java
===================================================================
--- invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/ExportedInvocationDispatcher.java 2010-03-27 20:27:37 UTC (rev 4194)
+++ invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/ExportedInvocationDispatcher.java 2010-03-29 14:43:51 UTC (rev 4195)
@@ -22,12 +22,14 @@
package org.jboss.invokable;
-import java.io.IOError;
import java.io.IOException;
+import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
import java.io.Serializable;
/**
+ * An exported dispatcher which refers to a local invocation context.
+ *
* @author <a href="mailto:david.lloyd at redhat.com">David M. Lloyd</a>
*/
final class ExportedInvocationDispatcher implements InvocationDispatcher, Serializable {
@@ -35,32 +37,33 @@
private static final long serialVersionUID = -3950038476252367014L;
private transient final NodeInvocationContext nodeInvocationContext;
- private final DispatcherLocation dispatcherLocation;
+ private final DispatcherIdentifier dispatcherIdentifier;
private static final FieldSetter<ExportedInvocationDispatcher> nodeInvocationContextSetter = FieldSetter.forField(ExportedInvocationDispatcher.class, "nodeInvocationContext");
- ExportedInvocationDispatcher(final NodeInvocationContext nodeInvocationContext, final DispatcherLocation dispatcherLocation) {
+ ExportedInvocationDispatcher(final NodeInvocationContext nodeInvocationContext, final DispatcherIdentifier dispatcherIdentifier) {
this.nodeInvocationContext = nodeInvocationContext;
- this.dispatcherLocation = dispatcherLocation;
+ this.dispatcherIdentifier = dispatcherIdentifier;
}
public InvocationReply dispatch(final Invocation invocation) throws InvocationException {
- final NodeAssociation association = nodeInvocationContext.getNodeAssociation(dispatcherLocation.getNodeLocation());
- final InvocationForwarder forwarder = association.getInvocationForwarder(dispatcherLocation.getContextName());
- try {
- return forwarder.dispatch(dispatcherLocation.getDispatcherName(), invocation);
- } catch (IOException e) {
- throw new IOError(e);
- }
+ final InvocationDispatcher dispatcher = nodeInvocationContext.getLocalDispatcher(dispatcherIdentifier);
+ return dispatcher.dispatch(invocation);
}
public <I> void accept(final Visitor<InvocationDispatcher, I> visitor, final I param) {
visitor.visit(this, param);
}
-
- private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
+ private void readObject(final ObjectInputStream ois) throws ClassNotFoundException, IOException {
ois.defaultReadObject();
+ if (dispatcherIdentifier == null) {
+ throw new InvalidObjectException("dispatcherIdentifier is null");
+ }
nodeInvocationContextSetter.set(this, NodeInvocationContext.requireCurrent());
}
+
+ public DispatcherIdentifier getDispatcherIdentifier() {
+ return dispatcherIdentifier;
+ }
}
Copied: invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/ForwardedInvocationDispatcher.java (from rev 4190, invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/ExportedInvocationDispatcher.java)
===================================================================
--- invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/ForwardedInvocationDispatcher.java (rev 0)
+++ invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/ForwardedInvocationDispatcher.java 2010-03-29 14:43:51 UTC (rev 4195)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.invokable;
+
+import java.io.IOError;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
+
+/**
+ * An exported dispatcher which refers to a remote invocation context.
+ *
+ * @author <a href="mailto:david.lloyd at redhat.com">David M. Lloyd</a>
+ */
+final class ForwardedInvocationDispatcher implements InvocationDispatcher, Serializable {
+
+ private static final long serialVersionUID = -3950038476252367014L;
+
+ private transient final NodeInvocationContext nodeInvocationContext;
+ private final String transport;
+ private final RemoteDispatcherLocation dispatcherLocation;
+
+ private static final FieldSetter<ForwardedInvocationDispatcher> nodeInvocationContextSetter = FieldSetter.forField(ForwardedInvocationDispatcher.class, "nodeInvocationContext");
+
+ ForwardedInvocationDispatcher(final NodeInvocationContext nodeInvocationContext, final RemoteDispatcherLocation dispatcherLocation, final String transport) {
+ this.nodeInvocationContext = nodeInvocationContext;
+ this.dispatcherLocation = dispatcherLocation;
+ this.transport = transport;
+ }
+
+ public InvocationReply dispatch(final Invocation invocation) throws InvocationException {
+ final NodeAssociation association = nodeInvocationContext.getNodeAssociation(dispatcherLocation.getNodeLocation());
+ final DispatcherIdentifier dispatcherIdentifier = dispatcherLocation.getDispatcherIdentifier();
+ try {
+ return association.getInvocationForwarder(dispatcherIdentifier.getContextName()).dispatch(dispatcherIdentifier.getDispatcherName(), invocation);
+ } catch (IOException e) {
+ throw new IOError(e);
+ }
+ }
+
+ public <I> void accept(final Visitor<InvocationDispatcher, I> visitor, final I param) {
+ visitor.visit(this, param);
+ }
+
+
+ private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
+ ois.defaultReadObject();
+ nodeInvocationContextSetter.set(this, NodeInvocationContext.requireCurrent());
+ }
+
+ public RemoteDispatcherLocation getLocation() {
+ return dispatcherLocation;
+ }
+}
\ No newline at end of file
Modified: invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/NodeInvocationContext.java
===================================================================
--- invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/NodeInvocationContext.java 2010-03-27 20:27:37 UTC (rev 4194)
+++ invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/NodeInvocationContext.java 2010-03-29 14:43:51 UTC (rev 4195)
@@ -22,6 +22,8 @@
package org.jboss.invokable;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -29,18 +31,73 @@
public final class NodeInvocationContext {
private final ConcurrentMap<NodeLocation, NodeAssociation> nodeAssociations = new ConcurrentHashMap<NodeLocation, NodeAssociation>();
+ private static final String NODE_NAME;
+
+ static {
+ // Inside the AS, this will use the AS settings. Outside, it will get the node name in a similar way.
+ String hostName = System.getProperty("jboss.host.name");
+ String qualifiedHostName = System.getProperty("jboss.qualified.host.name");
+ if (qualifiedHostName == null) {
+ // if host name is specified, don't pick a qualified host name that isn't related to it
+ qualifiedHostName = hostName;
+ if (qualifiedHostName == null) {
+ // POSIX-like OSes including Mac should have this set
+ qualifiedHostName = System.getenv("HOSTNAME");
+ }
+ if (qualifiedHostName == null) {
+ // Certain versions of Windows
+ qualifiedHostName = System.getenv("COMPUTERNAME");
+ }
+ if (qualifiedHostName == null) {
+ try {
+ qualifiedHostName = InetAddress.getLocalHost().getHostName();
+ } catch (UnknownHostException e) {
+ qualifiedHostName = null;
+ }
+ }
+ if (qualifiedHostName != null && qualifiedHostName.matches("^\\d+\\.\\d+\\.\\d+\\.\\d+$|:")) {
+ // IP address is not acceptable
+ qualifiedHostName = null;
+ }
+ if (qualifiedHostName == null) {
+ // Give up
+ qualifiedHostName = "unknown-host.unknown-domain";
+ }
+ qualifiedHostName = qualifiedHostName.trim().toLowerCase();
+ }
+ if (hostName == null) {
+ // Use the host part of the qualified host name
+ final int idx = qualifiedHostName.indexOf('.');
+ hostName = idx == -1 ? qualifiedHostName : qualifiedHostName.substring(0, idx);
+ }
+ // Set up the node name
+ String nodeName = System.getProperty("jboss.node.name");
+ if (nodeName == null) {
+ nodeName = hostName;
+ }
+ NODE_NAME = nodeName;
+ }
+
private static final ThreadLocal<NodeInvocationContext> current = new ThreadLocal<NodeInvocationContext>();
- private static final NodeInvocationContext global = null; // (todo - configure)
+ private static final NodeInvocationContext global = new NodeInvocationContext(NODE_NAME); // (todo - configure)
- public NodeAssociationHandle addNodeAssociation(final NodeLocation location, final NodeAssociation association) throws IllegalArgumentException {
+ private final String name;
+
+ public NodeInvocationContext(final String name) {
+ this.name = name;
+ }
+
+ public NodeAssociationHandle addNodeAssociation(final NodeLocation location, final String transport, final NodeAssociation association) throws IllegalArgumentException {
if (location == null) {
throw new IllegalArgumentException("location is null");
}
if (association == null) {
throw new IllegalArgumentException("association is null");
}
- final String transport = location.getTransport();
+ if (transport == null) {
+ throw new IllegalArgumentException("transport is null");
+ }
if (transport.length() == 0 || transport.equals("*")) {
throw new IllegalArgumentException(location.toString() + " does not specify a specific transport");
}
@@ -55,8 +112,8 @@
};
}
- public InvocationDispatcher createDispatcher(final DispatcherLocation dispatcherLocation) {
- return new ExportedInvocationDispatcher(this, dispatcherLocation);
+ public InvocationDispatcher createDispatcher(final RemoteDispatcherLocation dispatcherLocation) {
+ return new ExportedInvocationDispatcher(this, dispatcherLocation.getDispatcherIdentifier());
}
public static NodeInvocationContext getCurrent() {
@@ -90,7 +147,7 @@
public NodeAssociation getNodeAssociation(final NodeLocation nodeLocation) {
// (todo - access check)
- final String transport = nodeLocation.getTransport();
+ final String transport = null; // todo
if (transport.length() == 0 || transport.equals("*")) {
// (todo - index by transport type)
for (Map.Entry<NodeLocation, NodeAssociation> entry : nodeAssociations.entrySet()) {
@@ -103,4 +160,19 @@
return nodeAssociations.get(nodeLocation);
}
}
+
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Get a dispatcher which (directly or indirectly) forwards to a registered, exported dispatcher with the given
+ * identifier.
+ *
+ * @param dispatcherIdentifier the identifier
+ * @return the dispatcher
+ */
+ public InvocationDispatcher getLocalDispatcher(final DispatcherIdentifier dispatcherIdentifier) {
+ return null;
+ }
}
Modified: invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/NodeLocation.java
===================================================================
--- invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/NodeLocation.java 2010-03-27 20:27:37 UTC (rev 4194)
+++ invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/NodeLocation.java 2010-03-29 14:43:51 UTC (rev 4195)
@@ -33,29 +33,24 @@
private static final FieldSetter<NodeLocation> hashCodeSetter = FieldSetter.forField(NodeLocation.class, "hashCode");
- private final String transport;
private final String scheme;
private final String name;
private transient final int hashCode;
- public NodeLocation(final String transport, final String scheme, final String name) {
- if (transport == null) {
- throw new IllegalArgumentException("transport is null");
- }
+ public NodeLocation(final String scheme, final String name) {
if (scheme == null) {
throw new IllegalArgumentException("scheme is null");
}
if (name == null) {
throw new IllegalArgumentException("name is null");
}
- this.transport = transport;
this.scheme = scheme;
this.name = name;
- hashCode = hashCode(transport, scheme, name);
+ hashCode = hashCode(scheme, name);
}
- private static int hashCode(final String transport, final String scheme, final String name) {
- return (transport.hashCode() * 31 + scheme.hashCode()) * 31 + name.hashCode();
+ private static int hashCode(final String scheme, final String name) {
+ return scheme.hashCode() * 31 + name.hashCode();
}
public String getScheme() {
@@ -66,10 +61,6 @@
return name;
}
- public String getTransport() {
- return transport;
- }
-
public int hashCode() {
return hashCode;
}
@@ -83,24 +74,21 @@
}
public boolean equals(final NodeLocation other) {
- return this == other || other != null && hashCode == other.hashCode && scheme.equals(other.scheme) && name.equals(other.name) && transport.equals(other.transport);
+ return this == other || other != null && hashCode == other.hashCode && scheme.equals(other.scheme) && name.equals(other.name);
}
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
ois.defaultReadObject();
- if (transport == null) {
- throw new IllegalArgumentException("transport is null");
- }
if (scheme == null) {
throw new InvalidObjectException("scheme is null");
}
if (name == null) {
throw new InvalidObjectException("name is null");
}
- hashCodeSetter.setInt(this, hashCode(transport, scheme, name));
+ hashCodeSetter.setInt(this, hashCode(scheme, name));
}
public String toString() {
- return String.format("Node location \"%s:%s\" via \"%s\"", scheme, name, transport);
+ return String.format("Node location \"%s:%s\"", scheme, name);
}
}
Copied: invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/RemoteDispatcherLocation.java (from rev 4190, invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/DispatcherLocation.java)
===================================================================
--- invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/RemoteDispatcherLocation.java (rev 0)
+++ invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/RemoteDispatcherLocation.java 2010-03-29 14:43:51 UTC (rev 4195)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.invokable;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.Serializable;
+
+public final class RemoteDispatcherLocation implements Serializable {
+
+ private static final long serialVersionUID = -8104174497055191121L;
+
+ private static final FieldSetter<RemoteDispatcherLocation> hashCodeSetter = FieldSetter.forField(RemoteDispatcherLocation.class, "hashCode");
+
+ private final NodeLocation nodeLocation;
+ private final DispatcherIdentifier dispatcherIdentifier;
+ private transient final int hashCode;
+
+ public RemoteDispatcherLocation(final NodeLocation nodeLocation, final DispatcherIdentifier dispatcherIdentifier) {
+ if (nodeLocation == null) {
+ throw new IllegalArgumentException("nodeLocation is null");
+ }
+ if (dispatcherIdentifier == null) {
+ throw new IllegalArgumentException("dispatcherIdentifier is null");
+ }
+ this.nodeLocation = nodeLocation;
+ this.dispatcherIdentifier = dispatcherIdentifier;
+ hashCode = hashCode(nodeLocation, dispatcherIdentifier);
+ }
+
+ private static int hashCode(final NodeLocation nodeLocation, final DispatcherIdentifier dispatcherIdentifier) {
+ return nodeLocation.hashCode() * 31 + dispatcherIdentifier.hashCode();
+ }
+
+ public NodeLocation getNodeLocation() {
+ return nodeLocation;
+ }
+
+ public DispatcherIdentifier getDispatcherIdentifier() {
+ return dispatcherIdentifier;
+ }
+
+ public boolean equals(final Object obj) {
+ return obj instanceof RemoteDispatcherLocation && equals((RemoteDispatcherLocation) obj);
+ }
+
+ public boolean equals(final RemoteDispatcherLocation other) {
+ return this == other || other != null
+ && hashCode == other.hashCode
+ && nodeLocation.equals(other.nodeLocation)
+ && dispatcherIdentifier.equals(other.dispatcherIdentifier);
+ }
+
+ public int hashCode() {
+ return hashCode;
+ }
+
+ private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
+ ois.defaultReadObject();
+ hashCodeSetter.setInt(this, hashCode(nodeLocation, dispatcherIdentifier));
+ }
+
+ public String toString() {
+ return String.format("Remote dispatcher location {node=\"%s\", dispatcher=\"%s\"}", nodeLocation, dispatcherIdentifier);
+ }
+}
Modified: invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/ServerInvocationContext.java
===================================================================
--- invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/ServerInvocationContext.java 2010-03-27 20:27:37 UTC (rev 4194)
+++ invokablecontainer/trunk/api/src/main/java/org/jboss/invokable/ServerInvocationContext.java 2010-03-29 14:43:51 UTC (rev 4195)
@@ -23,8 +23,6 @@
package org.jboss.invokable;
import java.io.IOException;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
@@ -34,57 +32,12 @@
* @author <a href="mailto:david.lloyd at redhat.com">David M. Lloyd</a>
*/
public class ServerInvocationContext extends ClientInvocationContext {
+ private final NodeInvocationContext nodeInvocationContext;
private final String name;
- private static final String NODE_NAME;
-
- static {
- // Inside the AS, this will use the AS settings. Outside, it will get the node name in a similar way.
- String hostName = System.getProperty("jboss.host.name");
- String qualifiedHostName = System.getProperty("jboss.qualified.host.name");
- if (qualifiedHostName == null) {
- // if host name is specified, don't pick a qualified host name that isn't related to it
- qualifiedHostName = hostName;
- if (qualifiedHostName == null) {
- // POSIX-like OSes including Mac should have this set
- qualifiedHostName = System.getenv("HOSTNAME");
- }
- if (qualifiedHostName == null) {
- // Certain versions of Windows
- qualifiedHostName = System.getenv("COMPUTERNAME");
- }
- if (qualifiedHostName == null) {
- try {
- qualifiedHostName = InetAddress.getLocalHost().getHostName();
- } catch (UnknownHostException e) {
- qualifiedHostName = null;
- }
- }
- if (qualifiedHostName != null && qualifiedHostName.matches("^\\d+\\.\\d+\\.\\d+\\.\\d+$|:")) {
- // IP address is not acceptable
- qualifiedHostName = null;
- }
- if (qualifiedHostName == null) {
- // Give up
- qualifiedHostName = "unknown-host.unknown-domain";
- }
- qualifiedHostName = qualifiedHostName.trim().toLowerCase();
- }
- if (hostName == null) {
- // Use the host part of the qualified host name
- final int idx = qualifiedHostName.indexOf('.');
- hostName = idx == -1 ? qualifiedHostName : qualifiedHostName.substring(0, idx);
- }
- // Set up the node name
- String nodeName = System.getProperty("jboss.node.name");
- if (nodeName == null) {
- nodeName = hostName;
- }
- NODE_NAME = nodeName;
- }
-
- ServerInvocationContext(final String name) {
+ ServerInvocationContext(final String name, final NodeInvocationContext nodeInvocationContext) {
this.name = name;
+ this.nodeInvocationContext = nodeInvocationContext;
}
public static ServerInvocationContext getCurrent() {
@@ -105,7 +58,7 @@
}
public static ServerInvocationContext create(final String name) {
- return new ServerInvocationContext(name);
+ return new ServerInvocationContext(name, NodeInvocationContext.requireCurrent());
}
private final ConcurrentMap<String, Reg> exportedDispatchers = new ConcurrentHashMap<String, Reg>();
@@ -131,7 +84,7 @@
}
};
- public InvocationDispatcher export(InvocationDispatcher dispatcher) {
+ public InvocationDispatcher export(InvocationDispatcher dispatcher, String name) {
dispatcher.accept(new Visitor<InvocationDispatcher, Void>() {
public void visit(final InvocationDispatcher visited, final Void parameter) {
if (visited instanceof ExportedInvocationDispatcher) {
@@ -139,14 +92,18 @@
}
}
}, null);
- return new ExportedInvocationDispatcher(null, null, name, null, this);
+ return new ExportedInvocationDispatcher(nodeInvocationContext, new DispatcherIdentifier(getName(), name));
}
protected InvocationForwarder getForwarder(final String remoteNodeName, final String remoteContextName) {
- if (name.equals(remoteContextName) && remoteNodeName.equals(NODE_NAME)) {
+ if (name.equals(remoteContextName) && remoteNodeName.equals(NodeInvocationContext.getCurrent().getName())) {
return loopback;
} else {
return super.getForwarder(remoteNodeName, remoteContextName);
}
}
+
+ public String getName() {
+ return name;
+ }
}
More information about the jboss-svn-commits
mailing list