directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emmanuel Lecharny <elecha...@gmail.com>
Subject Re: Using DirectoryServiceFactory correcty
Date Thu, 25 Mar 2010 22:41:44 GMT
On 3/25/10 11:12 PM, Stefan Zoerner wrote:
> Hi all,
Hi Stefan,

I will respond in detail to you mail, but first, why not using the 
annotations to start a server ?

It's way easier, you don't have to worry about what's going on and what 
needs to be initialized first.

I'm also wondering if this should not be the standard way to start the 
server.

Let me give you an example :

package org.apache.directory.server.factory;

import org.apache.commons.io.FileUtils;
import org.apache.directory.server.core.DirectoryService;
import org.apache.directory.server.core.annotations.CreateDS;
import org.apache.directory.server.core.factory.DSAnnotationProcessor;

public class MyServer
{

     @CreateDS( name = "myServer" )
     public static void main( String[] args ) throws Exception
     {
         DirectoryService service = 
DSAnnotationProcessor.getDirectoryService();

         if ( service.isStarted() )
         {
             System.out.println( "Service started !" );
         }

         service.shutdown();
         FileUtils.deleteDirectory( service.getWorkingDirectory() );
     }
}

That should be enough to start a server.

You can of course define some more elements :

package org.apache.directory.server.factory;

import org.apache.commons.io.FileUtils;
import org.apache.directory.server.core.DirectoryService;
import org.apache.directory.server.core.annotations.CreateDS;
import org.apache.directory.server.core.factory.DSAnnotationProcessor;

public class MyBetterServer
{

     @CreateDS(
         name = "MethodDSWithPartition",
         partitions =
         {
             @CreatePartition(
                 name = "example",
                 suffix = "dc=example,dc=com",
                 contextEntry = @ContextEntry(
                     entryLdif =
                         "dn: dc=example,dc=com\n" +
                         "dc: example\n" +
                         "objectClass: top\n" +
                         "objectClass: domain\n\n" ),
                 indexes =
                 {
                     @CreateIndex( attribute = "objectClass" ),
                     @CreateIndex( attribute = "dc" ),
                     @CreateIndex( attribute = "ou" )
                 } )
         } )
     @CreateLdapServer (
         transports =
         {
             @CreateTransport( protocol = "LDAP" ),
             @CreateTransport( protocol = "LDAPS" )
         })
     public static void main( String[] args ) throws Exception
     {
         DirectoryService service = 
DSAnnotationProcessor.getDirectoryService();

         if ( service.isStarted() )
         {
             System.out.println( "Service started !" );
         }

         service.shutdown();
         FileUtils.deleteDirectory( service.getWorkingDirectory() );
     }
}


Does this sound good to you ?

-- 

Regards,
Cordialement,
Emmanuel L├ęcharny
www.nextury.com



Mime
View raw message