db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sanket Sharma" <sanketsha...@gmail.com>
Subject Re: How to add a new service to Derby?
Date Mon, 10 Jul 2006 11:32:43 GMT
Okay, for the impatient first, here is how to add a service to derby.
We'll code a new service called HelloService for Derby. The steps you
need to follow are:

Step 1: First, code the interface for your service. This is the
interface that Derby will use to locate your service and other modules
will use to call methods on your service. Put this interface.java file
in appropriate folder in org.apache.derby.iapi.services folder. I just
created another folder under services folder called hello and saved my
interface file there.
Here are then contents of the file:

HelloService.java

package org.apache.derby.iapi.services.hello;

public interface HelloService {

	public void sayHello();
}

Step 2: Once you have created HelloService.java in hello folder, you
need to write a class that implements this interface. So, we go and
create a folder called hello under org.apache.derby.impl.services and
put the following implementation file there. The file is called
HelloServiceImpl.java
Here are the contents:


package org.apache.derby.impl.services.hello;

/* Make sure you declare the class as PUBLIC!!!! */

public class HelloServiceImpl implements HelloService {


static {
 	System.out.println("HelloService initialized");
}

public HelloServiceImpl() {

	System.out.println("HelloService Object created and initialized");
}

public void sayHello() {
	System.out.println("Hello Derby World!");
}

Save the file.

Step 3: The final step is to add an entry to modules.properties
located in org.apache.derby folder.

add the following lines at the bottom of the file.

derby.module.HelloService=org.apache.derby.impl.services.hello.HelloServiceImpl
cloudscape.config.HelloService=all

Step 4:Thats all you need to do to add your service. To test your
service, you have the following options:

	Option 1: You can add the following lines in BaseMonitor.java located
under org.apache.derby.impl.services.monitor
	(Line no 373, below TimerFactory line.)
	//Print a message
	System.out.println("Starting Hello Service...");
	//load the service module
	helloService = (HelloService)
Monitor.startSystemModule("org.apache.derby.iapi.hello.HelloService");
	//call a method on the service
	helloService.sayHello();
	
	Please make sure you declared helloService as type HelloService
before you use it.

	Option 2: You can load the service by specifying the following at
runtime at the shell prompt
		java -Dderby.service.hello=org.apache.deryby.iapi.hello.HelloService
	You wont be able to call methods on your service this way, but it
should still show you the initialization messages etc.

Thats it! You've just added your own service to Derby. All you need to
do now is to compile and build jars for your new derby. The procedure
is simple and does not vary. Ant scripts are written so as to copile
and build everything inside the services directory automatically. Once
you have the derby.jar, try running the SimpleApp.java supplied on the
derby website .

One point I would like to state is that the actual implementation
procedure will vary slightly across implementations and depends more
on the kind of service you are trying to implement. For example, if
you are trying to implement a persistant service, than you will have
to implement the interface called ModuleControl etc.

Let me know If I've missed out anything.

Comments welcome.

Regards,
Sanket Sharma



On 7/7/06, Andreas Korneliussen <Andreas.Korneliussen@sun.com> wrote:
> Hi,
> Sorry nobody answered your question.
>
> I am quite interested in this topic myself. Did you find the information
> in any Derby doc on the website, or did you find it by reading the code
> / javadoc ?
>
> Would you mind posting your findings to the derby-dev list ?
>
> Regards
> --Andreas
>
>
> Sanket Sharma wrote:
> > Okay...I've figured out the way.
> >
> > Thanks anyways,
> >
> > Regards,
> > Sanket
> >
> > On 7/6/06, Sanket Sharma <sanketsharma@gmail.com> wrote:
> >> Hi,
> >>
> >> I was tinkering with Derby code for some time with JMX in my mind. I
> >> was wondering if there is a "recommended way" of adding new services
> >> to derby?
> >>
> >> The code documentation in Monitor.java says describes following ways
> >> to boot services (please correct me if I'm wrong):
> >>
> >> 1) having a property in the application properties or the system (JVM)
> >> set.
> >>
> >>         derby.service.service name=class name
> >>         e.g.
> >> 2) Added to the properties automatically by the class
> >> org.apache.derby.jdbc.EmbeddedDriver e.g.
> >> derby.service.service name=class name
> >>
> >> Does this imply that If I have to add JMX as non persistan service,
> >> all I need to do is:
> >> 1)Create my java files and classes that implement the classes
> >> 2) Assuming my class name is SystemManager,
> >>  java -Dderby.service.systemmanager = SystemManager?
> >>
> >> 3) Make sure SystemManager.class and related modules are in my classpath?
> >>
> >> or alternatively, add the same identifier and classname/factory name
> >> to application properties.
> >>
> >> Is that really all I need to do? I'm sure I'm missing something there.
> >>
> >> Regards,
> >> Sanket
> >>
>
>

Mime
View raw message