Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  Licensed to the Apache Software Foundation (ASF) under one
   *  or more contributor license agreements.  See the NOTICE file
   *  distributed with this work for additional information
   *  regarding copyright ownership.  The ASF licenses this file
   *  to you under the Apache License, Version 2.0 (the
   *  "License"); you may not use this file except in compliance
   *  with the License.  You may obtain a copy of the License at
   *  
  *    http://www.apache.org/licenses/LICENSE-2.0
  *  
  *  Unless required by applicable law or agreed to in writing,
  *  software distributed under the License is distributed on an
  *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  *  KIND, either express or implied.  See the License for the
  *  specific language governing permissions and limitations
  *  under the License. 
  *  
  */
 package org.apache.directory.server;
 
 
 import java.io.File;
 
DirectoryServer bean used by both the daemon code and by the ServerMain here.

Author(s):
Apache Directory Project
Version:
$Rev: 596797 $
 
 public class Service implements DaemonApplication
 {
     private static final Logger LOG = LoggerFactory.getLoggerService.class );
     private Thread workerThread;
     private SynchWorker worker = new SynchWorker();
     private ApacheDS apacheDS;
 
 
     public void initInstallationLayout installString[] args ) throws Exception
     {
         printBanner();
         long startTime = System.currentTimeMillis();
 
         if ( args.length > 0 && new Fileargs[0] ).exists() ) // hack that takes server.xml file argument
         {
             .info"server: loading settings from "args[0] );
              = new FileSystemXmlApplicationContextnew Fileargs[0] ).toURI().toURL().toString() );
              = ( ApacheDS ) .getBean"apacheDS" );
         }
         else
         {
             .info"server: using default settings ..." );
             DirectoryService directoryService = new DefaultDirectoryService();
             directoryService.startup();
             SocketAcceptor socketAcceptor = new SocketAcceptornull );
             LdapServer ldapServer = new LdapServer();
             ldapServer.setSocketAcceptorsocketAcceptor );
             ldapServer.setDirectoryServicedirectoryService );
             ldapServer.start();
             LdapServer ldapsServer = new LdapServer();
             ldapsServer.setEnableLdapstrue );
             ldapsServer.setSocketAcceptorsocketAcceptor );
             ldapsServer.setDirectoryServicedirectoryService );
             ldapsServer.start();
              = new ApacheDSdirectoryServiceldapServerldapsServer );
         }
 
         if ( install != null )
         {
             .getDirectoryService().setWorkingDirectoryinstall.getPartitionsDirectory() );
         }
 
         .startup();
 
         if ( .getSynchPeriodMillis() > 0 )
         {
              = new Thread"SynchWorkerThread" );
         }
         
         if ( .isInfoEnabled() )
         {
             .info"server: started in {} milliseconds", ( System.currentTimeMillis() - startTime ) + "" );
         }
     }
 
     public DirectoryService getDirectoryService() {
        return .getDirectoryService();
    }
    public void synch() throws Exception
    {
        .getDirectoryService().sync();
    }
    public void start()
    {
        if (  != null )
        {
            .start();
        }
    }
    public void stopString[] args ) throws Exception
    {
        if (  != null )
        {
            . = true;
            synchronized ( . )
            {
                ..notify();
            }
    
            while ( .isAlive() )
            {
                .info"Waiting for SynchWorkerThread to die." );
                .join( 500 );
            }
        }
        if ( != null)
        {
            .close();
        }
        .shutdown();
    }
    public void destroy()
    {
    }
    
    class SynchWorker implements Runnable
    {
        final Object lock = new Object();
        boolean stop;
        public void run()
        {
            while ( ! )
            {
                synchronized (  )
                {
                    try
                    {
                        .wait.getSynchPeriodMillis() );
                    }
                    catch ( InterruptedException e )
                    {
                        .warn"SynchWorker failed to wait on lock."e );
                    }
                }
                try
                {
                    synch();
                }
                catch ( Exception e )
                {
                    .error"SynchWorker failed to synch directory."e );
                }
            }
        }
    }
    public static final String BANNER = "           _                     _          ____  ____   \n"
        + "          / \\   _ __   __ _  ___| |__   ___|  _ \\/ ___|  \n"
        + "         / _ \\ | '_ \\ / _` |/ __| '_ \\ / _ \\ | | \\___ \\   \n"
        + "        / ___ \\| |_) | (_| | (__| | | |  __/ |_| |___) |  \n"
        + "       /_/   \\_\\ .__/ \\__,_|\\___|_| |_|\\___|____/|____/   \n"
        + "               |_|                                                               \n";
    public static void printBanner()
    {
        ..println );
    }
New to GrepCode? Check out our FAQ X