![]() |
|
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.
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;}
}
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.
server-config.xml. You can add your custom Service from Pramati Server Management Console. Goto Configure > Custom Services. Click Add.Service to Pramati Server Kernel by using the API on com.pramati.services.j2ee.spi.admin.KernelMBean
.
interface.CommandManager from the ServiceContext. A ServiceContext is associated with the service at service startup.
CommandManager cm = serviceContext.getKernel().getCommandManager(); cm.registerCommandHandler(myCommandHandler);
| © Pramati Technologies 2007 | Runs on Pramati Server | Feedback | Legal |