‚Äč
GetConnection Functions

Functions

Future< SSLSocket > com.mobiledgex.matchingengine.AppConnectionManager.getTcpSslSocket (final AppClient.FindCloudletReply findCloudletReply, final AppPort appPort, final int portNum, final int timeoutMs)
 
Future< Socket > com.mobiledgex.matchingengine.AppConnectionManager.getTcpSocket (final AppClient.FindCloudletReply findCloudletReply, final AppPort appPort, final int portNum, final int timeoutMs)
 
Future< DatagramSocket > com.mobiledgex.matchingengine.AppConnectionManager.getUdpSocket (final AppClient.FindCloudletReply findCloudletReply, final AppPort appPort, final int portNum, final int timeoutMs)
 
Future< OkHttpClient > com.mobiledgex.matchingengine.AppConnectionManager.getHttpClient (final long timeoutMs)
 

Detailed Description

GetConnection Workflow Example

Function Documentation

◆ getHttpClient()

Future<OkHttpClient> com.mobiledgex.matchingengine.AppConnectionManager.getHttpClient ( final long  timeoutMs)

Returns an HttpClient via OkHttpClient object, over a cellular network interface. Null is returned if a requested cellular network is not available or not allowed.

Convenience method. Get the network from NetworkManager, and set the SSLSocket factory for different communication protocols.

Parameters
timeoutMs(long): connect timeout in milliseconds.
Returns
Future<OkHttpClient>: null can be returned if the network does not exist, if network switching is disabled, of if a SSL Socket Factory cannot be created.

Example

Future<OkHttpClient> httpClientFuture = null;
httpClientFuture = appConnect.getHttpClient((int) GRPC_TIMEOUT_MS);

◆ getTcpSocket()

Future<Socket> com.mobiledgex.matchingengine.AppConnectionManager.getTcpSocket ( final AppClient.FindCloudletReply  findCloudletReply,
final AppPort  appPort,
final int  portNum,
final int  timeoutMs 
)

For early development only. This creates a connected Socket. Socket should be closed when the socket is no longer needed.

If a network goes down, sockets created using that network also gets killed.

Parameters
findCloudletReply(FindCloudletReply): A FindCloudletReply for the current location.
appPort(AppPort): This is the AppPort you want to connect to, based on the unmapped internal port number.
portNum(int): This is the internal port number of where the AppInst is actually made available in a particular cloudlet region. It may not match the appPort mapped public port number. If <= 0, it defaults to the public port.
timeoutMs(int): timeout in milliseconds. 0 for infinite.
Returns
Future<Socket>: null can be returned if the network does not exist, or if network switching is disabled.

Example

Future<Socket> sf = null;
Socket s = null;
try {
sf = me.getAppConnectionManager().getTcpSocket(reply, port, 4000, 10000);
s = sf.get();
} catch (ExecutionException ee) {
// Expected invalid port.
assertTrue("Expected invalid port", ee.getCause() instanceof InvalidPortException);
} catch (Exception e) {
assertFalse("Unexpected Exception hit: " + e.getMessage(), true);
} finally {
closeSocket(s);
}

◆ getTcpSslSocket()

Future<SSLSocket> com.mobiledgex.matchingengine.AppConnectionManager.getTcpSslSocket ( final AppClient.FindCloudletReply  findCloudletReply,
final AppPort  appPort,
final int  portNum,
final int  timeoutMs 
)

Returns a Future with a TCP SSL Socket from a default SSL Socket Factory, created on a cellular data network interface, where available. The created socket is already connected. If the timeout is 0, it will not timeout. Socket should be closed when the socket is no longer needed. If a network goes down, sockets created using that network also gets killed.

Parameters
findCloudletReply(FindCloudletReply)
appPort(AppPort): This is the AppPort you want to connect to, based on the unmapped internal port number.
portNum(int): This is the internal port number of where the AppInst is actually made available in a particular cloudlet region. It may not match the appPort mapped public port number. If <= 0, it defaults to the first public port.
timeoutMs(int): timeout in milliseconds. 0 for infinite.
Returns
Future<SSLSocket>: May be null if SSL socket factory cannot be created, or if it cannot find a cellular network.

◆ getUdpSocket()

Future<DatagramSocket> com.mobiledgex.matchingengine.AppConnectionManager.getUdpSocket ( final AppClient.FindCloudletReply  findCloudletReply,
final AppPort  appPort,
final int  portNum,
final int  timeoutMs 
)

Returns a UDP socket bound and connected to cellular interface. Socket should be closed when the socket is no longer needed.

If a network goes down, sockets created using that network also gets killed.

Parameters
findCloudletReply(FindCloudletReply): A FindCloudletReply for the current location.
appPort(AppPort): This is the AppPort you want to connect to, based on the unmapped internal port number.
portNum(int): This is the internal port number of where the AppInst is actually made available in a particular cloudlet region. It may not match the appPort mapped public port number. If <= 0, it defaults to the first public port.
timeoutMs(int): timeout in milliseconds. 0 for infinite.
Returns
Future<DatagramSocket>: null can be returned if the network does not exist, or if network switching is disabled.

Example

try {
Future<DatagramSocket> dsf = me.getAppConnectionManager().getUdpSocket(reply, uport, 8008, 10000);
DatagramSocket ds = dsf.get(); // Wrong port, and we know it doesn't exist.
assertTrue("Not bound!", ds.isBound() == true);
} catch (ExecutionException ee) {
// 8009 isn't valid.
assertTrue("Expected Connection Exception!", ee.getCause() instanceof ConnectException);
} catch (InterruptedException ie) {
assertFalse("Not expected InterruptedException: " + ie.getMessage(), true);
}