Embedded 1060 NetKernel Demonstration

Time Service

Description

The Time Service is a RESTful web service implemented by am instance of NetKernel embedded in a Servlet container.

The following are supported requests:

Request Description
/timeservice/ Returns this page
/timeservice/timezonelist.html Returns all supported time zone codes
/timeservice/timezonelist.xml Returns all supported time zone codes
/timeservice/timezone/<time-zone> Return the current time in the specified time zone.

Examples:

Request Description
/timeservice/timezone/America/Phoenix Returns time for Arizona
/timeservice/timezone/EST Return the time for US Eastern Standard Time
/timeservice/timezone/US/Hawaii Return the time for US Hawaii Time

Response

The response returned by this service is an HTML document with the time information formatted for display in a browser (except for timelist.xml, which is returned as an XML document).

If you enter an invalid timezone the service will default to GMT.

Version 1.0.0

Documentation

Embedding NetKernel

NetKernelServlet is used to embed an instance of NetKernel in a JEE Servlet container.

When the servlet is loaded by the container its init() method is called and the following occurs:

When any of the various do...() methods (e.g. doGet()) are called, the servlet creates a root request which is issued to the module urn:org:netkernel:servlet:http, which contains the ServletBridge overlay.

NetKernel Servlet Architecture

When the servlet's destroy() method is called, the servlet shuts down the instance of NetKernel.

Configuration

The NetKernelServlet is provided in the JAR file netkernelservlet.jar.

It is recommended that the servlet be configured using the <load-on-startup> element to ensure it is created when the container starts. A value of zero (0) will ensure it loads before other services. A typical configuration within the web.xml file is:

    <servlet>
      <description>Front end for embedded NetKernel</description>
      <display-name>NetKernel Servlet</display-name>
      <servlet-name>NetKernelServlet</servlet-name>
      <servlet-class>org.ten60.netkernel.servlet.NetKernelServlet</servlet-class>
      <init-param>
        <description>Sets the number of threads available to NetKernel microkernel</description>
        <param-name>netkernel.scheduler.threadcount</param-name>
        <param-value>6</param-value>
      </init-param>
      <load-on-startup>0</load-on-startup>
    </servlet>

The servlet-mapping section specifies which range of URLs will be forwarded to the servlet. In the case of this example, all URLs are directed to NetKernelServlet:

    <servlet-mapping>
      <servlet-name>NetKernelServlet</servlet-name>
      <url-pattern>/*</url-pattern>
    </servlet-mapping>

To boot NetKernel the following JAR files must be placed in the /WEB-INF/lib/ directory:

    urn.com.ten60.core.cache.se-1.x.x.jar
    urn.com.ten60.core.layer0-1.x.x.jar
    urn.com.ten60.core.module-standard-1.x.x.jar
    urn.com.ten60.core.netkernel.api-4.x.x.jar
    urn.com.ten60.core.netkernel.impl-4.x.x.jar

The modules.conf file is a text file that contains a list of modules that are to be loaded and commissioned by the NetKernel instance. The references are physical and can be either a JAR file or a directory. The following is the modules.conf file used for this demonstration:


    # list of module directory or JAR file names that are to be loaded for core NetKernel
    urn.org.netkernel.ext.layer1-1.x.x.jar
    urn.org.netkernel.ext.system-1.x.x.jar
    urn.org.netkernel.xml.core-1.x.x.jar
    urn.org.netkernel.lang.groovy-1.x.x.jar

    # Module for NetKernel Servlet adapter
    urn.org.netkernel.servlet.http/

    # Application modules next
    urn.org.netkernel.demo.timeservice/

    # These modules are required for the BEF support
    urn.org.netkernel.tpt.http-1.x.x.jar
    urn.org.netkernel.fulcrum.backend-1.x.x.jar
    urn.org.netkernel.ext.system-1.x.x.jar
    urn.org.netkernel.nkse.style-1.x.x.jar
    urn.org.netkernel.nkse.control.panel-2.x.x.jar
    urn.org.netkernel.ext.introspect-1.x.x.jar
    urn.org.netkernel.lang.xrl-1.x.x.jar
    urn.org.netkernel.mod.visualizer-1.x.x.jar

These modules must be physically located in the modules sub-directory of the web project.

The ServletFulcrum provided by the module urn:org:netkernel:servlet:http contains a dynamic import identifier ServletFulcrum. The time service demonstration module contains the resource res:/etc/system/SimpleDynamicImportHook.xml with the following contents in order to be imported into the ServletFulcrum and receive the Servlet requests:

    <connection>
      <type>ServletFulcrum</type>
    </connection>

The embedded version of NetKernel works very much like the NetKernel Standard Edition platform. Any number of modules may be imported into the ServletFulcrum and those modules may import other modules. The resources used for your modules in the servlet embedded instance of NetKernel are all live and can be modified within the container and will instantly be reflected in your application behavior. This means you could set up your development environment for this direct development or set it up to deploy to the container for each set of changes.

Time Service

The Time Service is implemented by the module urn:org:netkernel:demo:timeservice. A mapper overlay is used to define several web service and resource providing endpoints, such as res:/timeservice/timezonelist.html. The endpoints are mapped to Groovy scripts, the XSLT transformation service or mounted physical resources. Refer to the module itself for more information and documentation.

The Time Service provides the current local time for a specified time zone. The service is available at the URL .../timeservice/timezone/{time-zone}. For example, the URL .../timeservice/timezone/US/Hawaii will return the current time in Hawaii. A request for the resource timezonelist.html returns an HTML page with all supported time zones. The raw XML information is available from the resource timezonelist.xml

The Time Service is written using Groovy and and XSL transforms.

Code Description
time.gy Accessor for the timezonelist.xml resource.
timezonelist.gy Accessor returns an HTML document with the current time for the specified time zone.
formattimezones.xsl Formatting to convert timezonelist.xml into an HTML presentation.