use of com.mobiledgex.matchingengine.MatchingEngine in project edge-cloud-sampleapps by mobiledgex.
the class ComputerVisionRestUnitTest method registerAndFindCloudlet.
/*
* Return url of MobiledgeXSDK Demo backend
*/
private String registerAndFindCloudlet(Context ctx) {
MatchingEngine me = new MatchingEngine(ctx);
me.setMatchingEngineLocationAllowed(true);
me.setAllowSwitchIfNoSubscriberInfo(true);
try {
AppClient.RegisterClientRequest registerRequest = me.createDefaultRegisterClientRequest(ctx, orgName).setAppName(appName).setAppVers(appVers).build();
AppClient.RegisterClientReply registerReply = me.registerClient(registerRequest, GRPC_TIMEOUT_MS);
Thread.sleep(4000);
if (registerReply == null) {
Log.e(TAG, "Register Client reply is null");
return null;
}
if (registerReply.getStatus() != AppClient.ReplyStatus.RS_SUCCESS) {
Log.e(TAG, "Register Client reply status is " + registerReply.getStatus());
return null;
}
Location location = new Location("MobiledgeX_Loc_Sim");
location.setLatitude(latitude);
location.setLongitude(longitude);
AppClient.FindCloudletRequest findCloudletRequest = me.createDefaultFindCloudletRequest(ctx, location).build();
AppClient.FindCloudletReply findCloudletReply = me.findCloudlet(findCloudletRequest, GRPC_TIMEOUT_MS);
if (findCloudletReply == null) {
Log.e(TAG, "Find Cloudlet reply is null");
return null;
}
if (findCloudletReply.getStatus() != AppClient.FindCloudletReply.FindStatus.FIND_FOUND) {
Log.e(TAG, "Find Cloudlet find status is " + findCloudletReply.getStatus());
return null;
}
String fqdn = findCloudletReply.getFqdn();
Appcommon.AppPort appPort = findCloudletReply.getPorts(0);
int publicPort = appPort.getPublicPort();
String fqdnPrefix = appPort.getFqdnPrefix();
return "http://" + fqdnPrefix + fqdn + ":" + publicPort;
} catch (DmeDnsException dde) {
Log.e(TAG, "ExecutionException registering client. " + dde.getMessage());
return null;
} catch (ExecutionException ee) {
Log.e(TAG, "ExecutionException registering client. " + ee.getMessage());
return null;
} catch (InterruptedException ie) {
Log.e(TAG, "InterruptedException registering client. " + ie.getMessage());
return null;
} catch (PackageManager.NameNotFoundException nnfe) {
Log.e(TAG, "InterruptedException registering client. " + nnfe.getMessage());
return null;
}
}
use of com.mobiledgex.matchingengine.MatchingEngine in project edge-cloud-sampleapps by mobiledgex.
the class MainActivity method onResume.
@Override
public void onResume() {
super.onResume();
if (mRpUtil.getNeededPermissions(this).size() > 0) {
// Opens a UI. When it returns, onResume() is called again.
mRpUtil.requestMultiplePermissions(this);
return;
}
if (me == null) {
// ! [matchingengine_constructor]
// Permissions must be available. Check permissions upon OnResume(). Create a MobiledgeX MatchingEngine instance.
me = new MatchingEngine(this);
// ! [matchingengine_constructor]
// ! [enable_edgeevents]
// Register the class subscribing to EdgeEvents to the EdgeEventsBus (Guava EventBus interface).
// default is true.
me.setEnableEdgeEvents(true);
// ! [enable_edgeevents]
// ! [edgeevents_subsscriber_setup_example]
mEdgeEventsSubscriber = new EdgeEventsSubscriber();
me.getEdgeEventsBus().register(mEdgeEventsSubscriber);
// set a default config.
// There is also a parameterized version to further customize.
EdgeEventsConfig backgroundEdgeEventsConfig = me.createDefaultEdgeEventsConfig();
backgroundEdgeEventsConfig.latencyTestType = NetTest.TestType.CONNECT;
// This is the internal port, that has not been remapped to a public port for a particular appInst.
// 0 will favor the first TCP port if found for connect test.
backgroundEdgeEventsConfig.latencyInternalPort = 3765;
// Latency config. There is also a very similar location update config.
// Default is 0, which means test forever.
backgroundEdgeEventsConfig.latencyUpdateConfig.maxNumberOfUpdates = 0;
// The default is 30.
backgroundEdgeEventsConfig.latencyUpdateConfig.updateIntervalSeconds = 7;
backgroundEdgeEventsConfig.latencyThresholdTrigger = 186;
// ! [edgeevents_subsscriber_setup_example]
// backgroundEdgeEventsConfig.latencyUpdateConfig = null;
// backgroundEdgeEventsConfig.locationUpdateConfig = null; // app driven.
// ! [startedgeevents_example]
me.startEdgeEvents(backgroundEdgeEventsConfig);
// ! [startedgeevents_example]
}
if (mDoLocationUpdates) {
startLocationUpdates();
}
}
use of com.mobiledgex.matchingengine.MatchingEngine in project edge-cloud-sampleapps by mobiledgex.
the class MatchingEngineUnitTest method testRegisterClient.
@Test
public void testRegisterClient() {
Context ctx = getInstrumentation().getTargetContext();
MatchingEngine me = new MatchingEngine(ctx);
me.setMatchingEngineLocationAllowed(true);
me.setAllowSwitchIfNoSubscriberInfo(true);
registerClient(me, ctx);
}
use of com.mobiledgex.matchingengine.MatchingEngine in project edge-cloud-sampleapps by mobiledgex.
the class MatchingEngineUnitTest method testFindCloudletPerformance.
@Test
public void testFindCloudletPerformance() {
Context ctx = getInstrumentation().getTargetContext();
MatchingEngine me = new MatchingEngine(ctx);
me.setMatchingEngineLocationAllowed(true);
me.setAllowSwitchIfNoSubscriberInfo(true);
registerClient(me, ctx);
Location location = new Location("MobiledgeX_Loc_Sim");
location.setLatitude(latitude);
location.setLongitude(longitude);
try {
AppClient.FindCloudletRequest request = me.createDefaultFindCloudletRequest(ctx, location).build();
AppClient.FindCloudletReply reply = me.findCloudlet(request, GRPC_TIMEOUT_MS, MatchingEngine.FindCloudletMode.PERFORMANCE);
assertTrue("Unable to get FindCloudletReply", reply != null);
assertEquals("FindCloudlet status is " + reply.getStatus(), AppClient.FindCloudletReply.FindStatus.FIND_FOUND, reply.getStatus());
assertTrue("Fqdn in FindCloudletReply is " + reply.getFqdn(), reply.getFqdn() != null && reply.getFqdn() != "");
Log.i(TAG, "cloudlet location=" + reply.getCloudletLocation().getLatitude() + "," + reply.getCloudletLocation().getLongitude());
assertNotEquals("Latitude should not be 0.0, but it is", 0.0, reply.getCloudletLocation().getLatitude());
assertNotEquals("Longitude should not be 0.0, but it is", 0.0, reply.getCloudletLocation().getLongitude());
} catch (DmeDnsException dde) {
assertTrue("ExecutionException finding cloudlet. " + dde.getMessage(), false);
} catch (ExecutionException ee) {
assertTrue("ExecutionException finding cloudlet. " + ee.getMessage(), false);
} catch (InterruptedException ie) {
assertTrue("InterruptedException finding cloudlet. " + ie.getMessage(), false);
}
}
use of com.mobiledgex.matchingengine.MatchingEngine in project edge-cloud-sampleapps by mobiledgex.
the class MatchingEngineUnitTest method testGetAppInstList.
@Test
public void testGetAppInstList() {
Context ctx = getInstrumentation().getTargetContext();
MatchingEngine me = new MatchingEngine(ctx);
me.setMatchingEngineLocationAllowed(true);
me.setAllowSwitchIfNoSubscriberInfo(true);
registerClient(me, ctx);
Location location = new Location("MobiledgeX_Loc_Sim");
location.setLatitude(latitude);
location.setLongitude(longitude);
try {
AppClient.AppInstListRequest request = me.createDefaultAppInstListRequest(ctx, location).build();
AppClient.AppInstListReply reply = me.getAppInstList(request, GRPC_TIMEOUT_MS);
assertTrue("Unable to get AppInstListReply", reply != null);
assertEquals("AppInstListReply status is " + reply.getStatus(), AppClient.AppInstListReply.AIStatus.AI_SUCCESS, reply.getStatus());
} catch (DmeDnsException dde) {
assertTrue("ExecutionException getting app inst list. " + dde.getMessage(), false);
} catch (ExecutionException ee) {
assertTrue("ExecutionException getting app inst list. " + ee.getMessage(), false);
} catch (InterruptedException ie) {
assertTrue("InterruptedException getting app inst list. " + ie.getMessage(), false);
}
}
Aggregations