AbacusUtil Docs | Download | Javadoc | FAQ | Community

Deploy Once, Run Anytime

RemoteExecutor is designed to run the Big/Heavy data processes on N servers in parallel. Thinking about the scenarios: There are N data sources(e.g. Log files) located in N servers, It's required to do some analysis quickly on the data. The best/straight forward way is to write the program/code in local IDE and run them on the target servers, without keep deploying every time when the code/logic is changed. Here are the steps:

  • Step 1: Deploy com.landawn.abacus.http.JavaExecutionServlet under Tomcat on target remote servers with below configuration: web.xml. JDK 7 or above (JDK 8 for Lambda/stream) is required. (One of the easy way to prepare the application xxx*.war file is: 1) Unzip the abacus.war in HelloAbacusUtil.zip; 2) Put the common libraries and configuration files which are required to run the tasks in the folders: ./WEB-INF/lib/ and ./WEB-INF/config/; 3) Replace the abacus-util-*.jar file with the latest abacus-util-*.jar file. 4) Zip folders: ./META-INF/ and ./WEB-INF/ with the application name: xxx.war; 5) Put the xxx.war file under folder: ./Tomcat Home Directory/webapps/; 6) Start Tomcat. Refer to abacus.war in HelloAbacusUtil.zip)
  • <?xml version="1.0" encoding="ISO-8859-1"?>
    <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    	version="2.5">
    
    	<display-name>AbacusUtil</display-name>
    	
    	 <servlet>
    	     <servlet-name>javaExecution</servlet-name>
    	     <servlet-class>com.landawn.abacus.http.JavaExecutionServlet</servlet-class>
    	 </servlet>
    	 
    	 
    	 <servlet-mapping>
    	     <servlet-name>javaExecution</servlet-name>
    	     <url-pattern>/javaExecution/*</url-pattern>
     	</servlet-mapping>
    </web-app>
    


  • Step 2: Program in local IDE
  • public class LogParser implements RemoteTask<String, Integer> {
    
        // count key with "abc".
        @Override
        public Integer run(String filePath) {
            final File file = new File(filePath);
            final MutableInt count = new MutableInt();
    
            IOUtil.parse(file, line -> {
                if (line == null) {
                    return;
                }
    
                if (N.fromJSON(Map.class, line).containsKey("abc")) {
                    count.increment();
                }
            });
    
            return count.getValue();
        }
    }
    


  • Step 3: Execute on remote servers
  • public class RemoteExecutorTest {
        static final String url = "http://localhost:8080/abacus/javaExecution";
        static final RemoteExecutor remoteExecutor = new RemoteExecutor(url);
    
        @Test
        public void parseMLog() {
            // Preparing file for test
            final String mLogFilePath = "C:/logs/mLog.txt";
            final File file = new File(mLogFilePath);
            IOUtil.writeLines(file, N.asList("abc:123", "ef:56"));
    
            // Running the task on remote server just in one line!
            remoteExecutor.execute(LogParser.class, mLogFilePath);
        }
    }