View Javadoc

1   /*
2    * Copyright (c) 2002 Peter Antman, Teknik i Media  <peter.antman@tim.se>
3    *
4    * $Id: XindiceService.java,v 1.1.1.1 2004/05/19 14:10:47 pra Exp $
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Lesser General Public
8    * License as published by the Free Software Foundation; either
9    * version 2 of the License, or (at your option) any later version
10   * 
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Lesser General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Lesser General Public
17   * License along with this library; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19   */
20  package org.backsource.xindice.server;
21  import java.io.File;
22  import javax.management.ObjectName;
23  import javax.management.MBeanServer;
24  import javax.management.MalformedObjectNameException;
25  
26  import org.backsource.jmx.ServiceMBeanSupport;
27  import org.backsource.jmx.ObjectNameFactory;
28  
29  import org.apache.xindice.server.Kernel;
30  /***
31   * An embedded Xindice server to be run i JBoss.
32   *
33   * <p>The server will use jboss.server.data.dir and append xindice to set up xindice.home if the property XindiceHome is not set in the MBean. This is the prefered method to do it, but is dependant on a correct setup of a jboss-service or manuall setup of the db/xindice directory in the JBoss server i use. by setting <b>XindiceHome</b> it is possible to use an external home, for example a directopry where you have installed a stand alone version of Xindice.</p>
34   <p><b>openorb.home</b> will be set to the embedded home: db/xindice/openorb, but it seems as if it works agains the db/xindice dir instead. This needs to be further checked.</p>
35   <p><b>Installation</b> To be able to redeploy this service it seems as if the openorb.jar must be placed in the central lib, for example server/default/lib.
36   </p>
37   
38   
39   * @author <a href="mailto:pra@tim.se"></a>
40   * @version $Revision: 1.1.1.1 $
41   * @jmx:mbean name="xindice:service=XindiceServer" extends="org.backsource.jmx.ServiceMBean"
42   */
43  
44  public class XindiceService extends ServiceMBeanSupport implements org.backsource.xindice.server.XindiceServiceMBean{
45     public static final javax.management.ObjectName OBJECT_NAME = ObjectNameFactory.create("xindice:service=XindiceServer");
46     private ObjectName name = OBJECT_NAME;
47     private String xindiceHome;
48     private String xindiceDb;
49     private Kernel kernel;
50     
51     public XindiceService (){
52        
53     }
54     protected ObjectName getObjectName(MBeanServer server, ObjectName name)
55        throws MalformedObjectNameException
56     {
57        if ( name != null) {
58           this.name = name;
59        } // end of if ()
60  
61        return name;
62     }
63  
64     /***
65      * @jmx:managed-attribute
66      */
67     public void setXindiceHome(String xindiceHome) {
68        this.xindiceHome = xindiceHome;
69     }
70  
71     /***
72      * Dont use this, only for testing!
73      * @jmx:managed-attribute
74      */
75     public void setXindiceDb(String xindiceDb) {
76        this.xindiceDb = xindiceDb;
77     }
78  
79     protected void startService()
80        throws Exception
81     {      
82        String db = System.getProperty("jboss.server.data.dir");
83        xindiceDb = db +"/xindice";
84  
85        if ( xindiceHome != null && xindiceHome.length() >0) {
86           log.info("Setting xindice.home to an external home: " + xindiceHome);
87           System.setProperty("xindice.home",xindiceHome);
88        } else {
89            log.info("Setting xindice.home embedded home: " + xindiceDb);
90            System.setProperty("xindice.home",xindiceDb);
91        } // end of else
92             
93        // This does not seem to work, have to have config files in xindice.home/config to!
94        System.setProperty("openorb.home","file:"+xindiceDb+"/openorb");
95        File cfg = new File(new File( System.getProperty("xindice.home")), "/config/system.xml");
96        log.info("Starting Xindice in home: " + System.getProperty("xindice.home"));
97        kernel = new Kernel(cfg.getAbsolutePath(), false);
98     }
99     
100    protected void stopService()
101       throws Exception
102    {
103       if ( kernel != null) {
104          kernel.shutDown(1, false);
105       } // end of if ()
106       
107 
108    }
109 }// XindiceService