Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-10-29 04:30:57 -0400
committerEike Stepper2008-10-29 04:30:57 -0400
commitd424fb04451de010037852a37b97e88383dff3f0 (patch)
treead4e2502defaa200def8e6f00b8265f91e009908
parent11373f0a4fd47dad69cbd1c9501a29925964ade1 (diff)
downloadcdo-d424fb04451de010037852a37b97e88383dff3f0.tar.gz
cdo-d424fb04451de010037852a37b97e88383dff3f0.tar.xz
cdo-d424fb04451de010037852a37b97e88383dff3f0.zip
[252420] Provide no timeout option for IConnector
https://bugs.eclipse.org/bugs/show_bug.cgi?id=252420
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/connector/Connector.java28
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnector.java25
2 files changed, 45 insertions, 8 deletions
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/connector/Connector.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/connector/Connector.java
index a94e864e13..2602310faa 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/connector/Connector.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/connector/Connector.java
@@ -257,6 +257,9 @@ public abstract class Connector extends Container<IChannel> implements InternalC
public boolean waitForConnection(long timeout) throws ConnectorException
{
+ final long MAX_POLL_INTERVAL = 100L;
+ boolean withTimeout = timeout != NO_TIMEOUT;
+
try
{
if (TRACER.isEnabled())
@@ -264,14 +267,26 @@ public abstract class Connector extends Container<IChannel> implements InternalC
TRACER.trace("Waiting for connection...");
}
- do
+ for (;;)
{
+ long t = MAX_POLL_INTERVAL;
+ if (withTimeout)
+ {
+ t = Math.min(MAX_POLL_INTERVAL, timeout);
+ timeout -= MAX_POLL_INTERVAL;
+ }
+
+ if (t <= 0)
+ {
+ break;
+ }
+
if (finishedNegotiating == null)
{
break;
}
- if (finishedNegotiating.await(Math.min(100L, timeout), TimeUnit.MILLISECONDS))
+ if (finishedNegotiating.await(t, TimeUnit.MILLISECONDS))
{
break;
}
@@ -280,9 +295,7 @@ public abstract class Connector extends Container<IChannel> implements InternalC
{
break;
}
-
- timeout -= 100L;
- } while (timeout > 0);
+ }
return isConnected();
}
@@ -298,6 +311,11 @@ public abstract class Connector extends Container<IChannel> implements InternalC
return waitForConnection(timeout);
}
+ public boolean connect() throws ConnectorException
+ {
+ return connect(NO_TIMEOUT);
+ }
+
public ConnectorException disconnect()
{
Exception ex = deactivate();
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnector.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnector.java
index 09caaddb20..a5adcf0d4d 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnector.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnector.java
@@ -47,6 +47,11 @@ import org.eclipse.net4j.util.security.IUserAware;
*/
public interface IConnector extends IChannelMultiplexer, IUserAware
{
+ /**
+ * @since 2.0
+ */
+ public static final long NO_TIMEOUT = -1;
+
public String getURL();
/**
@@ -62,23 +67,37 @@ public interface IConnector extends IChannelMultiplexer, IUserAware
/**
* Asynchronous connect. May leave this {@link IConnector} in a state where <code>{@link #isConnected()} == false
* </code>.
- * <p>
+ *
+ * @see #waitForConnection(long)
+ * @see #connect(long)
*/
public void connectAsync() throws ConnectorException;
/**
* Blocks until <code>{@link #isConnected()} == true</code> or the given timeout expired.
- * <p>
*
+ * @param timeout
+ * The maximum number of milli seconds to block or {@link #NO_TIMEOUT} to block indefinetely in case no
+ * connection occurs.
* @throws ConnectorException
*/
public boolean waitForConnection(long timeout) throws ConnectorException;
/**
* Synchronous connect. Blocks until <code>{@link #isConnected()} == true</code> or the given timeout expired.
- * <p>
+ *
+ * @param timeout
+ * The maximum number of milli seconds to block or {@link #NO_TIMEOUT} to block indefinetely in case no
+ * connection occurs.
*/
public boolean connect(long timeout) throws ConnectorException;
+ /**
+ * Synchronous connect with infinite timeout value. Same as {@link #connect() connect(NO_TIMEOUT)}.
+ *
+ * @since 2.0
+ */
+ public boolean connect() throws ConnectorException;
+
public ConnectorException disconnect();
}

Back to the top