View Javadoc

1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.server;
21  
22  
23  import org.apache.directory.server.core.api.InstanceLayout;
24  import org.slf4j.Logger;
25  import org.slf4j.LoggerFactory;
26  
27  
28  /**
29   * The command line main for the server.
30   *
31   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
32   */
33  public class UberjarMain
34  {
35      /** A logger for this class */
36      private static final Logger LOG = LoggerFactory.getLogger( UberjarMain.class );
37  
38      /** The ApacheDS service */
39      ApacheDsService service;
40  
41  
42      /**
43       * Takes a single argument, the path to the installation home, which contains 
44       * the configuration to load with server startup settings.
45       *
46       * @param args the arguments
47       */
48      public static void main( String[] args ) throws Exception
49      {
50          if ( ( args != null ) && ( args.length == 1 ) )
51          {
52              UberjarMain uberjarMain = new UberjarMain();
53              
54              uberjarMain.start( args );
55          }
56          else
57          {
58              // TODO default to the current directory.
59              throw new IllegalArgumentException(
60                  "Program must be launched with 1 arguement, the path to the instance directory." );
61          }
62      }
63      
64      
65      public void start( String[] args )
66      {
67          // Creating ApacheDS service
68          service = new ApacheDsService();
69  
70          // Creating instance layouts from the argument
71          InstanceLayout instanceLayout = new InstanceLayout( args[0] );
72  
73          // Initializing the service
74          try
75          {
76              service.start( instanceLayout );
77          }
78          catch ( Exception e )
79          {
80              e.printStackTrace();
81              LOG.error( "Failed to start the service.", e );
82              System.exit( 1 );
83          }
84      }
85      
86      
87      public void stop()
88      {
89          if ( service != null )
90          {
91              try
92              {
93                  service.stop();
94              }
95              catch ( Exception e )
96              {
97                  e.printStackTrace();
98                  LOG.error( "Failed to start the service.", e );
99                  System.exit( 1 );
100             }
101         }
102     }
103 }