Author: david.lloyd(a)jboss.com
Date: 2009-09-16 12:09:24 -0400 (Wed, 16 Sep 2009)
New Revision: 5497
Modified:
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/Option.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/OptionMap.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Sequence.java
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProvider.java
Log:
Support passing options in to the connect() method
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-09-16
15:39:14 UTC (rev 5496)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Endpoint.java 2009-09-16
16:09:24 UTC (rev 5497)
@@ -78,10 +78,11 @@
* This method does not block; use the return value to wait for a result if you wish
to block.
*
* @param destination the destination
+ * @param connectOptions options to configure this connection
* @return the future connection
* @throws IOException if an error occurs while starting the connect attempt
*/
- IoFuture<? extends Connection> connect(URI destination) throws IOException;
+ IoFuture<? extends Connection> connect(URI destination, OptionMap
connectOptions) throws IOException;
/**
* Register a connection provider for a URI scheme. The provider factory is called
with the context which can
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-09-16
15:39:14 UTC (rev 5496)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/EndpointImpl.java 2009-09-16
16:09:24 UTC (rev 5497)
@@ -337,18 +337,22 @@
return registration;
}
- public IoFuture<? extends Connection> connect(final URI destination) throws
IOException {
+ public IoFuture<? extends Connection> connect(final URI destination, final
OptionMap connectOptions) throws IOException {
final SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(CONNECT_PERM);
}
- final ConnectionProvider connectionProvider =
connectionProviders.get(destination.getScheme());
+ final String scheme = destination.getScheme();
+ final ConnectionProvider connectionProvider = connectionProviders.get(scheme);
+ if (connectionProvider == null) {
+ throw new UnknownURISchemeException("No connection provider for URI
scheme \"" + scheme + "\" is installed");
+ }
final FutureResult<Connection, ConnectionHandlerFactory> futureResult = new
FutureResult<Connection, ConnectionHandlerFactory>() {
protected Connection translate(final ConnectionHandlerFactory result) {
return new ConnectionImpl(result);
}
};
- connectionProvider.connect(destination, futureResult.getResult());
+ connectionProvider.connect(destination, connectOptions,
futureResult.getResult());
return futureResult;
}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Option.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Option.java 2009-09-16
15:39:14 UTC (rev 5496)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Option.java 2009-09-16
16:09:24 UTC (rev 5497)
@@ -22,6 +22,8 @@
package org.jboss.remoting3;
+import java.util.Collection;
+
/**
* A strongly-typed option to configure an aspect of a service. Options are immutable
and use identity comparisons
* and hash codes, and they are not serializable.
@@ -120,7 +122,15 @@
}
public Sequence<T> cast(final Object o) {
- return ((Sequence<?>)o).cast(elementType);
+ if (o instanceof Sequence) {
+ return ((Sequence<?>)o).cast(elementType);
+ } else if (o instanceof Object[]){
+ return Sequence.of((Object[])o).cast(elementType);
+ } else if (o instanceof Collection) {
+ return Sequence.of((Collection<?>)o).cast(elementType);
+ } else {
+ throw new ClassCastException("Not a sequence");
+ }
}
}
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/OptionMap.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/OptionMap.java 2009-09-16
15:39:14 UTC (rev 5496)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/OptionMap.java 2009-09-16
16:09:24 UTC (rev 5497)
@@ -41,13 +41,23 @@
}
/**
+ * Determine whether this option map contains the given option.
+ *
+ * @param option the option to check
+ * @return {@code true} if the option is present in the option map
+ */
+ public boolean contains(Option<?> option) {
+ return value.containsKey(option);
+ }
+
+ /**
* Get the value of an option from this option map.
*
* @param option the option to get
* @param <T> the type of the option
* @return the option value, or {@code null} if it is not present
*/
- <T> T get(Option<T> option) {
+ public <T> T get(Option<T> option) {
return option.cast(value.get(option));
}
@@ -129,6 +139,22 @@
}
/**
+ * Add int values to an Integer sequence key.
+ *
+ * @param key the key
+ * @param values the values
+ * @return this builder
+ */
+ public Builder addSequence(Option<Sequence<Integer>> key, int...
values) {
+ Integer[] a = new Integer[values.length];
+ for (int i = 0; i < values.length; i++) {
+ a[i] = Integer.valueOf(values[i]);
+ }
+ list.add(new OVPair<Sequence<Integer>>(key, Sequence.of(a)));
+ return this;
+ }
+
+ /**
* Add a long value to a Long key.
*
* @param key the option
@@ -141,6 +167,22 @@
}
/**
+ * Add long values to an Long sequence key.
+ *
+ * @param key the key
+ * @param values the values
+ * @return this builder
+ */
+ public Builder addSequence(Option<Sequence<Long>> key, long...
values) {
+ Long[] a = new Long[values.length];
+ for (int i = 0; i < values.length; i++) {
+ a[i] = Long.valueOf(values[i]);
+ }
+ list.add(new OVPair<Sequence<Long>>(key, Sequence.of(a)));
+ return this;
+ }
+
+ /**
* Add a boolean value to a Boolean key.
*
* @param key the option
@@ -152,7 +194,24 @@
return this;
}
+
/**
+ * Add boolean values to an Boolean sequence key.
+ *
+ * @param key the key
+ * @param values the values
+ * @return this builder
+ */
+ public Builder addSequence(Option<Sequence<Boolean>> key, boolean...
values) {
+ Boolean[] a = new Boolean[values.length];
+ for (int i = 0; i < values.length; i++) {
+ a[i] = Boolean.valueOf(values[i]);
+ }
+ list.add(new OVPair<Sequence<Boolean>>(key, Sequence.of(a)));
+ return this;
+ }
+
+ /**
* Add a key-value pair, where the value is a sequence type.
*
* @param key the key
Modified: remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Sequence.java
===================================================================
---
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Sequence.java 2009-09-16
15:39:14 UTC (rev 5496)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/Sequence.java 2009-09-16
16:09:24 UTC (rev 5497)
@@ -79,6 +79,9 @@
* @return a sequence
*/
public static <T> Sequence<T> of(Collection<T> members) {
+ if (members instanceof Sequence) {
+ return (Sequence<T>) members;
+ }
final Object[] objects = members.toArray();
if (objects.length == 0) {
return empty();
Modified:
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 2009-09-16
15:39:14 UTC (rev 5496)
+++
remoting3/trunk/jboss-remoting/src/main/java/org/jboss/remoting3/spi/ConnectionProvider.java 2009-09-16
16:09:24 UTC (rev 5497)
@@ -23,6 +23,7 @@
package org.jboss.remoting3.spi;
import java.net.URI;
+import org.jboss.remoting3.OptionMap;
/**
* A connection provider. Used to establish connections with remote systems. There is
typically one instance
@@ -37,9 +38,10 @@
* stored in the result variable possibly asynchronously.
*
* @param uri the URI to connect to
+ * @param connectOptions the options to use for this connection
* @param result the result which should receive the connection
* @return a handle which may be used to cancel the connect attempt
* @throws IllegalArgumentException if the URI is not valid
*/
- Cancellable connect(URI uri, Result<ConnectionHandlerFactory> result) throws
IllegalArgumentException;
+ Cancellable connect(URI uri, OptionMap connectOptions,
Result<ConnectionHandlerFactory> result) throws IllegalArgumentException;
}