KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > security > test > opends > OpenDSService


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.test.security.test.opends;
8
9 import java.net.URL JavaDoc;
10 import java.security.AccessController JavaDoc;
11 import java.security.PrivilegedAction JavaDoc;
12
13 import org.jboss.system.ServiceMBeanSupport;
14 import org.opends.server.core.DirectoryServer;
15  
16
17 /**
18  * XMBean Service for OpenDS integration
19  * @author <a HREF="mailto:Anil.Saldhana@jboss.org">Anil Saldhana</a>
20  * @version $Revision$
21  * @since Sep 13, 2006
22  */

23 public class OpenDSService extends ServiceMBeanSupport
24 {
25    public static String JavaDoc objectName = "jboss.test:service=opends";
26    
27    private String JavaDoc newline = (String JavaDoc)
28             AccessController.doPrivileged(new GetSystemPropertyAction("line.separator"));
29    
30    
31    /**
32     * Print some information about the DS (eg: connections etc)
33     * @return
34     */

35    public String JavaDoc printDiagnostics()
36    {
37      StringBuilder JavaDoc sb = new StringBuilder JavaDoc();
38      sb.append("Maximum concurrent client connections allowed:");
39      sb.append(DirectoryServer.getMaxAllowedConnections());
40      sb.append(newline).append("# of client connections currently established:");
41      sb.append(DirectoryServer.getCurrentConnections());
42      return sb.toString();
43    }
44    
45    /**
46     * Restart the Directory Server
47     */

48    public void restart()
49    {
50      DirectoryServer.restart(getClass().getName(), "DS restart");
51    }
52    
53    protected void startService() throws Exception JavaDoc
54    {
55       super.startService();
56       
57       //Get the location of the conf directory
58
String JavaDoc confLoc = (String JavaDoc)AccessController.doPrivileged(
59             new GetSystemPropertyAction("jboss.server.config.url"));
60       
61       /**
62        * There seems to be a need to maintain the opends directory
63        * structure. We will create it under the conf dir
64        */

65       ClassLoader JavaDoc tcl = Thread.currentThread().getContextClassLoader();
66       URL JavaDoc ldif = tcl.getResource("opends/config/config.ldif");
67       log.debug("config ldif="+ldif);
68       
69       String JavaDoc[] strArr = new String JavaDoc[] {"--configClass",
70                                     "org.opends.server.config.ConfigFileHandler",
71                                     "--configFile",
72                                     ldif.getPath()};
73       //Start the OpenDS
74
DirectoryServer.main(strArr);
75    }
76
77    protected void stopService() throws Exception JavaDoc
78    {
79       log.debug("Asking DS to shutdown");
80       DirectoryServer.shutDown(getClass().getName(), "Shut down DS");
81    }
82    
83    
84    /**
85     *
86     * A GetSystemPropetyAction.
87     *
88     * @author <a HREF="anil.saldhana@jboss.com">Anil Saldhana</a>
89     * @version $Revision: 1.1 $
90     */

91    public class GetSystemPropertyAction implements PrivilegedAction JavaDoc
92    {
93       private String JavaDoc property;
94
95       public GetSystemPropertyAction(String JavaDoc prop)
96       {
97          this.property = prop;
98       }
99
100       public Object JavaDoc run()
101       {
102          return System.getProperty(property);
103       }
104    }
105 }
Popular Tags