DevPortal

How do I add or plug in a Service to Pramati Server?


Table of Contents


What is a Service?

A service in Pramati Server is an infrastructure component which plugs into the Pramati Server kernel and exposes a set of well-defined features/functionalites.

Custom services are services which are not part of the services bundled with Server distribution. The services framework allows you to create a service which can be deployed on Pramati Server. Customizing your own service allows you to perform operations within the runtime environment of the server.

Who wants to plug in a Service to Pramati Server?

The following kind of audience may want to plug in a service to Pramati Server:

How do I implement a Service?

Use the following steps to create a custom service:
  1. Implement the Service interface. Service interface is located in pramati_spi.jar.

    This is how the interface looks like:
    package com.pramati.services.framework;
    	public interface Service
    	{
    	 String getName();
    	 void initialize(ServiceData serviceData) throws ServiceInitializationException;
    	 void setContext(ServiceContext serviceContext);
    	 boolean refreshProperties(Properties properties);
    	 void start() throws ServiceStartException;
    	 void stop() throws ServiceStopException;
    	 boolean destroy();
    	}
    	
    For example, consider the sample for MyService provided below:
    package com.pramati.practice.services;
    
    	import com.pramati.services.framework.ServiceData;
    	import com.pramati.services.framework.ServiceContext;
    	import com.pramati.services.framework.exception.ServiceInitializationException;
    	import com.pramati.services.framework.exception.ServiceStartException;
    	import com.pramati.services.framework.exception.ServiceStopException;
    	import com.pramati.practice.services.admin.*;
    
    	import javax.management.*;
    	import java.util.Properties;
    
    	/**
    	 * MyService is a custom service that can be plugged into Pramati Server.
    	 */
    	public class MyService implements com.pramati.services.framework.Service {
    
    	    private ServiceContext serviceContext;
    	    private ServiceData serviceData;
    	    private static final String NAME = "MY SERVICE";
    
    	    /**
    	     * To get the name of the service
    	     * @return Service name as a String
    	     */
    	    public String getName()
    	    {return NAME;}
    
    	    public void initialize(ServiceData serviceData) throws ServiceInitializationException
    	    {this.serviceData=serviceData;
    	     System.out.println("Initialize invoked");}
    
    	    public void setContext(ServiceContext serviceContext)
    	    {this.serviceContext=serviceContext;}
    
    	    public boolean refreshProperties(Properties properties)
    	    {return false;}
    
    	    public void start() throws ServiceStartException
    	    {System.out.println("My Service Started");}
    
    	    public void stop() throws ServiceStopException
    	    {System.out.println("My Service Stopped");}
    
    	    public boolean destroy()
    	    {System.out.println("My Service Destroyed");
    	     return true;}
    	}
    	
  2. Compile the class and package it into a .jar file.
  3. Modify the server-config.xml to reflect the service implementation. When restarted, Pramati Server Kernel loads the Service implementation com.pramati.services.MyService class definition from Server system classpath (not in lib/ext).

    <service name="MyService" enabled="true" class-name="com.pramati.practice.services.MyService"></service>
    A Service may declare to depend on other existing services. Pramati Server Kernel starts the dependencies before starting your Service, if there is no circular dependency.
  4. Alternative to editing the server-config.xml. You can add your custom Service from Pramati Server Management Console. Goto Configure > Custom Services. Click Add.
  5. One can also add a new Service to Pramati Server Kernel by using the API on com.pramati.services.j2ee.spi.admin.KernelMBean.

How do I add manageability to my Service?


© Pramati Technologies 2007 Runs on Pramati Server | Feedback | Legal