# Automatically Injecting Robustness Statements into Distributed Applications
## 3 Proposed Approach for Improving Remote Calls  
### Overview  
When executing remote calls, the called services run on a different host, which can lead to delays due to relatively slower network communication, necessary security checks, data retrieval processes, and the potential workload of the remote server. To address these issues and improve performance and robustness, one effective strategy is to execute remote operations in a newly dedicated thread. Through offloading these operations to a separate thread, it becomes possible to handle them asynchronously, hence allowing the caller to execute other tasks, hence avoiding a blocking call, and then improving overall robustness, efficiency and responsiveness.  
To facilitate the development of a distributed application that includes such an advanced handling of remote calls, the overall strategy of the proposed approach entails analyzing the source code of a distributed Java application to identify remote calls, and then transforming them into new code fragments that preserve the application's intended behavior while enhancing performance, such as through asynchronous execution and improved resilience to network faults.  
Implementing asynchronous calls requires careful consideration of concurrency issues, such as race conditions and data consistency. Proper synchronization mechanisms must be employed to ensure that concurrent threads do not interfere with each other, leading to unpredictable behavior or data corruption. Conducting a data dependency analysis can help mitigate these risks by examining the instructions following the calls that are changed into asynchronous and inserting the necessary synchronization measures.  
Figure 1 illustrates the three main phases of the proposed approach: (i) remote call identification, which parses the Java code to locate all instances of remote calls (including, e.g., RMIs); (ii) data dependency analysis and code transformation, which replaces remote  
calls with new fragments of code that enhance the application's functionalities; (iii) project document update, which involves verifying and updating the application dependencies.  
Firstly, to identify remote calls in a Java source file, the code needs to be parsed. We used the JavaParser library ([[https://javaparser.org](https://javaparser.org)]([https://javaparser.org](https://javaparser.org)), accessed on 18 September 2024), which simplifies this task. A custom Visitor class was developed to examine the code and find classes implementing the Remote interface (defined in the standard Java library under java.rmi) and the track method calls on such classes. Secondly, the found method calls are then further analyzed to address potential synchronization, allowing for data consistency, and refactored to ensure asynchronous behavior and fault tolerance. Finally, application dependencies are updated using Apache Maven. The pom.xml file is modified to include all necessary dependencies for the transformed code, ensuring that the application's functionality is maintained.  
The final output of this process is represented by the transformed source code that, upon compilation and execution, offers enhanced functionalities. The following sections detail the three phases of the proposed approach, respectively.