private void createReplicas(String[] names) throws Exception { int lastAvailablePort = 1024;  Replica[] replicas = new Replica[ names.length ]; for( int i = 0; i < names.length; i ++ ) { int replicationPort = AvailablePortFinder.getNextAvailable( lastAvailablePort ); lastAvailablePort = replicationPort + 1;  replicas[ i ] = new Replica( new ReplicaId( names[ i ] ), new InetSocketAddress( "127.0.0.1", replicationPort )); }  Random random = new Random(); String homeDirectory = System.getProperty( "java.io.tmpdir" ) + File.separator + "mitosis-" + Long.toHexString( random.nextLong() );  for( int i = 0; i < replicas.length; i ++ ) { Replica replica = replicas[ i ]; String replicaId = replicas[ i ].getId().getId(); MutableStartupConfiguration ldapCfg = new MutableStartupConfiguration( replicaId );  File workDir = new File( homeDirectory + File.separator + ldapCfg.getInstanceId() );  ldapCfg.setShutdownHookEnabled( false ); ldapCfg.setWorkingDirectory( workDir );  List interceptorCfgs = ldapCfg.getInterceptorConfigurations();  ReplicationConfiguration replicationCfg = new ReplicationConfiguration(); replicationCfg.setReplicaId( replica.getId() ); replicationCfg.setServerPort( replica.getAddress().getPort() ); for( int j = 0; j < replicas.length; j ++ ) { if( replicas[ j ] != replica ) { replicationCfg.addPeerReplica( replicas[ j ] ); } }  ReplicationService replicationService = new ReplicationService(); replicationService.setConfiguration( replicationCfg );  MutableInterceptorConfiguration interceptorCfg = new MutableInterceptorConfiguration(); interceptorCfg.setName( "mitosis" ); interceptorCfg.setInterceptor( replicationService );  interceptorCfgs.add( interceptorCfg );  ldapCfg.setInterceptorConfigurations( interceptorCfgs );
private void createReplicas( String[] names ) throws Exception { int lastAvailablePort = 1024;
	private void createReplicas(String[] names) throws Exception	{		int lastAvailablePort = 1024;				Replica[] replicas = new Replica[ names.length ];		for( int i = 0; i < names.length; i ++ )		{			int replicationPort = AvailablePortFinder.getNextAvailable( lastAvailablePort );			lastAvailablePort = replicationPort + 1;						replicas[ i ] = new Replica(					new ReplicaId( names[ i ] ),					new InetSocketAddress( "127.0.0.1", replicationPort ));		}				Random random = new Random();		String homeDirectory =			System.getProperty( "java.io.tmpdir" ) + File.separator +			"mitosis-" + Long.toHexString( random.nextLong() );				for( int i = 0; i < replicas.length; i ++ )		{			Replica replica = replicas[ i ];		    String replicaId = replicas[ i ].getId().getId();			MutableStartupConfiguration ldapCfg =		    	new MutableStartupConfiguration( replicaId );		    		    File workDir = new File( homeDirectory + File.separator + ldapCfg.getInstanceId() );		    			ldapCfg.setShutdownHookEnabled( false );			ldapCfg.setWorkingDirectory( workDir );						List interceptorCfgs = ldapCfg.getInterceptorConfigurations();						ReplicationConfiguration replicationCfg = new ReplicationConfiguration();			replicationCfg.setReplicaId( replica.getId() );			replicationCfg.setServerPort( replica.getAddress().getPort() );			for( int j = 0; j < replicas.length; j ++ )			{				if( replicas[ j ] != replica )				{					replicationCfg.addPeerReplica( replicas[ j ] );				}			}						ReplicationService replicationService = new ReplicationService();			replicationService.setConfiguration( replicationCfg );						MutableInterceptorConfiguration interceptorCfg = new MutableInterceptorConfiguration();			interceptorCfg.setName( "mitosis" );			interceptorCfg.setInterceptor( replicationService );								interceptorCfgs.add( interceptorCfg );						ldapCfg.setInterceptorConfigurations( interceptorCfgs );			if( workDir.exists() )			{				FileUtils.deleteDirectory( workDir );			}				        Hashtable env = new Hashtable( ldapCfg.toJndiEnvironment() );	        env.put( Context.SECURITY_PRINCIPAL, "uid=admin,ou=system" );	        env.put( Context.SECURITY_CREDENTIALS, "secret" );	        env.put( Context.SECURITY_AUTHENTICATION, "simple" );	        env.put( Context.PROVIDER_URL, "" );	        env.put( Context.INITIAL_CONTEXT_FACTORY, CoreContextFactory.class.getName() );	        	        // Initialize the server instance.	        LdapContext context = new InitialLdapContext( env, null );	        contexts.put( replicaId, context );		}	}