com.funambol.util
Class ConnectionManager

java.lang.Object
  extended by com.funambol.util.ConnectionManager

public class ConnectionManager
extends java.lang.Object

Controls all of the connections requested by the API implementations. It is strongly recommended to use this class instead of the direct call to the Connector.open(String url) method. This class is based on the singleton pattern: it has private constructor and just one instance to be referenced calling the method ConnectionManager.getInstance() by other classes. The connection logic switch between all of the BlackberryConfiguration object returned by the Connection config class. The usage of the returned configuration is the following:


1. WIFI Network - just on the wifi capable devices, skipped if the wifi bearer is not present;



2. Custom TCP configuration - Manually configured by the user



3. APN gateway configuration - Carrier's Country based Configuration



4. Blackberry ServiceBook configuration WAP Transport entry - Blackberry ServiceBook based Configuration



NOTE 1: When a wifi network is no more available the system tries to configure a GPRS data connection in the same session.



NOTE 2: When the Manually configured TCP configuration is cancelled or become invalid (i.e.: an invalid APN is substituted to a valid one), the TCP configuration won't ever be used during the same session but the system will switch other provided configurations.



Note 3:When a configuration that is not WIFI or TCP based is validated, that configuration will be used for the entire session.


Field Summary
protected static int workingConfigID
          WORKING configurations ID
 
Constructor Summary
protected ConnectionManager()
          Singleton realization: Private constructor Use getInstance() method to acces the public methods
 
Method Summary
 ConnectionListener getConnectionListener()
          Accessor method to get the current connection listener
static ConnectionManager getInstance()
          Singleton implementation:
 javax.microedition.io.Connection open(java.lang.String url)
          Open up a connection to the given url with the default CLDC 1.0 API default values for the stream (READ_WRITE) and the value TRUE for the availability of InterruptedIOException to be thrown
 javax.microedition.io.Connection open(java.lang.String url, int accessMode, boolean enableTimeoutException)
          Open up a connection to the given url with the given access accessMode and
 HttpConnectionAdapter openHttpConnection(java.lang.String url, java.lang.Object extra)
          Open up a connection to the given url with the given access accessMode and
 SocketAdapter openSocketConnection(java.lang.String addr, int port, int mode, boolean timeout)
          Open a socket connection to the given URL
 void setConnectionListener(ConnectionListener cl)
          Accessor method to set the connection listener
 void setFixedApn(java.lang.String apn)
          Set the Connection parameters for this connection given the apn string
 void unsetFixedApn()
          Disable the connection parameters for the fixed APN usage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

workingConfigID

protected static int workingConfigID
WORKING configurations ID

Constructor Detail

ConnectionManager

protected ConnectionManager()
Singleton realization: Private constructor Use getInstance() method to acces the public methods

Method Detail

getInstance

public static ConnectionManager getInstance()
Singleton implementation:

Returns:
the current instance of this class or a new instance if it the current instance is null

open

public javax.microedition.io.Connection open(java.lang.String url)
                                      throws java.io.IOException
Open up a connection to the given url with the default CLDC 1.0 API default values for the stream (READ_WRITE) and the value TRUE for the availability of InterruptedIOException to be thrown

Parameters:
url - The URL for the connection
Returns:
the connection url with the given parameters
Throws:
java.io.IOException

open

public javax.microedition.io.Connection open(java.lang.String url,
                                             int accessMode,
                                             boolean enableTimeoutException)
                                      throws java.io.IOException
Open up a connection to the given url with the given access accessMode and

Parameters:
url - The URL for the connection
accessMode - the access accessMode that can be READ, WRITE, READ_WRITE
enableTimeoutException - A flag to indicate that the caller wants to enable the throwing of InterruptedIOException when a connection timeout occurs
Returns:
Connection related to the given parameters
Throws:
java.io.IOException

setConnectionListener

public void setConnectionListener(ConnectionListener cl)
Accessor method to set the connection listener

Parameters:
cl - the connection listener to be set

getConnectionListener

public ConnectionListener getConnectionListener()
Accessor method to get the current connection listener

Returns:
ConnectionListener related to this ConnectionManager instance

setFixedApn

public void setFixedApn(java.lang.String apn)
Set the Connection parameters for this connection given the apn string

Parameters:
apn - the fixed apn to be used.

unsetFixedApn

public void unsetFixedApn()
Disable the connection parameters for the fixed APN usage. Use this method after a setConnectionPaarameters call in order to use the device apn instead of the fixed one


openHttpConnection

public HttpConnectionAdapter openHttpConnection(java.lang.String url,
                                                java.lang.Object extra)
                                         throws java.io.IOException
Open up a connection to the given url with the given access accessMode and

Parameters:
url - The URL for the connection
extra - is some extra information that can be specified to specific implementations
Returns:
the connection (cannot be null)
Throws:
java.io.IOException

openSocketConnection

public SocketAdapter openSocketConnection(java.lang.String addr,
                                          int port,
                                          int mode,
                                          boolean timeout)
                                   throws java.io.IOException
Open a socket connection to the given URL

Parameters:
addr - is the server address
port - the port
mode - can be READ_WRITE
timeout - enable timeout on IO operations
Throws:
java.io.IOException


Copyright © 2001-2009 Funambol.