Using the RMI APIs

With the Enterprise Edition of KonaKart you have the ability to communicate with its engines using RMI. The KonaKart Application Engine is registered in an RMI Registry at a specified port with the name "konakart.kkeng" and the KonaKart Admin Engine is registered with the name "konakart.kkadmineng".

By default the RMI Server servlet sections in the respective web.xml files for the konakart and konakartadmin webapps are commented out so no RMI services are enabled.

When enabled in the respective web.xml files, by default the RMI Regsitry is created on port 8790 and the two engines are bound to the above names.

Once enabled in the web.xml file, this default behavior can be controlled using the following configuration options in the respective webapp's web.xml: (the first one here is for the konakart webapp):


<!-- Servlet for RMI Server -->
<servlet>
    <servlet-name>KonakartRMIServlet</servlet-name>
    <display-name>KonaKart RMI Server</display-name>
    <description>KonaKart RMI Server</description>
    <servlet-class>
        com.konakart.rmi.KKRMIServer
    </servlet-class>
    <init-param>
        <!-- The port number where the RMI registry will listen -->
        <param-name>port</param-name>
        <param-value>8790</param-value>
    </init-param>
	<init-param>
        <!-- Enable or Disable the RMI interface -->
        <param-name>rmiEnabled</param-name>
        <param-value>true</param-value>
    </init-param>
    <load-on-startup>20</load-on-startup>
</servlet>

Very similar configuration options are available for the RMI version of the KonaKart Admin Engine. The konakartadmin webapp's web.xml contains this servlet definition:


<!-- Servlet for RMI Server -->
<servlet>
    <servlet-name>KonakartAdminRMIServlet</servlet-name>
    <display-name>KonaKartAdmin RMI Server</display-name>
    <description>KonaKartAdmin RMI Server</description>
    <servlet-class>
         com.konakartadmin.rmi.KKRMIAdminServer
    </servlet-class>
    <init-param>
        <!-- The port number where the RMI registry will listen -->
        <param-name>port</param-name>
        <param-value>8790</param-value>
    </init-param>
    <init-param>
        <!-- Enable or Disable the RMI interface -->
        <param-name>rmiEnabled</param-name>
        <param-value>true</param-value>
    </init-param>
    <load-on-startup>20</load-on-startup>
</servlet>

Both the application and admin engines are bound in the same RMI Registry (assuming the port numbers remain the same in the respective web.xml configuration files) which is created to listen at the specified port if it isn't found.

You need to specify the mode that the RMI engines will use in the konakart.properties and konakartadmin.properties files in their respective webapps.


# -----------------------------------------------------------------------------------
# KonaKart engine class used by the RMI services
# For the default engine use:   com.konakart.app.KKEng
# For the custom engine use:    com.konakart.app.KKCustomEng

konakart.app.rmi.engine.classname = com.konakart.app.KKEng

# -----------------------------------------------------------------------------------
# RMI Registry Location - This is used to locate (not create) the RMI Registry
# The definition for the port that the RMI Registry will listen on is in the web.xml

konakart.rmi.host = localhost
konakart.rmi.port = 8790

Note that the values at the bottom (port and host) are used to locate the RMI Registry and not to define where it will be created. (Hence you could consider this a "client-side" definition for using your RMI services). See the above section that explains that the port number where the RMI Registry is created is declared in the web.xml.

A very similar definition exists in the konakartadmin.properties file for the KonaKart Admin RMI Engine definiton:


# -----------------------------------------------------------------------------------
# KonaKart engine class used by the Admin RMI services
# For the default engine use:   com.konakartadmin.bl.KKAdmin
# For the custom engine use:    com.konakartadmin.app.KKAdminCustomEng

konakart.admin.rmi.engine.classname = com.konakartadmin.bl.KKAdmin

# -----------------------------------------------------------------------------------
# RMI Registry Location - This is used to locate (not create) the RMI Registry
# The definition for the port that the RMI Registry will listen on is in the web.xml

konakart.rmi.host = localhost
konakart.rmi.port = 8790

As with the SOAP versions of the engines, it's easy to select which one you would like to use in your code by simply specifying it by name at runtime.

A very simple example of this is provided in the GetProduct.java example provided in the download kit (under the java_api_examples directory). The example demonstrates how simple it is to select different engines and get the same result with each:


/*
 * Get an instance of the KonaKart engine and retrieve. The method called can be found in
 * BaseApiExample.java
 */
EngineConfig engConf = new EngineConfig();
engConf.setMode(getEngineMode());
engConf.setStoreId(getStoreId());
engConf.setCustomersShared(isCustomersShared());
engConf.setProductsShared(isProductsShared());
engConf.setCategoriesShared(isCategoriesShared());

/*
 * Instantiate a direct java Engine by name - to find a product
 * KKEngIf eng = new KKEng(engConf);
 */
KKEngIf eng = getKKEngByName("com.konakart.app.KKEng", engConf);
System.out.println("Get a product using the KKEng engine");
getProductUsingEngine(eng);
           
/*
 * Instantiate a java RMI Engine by name - to find a product
 * KKEngIf rmiEng = new KKRMIEng(engConf);
 */
KKEngIf rmiEng = getKKEngByName("com.konakart.rmi.KKRMIEng", engConf);
System.out.println("Get a product using the KKRMIEng engine");
getProductUsingEngine(rmiEng);
			

Notice how both of the engines implement the KKEngIf. If you code your solution to the KKEngIf interface (and KKAdminIf interface for the Admin Engine) you can delay the decision about which engine to use until runtime or (probably more likely) until you have decided how you wish to distribute your KonaKart solution over multiple machines.

The implementation of the getKKEngByName() call used in the above example is provided in the GetProduct.java source file.

Since all three of the application engines implement the same KKEngIf interface the javadoc is applicable for every one. The equivalent is true for the KKAdminIf javadoc.