KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > embed > jboss > OzoneService


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// Copyright (C) 1997-@year@ by Per Nyfelt. All rights reserved.
5
// $Id: OzoneService.java,v 1.3 2003/11/29 16:19:28 per_nyfelt Exp $
6
package org.ozoneDB.embed.jboss;
7
8 import javax.naming.Context JavaDoc;
9 import javax.naming.InitialContext JavaDoc;
10
11 import org.jboss.naming.NonSerializableFactory;
12 import org.jboss.system.ServiceMBeanSupport;
13 import org.ozoneDB.LocalDatabase;
14 import org.ozoneDB.OzoneInterface;
15
16 /**
17  * Starts an Ozone Object server in the JMX context of JBoss.
18  * Ozone is accessed through JNDI as follows:
19  * <p>
20  * <code> <br>
21  * OzoneInterface db = new InitialContext().lookup(OzoneInterface.class.getName()); <br>
22  * Object bla = db.objectForName("bla"); <br>
23  * </code>
24  * </p>
25  * <br> Date: Sep 3, 2002
26  * @author Per Nyfelt
27  */

28 public class OzoneService extends ServiceMBeanSupport implements OzoneServiceMBean {
29
30     private LocalDatabase db;
31     private String JavaDoc dbLocation;
32     private Context JavaDoc context;
33
34
35     public OzoneService() {
36         try {
37             context = new InitialContext JavaDoc();
38         } catch (Exception JavaDoc e) {
39             log.error("Failed to create JNDI context" + e);
40         }
41     }
42
43     public String JavaDoc getDbLocation() {
44         return dbLocation;
45     }
46
47     public void setDbLocation(String JavaDoc dbLocation) {
48         this.dbLocation = dbLocation;
49     }
50
51     protected void startService() throws Exception JavaDoc {
52         log.info("Ozone ObjectServer - Starting up...");
53         // we pin on the jboss directory to dbLocation to get the full path of the database
54
String JavaDoc dbDir = System.getProperty("jboss.server.home.dir") + dbLocation;
55         try {
56             log.info("** Starting Database in " + dbDir + " **");
57             db = new LocalDatabase();
58             if (!db.exists(dbDir)) {
59                 log.info("\tNo DB found, creating new Database...");
60                 db.create(dbDir);
61             }
62             String JavaDoc debugLevel = null;
63             db.open(dbDir, debugLevel);
64             log.info("** Database ready **");
65         } catch (Exception JavaDoc e) {
66             throw new RuntimeException JavaDoc("Failed to start database: " + e.getMessage());
67         }
68
69         NonSerializableFactory.rebind(context, OzoneInterface.class.getName(), db);
70     }
71
72     protected void stopService() throws Exception JavaDoc {
73         NonSerializableFactory.unbind(OzoneInterface.class.getName());
74         db.close();
75     }
76
77 }
78
Popular Tags