JBoss Remoting SVN: r5035 - remoting2/branches/2.x/docs/guide/en.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 21:30:20 -0400 (Tue, 14 Apr 2009)
New Revision: 5035
Modified:
remoting2/branches/2.x/docs/guide/en/chap9.xml
Log:
JBREM-1082: Added reference to Client.USE_ALL_PARAMETERS; (2) JBREM-1112: added reference to FAILURE_DISCONNECT_TIMEOUT; (3) JBREM-1108: noted validatorPingPeriod should be longer than validatorPingTimeout.
Modified: remoting2/branches/2.x/docs/guide/en/chap9.xml
===================================================================
--- remoting2/branches/2.x/docs/guide/en/chap9.xml 2009-04-14 18:04:38 UTC (rev 5034)
+++ remoting2/branches/2.x/docs/guide/en/chap9.xml 2009-04-15 01:30:20 UTC (rev 5035)
@@ -57,13 +57,46 @@
"validatorPingTimeout") - specifies the time, in milliseconds, allowed for
arrival of a response to a PING message. The default value is 1000.</para>
- <para>For more configuration parameters, see <xref
- linkend="section-interactions"/>.</para>
+ <para><emphasis role="bold">FAILURE_DISCONNECT_TIMEOUT</emphasis> (actual value
+ "failureDisconnectTimeout") - if the parameter "stopLeaseOnFailure"
+ (see <xref linkend="section-interactions"/>) is set to
+ "true", then "failureDisconnectTimeout" determines the disconnect timeout value
+ to be used by <classname>org.jboss.remoting.LeasePinger</classname> in shutting
+ down. In particular, if "failureDisconnectTimeout" is set to "0", then
+ <classname>LeasePinger</classname> will avoid any network i/o.</para>
- <para>Note, also, that <classname>ConnectionValidator</classname> creates a
+ <para> Normally, the values for these parameters are obtained either from
+ the <classname>Client</classname>'s configuration map or the metadata map
+ passed to <methodname>addConnectionListener()</methodname>, with values in
+ the metadata map taking precedence. However, another relevant parameter is
+ defined in <classname>org.jboss.remoting.Client</classname>:</para>
+
+ <para><emphasis role="bold">USE_ALL_PARAMS</emphasis> (actual value
+ "useAllParams") - this parameter is searched for in the
+ <classname>InvokerLocator</classname>, in the configuration map passed to
+ the <classname>Client</classname>, and in the metadata map (in that order).
+ If the last occurrence found is set to "true", then parameter values are
+ first obtained from the <classname>InvokerLocator</classname>, followed by
+ the <classname>Client</classname>'s configuration map and the
+ metadata map.</para>
+
+ <para>Note that <classname>ConnectionValidator</classname> creates a
client invoker to sends the PING messages, and it passes the metadata map to
configure the client invoker.</para>
+ <para><emphasis role="bold">NOTE.</emphasis> The default values of VALIDATOR_PING_PERIOD
+ and VALIDATOR_PING_TIMEOUT have often been found in practice to be too small, increasing
+ the likelihood of spurious connection failures.</para>
+
+ <para><emphasis role="bold">NOTE.</emphasis> It is important to set VALIDATOR_PING_PERIOD
+ to a value greater than the value of VALIDATOR_PING_TIMEOUT. Doing so gives the
+ <classname>ConnectionValidator</classname> a chance to notify all
+ <classname>ConnectionListener</classname>s, which might result in shutting down the
+ connection, before the next PING is sent.</para>
+
+ <para>For more configuration parameters, see <xref
+ linkend="section-interactions"/>.</para>
+
</section>
<section id="section-server-side" xreflabel="Server side monitoring">
15 years, 7 months
JBoss Remoting SVN: r5034 - remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2009-04-14 14:04:38 -0400 (Tue, 14 Apr 2009)
New Revision: 5034
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java
Log:
Javadoc
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java 2009-04-14 18:00:58 UTC (rev 5033)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java 2009-04-14 18:04:38 UTC (rev 5034)
@@ -155,7 +155,9 @@
*/
ResourceType getResourceType(URI uri);
-
+ /**
+ * Flags which can be passed in to listener registration methods.
+ */
enum ListenerFlag {
/**
15 years, 7 months
JBoss Remoting SVN: r5033 - in remoting3/trunk: jboss-remoting/src/main/java/org/jboss/remoting3/spi and 2 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2009-04-14 14:00:58 -0400 (Tue, 14 Apr 2009)
New Revision: 5033
Removed:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientConnector.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientSourceConnector.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointConnector.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/QualifiedName.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/NamedServiceRegistry.java
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/spi/NameTestCase.java
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ResourceType.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceSpecification.java
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/simple/MultiplexClientExample.java
remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/simple/MultiplexServerExample.java
Log:
API cleanup, javadoc
Deleted: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientConnector.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientConnector.java 2009-04-14 17:18:15 UTC (rev 5032)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientConnector.java 2009-04-14 18:00:58 UTC (rev 5033)
@@ -1,47 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, 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.remoting3;
-
-import java.net.URI;
-import org.jboss.xnio.IoFuture;
-
-/**
- * A client connector. Opens a connection to a URI which provides a single {@code Client} instance. Instances of this
- * interface may only be able to support a single URI scheme. Depending on the implementation, the URI may be a
- * protocol URI or a service URI.
- */
-public interface ClientConnector extends HandleableCloseable<ClientConnector> {
-
- /**
- * Establish a client connection.
- *
- * @param requestType the request class
- * @param replyType the reply class
- * @param connectUri the URI to connect to
- * @param <I> the request type
- * @param <O> the reply type
- * @return the future client
- * @throws IllegalArgumentException if the provided URI scheme is not supported by this connector
- */
- <I, O> IoFuture<? extends Client<I, O>> openClient(Class<I> requestType, Class<O> replyType, URI connectUri) throws IllegalArgumentException;
-}
Deleted: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientSourceConnector.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientSourceConnector.java 2009-04-14 17:18:15 UTC (rev 5032)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientSourceConnector.java 2009-04-14 18:00:58 UTC (rev 5033)
@@ -1,47 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, 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.remoting3;
-
-import java.net.URI;
-import org.jboss.xnio.IoFuture;
-
-/**
- * A client source connector. Opens a connection to a URI which provides a {@code ClientSource} instance. Instances of this
- * interface may only be able to support a single URI scheme. Depending on the implementation, the URI may be a
- * protocol URI or a service URI.
- */
-public interface ClientSourceConnector extends HandleableCloseable<ClientSourceConnector> {
-
- /**
- * Establish a client source connection.
- *
- * @param requestType the request class
- * @param replyType the reply class
- * @param connectUri the URI to connect to
- * @param <I> the request type
- * @param <O> the reply type
- * @return the future client
- * @throws IllegalArgumentException if the provided URI scheme is not supported by this connector
- */
- <I, O> IoFuture<? extends ClientSource<I, O>> openClientSource(Class<I> requestType, Class<O> replyType, URI connectUri) throws IllegalArgumentException;
-}
\ No newline at end of file
Deleted: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointConnector.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointConnector.java 2009-04-14 17:18:15 UTC (rev 5032)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointConnector.java 2009-04-14 18:00:58 UTC (rev 5033)
@@ -1,42 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, 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.remoting3;
-
-import java.net.URI;
-import org.jboss.xnio.IoFuture;
-
-/**
- * An endpoint connector. Used to connect a whole endpoint to another whole endpoint. Typically, services are then
- * shared between the endpoints in some fashion, though this need not be the case.
- */
-public interface EndpointConnector extends HandleableCloseable<EndpointConnector> {
-
- /**
- * Connect the given endpoint to the remote URI.
- *
- * @param endpoint the endpoint to connect
- * @param connectUri the connection URI
- * @return the future handle, which may be used to terminate the connection
- */
- IoFuture<? extends HandleableCloseable> connect(Endpoint endpoint, URI connectUri);
-}
Deleted: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/QualifiedName.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/QualifiedName.java 2009-04-14 17:18:15 UTC (rev 5032)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/QualifiedName.java 2009-04-14 18:00:58 UTC (rev 5033)
@@ -1,258 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, 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.remoting3;
-
-import java.io.UnsupportedEncodingException;
-import java.net.URLDecoder;
-import java.net.URLEncoder;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-
-/**
- * A qualified name for service registration. A qualified name is a path-like structure comprised of a series of
- * zero or more name segments. The string representation of a qualified name is a sequence of a forward slash
- * ({@code /}) followed by a non-empty URL-encoded name segment.
- */
-public final class QualifiedName implements Comparable<QualifiedName>, Iterable<String> {
-
- /**
- * The root name.
- */
- public static final QualifiedName ROOT_NAME = new QualifiedName(new String[0]);
-
- private final String[] segments;
-
- /**
- * Create a new qualified name from the given name segments.
- *
- * @param nameSegments the name segments
- * @throws NullPointerException if {@code nameSegments} is {@code null} or if any element of that array is {@code null}
- * @throws IllegalArgumentException if an element of {@code nameSegments} is an empty string
- */
- public QualifiedName(final String[] nameSegments) throws NullPointerException, IllegalArgumentException {
- if (nameSegments == null) {
- throw new NullPointerException("segments is null");
- }
- String[] segments = nameSegments.clone();
- for (String s : segments) {
- if (s == null) {
- throw new NullPointerException("Null segment");
- }
- if (s.length() == 0) {
- throw new IllegalArgumentException("Empty segment");
- }
- }
- this.segments = segments;
- }
-
- /**
- * Compare this qualified name to another for equality. Returns {@code true} if both names have the same number of segments
- * with the same content.
- *
- * @param o the object to compare to
- * @return {@code true} if the given object is a qualified name which is equal to this name
- */
- public boolean equals(final Object o) {
- if (this == o) return true;
- if (! (o instanceof QualifiedName)) return false;
- final QualifiedName name = (QualifiedName) o;
- if (!Arrays.equals(segments, name.segments)) return false;
- return true;
- }
-
- /**
- * Get the hash code of this qualified name. Equal to the return value of {@link Arrays#hashCode(Object[]) Arrays.hashCode(segments)}
- * where {@code segments} is the array of decoded segment strings.
- *
- * @return the hash code
- */
- public int hashCode() {
- return Arrays.hashCode(segments);
- }
-
- /**
- * Compare this qualified name to another. Each segment is compared in turn; if they are equal then the comparison
- * carries on to the next segment. If all leading segments are equal but one qualified name has more segments,
- * then the longer name is said to come after the shorter name.
- *
- * @param o the other name
- * @return {@code 0} if the elements are equal, {@code -1} if this name comes before the given name, or {@code 1} if
- * this name comes after the given name
- */
- public int compareTo(final QualifiedName o) {
- if (this == o) return 0;
- String[] a = segments;
- String[] b = o.segments;
- final int alen = a.length;
- final int blen = b.length;
- for (int i = 0; i < alen && i < blen; i ++) {
- final int cmp = a[i].compareTo(b[i]);
- if (cmp != 0) {
- return cmp;
- }
- }
- if (alen < blen) {
- return -1;
- } else if (alen > blen) {
- return 1;
- } else {
- return 0;
- }
- }
-
- /**
- * Get the string representation of this qualified name. The root name is "{@code /}"; all other names are comprised
- * of one or more consecutive character sequences of a forward slash followed by one or more URL-encoded characters.
- *
- * @return the string representation of this name
- */
- public String toString() {
- StringBuilder builder = new StringBuilder();
- if (segments.length == 0) {
- return "/";
- } else for (String segment : segments) {
- try {
- builder.append('/');
- builder.append(URLEncoder.encode(segment, "utf-8"));
- } catch (UnsupportedEncodingException e) {
- // cannot happen
- throw new IllegalStateException(e);
- }
- }
- return builder.toString();
- }
-
- /**
- * Parse an absolute qualified name. An absolute qualified name must consist of either a single forward slash ("{@code /}") or else
- * a series of path components, each comprised of a single forward slash followed by a URL-encoded series of non-forward-slash
- * characters.
- *
- * @param path the encoded absolute path
- * @return the qualified name
- */
- public static QualifiedName parse(String path) {
- final int len = path.length();
- if (len < 1) {
- throw new IllegalArgumentException("Empty path");
- }
- if (path.charAt(0) != '/') {
- throw new IllegalArgumentException("Relative paths are not allowed");
- }
- if (len == 1) {
- return ROOT_NAME;
- }
- return ROOT_NAME.parseRelative(path.substring(1));
- }
-
- /**
- * Get an iterator over the sequence of strings.
- *
- * @return an iterator
- */
- public Iterator<String> iterator() {
- return new Iterator<String>() {
- int i;
-
- public boolean hasNext() {
- return i < segments.length;
- }
-
- public String next() {
- try {
- return segments[i++];
- } catch (ArrayIndexOutOfBoundsException e) {
- throw new NoSuchElementException("next() past end");
- }
- }
-
- public void remove() {
- throw new UnsupportedOperationException("remove()");
- }
- };
- }
-
- /**
- * Parse a qualified name relative to this one. A relative qualified name must consist of
- * a series of segments comprised of one or more URL-encoded characters separated by forward slashes ("{@code /}").
- *
- * @param path the encoded relative path
- * @return the qualified name
- */
- public QualifiedName parseRelative(String path) {
- if (path == null) {
- throw new NullPointerException("path is null");
- }
- List<String> decoded = new ArrayList<String>();
- int segStart = 0;
- int segEnd;
- do {
- segEnd = path.indexOf('/', segStart);
- String segment = segEnd == -1 ? path.substring(segStart) : path.substring(segStart, segEnd);
- if (segment.length() == 0) {
- throw new IllegalArgumentException(segEnd == -1 ? "Invalid trailing slash" : "Empty segment in path");
- }
- try {
- decoded.add(URLDecoder.decode(segment, "utf-8"));
- } catch (UnsupportedEncodingException e) {
- // cannot happen
- throw new IllegalStateException(e);
- }
- segStart = segEnd + 1;
- } while (segEnd != -1);
- final String[] segments = this.segments;
- final int length = segments.length;
- final String[] newSegments = new String[length + decoded.size()];
- System.arraycopy(segments, 0, newSegments, 0, length);
- for (int i = 0; i < decoded.size(); i ++) {
- newSegments[i + length] = decoded.get(i);
- }
- return new QualifiedName(newSegments);
- }
-
- /**
- * Get a new {@code org.jboss.remoting.QualifiedName} relative to this one.
- *
- * @param relativePath the segment to append
- * @return the new {@code org.jboss.remoting.QualifiedName} instance
- */
- public QualifiedName appendRelative(String relativePath) {
- final String[] segments = this.segments;
- final int length = segments.length;
- final String[] newSegments = new String[length + 1];
- System.arraycopy(segments, 0, newSegments, 0, length);
- newSegments[length] = relativePath;
- return new QualifiedName(newSegments);
- }
-
- /**
- * Get the number of segments in this name.
- *
- * @return the number of segments
- */
- public int length() {
- return segments.length;
- }
-}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ResourceType.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ResourceType.java 2009-04-14 17:18:15 UTC (rev 5032)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ResourceType.java 2009-04-14 18:00:58 UTC (rev 5033)
@@ -23,11 +23,29 @@
package org.jboss.remoting3;
/**
+ * The type of resource supported by a specific connection manager.
*
+ * @apiviz.excluded
*/
public enum ResourceType {
+
+ /**
+ * An unknown resource. Such a resource cannot be opened by an endpoint.
+ */
UNKNOWN,
+ /**
+ * A client resource. Use {@link Endpoint#openClient(java.net.URI, Class, Class) Endpoint.openClient(*)} to open
+ * a client resource URI.
+ */
CLIENT,
+ /**
+ * A client source resource. Use {@link Endpoint#openClientSource(java.net.URI, Class, Class) Endpoint.openClientSource(*)} to open
+ * a client source resource URI.
+ */
CLIENT_SOURCE,
+ /**
+ * An endpoint resource. Use {@link Endpoint#openEndpointConnection(java.net.URI) Endpoint.openEndpointConnection(*)} to open
+ * an endpoint resource URI.
+ */
ENDPOINT,
}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceSpecification.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceSpecification.java 2009-04-14 17:18:15 UTC (rev 5032)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceSpecification.java 2009-04-14 18:00:58 UTC (rev 5033)
@@ -34,6 +34,14 @@
private final String groupName;
private final String endpointName;
+ /**
+ * Construct a new instance. Each argument is validated and converted into a canonical form. The arguments
+ * may be "*" indicating that anything will match.
+ *
+ * @param serviceType the service type
+ * @param groupName the group name
+ * @param endpointName the endpoint name
+ */
public ServiceSpecification(final String serviceType, final String groupName, final String endpointName) {
if (serviceType == null) {
throw new NullPointerException("serviceType is null");
@@ -64,22 +72,49 @@
}
}
+ /**
+ * Create an instance from a service URI.
+ *
+ * @param uri the URI
+ * @return the specificaion
+ */
public static ServiceSpecification fromUri(final URI uri) {
return new ServiceSpecification(ServiceURI.getServiceType(uri), ServiceURI.getGroupName(uri), ServiceURI.getEndpointName(uri));
}
+ /**
+ * Get the service type of this specification.
+ *
+ * @return the service type
+ */
public String getServiceType() {
return serviceType;
}
+ /**
+ * Get the group name of this specification.
+ *
+ * @return the group name
+ */
public String getGroupName() {
return groupName;
}
+ /**
+ * Get the endpoint name of this specification.
+ *
+ * @return the endpoint name
+ */
public String getEndpointName() {
return endpointName;
}
+ /**
+ * Determine whether the given URI matches this specification.
+ *
+ * @param serviceUri the service URI
+ * @return {@code true} if the URI is a service which matches this specification
+ */
public boolean matches(final URI serviceUri) {
if (! ServiceURI.isRemotingServiceUri(serviceUri)) {
return false;
@@ -102,6 +137,7 @@
return true;
}
+ /** {@inheritDoc} */
public boolean equals(final Object o) {
if (this == o) return true;
if (! (o instanceof ServiceSpecification)) return false;
@@ -112,7 +148,7 @@
return true;
}
- @Override
+ /** {@inheritDoc} */
public int hashCode() {
int result = serviceType.hashCode();
result = 31 * result + groupName.hashCode();
Deleted: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/NamedServiceRegistry.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/NamedServiceRegistry.java 2009-04-14 17:18:15 UTC (rev 5032)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/NamedServiceRegistry.java 2009-04-14 18:00:58 UTC (rev 5033)
@@ -1,117 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, 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.remoting3.spi;
-
-import java.io.IOException;
-import java.util.Collections;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import org.jboss.remoting3.CloseHandler;
-import org.jboss.remoting3.QualifiedName;
-import org.jboss.remoting3.ServiceRegistrationException;
-import org.jboss.xnio.IoUtils;
-import org.jboss.xnio.log.Logger;
-
-/**
- * A registry associating names with services. Specifically, the name is associated with a handle to a request handler
- * source instance; this handle is owned by the registry, so closing the handle will remove the entry.
- */
-public final class NamedServiceRegistry {
- private static final Logger log = Logger.getLogger("org.jboss.remoting.named-registry");
-
- private final ConcurrentMap<QualifiedName, Handle<RequestHandlerSource>> map = new ConcurrentHashMap<QualifiedName, Handle<RequestHandlerSource>>();
-
- /**
- * Construct a new empty registry.
- */
- public NamedServiceRegistry() {
- }
-
- /**
- * Register a service at the given path. If the given service is closed, an exception will be thrown. Returns
- * a handle to the service which may be used to unregister this service from the registry. In addition, if the
- * service is closed, the registration will be automatically removed. To monitor the registration, add a close
- * handler to the returned handle.
- *
- * @param path the path of the service registration
- * @param service the service
- * @return a handle which can be used to unregister the service
- * @throws IOException if an error occurs
- */
- public Handle<RequestHandlerSource> registerService(final QualifiedName path, final RequestHandlerSource service) throws IOException {
- if (path == null) {
- throw new NullPointerException("path is null");
- }
- if (service == null) {
- throw new NullPointerException("service is null");
- }
- final Handle<RequestHandlerSource> handle = service.getHandle();
- boolean ok = false;
- try {
- final Handle<RequestHandlerSource> oldHandle = map.putIfAbsent(path, handle);
- if (oldHandle != null) {
- throw new ServiceRegistrationException(String.format("Failed to register a service at path \"%s\" on %s (a service is already registered at that location)", path, this));
- }
- handle.addCloseHandler(new CloseHandler<Handle<RequestHandlerSource>>() {
- public void handleClose(final Handle<RequestHandlerSource> closed) {
- if (map.remove(path, service)) {
- log.trace("Removed service %s at path \"%s\" on %s (service handle was closed)", service, path, this);
- }
- }
- });
- log.trace("Registered %s at path \"%s\" on %s", service, path, this);
- ok = true;
- return handle;
- } finally {
- if (! ok) IoUtils.safeClose(handle);
- }
- }
-
- /**
- * Find a service at a location in the registry.
- *
- * @param path the path
- * @return a handle to the service, or {@code null} if it is not found
- */
- public Handle<RequestHandlerSource> lookupService(QualifiedName path) {
- return map.get(path);
- }
-
- /**
- * Get an unmodifiable view of the entry set of the registry.
- *
- * @return a set view
- */
- public Set<Map.Entry<QualifiedName, Handle<RequestHandlerSource>>> getEntrySet() {
- return Collections.unmodifiableSet(map.entrySet());
- }
-
- /**
- * Returns a brief description of this object.
- */
- public String toString() {
- return "named service registry <" + Integer.toHexString(hashCode()) + ">";
- }
-}
Deleted: remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/spi/NameTestCase.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/spi/NameTestCase.java 2009-04-14 17:18:15 UTC (rev 5032)
+++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/spi/NameTestCase.java 2009-04-14 18:00:58 UTC (rev 5033)
@@ -1,89 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, 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.remoting3.spi;
-
-import junit.framework.TestCase;
-import org.jboss.remoting3.QualifiedName;
-import java.util.Iterator;
-
-/**
- *
- */
-public final class NameTestCase extends TestCase {
-
- public void testParseEmpty() {
- boolean ok = false;
- try {
- QualifiedName.parse("");
- } catch (IllegalArgumentException e) {
- assertEquals("Wrong exception message", "Empty path", e.getMessage());
- ok = true;
- }
- assertTrue("Exception not thrown", ok);
- }
-
- public void testParseRelative() {
- boolean ok = false;
- try {
- QualifiedName.parse("some relative path/foo/bar");
- } catch (IllegalArgumentException e) {
- assertEquals("Wrong exception message", "Relative paths are not allowed", e.getMessage());
- ok = true;
- }
- assertTrue("Exception not thrown", ok);
- }
-
- public void testParseRoot() {
- final Iterator<String> i = QualifiedName.parse("/").iterator();
- assertFalse(i.hasNext());
- }
-
- public void testParseOneLevel() {
- final Iterator<String> i = QualifiedName.parse("/firstElement").iterator();
- assertTrue(i.hasNext());
- assertEquals("Wrong segment name", "firstElement", i.next());
- assertFalse(i.hasNext());
- }
-
- public void testParseTwoLevel() {
- final Iterator<String> i = QualifiedName.parse("/firstElement/secondElement").iterator();
- assertTrue(i.hasNext());
- assertEquals("Wrong segment name", "firstElement", i.next());
- assertTrue(i.hasNext());
- assertEquals("Wrong segment name", "secondElement", i.next());
- assertFalse(i.hasNext());
- }
-
- public void testParseManyLevel() {
- final Iterator<String> i = QualifiedName.parse("/firstElement/secondElement/boo/test+with+spaces%20test").iterator();
- assertTrue(i.hasNext());
- assertEquals("Wrong segment name", "firstElement", i.next());
- assertTrue(i.hasNext());
- assertEquals("Wrong segment name", "secondElement", i.next());
- assertTrue(i.hasNext());
- assertEquals("Wrong segment name", "boo", i.next());
- assertTrue(i.hasNext());
- assertEquals("Wrong segment name", "test with spaces test", i.next());
- assertFalse(i.hasNext());
- }
-}
Modified: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/simple/MultiplexClientExample.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/simple/MultiplexClientExample.java 2009-04-14 17:18:15 UTC (rev 5032)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/simple/MultiplexClientExample.java 2009-04-14 18:00:58 UTC (rev 5033)
@@ -26,11 +26,9 @@
import org.jboss.remoting3.Remoting;
import org.jboss.remoting3.ClientSource;
import org.jboss.remoting3.Client;
-import org.jboss.remoting3.QualifiedName;
import org.jboss.remoting3.multiplex.MultiplexProtocol;
import org.jboss.remoting3.multiplex.MultiplexConfiguration;
import org.jboss.remoting3.multiplex.MultiplexConnection;
-import org.jboss.remoting3.spi.NamedServiceRegistry;
import org.jboss.remoting3.spi.RequestHandlerSource;
import org.jboss.remoting3.spi.Handle;
import org.jboss.xnio.IoUtils;
Modified: remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/simple/MultiplexServerExample.java
===================================================================
--- remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/simple/MultiplexServerExample.java 2009-04-14 17:18:15 UTC (rev 5032)
+++ remoting3/trunk/samples/src/main/java/org/jboss/remoting3/samples/simple/MultiplexServerExample.java 2009-04-14 18:00:58 UTC (rev 5033)
@@ -29,8 +29,6 @@
import org.jboss.remoting3.multiplex.MultiplexConfiguration;
import org.jboss.remoting3.spi.RequestHandlerSource;
import org.jboss.remoting3.spi.Handle;
-import org.jboss.remoting3.spi.NamedServiceRegistry;
-import org.jboss.remoting3.QualifiedName;
import org.jboss.xnio.IoUtils;
import org.jboss.xnio.Buffers;
import org.jboss.xnio.IoHandlerFactory;
15 years, 7 months
JBoss Remoting SVN: r5032 - in remoting3/trunk: jboss-remoting/src/main/java/org/jboss/remoting3/spi and 2 other directories.
by jboss-remoting-commits@lists.jboss.org
Author: david.lloyd(a)jboss.com
Date: 2009-04-14 13:18:15 -0400 (Tue, 14 Apr 2009)
New Revision: 5032
Added:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientConnector.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientSourceConnector.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointConnector.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ResourceType.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceLocationListener.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceRegistrationListener.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceSpecification.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/Cancellable.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProvider.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/EndpointConnection.java
Removed:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/FutureClientSource.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/RemoteServiceConfiguration.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceListener.java
Modified:
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientSource.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/HandleableCloseable.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/RequestListener.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceRegistration.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceURI.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/RemoteRequestContext.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/RequestHandler.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/RequestHandlerSource.java
remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/EndpointTestCase.java
remoting3/trunk/samples/src/test/java/org/jboss/remoting3/samples/protocol/basic/BasicTestCase.java
Log:
Endpoint API changes for working connection management, part 1
Added: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientConnector.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientConnector.java (rev 0)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientConnector.java 2009-04-14 17:18:15 UTC (rev 5032)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.remoting3;
+
+import java.net.URI;
+import org.jboss.xnio.IoFuture;
+
+/**
+ * A client connector. Opens a connection to a URI which provides a single {@code Client} instance. Instances of this
+ * interface may only be able to support a single URI scheme. Depending on the implementation, the URI may be a
+ * protocol URI or a service URI.
+ */
+public interface ClientConnector extends HandleableCloseable<ClientConnector> {
+
+ /**
+ * Establish a client connection.
+ *
+ * @param requestType the request class
+ * @param replyType the reply class
+ * @param connectUri the URI to connect to
+ * @param <I> the request type
+ * @param <O> the reply type
+ * @return the future client
+ * @throws IllegalArgumentException if the provided URI scheme is not supported by this connector
+ */
+ <I, O> IoFuture<? extends Client<I, O>> openClient(Class<I> requestType, Class<O> replyType, URI connectUri) throws IllegalArgumentException;
+}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientSource.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientSource.java 2009-04-14 10:34:23 UTC (rev 5031)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientSource.java 2009-04-14 17:18:15 UTC (rev 5032)
@@ -22,25 +22,17 @@
package org.jboss.remoting3;
-import java.io.IOException;
-
/**
- * A source for new Remoting contexts.
+ * A source for new Remoting clients.
*
* @param <I> the request type
* @param <O> the reply type
*/
public interface ClientSource<I, O> extends HandleableCloseable<ClientSource<I, O>> {
/**
- * Close the context source. New contexts may no longer be created after this
- * method is called. Subsequent calls to this method have no additional effect.
- */
- void close() throws IOException;
-
- /**
- * Create a new communications context.
+ * Create a new client instance.
*
- * @return the new context
+ * @return the client
*/
- Client<I, O> createClient() throws IOException;
+ Client<I, O> createClient();
}
Added: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientSourceConnector.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientSourceConnector.java (rev 0)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ClientSourceConnector.java 2009-04-14 17:18:15 UTC (rev 5032)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.remoting3;
+
+import java.net.URI;
+import org.jboss.xnio.IoFuture;
+
+/**
+ * A client source connector. Opens a connection to a URI which provides a {@code ClientSource} instance. Instances of this
+ * interface may only be able to support a single URI scheme. Depending on the implementation, the URI may be a
+ * protocol URI or a service URI.
+ */
+public interface ClientSourceConnector extends HandleableCloseable<ClientSourceConnector> {
+
+ /**
+ * Establish a client source connection.
+ *
+ * @param requestType the request class
+ * @param replyType the reply class
+ * @param connectUri the URI to connect to
+ * @param <I> the request type
+ * @param <O> the reply type
+ * @return the future client
+ * @throws IllegalArgumentException if the provided URI scheme is not supported by this connector
+ */
+ <I, O> IoFuture<? extends ClientSource<I, O>> openClientSource(Class<I> requestType, Class<O> replyType, URI connectUri) throws IllegalArgumentException;
+}
\ No newline at end of file
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java 2009-04-14 10:34:23 UTC (rev 5031)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java 2009-04-14 17:18:15 UTC (rev 5032)
@@ -1,11 +1,14 @@
package org.jboss.remoting3;
+import java.io.Closeable;
import java.io.IOException;
import java.net.URI;
+import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import org.jboss.remoting3.spi.Handle;
import org.jboss.remoting3.spi.RequestHandler;
import org.jboss.remoting3.spi.RequestHandlerSource;
+import org.jboss.remoting3.spi.ConnectionProvider;
import org.jboss.xnio.IoFuture;
/**
@@ -45,7 +48,7 @@
* @return a handle for the client
* @throws IOException if an error occurs
*/
- <I, O> Handle<RequestHandler> createRequestHandler(RequestListener<I, O> requestListener, final Class<I> requestClass, final Class<O> replyClass) throws IOException;
+ <I, O> Handle<RequestHandler> createLocalRequestHandler(RequestListener<I, O> requestListener, final Class<I> requestClass, final Class<O> replyClass) throws IOException;
/**
* Create a request handler source that can be used to acquire clients associated with a request listener on this endpoint.
@@ -62,6 +65,15 @@
<I, O> Handle<RequestHandlerSource> registerService(LocalServiceConfiguration<I, O> configuration) throws IOException;
/**
+ * Add a service registration listener which is called whenever a local service is registered.
+ *
+ * @param listener the listener
+ * @param flags the flags to apply to the listener
+ * @return a handle which may be used to remove the listener registration
+ */
+ SimpleCloseable addServiceRegistrationListener(ServiceRegistrationListener listener, Set<ListenerFlag> flags);
+
+ /**
* Create a client that uses the given request handler to handle its requests.
*
* You must have the {@link org.jboss.remoting3.EndpointPermission createClient EndpointPermission} to invoke this method.
@@ -92,42 +104,63 @@
<I, O> ClientSource<I, O> createClientSource(RequestHandlerSource handlerSource, Class<I> requestClass, Class<O> replyClass) throws IOException;
/**
- * Attempt to locate a service. The return value then be queried for the service's {@code ClientSource}.
+ * Attempt to open a client source by URI.
*
* @param <I> the request type
* @param <O> the reply type
- * @param serviceUri the URI of the service
+ * @param uri the URI of the service
* @param requestClass the class of requests sent through the client source
* @param replyClass the class of replies received back through the client source
* @return the future service
- * @throws IllegalArgumentException if the given URI is not a valid Remoting service URI
+ * @throws IllegalArgumentException if the URI scheme does not correspond to a client souerce connection provider
*/
- <I, O> IoFuture<ClientSource<I, O>> locateService(URI serviceUri, Class<I> requestClass, Class<O> replyClass) throws IllegalArgumentException;
+ <I, O> IoFuture<? extends ClientSource<I, O>> openClientSource(URI uri, Class<I> requestClass, Class<O> replyClass) throws IllegalArgumentException;
/**
- * Register a remotely available service.<p>
- * The remote endpoint must not have the same name as this endpoint. The group name and service type must be
- * non-{@code null} and non-empty. The metric must be greater than zero.
+ * Attempt to open a client by URI.
*
- * You must have the {@link org.jboss.remoting3.EndpointPermission registerRemoteService EndpointPermission} to invoke this method.
+ * @param <I> the request type
+ * @param <O> the reply type
+ * @param uri the URI of the service
+ * @param requestClass the class of requests sent through the client source
+ * @param replyClass the class of replies received back through the client source
+ * @return the future service
+ * @throws IllegalArgumentException if the URI scheme does not correspond to a client connection provider
+ */
+ <I, O> IoFuture<? extends Client<I, O>> openClient(URI uri, Class<I> requestClass, Class<O> replyClass) throws IllegalArgumentException;
+
+ /**
+ * Connect to a remote endpoint.
*
- * @param configuration the remote service configuration
- * @return a closeable that may be used to remove the registration
- * @throws IllegalArgumentException if one of the given arguments was not valid
- * @throws IOException if an error occurs with the registration
+ * @param endpointUri the URI of the endpoint to connect to
+ * @return the future connection
+ * @throws IllegalArgumentException if the URI scheme does not correspond to an endpoint connection provider
*/
- SimpleCloseable registerRemoteService(RemoteServiceConfiguration configuration) throws IllegalArgumentException, IOException;
+ IoFuture<? extends Closeable> openEndpointConnection(URI endpointUri) throws IllegalArgumentException;
/**
- * Add a listener for observing when local and remote services are added. The caller may specify whether the listener
- * should be notified of the complete list of currently registered services (set {@code onlyNew} to {@code false})
- * or only services registered after the time of calling this method (set {@code onlyNew} to {@code true}).
+ * Register a connection provider for a URI scheme.
*
- * You must have the {@link org.jboss.remoting3.EndpointPermission addServiceListener EndpointPermission} to invoke this method.
+ * @param uriScheme the URI scheme
+ * @param provider the provider
+ * @return a handle which may be used to remove the registration
+ */
+ SimpleCloseable addConnectionProvider(String uriScheme, ConnectionProvider<?> provider);
+
+ /**
+ * Get the type of resource specified by the given URI. If the type cannot be determined, returns {@link org.jboss.remoting3.ResourceType#UNKNOWN UNKNOWN}.
*
- * @param serviceListener the listener
- * @param onlyNew {@code true} if only new registrations should be sent to the listener
- * @return a handle which may be used to unregister the listener
+ * @param uri the connection URI
+ * @return the resource type
*/
- SimpleCloseable addServiceListener(ServiceListener serviceListener, boolean onlyNew);
+ ResourceType getResourceType(URI uri);
+
+
+ enum ListenerFlag {
+
+ /**
+ * Include old registrations.
+ */
+ INCLUDE_OLD,
+ }
}
Added: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointConnector.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointConnector.java (rev 0)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointConnector.java 2009-04-14 17:18:15 UTC (rev 5032)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.remoting3;
+
+import java.net.URI;
+import org.jboss.xnio.IoFuture;
+
+/**
+ * An endpoint connector. Used to connect a whole endpoint to another whole endpoint. Typically, services are then
+ * shared between the endpoints in some fashion, though this need not be the case.
+ */
+public interface EndpointConnector extends HandleableCloseable<EndpointConnector> {
+
+ /**
+ * Connect the given endpoint to the remote URI.
+ *
+ * @param endpoint the endpoint to connect
+ * @param connectUri the connection URI
+ * @return the future handle, which may be used to terminate the connection
+ */
+ IoFuture<? extends HandleableCloseable> connect(Endpoint endpoint, URI connectUri);
+}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java 2009-04-14 10:34:23 UTC (rev 5031)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java 2009-04-14 17:18:15 UTC (rev 5032)
@@ -27,24 +27,31 @@
import java.lang.ref.WeakReference;
import java.net.URI;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.List;
import java.util.Map;
+import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.Executor;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
import org.jboss.remoting3.spi.AbstractHandleableCloseable;
import org.jboss.remoting3.spi.AbstractSimpleCloseable;
+import org.jboss.remoting3.spi.ConnectionProvider;
import org.jboss.remoting3.spi.Handle;
import org.jboss.remoting3.spi.RequestHandler;
import org.jboss.remoting3.spi.RequestHandlerSource;
-import org.jboss.xnio.FailedIoFuture;
-import org.jboss.xnio.FinishedIoFuture;
+import org.jboss.remoting3.spi.Cancellable;
+import org.jboss.remoting3.spi.EndpointConnection;
import org.jboss.xnio.IoFuture;
import org.jboss.xnio.IoUtils;
import org.jboss.xnio.WeakCloseable;
+import org.jboss.xnio.AbstractIoFuture;
import org.jboss.xnio.log.Logger;
/**
@@ -57,6 +64,10 @@
Logger.getLogger("org.jboss.remoting").info("JBoss Remoting version %s", Version.VERSION);
}
+ static <K, V> ConcurrentMap<K, V> concurrentHashMap() {
+ return new ConcurrentHashMap<K, V>();
+ }
+
static <K, V> Map<K, V> hashMap() {
return new HashMap<K, V>();
}
@@ -65,23 +76,38 @@
return new HashSet<T>();
}
+ static <T> Queue<T> concurrentLinkedQueue() {
+ return new ConcurrentLinkedQueue<T>();
+ }
+
private static final Logger log = Logger.getLogger("org.jboss.remoting.endpoint");
private final String name;
- private final ConcurrentMap<Object, Object> endpointMap = new ConcurrentHashMap<Object, Object>();
+ /**
+ * Snapshot lock. Hold this lock while reading or updating {@link #serviceListenerRegistrations} or while updating
+ * {@link #registeredLocalServices}. Allows atomic snapshot of existing service registrations and listener add.
+ */
+ private final Lock serviceRegistrationLock = new ReentrantLock();
- private final Object serviceLock = new Object();
- private final Map<Object, ServiceListenerRegistration> serviceListenerMap = hashMap();
- private final Set<ServiceRegistration> serviceRegistrations = hashSet();
+ /**
+ *
+ */
+ private final Queue<Registration<ServiceRegistrationListener>> serviceListenerRegistrations = concurrentLinkedQueue();
+ private final ConcurrentMap<String, ServiceRegistration> registeredLocalServices = concurrentHashMap();
+
+ private final ConcurrentMap<String, ConnectionProvider<?>> connectionProviders = concurrentHashMap();
+
+ private final ConcurrentMap<Object, Object> endpointMap = concurrentHashMap();
+
private static final EndpointPermission CREATE_ENDPOINT_PERM = new EndpointPermission("createEndpoint");
private static final EndpointPermission CREATE_REQUEST_HANDLER_PERM = new EndpointPermission("createRequestHandler");
private static final EndpointPermission REGISTER_SERVICE_PERM = new EndpointPermission("registerService");
private static final EndpointPermission CREATE_CLIENT_PERM = new EndpointPermission("createClient");
private static final EndpointPermission CREATE_CLIENT_SOURCE_PERM = new EndpointPermission("createClientSource");
- private static final EndpointPermission REGISTER_REMOTE_SERVICE_PERM = new EndpointPermission("registerRemoteService");
private static final EndpointPermission ADD_SERVICE_LISTENER_PERM = new EndpointPermission("addServiceListener");
+ private static final EndpointPermission ADD_CONNECTION_PROVIDER_PERM = new EndpointPermission("addConnectionProvider");
public EndpointImpl(final Executor executor, final String name) {
super(executor);
@@ -89,6 +115,7 @@
if (sm != null) {
sm.checkPermission(CREATE_ENDPOINT_PERM);
}
+ connectionProviders.put("jrs", new JrsConnectionProvider());
this.executor = executor;
this.name = name;
}
@@ -113,7 +140,7 @@
return endpointMap;
}
- public <I, O> Handle<RequestHandler> createRequestHandler(final RequestListener<I, O> requestListener, final Class<I> requestClass, final Class<O> replyClass) throws IOException {
+ public <I, O> Handle<RequestHandler> createLocalRequestHandler(final RequestListener<I, O> requestListener, final Class<I> requestClass, final Class<O> replyClass) throws IOException {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(CREATE_REQUEST_HANDLER_PERM);
@@ -146,21 +173,12 @@
final String serviceType = configuration.getServiceType();
final String groupName = configuration.getGroupName();
final int metric = configuration.getMetric();
- if (serviceType == null) {
- throw new NullPointerException("serviceType is null");
- }
- if (groupName == null) {
- throw new NullPointerException("groupName is null");
- }
- if (serviceType.length() == 0) {
- throw new IllegalArgumentException("serviceType is empty");
- }
- if (groupName.length() == 0) {
- throw new IllegalArgumentException("groupName is empty");
- }
if (metric < 0) {
throw new IllegalArgumentException("metric must be greater than or equal to zero");
}
+ ServiceURI.validateServiceType(serviceType);
+ ServiceURI.validateGroupName(groupName);
+ final String serviceKey = serviceType.toLowerCase() + ":" + groupName.toLowerCase();
final LocalRequestHandlerSource.Config<I, O> config = new LocalRequestHandlerSource.Config<I,O>(configuration.getRequestClass(), configuration.getReplyClass());
config.setRequestListener(configuration.getRequestListener());
config.setExecutor(executor);
@@ -168,32 +186,21 @@
final ServiceRegistration registration = new ServiceRegistration(serviceType, groupName, name, localRequestHandlerSource);
final AbstractSimpleCloseable newHandle = new AbstractSimpleCloseable(executor) {
protected void closeAction() throws IOException {
- synchronized (serviceLock) {
- serviceRegistrations.remove(registration);
- }
+ // todo fix
+ registeredLocalServices.remove(serviceKey);
}
};
registration.setHandle(newHandle);
- synchronized (serviceLock) {
- serviceRegistrations.add(registration);
- for (final ServiceListenerRegistration slr : serviceListenerMap.values()) {
- final ServiceListener listener = slr.getServiceListener();
- try {
- final ServiceListener.ServiceInfo serviceInfo = new ServiceListener.ServiceInfo();
- serviceInfo.setEndpointName(name);
- serviceInfo.setGroupName(groupName);
- serviceInfo.setServiceType(serviceType);
- serviceInfo.setMetric(metric);
- serviceInfo.setRegistrationHandle(newHandle);
- serviceInfo.setRemote(false);
- serviceInfo.setRequestHandlerSource(localRequestHandlerSource);
- listener.serviceRegistered(slr.handle, serviceInfo);
- } catch (Throwable t) {
- logListenerError(t);
- }
+ final Lock lock = serviceRegistrationLock;
+ lock.lock();
+ try {
+ if (registeredLocalServices.putIfAbsent(serviceKey, registration) != null) {
+ throw new ServiceRegistrationException("Registration of service of type \"" + serviceType + "\" in group \"" + groupName + "\" duplicates an already-registered service's specification");
}
+ } finally {
+ lock.unlock();
}
- final WeakCloseable lrhCloseable = new WeakCloseable(new WeakReference<Closeable>(localRequestHandlerSource));
+ final WeakCloseable lrhCloseable = new WeakCloseable(localRequestHandlerSource);
final Key key = addCloseHandler(new CloseHandler<Endpoint>() {
public void handleClose(final Endpoint closed) {
IoUtils.safeClose(lrhCloseable);
@@ -205,6 +212,23 @@
}
});
localRequestHandlerSource.open();
+ for (Registration<ServiceRegistrationListener> slr : serviceListenerRegistrations) {
+ final ServiceRegistrationListener registrationListener = slr.getResource();
+ try {
+ final ServiceRegistrationListener.ServiceInfo serviceInfo = new ServiceRegistrationListener.ServiceInfo();
+ serviceInfo.setGroupName(groupName);
+ serviceInfo.setServiceType(serviceType);
+ serviceInfo.setMetric(metric);
+ serviceInfo.setRegistrationHandle(newHandle);
+ serviceInfo.setRequestHandlerSource(localRequestHandlerSource);
+ registrationListener.serviceRegistered(slr, serviceInfo);
+ } catch (VirtualMachineError vme) {
+ // panic!
+ throw vme;
+ } catch (Throwable t) {
+ logListenerError(t);
+ }
+ }
return localRequestHandlerSource.getHandle();
}
@@ -270,204 +294,231 @@
}
}
- public <I, O> IoFuture<ClientSource<I, O>> locateService(final URI serviceUri, final Class<I> requestClass, final Class<O> replyClass) throws IllegalArgumentException {
- if (serviceUri == null) {
- throw new NullPointerException("serviceUri is null");
+ public <I, O> IoFuture<ClientSource<I, O>> openClientSource(final URI uri, final Class<I> requestClass, final Class<O> replyClass) throws IllegalArgumentException {
+ final ConnectionProvider<RequestHandlerSource> cp = getConnectionProvider(uri);
+ if (cp.getResourceType() != ResourceType.CLIENT_SOURCE) {
+ throw new IllegalArgumentException("URI can not be used to open a client source");
}
- if (! ServiceURI.isRemotingServiceUri(serviceUri)) {
- throw new IllegalArgumentException("Not a valid remoting service URI");
+ final FutureResult<ClientSource<I, O>> futureClientSource = new FutureResult<ClientSource<I, O>>();
+ cp.connect(uri, new ConnectionProvider.Result<RequestHandlerSource>() {
+ public void setResult(final RequestHandlerSource result) {
+ final ClientSource<I, O> clientSource;
+ try {
+ clientSource = createClientSource(result, requestClass, replyClass);
+ } catch (IOException e) {
+ IoUtils.safeClose(result);
+ futureClientSource.setException(e);
+ return;
+ }
+ futureClientSource.setResult(clientSource);
+ }
+
+ public void setException(final IOException exception) {
+ futureClientSource.setException(exception);
+ }
+
+ public void setCancelled() {
+ futureClientSource.finishCancel();
+ }
+ });
+ return futureClientSource;
+ }
+
+ public <I, O> IoFuture<? extends Client<I, O>> openClient(final URI uri, final Class<I> requestClass, final Class<O> replyClass) throws IllegalArgumentException {
+ final ConnectionProvider<RequestHandler> cp = getConnectionProvider(uri);
+ if (cp.getResourceType() != ResourceType.CLIENT) {
+ throw new IllegalArgumentException("URI can not be used to open a client");
}
- final String endpointName = ServiceURI.getEndpointName(serviceUri);
- final String groupName = ServiceURI.getGroupName(serviceUri);
- final String serviceType = ServiceURI.getServiceType(serviceUri);
- synchronized (serviceLock) {
- int bestMetric = Integer.MAX_VALUE;
- List<ServiceRegistration> candidates = new ArrayList<ServiceRegistration>();
- for (ServiceRegistration svc : serviceRegistrations) {
- if (svc.matches(serviceType, groupName, endpointName)) {
- final int metric = svc.getMetric();
- if (metric < bestMetric) {
- candidates.clear();
- candidates.add(svc);
- } else if (metric == bestMetric) {
- candidates.add(svc);
- }
+ final FutureResult<Client<I, O>> futureClient = new FutureResult<Client<I, O>>();
+ cp.connect(uri, new ConnectionProvider.Result<RequestHandler>() {
+ public void setResult(final RequestHandler result) {
+ final Client<I, O> client;
+ try {
+ client = createClient(result, requestClass, replyClass);
+ } catch (IOException e) {
+ IoUtils.safeClose(result);
+ futureClient.setException(e);
+ return;
}
+ futureClient.setResult(client);
}
- final int size = candidates.size();
- if (size == 0) {
- final FutureClientSource<I, O> futureClientSource = new FutureClientSource<I, O>();
- final SimpleCloseable listenerHandle = addServiceListener(new ServiceListener() {
- public void serviceRegistered(final SimpleCloseable listenerHandle, final ServiceInfo info) {
- final String addedEndpointName = info.getEndpointName();
- final String addedServiceType = info.getServiceType();
- final String addedGroupName = info.getGroupName();
- final RequestHandlerSource requestHandlerSource = info.getRequestHandlerSource();
- if (endpointName != null && endpointName.length() > 0 && !endpointName.equals(addedEndpointName)) {
- // no match
- return;
- }
- if (serviceType != null && serviceType.length() > 0 && !serviceType.equals(addedServiceType)) {
- // no match
- return;
- }
- if (groupName != null && groupName.length() > 0 && !groupName.equals(addedGroupName)) {
- // no match
- return;
- }
- try {
- // match!
- final ClientSource<I, O> clientSource = createClientSource(requestHandlerSource, requestClass, replyClass);
- futureClientSource.setResult(clientSource);
- } catch (IOException e) {
- futureClientSource.setException(e);
- } finally {
- IoUtils.safeClose(listenerHandle);
- }
+
+ public void setException(final IOException exception) {
+ futureClient.setException(exception);
+ }
+
+ public void setCancelled() {
+ futureClient.finishCancel();
+ }
+ });
+ return futureClient;
+ }
+
+ public IoFuture<? extends Closeable> openEndpointConnection(final URI endpointUri) throws IllegalArgumentException {
+ final ConnectionProvider<EndpointConnection> cp = getConnectionProvider(endpointUri);
+ if (cp.getResourceType() != ResourceType.CLIENT) {
+ throw new IllegalArgumentException("URI can not be used to open an endpoint connection");
+ }
+ final FutureResult<SimpleCloseable> futureEndpointConn = new FutureResult<SimpleCloseable>();
+ cp.connect(endpointUri, new ConnectionProvider.Result<EndpointConnection>() {
+ public void setResult(final EndpointConnection result) {
+ if (futureEndpointConn.setResult(new AbstractSimpleCloseable(executor) {
+ protected void closeAction() throws IOException {
+ result.close();
}
- }, true);
- futureClientSource.setListenerHandle(listenerHandle);
- return futureClientSource;
+ })) {
+ // todo - add the endpoint connection to the endpoint registry; notify listeners; etc.
+ }
}
- final RequestHandlerSource handlerSource;
- if (size == 1) {
- handlerSource = candidates.get(0).getHandlerSource();
- } else {
- int idx = (int) ((double) candidates.size() * Math.random());
- handlerSource = candidates.get(idx).getHandlerSource();
+
+ public void setException(final IOException exception) {
+ futureEndpointConn.setException(exception);
}
- try {
- return new FinishedIoFuture<ClientSource<I,O>>(createClientSource(handlerSource, requestClass, replyClass));
- } catch (IOException e) {
- return new FailedIoFuture<ClientSource<I,O>>(e);
+
+ public void setCancelled() {
+ futureEndpointConn.finishCancel();
}
- }
+ });
+ return futureEndpointConn;
}
- public SimpleCloseable registerRemoteService(final RemoteServiceConfiguration configuration) throws IllegalArgumentException, IOException {
- SecurityManager sm = System.getSecurityManager();
+ public SimpleCloseable addConnectionProvider(final String uriScheme, final ConnectionProvider<?> provider) {
+ final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
- sm.checkPermission(REGISTER_REMOTE_SERVICE_PERM);
+ sm.checkPermission(ADD_CONNECTION_PROVIDER_PERM);
}
- final RequestHandlerSource handlerSource = configuration.getRequestHandlerSource();
- final String serviceType = configuration.getServiceType();
- final String groupName = configuration.getGroupName();
- final String endpointName = configuration.getEndpointName();
- final int metric = configuration.getMetric();
- if (handlerSource == null) {
- throw new NullPointerException("handlerSource is null");
+ final String key = uriScheme.toLowerCase();
+ if (connectionProviders.putIfAbsent(key, provider) != null) {
+ throw new IllegalArgumentException("Provider already registered for scheme \"" + uriScheme + "\"");
}
- if (serviceType == null) {
- throw new NullPointerException("serviceType is null");
+ return new AbstractSimpleCloseable(executor) {
+ protected void closeAction() throws IOException {
+ connectionProviders.remove(key, provider);
+ }
+ };
+ }
+
+ public ResourceType getResourceType(final URI uri) {
+ final String scheme = uri.getScheme().toLowerCase();
+ final ConnectionProvider<?> provider = connectionProviders.get(scheme);
+ return provider != null ? provider.getResourceType() : ResourceType.UNKNOWN;
+ }
+
+ @SuppressWarnings({ "unchecked" })
+ private <T> ConnectionProvider<T> getConnectionProvider(final URI uri) {
+ if (uri == null) {
+ throw new NullPointerException("serviceUri is null");
}
- if (groupName == null) {
- throw new NullPointerException("groupName is null");
+ final String scheme = uri.getScheme();
+ // this cast is checked later, indirectly
+ final ConnectionProvider<T> cp = (ConnectionProvider<T>) connectionProviders.get(scheme);
+ if (cp == null) {
+ throw new IllegalArgumentException("No connection providers available for URI scheme \"" + scheme + "\"");
}
- if (endpointName == null) {
- throw new NullPointerException("endpointName is null");
+ if (! ServiceURI.isRemotingServiceUri(uri)) {
+ throw new IllegalArgumentException("Not a valid remoting service URI");
}
- if (serviceType.length() == 0) {
- throw new IllegalArgumentException("serviceType is empty");
+ return cp;
+ }
+
+ public SimpleCloseable addServiceRegistrationListener(final ServiceRegistrationListener listener, final Set<ListenerFlag> flags) {
+ final SecurityManager sm = System.getSecurityManager();
+ if (sm != null) {
+ sm.checkPermission(ADD_SERVICE_LISTENER_PERM);
}
- if (groupName.length() == 0) {
- throw new IllegalArgumentException("groupName is empty");
+ final Registration<ServiceRegistrationListener> registration = new Registration<ServiceRegistrationListener>(executor, listener, serviceListenerRegistrations);
+ final Lock lock = serviceRegistrationLock;
+ final Collection<ServiceRegistration> services;
+ lock.lock();
+ try {
+ if (flags == null || ! flags.contains(ListenerFlag.INCLUDE_OLD)) {
+ services = new ArrayList<ServiceRegistration>(registeredLocalServices.values());
+ } else {
+ services = Collections.emptySet();
+ }
+ } finally {
+ lock.unlock();
}
- if (endpointName.length() == 0) {
- throw new IllegalArgumentException("endpointName is empty");
+ serviceListenerRegistrations.add(registration);
+ for (ServiceRegistration service : services) {
+ final ServiceRegistrationListener.ServiceInfo serviceInfo = new ServiceRegistrationListener.ServiceInfo();
+ serviceInfo.setGroupName(service.getGroupName());
+ serviceInfo.setMetric(service.getMetric());
+ serviceInfo.setRegistrationHandle(service.getHandle());
+ serviceInfo.setRequestHandlerSource(service.getHandlerSource());
+ serviceInfo.setServiceType(service.getServiceType());
+ listener.serviceRegistered(registration, serviceInfo);
+ if (! registration.isOpen()) {
+ break;
+ }
}
- if (endpointName.equals(name)) {
- throw new IllegalArgumentException("remote endpoint has the same name as the local endpoint");
+ return registration;
+ }
+
+ private static final class Registration<T> extends AbstractSimpleCloseable {
+ private final T resource;
+ private final Queue<Registration<T>> resourceQueue;
+
+ private Registration(final Executor executor, final T resource, final Queue<Registration<T>> resourceQueue) {
+ super(executor);
+ this.resource = resource;
+ this.resourceQueue = resourceQueue;
}
- if (metric < 1) {
- throw new IllegalArgumentException("metric must be greater than zero");
+
+ protected void closeAction() throws IOException {
+ resourceQueue.remove(this);
}
- final ServiceRegistration registration = new ServiceRegistration(serviceType, groupName, endpointName, metric, handlerSource);
- final AbstractSimpleCloseable newHandle = new AbstractSimpleCloseable(executor) {
- protected void closeAction() throws IOException {
- synchronized (serviceLock) {
- serviceRegistrations.remove(registration);
- }
- }
- };
- registration.setHandle(newHandle);
- synchronized (serviceLock) {
- serviceRegistrations.add(registration);
- for (final ServiceListenerRegistration slr : serviceListenerMap.values()) {
- final ServiceListener listener = slr.getServiceListener();
- try {
- final ServiceListener.ServiceInfo info = new ServiceListener.ServiceInfo();
- info.setEndpointName(endpointName);
- info.setGroupName(groupName);
- info.setMetric(metric);
- info.setRegistrationHandle(newHandle);
- info.setRemote(true);
- info.setRequestHandlerSource(handlerSource);
- info.setServiceType(serviceType);
- listener.serviceRegistered(slr.handle, info);
- } catch (Throwable t) {
- logListenerError(t);
- }
- }
+
+ protected boolean isOpen() {
+ return super.isOpen();
}
- return newHandle;
+
+ T getResource() {
+ return resource;
+ }
}
- public SimpleCloseable addServiceListener(final ServiceListener serviceListener, final boolean onlyNew) {
- SecurityManager sm = System.getSecurityManager();
- if (sm != null) {
- sm.checkPermission(ADD_SERVICE_LISTENER_PERM);
- }
- final Object key = new Object();
- synchronized (serviceLock) {
- final ServiceListenerRegistration registration = new ServiceListenerRegistration(serviceListener);
- serviceListenerMap.put(key, registration);
- final AbstractSimpleCloseable handle = new AbstractSimpleCloseable(executor) {
- protected void closeAction() throws IOException {
- synchronized (serviceLock) {
- serviceListenerMap.remove(key);
- }
+ public String toString() {
+ return "endpoint \"" + name + "\" <" + Integer.toHexString(hashCode()) + ">";
+ }
+
+ final class JrsConnectionProvider implements ConnectionProvider<RequestHandlerSource> {
+
+ public Cancellable connect(final URI uri, final Result<RequestHandlerSource> requestHandlerSourceResult) throws IllegalArgumentException {
+ final ServiceSpecification spec = ServiceSpecification.fromUri(uri);
+ for (ServiceRegistration sr : registeredLocalServices.values()) {
+ if (sr.matches(spec)) {
+ requestHandlerSourceResult.setResult(sr.getHandlerSource());
}
- };
- registration.setHandle(handle);
- if (! onlyNew) {
- for (final ServiceRegistration reg : serviceRegistrations) {
- try {
- final ServiceListener.ServiceInfo info = new ServiceListener.ServiceInfo();
- info.setEndpointName(reg.getEndpointName());
- info.setGroupName(reg.getGroupName());
- info.setMetric(reg.getMetric());
- info.setRegistrationHandle(reg.getHandle());
- info.setRemote(reg.isRemote());
- info.setRequestHandlerSource(reg.getHandlerSource());
- info.setServiceType(reg.getServiceType());
- serviceListener.serviceRegistered(handle, info);
- } catch (Throwable t) {
- logListenerError(t);
- }
- }
}
- return handle;
+ // todo - iterate through discovered services as well
+ return Cancellable.NULL_CANCELLABLE;
}
+
+ public URI getConnectionUri(final URI uri) {
+ return uri;
+ }
+
+ public ResourceType getResourceType() {
+ return ResourceType.CLIENT_SOURCE;
+ }
}
- private static final class ServiceListenerRegistration {
- private final ServiceListener serviceListener;
- private volatile SimpleCloseable handle;
+ /**
+ *
+ */
+ static final class FutureResult<T> extends AbstractIoFuture<T> {
- private ServiceListenerRegistration(final ServiceListener serviceListener) {
- this.serviceListener = serviceListener;
+ protected boolean setException(final IOException exception) {
+ return super.setException(exception);
}
- ServiceListener getServiceListener() {
- return serviceListener;
+ protected boolean setResult(final T result) {
+ return super.setResult(result);
}
- void setHandle(final SimpleCloseable handle) {
- this.handle = handle;
+ protected boolean finishCancel() {
+ return super.finishCancel();
}
}
-
- public String toString() {
- return "endpoint \"" + name + "\" <" + Integer.toString(hashCode()) + ">";
- }
}
Deleted: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/FutureClientSource.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/FutureClientSource.java 2009-04-14 10:34:23 UTC (rev 5031)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/FutureClientSource.java 2009-04-14 17:18:15 UTC (rev 5032)
@@ -1,53 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, 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.remoting3;
-
-import java.io.IOException;
-import org.jboss.xnio.AbstractIoFuture;
-import org.jboss.xnio.IoFuture;
-import org.jboss.xnio.IoUtils;
-
-/**
- *
- */
-final class FutureClientSource<I, O> extends AbstractIoFuture<ClientSource<I, O>> {
-
- private volatile SimpleCloseable listenerHandle;
-
- protected boolean setException(final IOException exception) {
- return super.setException(exception);
- }
-
- protected boolean setResult(final ClientSource<I, O> result) {
- return super.setResult(result);
- }
-
- public IoFuture<ClientSource<I, O>> cancel() {
- IoUtils.safeClose(listenerHandle);
- return this;
- }
-
- void setListenerHandle(final SimpleCloseable listenerHandle) {
- this.listenerHandle = listenerHandle;
- }
-}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/HandleableCloseable.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/HandleableCloseable.java 2009-04-14 10:34:23 UTC (rev 5031)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/HandleableCloseable.java 2009-04-14 17:18:15 UTC (rev 5032)
@@ -35,15 +35,16 @@
public interface HandleableCloseable<T> extends Closeable {
/**
- * Close, waiting for any outstanding processing to finish.
+ * Close this resource. Call any registered close handlers. Calling this method more than once will not have
+ * any additional effect.
*
* @throws IOException if the close failed
*/
void close() throws IOException;
/**
- * Add a handler that will be called upon close. The handler may be called before or after the close acutally
- * takes place.
+ * Add a handler that will be called upon close. If the resource is already closed, the handler will be called
+ * immediately.
*
* @param handler the close handler
* @return a key which may be used to later remove this handler
Deleted: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/RemoteServiceConfiguration.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/RemoteServiceConfiguration.java 2009-04-14 10:34:23 UTC (rev 5031)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/RemoteServiceConfiguration.java 2009-04-14 17:18:15 UTC (rev 5032)
@@ -1,134 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, 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.remoting3;
-
-import org.jboss.remoting3.spi.RequestHandlerSource;
-
-/**
- * A configuration for registering a remote service with an endpoint.
- *
- * @apiviz.exclude
- */
-public final class RemoteServiceConfiguration {
- private String serviceType;
- private String groupName;
- private String endpointName;
- private RequestHandlerSource requestHandlerSource;
- private int metric;
-
- /**
- * Construct a new instance.
- */
- public RemoteServiceConfiguration() {
- }
-
- /**
- * Get the service type.
- *
- * @return the service type
- */
- public String getServiceType() {
- return serviceType;
- }
-
- /**
- * Set the service type.
- *
- * @param serviceType the service type
- */
- public void setServiceType(final String serviceType) {
- this.serviceType = serviceType;
- }
-
- /**
- * Get the service group name.
- *
- * @return the group name
- */
- public String getGroupName() {
- return groupName;
- }
-
- /**
- * Set the service group name.
- *
- * @param groupName the group name
- */
- public void setGroupName(final String groupName) {
- this.groupName = groupName;
- }
-
- /**
- * Get the remote endpoint name.
- *
- * @return the remote endpoint name
- */
- public String getEndpointName() {
- return endpointName;
- }
-
- /**
- * Set the remote endpoint name.
- *
- * @param endpointName the remote endpoint name
- */
- public void setEndpointName(final String endpointName) {
- this.endpointName = endpointName;
- }
-
- /**
- * Get the request handler source of the remote service.
- *
- * @return the request handler source
- */
- public RequestHandlerSource getRequestHandlerSource() {
- return requestHandlerSource;
- }
-
- /**
- * Set the request handler source of the remote service.
- *
- * @param requestHandlerSource the request handler source
- */
- public void setRequestHandlerSource(final RequestHandlerSource requestHandlerSource) {
- this.requestHandlerSource = requestHandlerSource;
- }
-
- /**
- * Get the metric of the remote service.
- *
- * @return the metric
- */
- public int getMetric() {
- return metric;
- }
-
- /**
- * Set the metric of the remote service.
- *
- * @param metric the metric
- */
- public void setMetric(final int metric) {
- this.metric = metric;
- }
-}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java 2009-04-14 10:34:23 UTC (rev 5031)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Remoting.java 2009-04-14 17:18:15 UTC (rev 5032)
@@ -126,7 +126,7 @@
* @throws IOException if an error occurs
*/
public static <I, O> Client<I, O> createLocalClient(final Endpoint endpoint, final RequestListener<I, O> requestListener, final Class<I> requestClass, final Class<O> replyClass) throws IOException {
- final Handle<RequestHandler> handle = endpoint.createRequestHandler(requestListener, requestClass, replyClass);
+ final Handle<RequestHandler> handle = endpoint.createLocalRequestHandler(requestListener, requestClass, replyClass);
try {
return endpoint.createClient(handle.getResource(), requestClass, replyClass);
} finally {
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/RequestListener.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/RequestListener.java 2009-04-14 10:34:23 UTC (rev 5031)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/RequestListener.java 2009-04-14 17:18:15 UTC (rev 5032)
@@ -49,8 +49,7 @@
* Handle a request. If this method throws {@code RemoteExecutionException}, then that exception is passed
* back to the caller and the request is marked as complete. Otherwise, the request
* listener must send back either a reply (using the {@code sendReply()} method on the {@code RequestContext}) or
- * an exception (using the {@code sendException()} method on the {@code RequestContext}). Failure to do so may
- * cause the client to hang indefinitely.
+ * an exception (using the {@code sendException()} method on the {@code RequestContext}).
*
* @param context the context on which a reply may be sent
* @param request the received request
Added: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ResourceType.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ResourceType.java (rev 0)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ResourceType.java 2009-04-14 17:18:15 UTC (rev 5032)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.remoting3;
+
+/**
+ *
+ */
+public enum ResourceType {
+ UNKNOWN,
+ CLIENT,
+ CLIENT_SOURCE,
+ ENDPOINT,
+}
Deleted: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceListener.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceListener.java 2009-04-14 10:34:23 UTC (rev 5031)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceListener.java 2009-04-14 17:18:15 UTC (rev 5032)
@@ -1,188 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, 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.remoting3;
-
-import org.jboss.remoting3.spi.RequestHandlerSource;
-
-/**
- * A listener for watching service registrations on an endpoint.
- *
- * @apiviz.landmark
- */
-public interface ServiceListener {
-
- /**
- * Receive notification that a service was registered.
- *
- * @param listenerHandle the handle to this listener
- * @param info the servce information
- */
- void serviceRegistered(SimpleCloseable listenerHandle, ServiceInfo info);
-
- /**
- * Information about a registered service.
- *
- * @apiviz.exclude
- */
- final class ServiceInfo {
- private String endpointName;
- private String serviceType;
- private String groupName;
- private boolean remote;
- private int metric;
- private RequestHandlerSource requestHandlerSource;
- private SimpleCloseable registrationHandle;
-
- /**
- * Construct a new instance.
- */
- public ServiceInfo() {
- }
-
- /**
- * Get the service type.
- *
- * @return the service type
- */
- public String getServiceType() {
- return serviceType;
- }
-
- /**
- * Set the service type.
- *
- * @param serviceType the service type
- */
- public void setServiceType(final String serviceType) {
- this.serviceType = serviceType;
- }
-
- /**
- * Get the group name.
- *
- * @return the group name
- */
- public String getGroupName() {
- return groupName;
- }
-
- /**
- * Set the group name.
- *
- * @param groupName the group name
- */
- public void setGroupName(final String groupName) {
- this.groupName = groupName;
- }
-
- /**
- * Get the metric.
- *
- * @return the metric
- */
- public int getMetric() {
- return metric;
- }
-
- /**
- * Set the metric.
- *
- * @param metric the metric
- */
- public void setMetric(final int metric) {
- this.metric = metric;
- }
-
- /**
- * Get the request handler source.
- *
- * @return the request handler source
- */
- public RequestHandlerSource getRequestHandlerSource() {
- return requestHandlerSource;
- }
-
- /**
- * Set the request handler source.
- *
- * @param requestHandlerSource the request handler source
- */
- public void setRequestHandlerSource(final RequestHandlerSource requestHandlerSource) {
- this.requestHandlerSource = requestHandlerSource;
- }
-
- /**
- * Get the registration handle. Closing this handle will remove the registration.
- *
- * @return the registration handle
- */
- public SimpleCloseable getRegistrationHandle() {
- return registrationHandle;
- }
-
- /**
- * Set the registration handle.
- *
- * @param registrationHandle the registration handle
- */
- public void setRegistrationHandle(final SimpleCloseable registrationHandle) {
- this.registrationHandle = registrationHandle;
- }
-
- /**
- * Get the endpoint name. For local services, this will be the name of the local endpoint.
- *
- * @return the endpoint name
- */
- public String getEndpointName() {
- return endpointName;
- }
-
- /**
- * Set the endpoint name.
- *
- * @param endpointName the endpoint name
- */
- public void setEndpointName(final String endpointName) {
- this.endpointName = endpointName;
- }
-
- /**
- * Determine whether this service is remote.
- *
- * @return {@code true} if this service is remote
- */
- public boolean isRemote() {
- return remote;
- }
-
- /**
- * Specify whether this service is remote.
- *
- * @param remote {@code true} if this service is remote
- */
- public void setRemote(final boolean remote) {
- this.remote = remote;
- }
- }
-}
Added: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceLocationListener.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceLocationListener.java (rev 0)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceLocationListener.java 2009-04-14 17:18:15 UTC (rev 5032)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.remoting3;
+
+import java.net.URI;
+
+/**
+ * A listener for watching service location events on an endpoint.
+ *
+ * @apiviz.landmark
+ */
+public interface ServiceLocationListener {
+ void serviceLocated(SimpleCloseable listenerHandler, ServiceInfo info);
+
+ final class ServiceInfo {
+ private URI serviceUri;
+ private URI locationUri;
+ private int preference;
+
+ public URI getServiceUri() {
+ return serviceUri;
+ }
+
+ public void setServiceUri(final URI serviceUri) {
+ this.serviceUri = serviceUri;
+ }
+
+ public URI getLocationUri() {
+ return locationUri;
+ }
+
+ public void setLocationUri(final URI locationUri) {
+ this.locationUri = locationUri;
+ }
+
+ public int getPreference() {
+ return preference;
+ }
+
+ public void setPreference(final int preference) {
+ this.preference = preference;
+ }
+ }
+}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceRegistration.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceRegistration.java 2009-04-14 10:34:23 UTC (rev 5031)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceRegistration.java 2009-04-14 17:18:15 UTC (rev 5032)
@@ -55,11 +55,18 @@
}
public boolean matches(final String serviceType, final String groupName, final String endpointName) {
- return (serviceType == null || serviceType.length() == 0 || serviceType.equals(this.serviceType)) &&
- (groupName == null || groupName.length() == 0 || groupName.equals(this.groupName)) &&
- (endpointName == null || endpointName.length() == 0 || endpointName.equals(this.endpointName));
+ return (serviceType == null || serviceType.length() == 0 || "*".equals(serviceType) || serviceType.equals(this.serviceType)) &&
+ (groupName == null || groupName.length() == 0 || "*".equals(groupName) || groupName.equals(this.groupName)) &&
+ (endpointName == null || endpointName.length() == 0 || "*".equals(endpointName) || endpointName.equals(this.endpointName));
}
+ public boolean matches(final ServiceSpecification spec) {
+ final String serviceType = spec.getServiceType();
+ final String groupName = spec.getGroupName();
+ final String endpointName = spec.getEndpointName();
+ return matches(serviceType, groupName, endpointName);
+ }
+
public boolean isRemote() {
return remote;
}
Copied: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceRegistrationListener.java (from rev 4903, remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceListener.java)
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceRegistrationListener.java (rev 0)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceRegistrationListener.java 2009-04-14 17:18:15 UTC (rev 5032)
@@ -0,0 +1,150 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.remoting3;
+
+import org.jboss.remoting3.spi.RequestHandlerSource;
+
+/**
+ * A listener for watching service registrations on an endpoint.
+ *
+ * @apiviz.landmark
+ */
+public interface ServiceRegistrationListener {
+
+ /**
+ * Receive notification that a service was registered.
+ *
+ * @param listenerHandle the handle to this listener
+ * @param info the servce information
+ */
+ void serviceRegistered(SimpleCloseable listenerHandle, ServiceInfo info);
+
+ /**
+ * Information about a registered service.
+ *
+ * @apiviz.exclude
+ */
+ final class ServiceInfo {
+ private String serviceType;
+ private String groupName;
+ private int metric;
+ private RequestHandlerSource requestHandlerSource;
+ private SimpleCloseable registrationHandle;
+
+ /**
+ * Construct a new instance.
+ */
+ public ServiceInfo() {
+ }
+
+ /**
+ * Get the service type.
+ *
+ * @return the service type
+ */
+ public String getServiceType() {
+ return serviceType;
+ }
+
+ /**
+ * Set the service type.
+ *
+ * @param serviceType the service type
+ */
+ public void setServiceType(final String serviceType) {
+ this.serviceType = serviceType;
+ }
+
+ /**
+ * Get the group name.
+ *
+ * @return the group name
+ */
+ public String getGroupName() {
+ return groupName;
+ }
+
+ /**
+ * Set the group name.
+ *
+ * @param groupName the group name
+ */
+ public void setGroupName(final String groupName) {
+ this.groupName = groupName;
+ }
+
+ /**
+ * Get the metric.
+ *
+ * @return the metric
+ */
+ public int getMetric() {
+ return metric;
+ }
+
+ /**
+ * Set the metric.
+ *
+ * @param metric the metric
+ */
+ public void setMetric(final int metric) {
+ this.metric = metric;
+ }
+
+ /**
+ * Get the request handler source.
+ *
+ * @return the request handler source
+ */
+ public RequestHandlerSource getRequestHandlerSource() {
+ return requestHandlerSource;
+ }
+
+ /**
+ * Set the request handler source.
+ *
+ * @param requestHandlerSource the request handler source
+ */
+ public void setRequestHandlerSource(final RequestHandlerSource requestHandlerSource) {
+ this.requestHandlerSource = requestHandlerSource;
+ }
+
+ /**
+ * Get the registration handle. Closing this handle will remove the registration.
+ *
+ * @return the registration handle
+ */
+ public SimpleCloseable getRegistrationHandle() {
+ return registrationHandle;
+ }
+
+ /**
+ * Set the registration handle.
+ *
+ * @param registrationHandle the registration handle
+ */
+ public void setRegistrationHandle(final SimpleCloseable registrationHandle) {
+ this.registrationHandle = registrationHandle;
+ }
+ }
+}
Added: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceSpecification.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceSpecification.java (rev 0)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceSpecification.java 2009-04-14 17:18:15 UTC (rev 5032)
@@ -0,0 +1,122 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.remoting3;
+
+import java.net.URI;
+
+/**
+ * A specification of a JBoss Remoting service.
+ *
+ * @apiviz.exclude
+ */
+public final class ServiceSpecification {
+ private final String serviceType;
+ private final String groupName;
+ private final String endpointName;
+
+ public ServiceSpecification(final String serviceType, final String groupName, final String endpointName) {
+ if (serviceType == null) {
+ throw new NullPointerException("serviceType is null");
+ }
+ if (groupName == null) {
+ throw new NullPointerException("groupName is null");
+ }
+ if (endpointName == null) {
+ throw new NullPointerException("endpointName is null");
+ }
+ if (serviceType.length() > 0 && ! "*".equals(serviceType)) {
+ ServiceURI.validateServiceType(serviceType);
+ this.serviceType = serviceType.toLowerCase();
+ } else {
+ this.serviceType = "*";
+ }
+ if (groupName.length() > 0 && ! "*".equals(groupName)) {
+ ServiceURI.validateGroupName(groupName);
+ this.groupName = groupName.toLowerCase();
+ } else {
+ this.groupName = "*";
+ }
+ if (endpointName.length() > 0 && ! "*".equals(endpointName)) {
+ ServiceURI.validateEndpointName(endpointName);
+ this.endpointName = endpointName.toLowerCase();
+ } else {
+ this.endpointName = "*";
+ }
+ }
+
+ public static ServiceSpecification fromUri(final URI uri) {
+ return new ServiceSpecification(ServiceURI.getServiceType(uri), ServiceURI.getGroupName(uri), ServiceURI.getEndpointName(uri));
+ }
+
+ public String getServiceType() {
+ return serviceType;
+ }
+
+ public String getGroupName() {
+ return groupName;
+ }
+
+ public String getEndpointName() {
+ return endpointName;
+ }
+
+ public boolean matches(final URI serviceUri) {
+ if (! ServiceURI.isRemotingServiceUri(serviceUri)) {
+ return false;
+ }
+ if (! "*".equals(serviceType)) {
+ if (! serviceType.equals(ServiceURI.getServiceType(serviceUri))) {
+ return false;
+ }
+ }
+ if (! "*".equals(groupName)) {
+ if (! groupName.equals(ServiceURI.getGroupName(serviceUri))) {
+ return false;
+ }
+ }
+ if (! "*".equals(endpointName)) {
+ if (! endpointName.equals(ServiceURI.getEndpointName(serviceUri))) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public boolean equals(final Object o) {
+ if (this == o) return true;
+ if (! (o instanceof ServiceSpecification)) return false;
+ final ServiceSpecification that = (ServiceSpecification) o;
+ if (!endpointName.equals(that.endpointName)) return false;
+ if (!groupName.equals(that.groupName)) return false;
+ if (!serviceType.equals(that.serviceType)) return false;
+ return true;
+ }
+
+ @Override
+ public int hashCode() {
+ int result = serviceType.hashCode();
+ result = 31 * result + groupName.hashCode();
+ result = 31 * result + endpointName.hashCode();
+ return result;
+ }
+}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceURI.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceURI.java 2009-04-14 10:34:23 UTC (rev 5031)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/ServiceURI.java 2009-04-14 17:18:15 UTC (rev 5032)
@@ -24,6 +24,7 @@
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.regex.Pattern;
/**
* A parser for JBoss Remoting URI types.
@@ -65,7 +66,7 @@
} else {
serviceType = ssp.substring(0, firstColon);
}
- return serviceType;
+ return serviceType.toLowerCase();
}
/**
@@ -91,7 +92,7 @@
} else {
groupName = ssp.substring(firstColon + 1, secondColon);
}
- return groupName;
+ return groupName.toLowerCase();
}
/**
@@ -122,7 +123,7 @@
} else {
endpointName = ssp.substring(secondColon + 1, thirdColon);
}
- return endpointName;
+ return endpointName.toLowerCase();
}
/**
@@ -152,4 +153,35 @@
throw new IllegalStateException("URI syntax exception should not be possible here", e);
}
}
+
+ private static final Pattern VALID_SERVICE_TYPE = Pattern.compile("^(?:[_a-z][_a-z0-9]*)(?:\\.[_a-z][_a-z0-9]*)*$", Pattern.CASE_INSENSITIVE);
+ private static final Pattern VALID_GROUP_NAME = Pattern.compile("^(?:[_a-z0-9]+)(?:\\.[_a-z0-9]+)*$", Pattern.CASE_INSENSITIVE);
+ private static final Pattern VALID_ENDPOINT_NAME = VALID_SERVICE_TYPE;
+
+ public static void validateServiceType(final CharSequence serviceType) {
+ if (serviceType == null) {
+ throw new NullPointerException("serviceType is null");
+ }
+ if (! VALID_SERVICE_TYPE.matcher(serviceType).matches()) {
+ throw new IllegalArgumentException("Service type \"" + serviceType + "\" is not valid");
+ }
+ }
+
+ public static void validateGroupName(final CharSequence groupName) {
+ if (groupName == null) {
+ throw new NullPointerException("groupName is null");
+ }
+ if (! VALID_GROUP_NAME.matcher(groupName).matches()) {
+ throw new IllegalArgumentException("Group name \"" + groupName + "\" is not valid");
+ }
+ }
+
+ public static void validateEndpointName(final String endpointName) {
+ if (endpointName == null) {
+ throw new NullPointerException("endpointName is null");
+ }
+ if (! VALID_ENDPOINT_NAME.matcher(endpointName).matches()) {
+ throw new IllegalArgumentException("Endpoint name \"" + endpointName + "\" is not valid");
+ }
+ }
}
Added: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/Cancellable.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/Cancellable.java (rev 0)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/Cancellable.java 2009-04-14 17:18:15 UTC (rev 5032)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.remoting3.spi;
+
+/**
+ * A handle which can be used to cancel an operation. Cancellation is not mandatory; calling this method merely indicates
+ * that the operation need not complete.
+ */
+public interface Cancellable {
+
+ /**
+ * Cancel the operation. Calling this method more than one time has no additional effect.
+ */
+ void cancel();
+
+ /**
+ * A Cancellable instance which does nothing.
+ */
+ Cancellable NULL_CANCELLABLE = new Cancellable() {
+ public void cancel() {
+ }
+ };
+}
Added: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProvider.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProvider.java (rev 0)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProvider.java 2009-04-14 17:18:15 UTC (rev 5032)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.remoting3.spi;
+
+import java.io.IOException;
+import java.net.URI;
+import org.jboss.remoting3.ResourceType;
+
+/**
+ *
+ */
+public interface ConnectionProvider<T> {
+ Cancellable connect(URI uri, Result<T> result) throws IllegalArgumentException;
+
+ URI getConnectionUri(URI uri);
+
+ ResourceType getResourceType();
+
+ interface Result<T> {
+ void setResult(T result);
+
+ void setException(IOException exception);
+
+ void setCancelled();
+ }
+}
Added: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/EndpointConnection.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/EndpointConnection.java (rev 0)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/EndpointConnection.java 2009-04-14 17:18:15 UTC (rev 5032)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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.remoting3.spi;
+
+import java.io.Closeable;
+
+/**
+ * A connection to a foreign endpoint.
+ */
+public interface EndpointConnection extends Closeable {
+ String getEndpointName();
+
+ int getMetric();
+
+ ConnectionProvider<RequestHandler> getRequestHandlerConnectionProvider();
+
+ ConnectionProvider<RequestHandlerSource> getRequestHandlerSourceConnectionProvider();
+}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/RemoteRequestContext.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/RemoteRequestContext.java 2009-04-14 10:34:23 UTC (rev 5031)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/RemoteRequestContext.java 2009-04-14 17:18:15 UTC (rev 5032)
@@ -26,7 +26,7 @@
* The context of an outstanding remote request. This instance should be discarded when a reply (of any sort)
* is received for the request.
*/
-public interface RemoteRequestContext {
+public interface RemoteRequestContext extends Cancellable {
/**
* Signal that the request should be cancelled, if possible.
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/RequestHandler.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/RequestHandler.java 2009-04-14 10:34:23 UTC (rev 5031)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/RequestHandler.java 2009-04-14 17:18:15 UTC (rev 5032)
@@ -22,9 +22,6 @@
package org.jboss.remoting3.spi;
-import java.io.IOException;
-import org.jboss.remoting3.CloseHandler;
-
/**
* A request handler, which can be passed to remote endpoints. Remote systems can then use the handler
* to make invocations, or they may forward a handler on to other remote systems.
@@ -46,30 +43,4 @@
* @return a context which may be used to cancel the request
*/
RemoteRequestContext receiveRequest(Object request, ReplyHandler replyHandler);
-
- /**
- * Get a handle to this request handler. The request handler will not auto-close as long as there is at least
- * one open handle. If a handle is "leaked", it will be closed
- * automatically if/when the garbage collector invokes its {@link Object#finalize()} method, with a log message
- * warning of the leak.
- *
- * @return the handle
- * @throws IOException if a handle could not be acquired
- */
- Handle<RequestHandler> getHandle() throws IOException;
-
- /**
- * Close this request handler. The outcome of any outstanding requests is not defined, though implementations
- * should make an effort to cancel any outstanding requests.
- *
- * @throws java.io.IOException if the client endpoint could not be closed
- */
- void close() throws IOException;
-
- /**
- * Add a handler that is called when the request handler is closed.
- *
- * @param handler the handler to be called
- */
- Key addCloseHandler(final CloseHandler<? super RequestHandler> handler);
}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/RequestHandlerSource.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/RequestHandlerSource.java 2009-04-14 10:34:23 UTC (rev 5031)
+++ remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/RequestHandlerSource.java 2009-04-14 17:18:15 UTC (rev 5032)
@@ -23,8 +23,6 @@
package org.jboss.remoting3.spi;
import java.io.IOException;
-import org.jboss.remoting3.CloseHandler;
-import org.jboss.remoting3.RemotingException;
/**
* A request handler source, which can be passed to remote endpoints. Remote systems can then use the handler source
@@ -38,30 +36,7 @@
* Create a request handler for the service corresponding to this request handler source.
*
* @return a request handler
- * @throws RemotingException if a client could not be opened
+ * @throws IOException if a client could not be opened
*/
Handle<RequestHandler> createRequestHandler() throws IOException;
-
- /**
- * Get a handle to this request handler source. The request handler source will not auto-close as long as there is at least
- * one open handle, or request handler. If a handle is "leaked", it will be closed
- * automatically if/when the garbage collector invokes its {@link Object#finalize()} method, with a log message
- * warning of the leak.
- *
- * @return the handle
- * @throws RemotingException if a handle could not be acquired
- */
- Handle<RequestHandlerSource> getHandle() throws IOException;
-
- /**
- * Close this request handler source immediately.
- */
- void close() throws IOException;
-
- /**
- * Add a handler that is called when the request handler source is closed.
- *
- * @param handler the handler to be called
- */
- Key addCloseHandler(final CloseHandler<? super RequestHandlerSource> handler);
}
Modified: remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/EndpointTestCase.java
===================================================================
--- remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/EndpointTestCase.java 2009-04-14 10:34:23 UTC (rev 5031)
+++ remoting3/trunk/jboss-remoting/src/test/java/org/jboss/remoting3/EndpointTestCase.java 2009-04-14 17:18:15 UTC (rev 5032)
@@ -68,7 +68,7 @@
final Object requestObj = new Object();
final Object replyObj = new Object();
try {
- final Handle<RequestHandler> handle = endpoint.createRequestHandler(new AbstractRequestListener<Object, Object>() {
+ final Handle<RequestHandler> handle = endpoint.createLocalRequestHandler(new AbstractRequestListener<Object, Object>() {
public void handleRequest(final RequestContext<Object> context, final Object request) throws RemoteExecutionException {
assertEquals(request, requestObj);
try {
@@ -126,7 +126,7 @@
try {
final Object requestObj = new Object();
final Object replyObj = new Object();
- final Handle<RequestHandler> handle = endpoint.createRequestHandler(new AbstractRequestListener<Object, Object>() {
+ final Handle<RequestHandler> handle = endpoint.createLocalRequestHandler(new AbstractRequestListener<Object, Object>() {
public void handleRequest(final RequestContext<Object> context, final Object request) throws RemoteExecutionException {
assertEquals(request, requestObj);
try {
@@ -183,7 +183,7 @@
final EndpointImpl endpoint = new EndpointImpl(executorService, "test-endpoint");
try {
final Object requestObj = new Object();
- final Handle<RequestHandler> handle = endpoint.createRequestHandler(new AbstractRequestListener<Object, Object>() {
+ final Handle<RequestHandler> handle = endpoint.createLocalRequestHandler(new AbstractRequestListener<Object, Object>() {
public void handleRequest(final RequestContext<Object> context, final Object request) throws RemoteExecutionException {
assertEquals(request, requestObj);
// don't send a reply!!
@@ -220,7 +220,7 @@
final EndpointImpl endpoint = new EndpointImpl(executorService, "test-endpoint");
try {
final Object requestObj = new Object();
- final Handle<RequestHandler> handle = endpoint.createRequestHandler(new AbstractRequestListener<Object, Object>() {
+ final Handle<RequestHandler> handle = endpoint.createLocalRequestHandler(new AbstractRequestListener<Object, Object>() {
public void handleRequest(final RequestContext<Object> context, final Object request) throws RemoteExecutionException {
assertEquals(request, requestObj);
context.execute(new Runnable() {
Modified: remoting3/trunk/samples/src/test/java/org/jboss/remoting3/samples/protocol/basic/BasicTestCase.java
===================================================================
--- remoting3/trunk/samples/src/test/java/org/jboss/remoting3/samples/protocol/basic/BasicTestCase.java 2009-04-14 10:34:23 UTC (rev 5031)
+++ remoting3/trunk/samples/src/test/java/org/jboss/remoting3/samples/protocol/basic/BasicTestCase.java 2009-04-14 17:18:15 UTC (rev 5032)
@@ -63,7 +63,7 @@
configuration.setMarshallingConfiguration(marshallingConfiguration);
final Endpoint endpoint = Remoting.createEndpoint(executor, "test");
try {
- final Handle<RequestHandler> requestHandlerHandle = endpoint.createRequestHandler(new AbstractRequestListener<Object, Object>() {
+ final Handle<RequestHandler> requestHandlerHandle = endpoint.createLocalRequestHandler(new AbstractRequestListener<Object, Object>() {
public void handleRequest(final RequestContext<Object> context, final Object request) throws RemoteExecutionException {
System.out.println("Got a request! " + request.toString());
try {
15 years, 7 months
JBoss Remoting SVN: r5031 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http/proxy.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:34:23 -0400 (Tue, 14 Apr 2009)
New Revision: 5031
Modified:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http/proxy/ProxyAuthenticationTestCase.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http/proxy/ProxyAuthenticationTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http/proxy/ProxyAuthenticationTestCase.java 2009-04-14 10:33:39 UTC (rev 5030)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http/proxy/ProxyAuthenticationTestCase.java 2009-04-14 10:34:23 UTC (rev 5031)
@@ -27,6 +27,9 @@
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import java.util.Map;
@@ -119,11 +122,11 @@
setupServer();
// Set system properties.
- SecurityUtility.setSystemProperty("http.proxyHost", server.host);
- SecurityUtility.setSystemProperty("http.proxyPort", Integer.toString(server.port));
- SecurityUtility.setSystemProperty("proxySet", "true");
- SecurityUtility.setSystemProperty("http.proxy.username", "sysprop");
- SecurityUtility.setSystemProperty("http.proxy.password", "abc");
+ setSystemProperty("http.proxyHost", server.host);
+ setSystemProperty("http.proxyPort", Integer.toString(server.port));
+ setSystemProperty("proxySet", "true");
+ setSystemProperty("http.proxy.username", "sysprop");
+ setSystemProperty("http.proxy.password", "abc");
// Create invocation metadata map.
HashMap metadata = new HashMap();
@@ -149,8 +152,8 @@
setupServer();
// Set system properties.
- SecurityUtility.setSystemProperty("http.proxy.username", "sysprop");
- SecurityUtility.setSystemProperty("http.proxy.password", "abc");
+ setSystemProperty("http.proxy.username", "sysprop");
+ setSystemProperty("http.proxy.password", "abc");
// Create invocation metadata map.
HashMap metadata = new HashMap();
@@ -177,8 +180,8 @@
setupServer();
// Set system properties.
- SecurityUtility.setSystemProperty("http.proxy.username", "sysprop");
- SecurityUtility.setSystemProperty("http.proxy.password", "abc");
+ setSystemProperty("http.proxy.username", "sysprop");
+ setSystemProperty("http.proxy.password", "abc");
// Create invocation metadata map.
HashMap metadata = new HashMap();
@@ -305,4 +308,28 @@
return auth;
}
}
+
+ static private void setSystemProperty(final String name, final String value)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ System.setProperty(name, value);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return System.setProperty(name, value);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (RuntimeException) e.getCause();
+ }
+ }
}
\ No newline at end of file
15 years, 7 months
JBoss Remoting SVN: r5030 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/timertask.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:33:39 -0400 (Tue, 14 Apr 2009)
New Revision: 5030
Modified:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/timertask/TimerTaskTestCase.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/timertask/TimerTaskTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/timertask/TimerTaskTestCase.java 2009-04-14 10:31:53 UTC (rev 5029)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/bisocket/timertask/TimerTaskTestCase.java 2009-04-14 10:33:39 UTC (rev 5030)
@@ -24,6 +24,9 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.net.InetAddress;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@@ -94,7 +97,7 @@
try
{
- SecurityUtility.getDeclaredMethod(Timer.class, "purge", new Class[]{});
+ getDeclaredMethod(Timer.class, "purge", new Class[]{});
purgeMethodAvailable = true;
}
catch (Exception e)
@@ -340,4 +343,32 @@
log.info("received callback");
}
}
+
+ static private Method getDeclaredMethod(final Class c, final String name, final Class[] parameterTypes)
+ throws NoSuchMethodException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ Method m = c.getDeclaredMethod(name, parameterTypes);
+ m.setAccessible(true);
+ return m;
+ }
+
+ try
+ {
+ return (Method) AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws NoSuchMethodException
+ {
+ Method m = c.getDeclaredMethod(name, parameterTypes);
+ m.setAccessible(true);
+ return m;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (NoSuchMethodException) e.getCause();
+ }
+ }
}
\ No newline at end of file
15 years, 7 months
JBoss Remoting SVN: r5029 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/startup.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:31:53 -0400 (Tue, 14 Apr 2009)
New Revision: 5029
Modified:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/startup/JNDIDetectorServer.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/startup/JNDIDetectorServer.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/startup/JNDIDetectorServer.java 2009-04-14 10:31:30 UTC (rev 5028)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/startup/JNDIDetectorServer.java 2009-04-14 10:31:53 UTC (rev 5029)
@@ -38,6 +38,9 @@
import java.lang.reflect.Method;
import java.net.InetAddress;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
/**
* @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
@@ -62,7 +65,7 @@
namingBeanImplClass = Class.forName("org.jnp.server.NamingBeanImpl");
namingBean = namingBeanImplClass.newInstance();
Method startMethod = namingBeanImplClass.getMethod("start", new Class[] {});
- SecurityUtility.setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
+ setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
startMethod.invoke(namingBean, new Object[] {});
}
catch (Exception e)
@@ -158,5 +161,28 @@
}
-
+
+ static private void setSystemProperty(final String name, final String value)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ System.setProperty(name, value);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return System.setProperty(name, value);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (RuntimeException) e.getCause();
+ }
+ }
}
\ No newline at end of file
15 years, 7 months
JBoss Remoting SVN: r5028 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/deadlock3.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:31:30 -0400 (Tue, 14 Apr 2009)
New Revision: 5028
Modified:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/deadlock3/Server.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/deadlock3/Server.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/deadlock3/Server.java 2009-04-14 10:31:06 UTC (rev 5027)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/deadlock3/Server.java 2009-04-14 10:31:30 UTC (rev 5028)
@@ -45,6 +45,9 @@
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.UnknownHostException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import java.util.Map;
@@ -201,7 +204,7 @@
namingBeanImplClass = Class.forName("org.jnp.server.NamingBeanImpl");
namingBean = namingBeanImplClass.newInstance();
Method startMethod = namingBeanImplClass.getMethod("start", new Class[] {});
- SecurityUtility.setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
+ setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
startMethod.invoke(namingBean, new Object[] {});
}
catch (Exception e)
@@ -317,6 +320,29 @@
}
}
-
+
+ static private void setSystemProperty(final String name, final String value)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ System.setProperty(name, value);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return System.setProperty(name, value);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (RuntimeException) e.getCause();
+ }
+ }
}
15 years, 7 months
JBoss Remoting SVN: r5027 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/deadlock.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:31:06 -0400 (Tue, 14 Apr 2009)
New Revision: 5027
Modified:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/deadlock/Server.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/deadlock/Server.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/deadlock/Server.java 2009-04-14 10:30:40 UTC (rev 5026)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/deadlock/Server.java 2009-04-14 10:31:06 UTC (rev 5027)
@@ -45,6 +45,9 @@
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.UnknownHostException;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import java.util.Map;
@@ -228,7 +231,7 @@
namingBeanImplClass = Class.forName("org.jnp.server.NamingBeanImpl");
namingBean = namingBeanImplClass.newInstance();
Method startMethod = namingBeanImplClass.getMethod("start", new Class[] {});
- SecurityUtility.setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
+ setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
startMethod.invoke(namingBean, new Object[] {});
}
catch (Exception e)
@@ -347,6 +350,29 @@
}
}
-
+
+ static private void setSystemProperty(final String name, final String value)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ System.setProperty(name, value);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return System.setProperty(name, value);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (RuntimeException) e.getCause();
+ }
+ }
}
15 years, 7 months
JBoss Remoting SVN: r5026 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi.
by jboss-remoting-commits@lists.jboss.org
Author: ron.sigal(a)jboss.com
Date: 2009-04-14 06:30:40 -0400 (Tue, 14 Apr 2009)
New Revision: 5026
Modified:
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/CleanDetectionTestClient.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/CleanDetectionTestServer.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/JNDIDetector2TestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/JNDIDetectorTest1.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/JNDIDetectorTestCase.java
remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/RestartTestServer.java
Log:
JBREM-1116: Eliminated dependence on SecurityUtility.
Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/CleanDetectionTestClient.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/CleanDetectionTestClient.java 2009-04-14 10:27:24 UTC (rev 5025)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/CleanDetectionTestClient.java 2009-04-14 10:30:40 UTC (rev 5026)
@@ -25,6 +25,9 @@
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.Properties;
import javax.naming.Binding;
@@ -98,7 +101,7 @@
// Get detection message from JNDI server.
createContext();
- NamingEnumeration enumeration = SecurityUtility.listBindings(context, "");
+ NamingEnumeration enumeration = listBindings(context, "");
assertTrue(enumeration.hasMore());
Binding binding = (Binding) enumeration.next();
assertFalse(enumeration.hasMore());
@@ -117,7 +120,7 @@
Thread.sleep(4000);
// Get new detection message from JNDI server.
- enumeration = SecurityUtility.listBindings(context, "");
+ enumeration = listBindings(context, "");
assertTrue(enumeration.hasMore());
binding = (Binding) enumeration.next();
log.info(binding);
@@ -158,20 +161,91 @@
String subContextName = JNDIDetector.DETECTION_SUBCONTEXT_NAME;
try
{
- context = SecurityUtility.initialContextLookup(initialContext, subContextName);
+ context = initialContextLookup(initialContext, subContextName);
}
catch(NamingException e)
{
try
{
- context = SecurityUtility.createSubcontext(initialContext, subContextName);
+ context = createSubcontext(initialContext, subContextName);
}
catch(NameAlreadyBoundException e1)
{
log.debug("The sub context " + subContextName + " was created before we could.");
- context = SecurityUtility.initialContextLookup(initialContext, subContextName);
+ context = initialContextLookup(initialContext, subContextName);
}
}
}
+
+ static private Context createSubcontext(final InitialContext initialContext, final String subContextName)
+ throws NamingException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return initialContext.createSubcontext(subContextName);
+ }
+ try
+ {
+ return (Context) AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws NamingException
+ {
+ return initialContext.createSubcontext(subContextName);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (NamingException) e.getCause();
+ }
+ }
+
+ static private Context initialContextLookup(final InitialContext initialContext, final String subContextName)
+ throws NamingException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return (Context) initialContext.lookup(subContextName);
+ }
+
+ try
+ {
+ return (Context) AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws NamingException
+ {
+ return initialContext.lookup(subContextName);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (NamingException) e.getCause();
+ }
+ }
+
+ static private NamingEnumeration listBindings(final Context context, final String bindName)
+ throws NamingException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ return context.listBindings(bindName);
+ }
+
+ try
+ {
+ return (NamingEnumeration) AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws NamingException
+ {
+ return context.listBindings(bindName);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (NamingException) e.getCause();
+ }
+ }
}
Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/CleanDetectionTestServer.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/CleanDetectionTestServer.java 2009-04-14 10:27:24 UTC (rev 5025)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/CleanDetectionTestServer.java 2009-04-14 10:30:40 UTC (rev 5026)
@@ -43,10 +43,14 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import java.util.Map;
import java.util.Timer;
@@ -135,8 +139,8 @@
namingBeanImplClass = Class.forName("org.jnp.server.NamingBeanImpl");
namingBean = namingBeanImplClass.newInstance();
Method startMethod = namingBeanImplClass.getMethod("start", new Class[] {});
- SecurityUtility.setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
- SecurityUtility.namingBeanImplStart(namingBean, startMethod);
+ setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
+ namingBeanImplStart(namingBean, startMethod);
}
catch (Exception e)
{
@@ -331,4 +335,58 @@
// NO OP as we do not need a reference back to the server invoker
}
}
+
+ static private void setSystemProperty(final String name, final String value)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ System.setProperty(name, value);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return System.setProperty(name, value);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (RuntimeException) e.getCause();
+ }
+ }
+
+ static private void namingBeanImplStart(final Object namingBean, final Method startMethod)
+ throws IllegalAccessException, InvocationTargetException
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ startMethod.invoke(namingBean, new Object[] {});
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws IllegalAccessException, InvocationTargetException
+ {
+ startMethod.invoke(namingBean, new Object[] {});
+ return null;
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ Throwable cause = e.getCause();
+ if (cause instanceof IllegalAccessException)
+ throw (IllegalAccessException) cause;
+ else
+ throw (InvocationTargetException) cause;
+ }
+ }
}
Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/JNDIDetector2TestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/JNDIDetector2TestCase.java 2009-04-14 10:27:24 UTC (rev 5025)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/JNDIDetector2TestCase.java 2009-04-14 10:30:40 UTC (rev 5026)
@@ -8,6 +8,9 @@
import java.lang.reflect.Method;
import java.net.InetAddress;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
/**
* This should be used as the main test case for JNDI detector.
@@ -36,7 +39,7 @@
namingBeanImplClass = Class.forName("org.jnp.server.NamingBeanImpl");
namingBean = namingBeanImplClass.newInstance();
Method startMethod = namingBeanImplClass.getMethod("start", new Class[] {});
- SecurityUtility.setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
+ setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
startMethod.invoke(namingBean, new Object[] {});
}
catch (Exception e)
@@ -109,4 +112,28 @@
{
return 300000;
}
+
+ static private void setSystemProperty(final String name, final String value)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ System.setProperty(name, value);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return System.setProperty(name, value);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (RuntimeException) e.getCause();
+ }
+ }
}
Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/JNDIDetectorTest1.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/JNDIDetectorTest1.java 2009-04-14 10:27:24 UTC (rev 5025)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/JNDIDetectorTest1.java 2009-04-14 10:30:40 UTC (rev 5026)
@@ -24,6 +24,10 @@
import java.lang.reflect.Method;
import java.net.InetAddress;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
@@ -176,7 +180,7 @@
namingBeanImplClass = Class.forName("org.jnp.server.NamingBeanImpl");
namingBean = namingBeanImplClass.newInstance();
Method startMethod = namingBeanImplClass.getMethod("start", new Class[] {});
- SecurityUtility.setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
+ setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
startMethod.invoke(namingBean, new Object[] {});
}
catch (Exception e)
@@ -218,5 +222,28 @@
return new JNDIDetectorTest1.TestNetworkRegistry();
}
}
-
+
+ static private void setSystemProperty(final String name, final String value)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ System.setProperty(name, value);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return System.setProperty(name, value);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (RuntimeException) e.getCause();
+ }
+ }
}
\ No newline at end of file
Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/JNDIDetectorTestCase.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/JNDIDetectorTestCase.java 2009-04-14 10:27:24 UTC (rev 5025)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/JNDIDetectorTestCase.java 2009-04-14 10:30:40 UTC (rev 5026)
@@ -24,6 +24,10 @@
import java.lang.reflect.Method;
import java.net.InetAddress;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
import org.apache.log4j.Level;
import org.jboss.jrunit.harness.TestDriver;
import org.jboss.remoting.samples.detection.jndi.SimpleJNDIServer;
@@ -58,7 +62,7 @@
namingBeanImplClass = Class.forName("org.jnp.server.NamingBeanImpl");
namingBean = namingBeanImplClass.newInstance();
Method startMethod = namingBeanImplClass.getMethod("start", new Class[] {});
- SecurityUtility.setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
+ setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
startMethod.invoke(namingBean, new Object[] {});
}
catch (Exception e)
@@ -130,4 +134,28 @@
{
return 300000;
}
+
+ static private void setSystemProperty(final String name, final String value)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ System.setProperty(name, value);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return System.setProperty(name, value);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (RuntimeException) e.getCause();
+ }
+ }
}
\ No newline at end of file
Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/RestartTestServer.java
===================================================================
--- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/RestartTestServer.java 2009-04-14 10:27:24 UTC (rev 5025)
+++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/detection/jndi/RestartTestServer.java 2009-04-14 10:30:40 UTC (rev 5026)
@@ -44,6 +44,9 @@
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
import java.util.Map;
@@ -132,7 +135,7 @@
namingBeanImplClass = Class.forName("org.jnp.server.NamingBeanImpl");
namingBean = namingBeanImplClass.newInstance();
Method startMethod = namingBeanImplClass.getMethod("start", new Class[] {});
- SecurityUtility.setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
+ setSystemProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
startMethod.invoke(namingBean, new Object[] {});
}
catch (Exception e)
@@ -313,4 +316,28 @@
// NO OP as we do not need a reference back to the server invoker
}
}
+
+ static private void setSystemProperty(final String name, final String value)
+ {
+ if (SecurityUtility.skipAccessControl())
+ {
+ System.setProperty(name, value);
+ return;
+ }
+
+ try
+ {
+ AccessController.doPrivileged( new PrivilegedExceptionAction()
+ {
+ public Object run() throws Exception
+ {
+ return System.setProperty(name, value);
+ }
+ });
+ }
+ catch (PrivilegedActionException e)
+ {
+ throw (RuntimeException) e.getCause();
+ }
+ }
}
15 years, 7 months