Wiki

Clone wiki

luci2 / Create a new Remote Service in Java

  1. Create a new Maven Project:
    Create a new Maven Project
  2. Edit the pom.xml: NOTE: since luci is not published to a maven repo yet, you need to make sure the dependencies are available in you local maven repo - by either checking out the luci projects and build them with maven, download the jars from the download section and add them to your local maven repo or add the jars to your java build path with the traditional java/eclipse means.

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>your</groupId>
      <artifactId>project</artifactId>
      <version>0.0.1-SNAPSHOT</version>
    
      <dependencies>
    
            <dependency>
                <groupId>org.luci</groupId>
                <artifactId>connect</artifactId>
                <!-- edit the version here -->
                <version>0.0.1-SNAPSHOT</version>
            </dependency>
    
        </dependencies>
    </project>
    
  3. Create a class that extends LcRemoteService:
    remoteService.png

  4. Your file should look like this:

    /**
     * Your license information
     */
    package project;
    
    import org.json.JSONObject;
    
    import luci.connect.LcRemoteService;
    import luci.connect.Message;
    
    /**
     * 
     * @author you
     *
     */
    public class YourService extends LcRemoteService {
    
        /**
         * @return JSONObject specifying the required inputs
         */
        @Override
        protected JSONObject specifyInputs() {
            return null;
        }
    
        /**
         * @return JSONObject specifying the delivered outputs 
         */
        @Override
        protected JSONObject specifyOutputs() {
            return null;
        }
    
        /**
         * @return JSONObject representing an example call to facilitate reading of the input 
         * specification and avoid misunderstandings
         */
        @Override
        protected JSONObject exampleCall() {
            return null;
        }
    
        /**Allows clients to implement their own response handlers
         * @return the response handler associated with this client
         */
        @Override
        protected ResponseHandler getResponseHandler() {
            return new RemoteServiceResponseHandler(){
    
                public void processResponse(Message m) {
                    // services can call other services (invisible to 
                    // subscription/workflow managment) and need to 
                    // handle the RESPONSE
                }
    
                public void processError(Message m) {
                    // services can call other services (invisible to 
                    // subscription/workflow managment) and need to 
                    // handle ERRORS
                }
    
                public void processProgress(Message m) {
                    // services can call other services (invisible to 
                    // subscription/workflow managment) and need to 
                    // handle PROGRESS notifications
                }
    
                public void processResult(Message m) {
                    // services can call other services (invisible to 
                    // subscription/workflow managment) and need to 
                    // handle the RESULT
                }
    
                public void processRun(Message m) {
                    // actual implementation of your service
                }
    
                public void processCancel(Message m) {
                    // cancel the implementation                
                }   
            };
        }
    }
    
  5. Add a main method to run it:

        public static void main(String[] args){
            Log.set(Log.LEVEL_DEBUG);
            String hostname = "localhost";
            int port = 7654;
            if (args.length > 1) port = Integer.parseInt(args[1]);
            if (args.length > 0) hostname = args[0];
            System.out.println("registering at "+hostname+":"+port);
            YourService yourService = new YourService();
            new Thread(yourService).start();
            yourService.connect(hostname, port);
        }
    

Updated