1 package org.ozoneDB.embed.jboss; 7 8 import javax.naming.Context ; 9 import javax.naming.InitialContext ; 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 28 public class OzoneService extends ServiceMBeanSupport implements OzoneServiceMBean { 29 30 private LocalDatabase db; 31 private String dbLocation; 32 private Context context; 33 34 35 public OzoneService() { 36 try { 37 context = new InitialContext (); 38 } catch (Exception e) { 39 log.error("Failed to create JNDI context" + e); 40 } 41 } 42 43 public String getDbLocation() { 44 return dbLocation; 45 } 46 47 public void setDbLocation(String dbLocation) { 48 this.dbLocation = dbLocation; 49 } 50 51 protected void startService() throws Exception { 52 log.info("Ozone ObjectServer - Starting up..."); 53 String 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 debugLevel = null; 63 db.open(dbDir, debugLevel); 64 log.info("** Database ready **"); 65 } catch (Exception e) { 66 throw new RuntimeException ("Failed to start database: " + e.getMessage()); 67 } 68 69 NonSerializableFactory.rebind(context, OzoneInterface.class.getName(), db); 70 } 71 72 protected void stopService() throws Exception { 73 NonSerializableFactory.unbind(OzoneInterface.class.getName()); 74 db.close(); 75 } 76 77 } 78 | Popular Tags |