env.put( "java.naming.provider.url", "ldap://" + host + ":" + port );
env.put( "java.naming.security.principal", "uid=admin,ou=system" );
env.put( "java.naming.security.credentials", password );
env.put( "java.naming.security.authentication", "simple" );
LdapContext ctx = new InitialLdapContext( env, null );
if ( !isQuietEnabled() )
{
System.out.println( "Connection to the server established.\n"
+ "Sending extended request and blocking for shutdown:" );
isWaiting = true;
Thread t = new Thread( new Ticker() );
t.start();
}
try
{
ctx.extendedOperation( new GracefulShutdownRequest( 0, timeOffline, delay ) );
isSuccess = true;
}
catch ( Throwable t )
{
/*
* Sometimes because of timing issues we show a failure when the
* shutdown has succeeded so we should check if the server is up
* before we set success to false.
*/
try
{
new InitialLdapContext( env, null );
isSuccess = false;
System.err.print( "shutdown request failed with error: " + t.getLocalizedMessage() );
}
catch ( CommunicationException e )
{
isSuccess = true;
}
}
isWaiting = false;
ctx.close();
}