The "Loadable" POWER of the ArcGIS Runtime SDK!!

445
0
03-13-2018 05:00 AM
KwasiAsante1
New Contributor III
1 0 445

The release of version 100.x of the ArcGIS Runtime SDK brought with it a plethora of advantages and advancements. Among these is the loadable pattern for asynchronous resources. This pattern provides a common theme for resources in loading metadata in an asynchronous manner in the ArcGIS Runtime API across all the supported platforms. Hence resources that lend to this pattern are referred to as "loadable". This coding pattern also provides an important mechanism to retry loading in the event that something goes wrong and the initial loading fails. This is particularly critical in cases where resources are accessed over a network (which is basically the majority of cases in an enterprise-GIS infrastructure). 

Developers do not need to worry about concurrency issues as the pattern handles concurrent and repeated requests when loading resources in order to account for cases where the same resource instance is to be shared around different parts of an application. One can cancel loading a resource in the event of a slow response or simply access the loading state (load status) of the resource with the getLoadStatus method on the Loadable interface. This returns the status of the loadable resource which can then be used for decisions ranging from informing the app-user of an operation's state, allow for providing logic to retry loading, writing easily debuggable code etc. 

One of these decisions is illustrated in the code snippets below;

/**

* Load geodabase file from disk; add a listener, check load status and make appropriate decision

*/

Geodatabase geodatabase = new Geodatabase(selectedFile.getAbsolutePath());
geodatabase.loadAsync();
geodatabase.addDoneLoadingListener(()->{
if(geodatabase.getLoadStatus() == LoadStatus.LOADED){
List<GeodatabaseFeatureTable> listOfFeatureTables = geodatabase.getGeodatabaseFeatureTables();
featureLayer = new FeatureLayer(listOfFeatureTables.get(0)); //instance variable instantiation
featureLayer.loadAsync(); 
}else if(geodatabase.getLoadError() != null)
featureLayer.retryLoadAsync();
});

This code is part of a larger demo application meant to illustrate some of the powerful features of the ArcGIS Runtime SDK. You can fork the repo at GitHub - mrasante/LoadableDemo. Please note that this is a bigger application meant to demonstrate the power of the ArcGIS Runtime platform as relates to the loadable pattern, so certain aspects might not be necessarily relevant to the pattern itself. Nonetheless it serves a the purpose of showing the pattern in a working application. 

Give it a try; post issues, comments, complaints, critiques etc. You can also catch me live at DevSummit 2018 – Palm Springs, CA; stop by during my demo theater presentation (https://devsummit2018.schedule.esri.com/schedule/2079770770) which will feature some focus on the loadable and task-jobs paradigm in the Runtime SDK. 

The completed code used for the dev summit presentation is now updated at the above github repo. Please fork it and try it out; as I indicated earlier, you can report issues or areas you need further explanation on and I will do my best to respond as soon as possible.