org.j4me.util
Class ConnectorHelper

java.lang.Object
  extended by java.lang.Thread
      extended by org.j4me.util.ConnectorHelper
All Implemented Interfaces:
java.lang.Runnable

public class ConnectorHelper
extends java.lang.Thread

Substitute for Connector.open that forces a timeout on all platforms.

The (StreamConnection) Connector.open(url, Connector.READ, true) call is not guaranteed to timeout. On some phones this will cause indefinate blocking and make the application unresponsive. To get around this the connection must be made on a secondary thread that is killed after some timeout period has expired.

See Also:
Connector.open(java.lang.String, int, boolean)

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Method Summary
 javax.microedition.io.StreamConnection blockUntilConnected()
          The owner should call this method to block until the connection is either established, has timed out, or encountered some other connection exception.
static javax.microedition.io.Connection open(java.lang.String url, int mode, int timeout)
          Create and open a Connection.
 void run()
          Executed by thread to establish the connection when the owner calls start.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

run

public void run()
Executed by thread to establish the connection when the owner calls start.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

blockUntilConnected

public javax.microedition.io.StreamConnection blockUntilConnected()
                                                           throws java.io.IOException,
                                                                  java.lang.SecurityException
The owner should call this method to block until the connection is either established, has timed out, or encountered some other connection exception.

Returns:
A connection to the device; null if it timed out and was unsuccessful.
Throws:
java.io.IOException - - If some other kind of I/O error occurs.
java.lang.SecurityException - - May be thrown if access to the protocol handler is prohibited.

open

public static javax.microedition.io.Connection open(java.lang.String url,
                                                    int mode,
                                                    int timeout)
                                             throws java.lang.IllegalArgumentException,
                                                    javax.microedition.io.ConnectionNotFoundException,
                                                    java.io.IOException,
                                                    java.lang.SecurityException
Create and open a Connection.

Parameters:
url - is the URL for the connection.
mode - is the access mode. It is either Connector.READ, Connector.WRITE, or Connector.READ_WRITE.
timeout - is the the number of milliseconds before the open attempt times out.
Returns:
A new Connection object.
Throws:
java.lang.IllegalArgumentException - if a parameter is invalid.
javax.microedition.io.ConnectionNotFoundException - if the target of the name cannot be found, or if the requested protocol type is not supported.
java.io.IOException - if some other kind of I/O error occurs.
java.lang.SecurityException - may be thrown if access to the protocol handler is prohibited. Some platforms throw IOException instead to try to be MIDP 1.0 compatible.
See Also:
Connector.open(java.lang.String, int, boolean)