MoreMotion Base Classes / Interfaces

Top  Previous  Next

MoreMotion API provides base classes and Interfaces to develop Action Services, Data Service and Processes.

Action Services

Data Services

Process Classes

 

Clear Separation of the Data and the Representation

No matter what type is it, a MoreMotion Java Class never generates the response by itself as long as the response is a web page. The generating the response is the task of the MoreMotion. The responsibility of a service class is to do its work and populate the data in ADOM objects as the result of the work.

The data in ADOM objects are converted to XML by MoreMotion when they are needed by the page to be displayed. In contrary to a JSP or ASP programmer, a MoreMotion programmer never thinks about how the data he populates is rendered on the user interface.

MoreMotion service classes are "Single Threaded"

Please be aware that a MoreMotion Service Class (Action Service, Data Service) is executed as single threaded, that means MoreMotion will load only one instance of the service class and call it for all the requests.

You have to be careful when using the private data members of the class since they are shared by all the requests. Otherwise you may encounter unpredictable results.

Avoid this

 

  class MyService implements ActionService {

 

    private int count = 0;  

    // 'count' is a private data member and it will be 

    // shared by all the simultaneous executions 

 

    public void doService(ActionServiceContext asc) 

    throws ServiceException, java.io.IOException {

      try {

        count = request.getParameterAsInt("count",0);

        increaseCount();

       

      } catch (Exception e) {

        e.printStackTrace();

        throw new ServiceException(e.getMessage());

      }

    }

 

    private void increaseCount() {

      count++; // Can produce an unpredictable result.

    }

 

  }

 

The Correct Way

 

  class MyService implements ActionService {

 

    public void doService(ActionServiceContext asc) 

    throws ServiceException, java.io.IOException {

      try {

 

        // 'count' is an automatic variable

        int count = request.getParameterAsInt("count",0);  

        // Automatic variables are created in the stack, 

        // therefore it is safe even for the simultaneous executions 

 

        // Do not use private members, instead use automatic variables and pass 

        // them as parameters.

        count = increaseCount(count);

       

      } catch (Exception e) {

        e.printStackTrace();

        throw new ServiceException(e.getMessage());

      }

    }

 

    private void increaseCount(int value) {

      return value + 1;

    }

 

  }