directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r373677 - in /directory/trunks: apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/gui/ apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/support/extended/ apacheds/standalone/daemon/src/main/java/org/...
Date Tue, 31 Jan 2006 02:57:31 GMT
Author: akarasulu
Date: Mon Jan 30 18:57:18 2006
New Revision: 373677

URL: http://svn.apache.org/viewcvs?rev=373677&view=rev
Log:
changes ...

 o added ability to unbind the server socket in diagnostic UI
 o added ability to rebind server socket 
 o besides notice of disconnect you can now send a graceful disconnect
 o throwing exceptions rather than swallowing them in ldap-common graceful codec
 o bootstrapper now cleans up shutdownPort file using a runtime hook
 o new frames for specifying graceful shutdown parameters on diagnostic ui
 o progress dialog when waiting for delay period


Added:
    directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/gui/ShutdownParamDialog.java
    directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/gui/ShutdownProgress.java
Modified:
    directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/gui/SessionsFrame.java
    directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/support/extended/GracefulShutdownHandler.java
    directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/support/extended/LaunchDiagnosticUiHandler.java
    directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/Bootstrapper.java
    directory/trunks/apacheds/standalone/installers/test/src/main/installers/log4j.properties
    directory/trunks/apacheds/standalone/simple/jndi/   (props changed)
    directory/trunks/apacheds/standalone/simple/jndi/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java
    directory/trunks/apacheds/tools/src/main/java/org/apache/ldap/server/dumptool/GracefulShutdown.java
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/extended/GracefulDisconnect.java
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/extended/GracefulShutdownRequest.java

Modified: directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/gui/SessionsFrame.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/gui/SessionsFrame.java?rev=373677&r1=373676&r2=373677&view=diff
==============================================================================
--- directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/gui/SessionsFrame.java
(original)
+++ directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/gui/SessionsFrame.java
Mon Jan 30 18:57:18 2006
@@ -2,9 +2,17 @@
 
 
 import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Point;
+import java.awt.Toolkit;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 
+import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JFrame;
 import javax.swing.JScrollPane;
@@ -18,9 +26,17 @@
 import javax.swing.event.ListSelectionEvent;
 import javax.swing.event.ListSelectionListener;
 
+import org.apache.ldap.common.message.extended.GracefulDisconnect;
 import org.apache.ldap.common.message.extended.NoticeOfDisconnect;
 import org.apache.ldap.server.protocol.SessionRegistry;
+import org.apache.ldap.server.protocol.support.extended.GracefulShutdownHandler;
+import org.apache.mina.common.CloseFuture;
+import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoSession;
+import org.apache.mina.common.WriteFuture;
+import org.apache.mina.registry.Service;
+import org.apache.mina.registry.ServiceRegistry;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -31,6 +47,13 @@
 {
     private static final Logger log = LoggerFactory.getLogger( SessionsFrame.class );
     private static final long serialVersionUID = -863445561454536133L;
+    private static final String REFRESH_COMMAND = "Refresh";
+
+    boolean isServiceBound = true;
+    private IoSession requestor;
+    private ServiceRegistry minaRegistry;
+    private Service ldapService;
+    private IoHandler ldapProvider;
     private JPanel jContentPane = null;
     private JPanel mainPanel = null;
     private JScrollPane sessionsPane = null;
@@ -60,8 +83,8 @@
     
     
     private IoSession selected;
-    
-    
+    private JMenuItem unbindItem = null;
+    private JMenuItem bindItem = null;
     /**
      * This is the default constructor
      */
@@ -333,6 +356,8 @@
             menuSession.add(getMenuSendNoD());
             menuSendNoD.setEnabled( false );
             menuSession.add(getShowRequests());
+            menuSession.add(getUnbindItem());
+            menuSession.add(getBindItem());
             showRequests.setEnabled( false );
         }
         return menuSession;
@@ -469,12 +494,14 @@
             {
                 public void actionPerformed(java.awt.event.ActionEvent e)
                 {
-                    selected.write( NoticeOfDisconnect.STRONGAUTHREQUIRED ); 
+                    WriteFuture future = selected.write( NoticeOfDisconnect.STRONGAUTHREQUIRED
); 
                     try
                     {
-                        Thread.sleep( 250 );
+                        future.join( 1000 );
+                        CloseFuture cfuture = selected.close();
+                        cfuture.join( 1000 );
                     }
-                    catch ( InterruptedException e1 )
+                    catch ( Exception e1 )
                     {
                         log.error( "", e1 );
                     }
@@ -649,8 +676,6 @@
 //        return jMenuItem4;
 //    }
 
-
-    private static final String REFRESH_COMMAND = "Refresh";
     /**
      * This method initializes jButton2	
      * 	
@@ -684,5 +709,201 @@
         closeItem.setEnabled( false );
         menuSendNoD.setEnabled( false );
         showRequests.setEnabled( false );
+        unbindItem.setEnabled( isServiceBound );
+        bindItem.setEnabled( ! isServiceBound );
+    }
+
+
+    public void setMinaRegistry( ServiceRegistry minaRegistry )
+    {
+        this.minaRegistry = minaRegistry;
+    }
+
+
+    public void setLdapService( Service ldapService )
+    {
+        this.ldapService = ldapService;
+    }
+    
+    
+    public void setRequestor( IoSession requestor )
+    {
+        this.requestor = requestor;
+    }
+
+
+    /**
+     * This method initializes jMenuItem	
+     * 	
+     * @return javax.swing.JMenuItem	
+     */
+    private JMenuItem getUnbindItem()
+    {
+        if ( unbindItem == null )
+        {
+            unbindItem = new JMenuItem();
+            unbindItem.setText("Unbind Service");
+            unbindItem.setEnabled( isServiceBound );
+            unbindItem.addActionListener( new java.awt.event.ActionListener()
+            {
+                public void actionPerformed( java.awt.event.ActionEvent e )
+                {
+                    int input = JOptionPane.showConfirmDialog( SessionsFrame.this, 
+                        "Selecting no will send a notice of disconnect ONLY.  " +
+                        "\nSelecting yes will send both.  Cancel will abort unbind.", 
+                        "Send graceful disconnect before disconnect notice?", 
+                        JOptionPane.YES_NO_CANCEL_OPTION );
+                    IoAcceptor acceptor = minaRegistry.getAcceptor( ldapService.getTransportType()
);
+                    List sessions = new ArrayList( acceptor.getManagedSessions( ldapService.getAddress()
) );
+//                    ServerLdapContext ctx;
+//                    try
+//                    {
+//                        ctx = ( ServerLdapContext ) SessionRegistry.getSingleton()
+//                            .getLdapContext( requestor, null, false );
+//                    }
+//                    catch ( NamingException ne )
+//                    {
+//                        JOptionPane.showInternalMessageDialog( SessionsFrame.this, 
+//                            ne.getMessage(), "Encountered an Error", JOptionPane.ERROR_MESSAGE
);
+//                        log.warn( "Could not access requestor's context.", ne );
+//                        return;
+//                    }
+//                    DirectoryService service = ctx.getService();
+//                    StartupConfiguration cfg = service.getConfiguration().getStartupConfiguration();
+                    // might add an exit vm feature using the default from the 
+                    // configuration property
+                    
+                    if ( input == JOptionPane.CANCEL_OPTION )
+                    {
+                        return;
+                    }
+                    else if ( input == JOptionPane.NO_OPTION )
+                    {
+                        GracefulShutdownHandler.sendNoticeOfDisconnect( sessions, requestor
);
+                        minaRegistry.unbind( ldapService );
+                        isServiceBound = false;
+                        unbindItem.setEnabled( isServiceBound );
+                        bindItem.setEnabled( ! isServiceBound );
+                        JOptionPane.showMessageDialog( SessionsFrame.this, "Ldap service
for " + 
+                            ldapService.getAddress() + " has been successfully unbound.",

+                            "Success!", JOptionPane.INFORMATION_MESSAGE );
+                        refresh();
+                        return;
+                    }
+                    else
+                    {
+                        ShutdownParamDialog dialog = new ShutdownParamDialog();
+                        setCenteredPosition( SessionsFrame.this, dialog );
+                        dialog.setModal( true );
+                        dialog.setVisible( true );
+                        
+
+                        if ( dialog.isSendCanceled() )
+                        {
+                            log.debug( "GracefulShutdown was canceled." );
+                            JOptionPane.showMessageDialog( SessionsFrame.this, "Shutdown
has been canceled.", 
+                                "Graceful Shutdown Aborted", JOptionPane.OK_OPTION );
+                            return;
+                        }
+                        
+                        log.debug( "GracefulShutdown parameters captured." );
+                        int timeOffline = dialog.getTimeOffline();
+                        int delay = dialog.getDelay();
+                        GracefulDisconnect graceful = new GracefulDisconnect( timeOffline,
delay );
+                        GracefulShutdownHandler.sendGracefulDisconnect( sessions, graceful,
requestor );
+                        minaRegistry.unbind( ldapService );
+                        isServiceBound = false;
+                        unbindItem.setEnabled( isServiceBound );
+                        bindItem.setEnabled( ! isServiceBound ); 
+                        
+                        // do progress dialog with bypass button to wait for delay time
+                        if ( delay > 0 )
+                        {
+                            ShutdownProgress progress = new ShutdownProgress();
+                            setCenteredPosition( SessionsFrame.this, progress );
+                            progress.setModal( true );
+                            progress.setTime( delay * 1000 );
+                            Thread t = new Thread( progress );
+                            t.start();
+                            progress.setVisible( true );
+                        }
+                        
+                        // now send the notice of disconnect
+                        GracefulShutdownHandler.sendNoticeOfDisconnect( sessions, requestor
);
+                        JOptionPane.showMessageDialog( SessionsFrame.this, "Ldap service
for " + 
+                            ldapService.getAddress() + " has been successfully unbound.",

+                            "Success!", JOptionPane.OK_OPTION );
+                        refresh();
+                    }
+                }
+            } );
+        }
+        return unbindItem;
+    }
+
+    
+    private void setCenteredPosition( JFrame frame, Component comp )
+    {
+        Point pt = new Point();
+        Toolkit tk = Toolkit.getDefaultToolkit();
+        Dimension screenSize = tk.getScreenSize();
+        pt.x = ( screenSize.width - frame.getWidth() ) / 2;
+        pt.y = ( screenSize.height - frame.getHeight() ) / 2;
+        
+        pt.x += ( frame.getWidth() - comp.getWidth() )/2;
+        pt.y += ( frame.getHeight() - comp.getHeight() )/2;
+        comp.setLocation( pt );
+    }
+
+
+    /**
+     * This method initializes jMenuItem	
+     * 	
+     * @return javax.swing.JMenuItem	
+     */
+    private JMenuItem getBindItem()
+    {
+        if ( bindItem == null )
+        {
+            bindItem = new JMenuItem();
+            bindItem.setText("Bind Service");
+            unbindItem.setEnabled( !isServiceBound );
+            bindItem.addActionListener( new java.awt.event.ActionListener()
+                {
+                    public void actionPerformed( java.awt.event.ActionEvent e )
+                    {
+                        try
+                        {
+                            minaRegistry.bind( ldapService, getLdapProvider() );
+                            JOptionPane.showMessageDialog( SessionsFrame.this, 
+                                "Ldap service " + ldapService.getAddress() + " has been successfully
bound.\n"
+                                + " Clients may now connect to the server once again.", 
+                                "Success!", JOptionPane.INFORMATION_MESSAGE );  
+                            isServiceBound = true;
+                            unbindItem.setEnabled( isServiceBound );
+                            bindItem.setEnabled( ! isServiceBound );
+                        }
+                        catch ( IOException e1 )
+                        {
+                            log.error( "failed to rebind ldap service", e1 );
+                            JOptionPane.showMessageDialog( SessionsFrame.this, e1.getMessage(),
"Error encountered!", 
+                                JOptionPane.ERROR_MESSAGE );
+                        }
+                    }
+                });
+        }
+        return bindItem;
+    }
+
+
+    public void setLdapProvider( IoHandler ldapProvider )
+    {
+        this.ldapProvider = ldapProvider;
+    }
+
+
+    public IoHandler getLdapProvider()
+    {
+        return ldapProvider;
     }
 }  //  @jve:decl-index=0:visual-constraint="10,10"

Added: directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/gui/ShutdownParamDialog.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/gui/ShutdownParamDialog.java?rev=373677&view=auto
==============================================================================
--- directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/gui/ShutdownParamDialog.java
(added)
+++ directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/gui/ShutdownParamDialog.java
Mon Jan 30 18:57:18 2006
@@ -0,0 +1,295 @@
+package org.apache.ldap.server.protocol.gui;
+
+
+import java.awt.BorderLayout;
+
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JDialog;
+import javax.swing.JButton;
+import javax.swing.JTextField;
+import javax.swing.BoxLayout;
+import javax.swing.JLabel;
+
+
+public class ShutdownParamDialog extends JDialog
+{
+    private static final long serialVersionUID = -6681747075037789868L;
+
+    private JPanel jContentPane = null;
+    private JPanel inputsPanel = null;
+    private JPanel buttonsPanel = null;
+    private JButton sendButton = null;
+    private JButton cancelButton = null;
+    private JPanel jPanel = null;
+    private JPanel jPanel1 = null;
+    private JLabel jLabel = null;
+    private JTextField timeOfflineField = null;
+    private JLabel jLabel1 = null;
+    private JTextField delayField = null;
+    private boolean canceled = true;
+
+    
+    /**
+     * This is the default constructor
+     */
+    public ShutdownParamDialog()
+    {
+        super();
+        initialize();
+    }
+
+    
+    public boolean isSendCanceled()
+    {
+        return canceled;
+    }
+    
+    
+    public int getTimeOffline()
+    {
+        return Integer.parseInt( timeOfflineField.getText() );
+    }
+    
+
+    public int getDelay()
+    {
+        return Integer.parseInt( delayField.getText() );
+    }
+    
+    
+    public boolean isCanceled()
+    {
+        return canceled;
+    }
+    
+
+    /**
+     * This method initializes this
+     * 
+     * @return void
+     */
+    private void initialize()
+    {
+        this.setSize(248, 171);
+        this.setTitle("Shutdown Parameters");
+        this.setContentPane( getJContentPane() );
+    }
+
+
+    /**
+     * This method initializes jContentPane
+     * 
+     * @return javax.swing.JPanel
+     */
+    private JPanel getJContentPane()
+    {
+        if ( jContentPane == null )
+        {
+            jContentPane = new JPanel();
+            jContentPane.setLayout( new BorderLayout() );
+            jContentPane.add(getJPanel(), java.awt.BorderLayout.CENTER);
+            jContentPane.add(getJPanel2(), java.awt.BorderLayout.SOUTH);
+        }
+        return jContentPane;
+    }
+
+
+    /**
+     * This method initializes jPanel	
+     * 	
+     * @return javax.swing.JPanel	
+     */
+    private JPanel getJPanel()
+    {
+        if ( inputsPanel == null )
+        {
+            inputsPanel = new JPanel();
+            inputsPanel.setLayout(null);
+            inputsPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));
+            inputsPanel.add(getJPanel3(), null);
+            inputsPanel.add(getJPanel1(), null);
+        }
+        return inputsPanel;
+    }
+
+
+    /**
+     * This method initializes jPanel	
+     * 	
+     * @return javax.swing.JPanel	
+     */
+    private JPanel getJPanel2()
+    {
+        if ( buttonsPanel == null )
+        {
+            buttonsPanel = new JPanel();
+            buttonsPanel.add(getJButton(), null);
+            buttonsPanel.add(getJButton2(), null);
+        }
+        return buttonsPanel;
+    }
+
+
+    /**
+     * This method initializes jButton	
+     * 	
+     * @return javax.swing.JButton	
+     */
+    private JButton getJButton()
+    {
+        if ( sendButton == null )
+        {
+            sendButton = new JButton();
+            sendButton.setText("Send");
+            sendButton.addActionListener( new java.awt.event.ActionListener()
+            {
+                public void actionPerformed( java.awt.event.ActionEvent e )
+                {
+                    int timeOffline = 0;
+                    try
+                    {
+                        timeOffline = Integer.parseInt( timeOfflineField.getText() );
+                        if ( timeOffline > 720 || timeOffline < 0 )
+                        {
+                            JOptionPane.showMessageDialog( ShutdownParamDialog.this,
+                                "Time Offline is out of range: 0 ... 720", "Range Problem",
JOptionPane.ERROR_MESSAGE );
+                            timeOfflineField.setText( "" );
+                            return;
+                        }
+                    }
+                    catch( NumberFormatException nfe )
+                    {
+                        JOptionPane.showMessageDialog( ShutdownParamDialog.this,
+                            "The value for Time Offline is not a number", "Not a Number",
JOptionPane.ERROR_MESSAGE );
+                        timeOfflineField.setText( "" );
+                        return;
+                    }
+                    int delay = 0;
+                    try
+                    {
+                        delay = Integer.parseInt( delayField.getText() );
+                        if ( delay > 86400 || delay < 0 )
+                        {
+                            JOptionPane.showMessageDialog( ShutdownParamDialog.this,
+                                "Delay is out of range: 0 ... 86400", "Range Problem", JOptionPane.ERROR_MESSAGE
);
+                            delayField.setText( "" );
+                            return;
+                        }
+                    }
+                    catch( NumberFormatException nfe )
+                    {
+                        JOptionPane.showMessageDialog( ShutdownParamDialog.this,
+                            "Delay is not a number", "Not a Number", JOptionPane.ERROR_MESSAGE
);
+                        delayField.setText( "" );
+                        return;
+                    }
+                    canceled = false;
+                    setVisible( false );
+                    dispose();
+                }
+            } );
+        }
+        return sendButton;
+    }
+
+
+    /**
+     * This method initializes jButton	
+     * 	
+     * @return javax.swing.JButton	
+     */
+    private JButton getJButton2()
+    {
+        if ( cancelButton == null )
+        {
+            cancelButton = new JButton();
+            cancelButton.setText("Cancel");
+            cancelButton.setSelected(true);
+            cancelButton.addActionListener( new java.awt.event.ActionListener()
+            {
+                public void actionPerformed( java.awt.event.ActionEvent e )
+                {
+                    canceled = true;
+                    setVisible( false );
+                    dispose();
+                    return;
+                }
+            } );
+        }
+        return cancelButton;
+    }
+
+
+    /**
+     * This method initializes jPanel	
+     * 	
+     * @return javax.swing.JPanel	
+     */
+    private JPanel getJPanel3()
+    {
+        if ( jPanel == null )
+        {
+            jLabel = new JLabel();
+            jLabel.setText("Minutes Offline: ");
+            jPanel = new JPanel();
+            jPanel.setLayout(new BoxLayout(getJPanel3(), BoxLayout.X_AXIS));
+            jPanel.setBounds(new java.awt.Rectangle(35,28,163,16));
+            jPanel.add(jLabel, null);
+            jPanel.add(getJTextField(), null);
+        }
+        return jPanel;
+    }
+
+
+    /**
+     * This method initializes jPanel1	
+     * 	
+     * @return javax.swing.JPanel	
+     */
+    private JPanel getJPanel1()
+    {
+        if ( jPanel1 == null )
+        {
+            jLabel1 = new JLabel();
+            jLabel1.setText("Seconds Delay: ");
+            jPanel1 = new JPanel();
+            jPanel1.setLayout(new BoxLayout(getJPanel1(), BoxLayout.X_AXIS));
+            jPanel1.setBounds(new java.awt.Rectangle(42,57,156,16));
+            jPanel1.add(jLabel1, null);
+            jPanel1.add(getJTextField1(), null);
+        }
+        return jPanel1;
+    }
+
+
+    /**
+     * This method initializes jTextField	
+     * 	
+     * @return javax.swing.JTextField	
+     */
+    private JTextField getJTextField()
+    {
+        if ( timeOfflineField == null )
+        {
+            timeOfflineField = new JTextField();
+        }
+        return timeOfflineField;
+    }
+
+
+    /**
+     * This method initializes jTextField1	
+     * 	
+     * @return javax.swing.JTextField	
+     */
+    private JTextField getJTextField1()
+    {
+        if ( delayField == null )
+        {
+            delayField = new JTextField();
+        }
+        return delayField;
+    }
+
+}  //  @jve:decl-index=0:visual-constraint="10,10"

Added: directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/gui/ShutdownProgress.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/gui/ShutdownProgress.java?rev=373677&view=auto
==============================================================================
--- directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/gui/ShutdownProgress.java
(added)
+++ directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/gui/ShutdownProgress.java
Mon Jan 30 18:57:18 2006
@@ -0,0 +1,155 @@
+package org.apache.ldap.server.protocol.gui;
+
+
+import java.awt.BorderLayout;
+import java.awt.Cursor;
+
+import javax.swing.JPanel;
+import javax.swing.JDialog;
+import javax.swing.JButton;
+import javax.swing.JProgressBar;
+
+
+public class ShutdownProgress extends JDialog implements Runnable
+{
+    private static final long serialVersionUID = 1L;
+    private JPanel jContentPane = null;
+    private JPanel jPanel = null;
+    private JButton jButton = null;
+    private JProgressBar jProgressBar = null;
+    private long timeMillis = 0;
+    private boolean bypass = false;
+    
+    
+    public void setTime( long millis )
+    {
+        this.timeMillis = millis;
+    }
+    
+    
+    public void run()
+    {
+        setCursor( Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR ) );
+        jProgressBar.setEnabled( true );
+        jProgressBar.setMinimum( 0 );
+        jProgressBar.setMaximum( ( int ) timeMillis );
+        jProgressBar.setValue( 0 );
+        jProgressBar.setStringPainted( true );
+        final long startTime = System.currentTimeMillis();
+        while ( System.currentTimeMillis() - startTime < timeMillis && ! bypass
)
+        {
+            try
+            {
+                Thread.sleep( 100 );
+            }
+            catch ( InterruptedException e )
+            {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+            jProgressBar.setString( ( timeMillis - ( System.currentTimeMillis() - startTime
) )/1000 + " seconds remaining ..." );
+            jProgressBar.setValue( jProgressBar.getValue() + 100 );
+            this.repaint();
+        }
+        
+        setCursor( null );
+        setVisible( false );
+        dispose();
+    }
+    
+    
+    /**
+     * This is the default constructor
+     */
+    public ShutdownProgress()
+    {
+        super();
+        initialize();
+    }
+
+
+    /**
+     * This method initializes this
+     * 
+     * @return void
+     */
+    private void initialize()
+    {
+        this.setSize(300, 104);
+        this.setContentPane( getJContentPane() );
+    }
+
+    
+    /**
+     * This method initializes jContentPane
+     * 
+     * @return javax.swing.JPanel
+     */
+    private JPanel getJContentPane()
+    {
+        if ( jContentPane == null )
+        {
+            jContentPane = new JPanel();
+            jContentPane.setLayout( new BorderLayout() );
+            jContentPane.add(getJPanel(), java.awt.BorderLayout.SOUTH);
+            jContentPane.add(getJProgressBar(), java.awt.BorderLayout.CENTER);
+        }
+        return jContentPane;
+    }
+
+
+    /**
+     * This method initializes jPanel	
+     * 	
+     * @return javax.swing.JPanel	
+     */
+    private JPanel getJPanel()
+    {
+        if ( jPanel == null )
+        {
+            jPanel = new JPanel();
+            jPanel.add(getJButton(), null);
+        }
+        return jPanel;
+    }
+
+
+    /**
+     * This method initializes jButton	
+     * 	
+     * @return javax.swing.JButton	
+     */
+    private JButton getJButton()
+    {
+        if ( jButton == null )
+        {
+            jButton = new JButton();
+            jButton.setText("Bypass Delay");
+            jButton.setText("Bypass Delay");
+            jButton.addActionListener( new java.awt.event.ActionListener()
+            {
+                public void actionPerformed( java.awt.event.ActionEvent e )
+                {
+                    bypass = true;
+                }
+            } );
+        }
+        return jButton;
+    }
+
+
+    /**
+     * This method initializes jProgressBar	
+     * 	
+     * @return javax.swing.JProgressBar	
+     */
+    private JProgressBar getJProgressBar()
+    {
+        if ( jProgressBar == null )
+        {
+            jProgressBar = new JProgressBar();
+        }
+        return jProgressBar;
+    }
+
+}  //  @jve:decl-index=0:visual-constraint="10,10"

Modified: directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/support/extended/GracefulShutdownHandler.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/support/extended/GracefulShutdownHandler.java?rev=373677&r1=373676&r2=373677&view=diff
==============================================================================
--- directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/support/extended/GracefulShutdownHandler.java
(original)
+++ directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/support/extended/GracefulShutdownHandler.java
Mon Jan 30 18:57:18 2006
@@ -124,53 +124,30 @@
         GracefulShutdownRequest gsreq = ( GracefulShutdownRequest ) req;
 
         // build the graceful disconnect message with replicationContexts
-        GracefulDisconnect notice = new GracefulDisconnect( gsreq.getTimeOffline(), gsreq.getDelay()
);
-        // @todo add the referral objects for replication contexts using setup code below
-//        DirectoryPartitionNexus nexus = service.getConfiguration().getPartitionNexus();
-//        Iterator list = nexus.listSuffixes( true );
-//        while ( list.hasNext() )
-//        {
-//            LdapName dn = new LdapName( ( String ) list.next() );
-//            DirectoryPartition partition = nexus.getPartition( dn );
-//        }
+        DirectoryPartitionNexus nexus = service.getConfiguration().getPartitionNexus();
+        GracefulDisconnect notice = getGracefulDisconnect( gsreq.getTimeOffline(), gsreq.getDelay(),
nexus );
 
         // send (synch) the GracefulDisconnect to each client before unbinding
         sendGracefulDisconnect( sessions, notice, requestor );
 
         // wait for the specified delay before we unbind the service 
-        if ( gsreq.getDelay() > 0 )
-        {
-            // delay is in seconds
-            long delay = gsreq.getDelay() * 1000;
-            long startTime = System.currentTimeMillis();
-            
-            while ( ( System.currentTimeMillis() - startTime ) < delay )
-            {
-                try
-                {
-                    Thread.sleep( 250 );
-                }
-                catch ( InterruptedException e )
-                {
-                    log.warn( "Got interrupted while waiting for delay before shutdown",
e );
-                }
-            }
-        }
+        waitForDelay( gsreq.getDelay() );
         
+        // -------------------------------------------------------------------
         // unbind the server socket for the LDAP service here so no new 
         // connections are accepted while we process this shutdown request
         // note that the following must be issued before binding the ldap
         // service in order to prevent client disconnects on service unbind:
         // 
-        // minaRegistry.getAcceptor( service.getTransportType() ).setDisconnectClientsOnUnbind(
false );
-        //
+        // minaRegistry.getAcceptor( service.getTransportType() )
+        //                       .setDisconnectClientsOnUnbind( false );
+        // -------------------------------------------------------------------
         serviceRegistry.unbind( ldapService );
         
         // -------------------------------------------------------------------
         // synchronously send a NoD to clients that are not aware of this resp
         // after sending the NoD the client is disconnected if still connected
         // -------------------------------------------------------------------
-
         sendNoticeOfDisconnect( sessions, requestor );
 
         // -------------------------------------------------------------------
@@ -180,8 +157,26 @@
         // preventing new connections; after recieving this response the 
         // requestor should disconnect and stop using the connection
         // -------------------------------------------------------------------
+        sendShutdownResponse( requestor, req.getMessageId() );
 
-        GracefulShutdownResponse msg = new GracefulShutdownResponse( req.getMessageId(),
ResultCodeEnum.SUCCESS );
+        if ( cfg.isExitVmOnShutdown() )
+        {
+            System.exit( 0 );
+        }
+        
+        return;
+    }
+    
+    
+    /**
+     * Sends a successful response.
+     * 
+     * @param requestor
+     * @param messageId
+     */
+    public static void sendShutdownResponse( IoSession requestor, int messageId )
+    {
+        GracefulShutdownResponse msg = new GracefulShutdownResponse( messageId, ResultCodeEnum.SUCCESS
);
         WriteFuture future = requestor.write( msg );
         future.join();
         if ( future.isWritten() )
@@ -196,13 +191,6 @@
             log.error( "Failed to write GracefulShutdownResponse to client: " + requestor.getRemoteAddress()
);
         }
         requestor.close();
-
-        if ( cfg.isExitVmOnShutdown() )
-        {
-            System.exit( 0 );
-        }
-        
-        return;
     }
     
     
@@ -213,7 +201,7 @@
      * @param msg the graceful disconnec extended request to send
      * @param requestor the session of the graceful shutdown requestor
      */
-    private void sendGracefulDisconnect( List sessions, GracefulDisconnect msg, IoSession
requestor )
+    public static void sendGracefulDisconnect( List sessions, GracefulDisconnect msg, IoSession
requestor )
     {
         List writeFutures = new ArrayList();
         
@@ -268,7 +256,7 @@
      * 
      * @param requestor the session of the graceful shutdown requestor
      */
-    private void sendNoticeOfDisconnect( List sessions, IoSession requestor )
+    public static void sendNoticeOfDisconnect( List sessions, IoSession requestor )
     {
         List writeFutures = new ArrayList();
         
@@ -310,6 +298,44 @@
             catch( Exception e )
             {
                 log.warn( "Failed to sent NoD.", e );
+            }
+        }
+    }
+
+
+    public static GracefulDisconnect getGracefulDisconnect( int timeOffline, int delay, DirectoryPartitionNexus
nexus )
+    {
+        // build the graceful disconnect message with replicationContexts
+        GracefulDisconnect notice = new GracefulDisconnect( timeOffline, delay );
+        // @todo add the referral objects for replication contexts using setup code below
+//        Iterator list = nexus.listSuffixes( true );
+//        while ( list.hasNext() )
+//        {
+//            LdapName dn = new LdapName( ( String ) list.next() );
+//            DirectoryPartition partition = nexus.getPartition( dn );
+//        }
+        return notice;
+    }
+
+
+    public static void waitForDelay( int delay )
+    {
+        if ( delay > 0 )
+        {
+            // delay is in seconds
+            long delayMillis = delay * 1000;
+            long startTime = System.currentTimeMillis();
+            
+            while ( ( System.currentTimeMillis() - startTime ) < delayMillis )
+            {
+                try
+                {
+                    Thread.sleep( 250 );
+                }
+                catch ( InterruptedException e )
+                {
+                    log.warn( "Got interrupted while waiting for delay before shutdown",
e );
+                }
             }
         }
     }

Modified: directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/support/extended/LaunchDiagnosticUiHandler.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/support/extended/LaunchDiagnosticUiHandler.java?rev=373677&r1=373676&r2=373677&view=diff
==============================================================================
--- directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/support/extended/LaunchDiagnosticUiHandler.java
(original)
+++ directory/trunks/apacheds/protocols/ldap/src/main/java/org/apache/ldap/server/protocol/support/extended/LaunchDiagnosticUiHandler.java
Mon Jan 30 18:57:18 2006
@@ -38,22 +38,30 @@
 import org.apache.ldap.server.partition.impl.btree.BTreeDirectoryPartition;
 import org.apache.ldap.server.partition.impl.btree.gui.PartitionFrame;
 import org.apache.ldap.server.protocol.ExtendedOperationHandler;
+import org.apache.ldap.server.protocol.LdapProtocolProvider;
 import org.apache.ldap.server.protocol.SessionRegistry;
 import org.apache.ldap.server.protocol.gui.SessionsFrame;
 import org.apache.mina.common.IoSession;
+import org.apache.mina.registry.Service;
+import org.apache.mina.registry.ServiceRegistry;
 
 
 public class LaunchDiagnosticUiHandler implements ExtendedOperationHandler
 {
+    private Service ldapService;
+    private ServiceRegistry minaRegistry;
+    private LdapProtocolProvider ldapProvider;
+    
+    
     public String getOid()
     {
         return LaunchDiagnosticUiRequest.EXTENSION_OID;
     }
 
     
-    public void handleExtendedOperation( IoSession session, SessionRegistry registry, ExtendedRequest
req ) throws NamingException 
+    public void handleExtendedOperation( IoSession requestor, SessionRegistry registry, ExtendedRequest
req ) throws NamingException 
     {
-        LdapContext ctx = registry.getLdapContext( session, null, false );
+        LdapContext ctx = registry.getLdapContext( requestor, null, false );
         ctx = ( LdapContext ) ctx.lookup( "" );
         
         if ( ctx instanceof ServerLdapContext )
@@ -63,11 +71,11 @@
             
             if ( ! slc.getPrincipal().getName().equalsIgnoreCase( DirectoryPartitionNexus.ADMIN_PRINCIPAL
) )
             {
-                session.write( new LaunchDiagnosticUiResponse( req.getMessageId(), ResultCodeEnum.INSUFFICIENTACCESSRIGHTS
) );
+                requestor.write( new LaunchDiagnosticUiResponse( req.getMessageId(), ResultCodeEnum.INSUFFICIENTACCESSRIGHTS
) );
                 return;
             }
 
-            session.write( new LaunchDiagnosticUiResponse( req.getMessageId() ) );
+            requestor.write( new LaunchDiagnosticUiResponse( req.getMessageId() ) );
 
             DirectoryPartitionNexus nexus = service.getConfiguration().getPartitionNexus();
             Iterator list = nexus.listSuffixes( true );
@@ -91,6 +99,10 @@
             }
             
             SessionsFrame sessions = new SessionsFrame();
+            sessions.setMinaRegistry( minaRegistry );
+            sessions.setLdapService( ldapService );
+            sessions.setRequestor( requestor );
+            sessions.setLdapProvider( ldapProvider.getHandler() );
             Point pos = getCenteredPosition( sessions );
             pos.y = launchedWindowCount*20 + pos.y;
             double multiplier = getAspectRatio() * 20.0;
@@ -100,7 +112,7 @@
             return;
         }
 
-        session.write( new LaunchDiagnosticUiResponse( req.getMessageId(), ResultCodeEnum.OPERATIONSERROR
) );
+        requestor.write( new LaunchDiagnosticUiResponse( req.getMessageId(), ResultCodeEnum.OPERATIONSERROR
) );
     }
     
     
@@ -120,5 +132,35 @@
         pt.x = ( screenSize.width - frame.getWidth() ) / 2;
         pt.y = ( screenSize.height - frame.getHeight() ) / 2;
         return pt;
+    }
+
+
+    public void setLdapService( Service ldapService )
+    {
+        this.ldapService = ldapService;
+    }
+
+
+    public Service getLdapService()
+    {
+        return ldapService;
+    }
+
+
+    public void setServiceRegistry( ServiceRegistry minaRegistry )
+    {
+        this.minaRegistry = minaRegistry;
+    }
+
+
+    public ServiceRegistry getMinaRegistry()
+    {
+        return minaRegistry;
+    }
+
+
+    public void setLdapProvider( LdapProtocolProvider ldapProvider )
+    {
+        this.ldapProvider = ldapProvider;
     }
 }

Modified: directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/Bootstrapper.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/Bootstrapper.java?rev=373677&r1=373676&r2=373677&view=diff
==============================================================================
--- directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/Bootstrapper.java
(original)
+++ directory/trunks/apacheds/standalone/daemon/src/main/java/org/apache/directory/server/standalone/daemon/Bootstrapper.java
Mon Jan 30 18:57:18 2006
@@ -305,11 +305,26 @@
                 String msg = "Shutdown port file " + shutdownPortFile + " exists. ";
                 msg += "\nEither an instance is already running or a previous run existed
abruptly.";
                 log.warn( msg );
+                shutdownPortFile.delete();
             }
             PrintWriter out = new PrintWriter( new FileWriter( shutdownPortFile ) );
             out.println( shutdownPort );
             out.flush();
             out.close();
+
+            // register shutdown hook in case we get shutdown abruptly without 
+            // cleaning up the shutdown file containing the shutdown port
+            Runtime.getRuntime().addShutdownHook( new Thread( "Bootstrapper cleanup" ) {
+                public void run()
+                {
+                    File shutdownPortFile = new File( layout.getRunDirectory(), SHUTDOWN_FILE
);
+                    if ( shutdownPortFile.exists() )
+                    {
+                        shutdownPortFile.delete();
+                        log.info( "Deleted shutdown port file: " + shutdownPort );
+                    }
+                }
+            } );
         }
         catch ( IOException e )
         {

Modified: directory/trunks/apacheds/standalone/installers/test/src/main/installers/log4j.properties
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/standalone/installers/test/src/main/installers/log4j.properties?rev=373677&r1=373676&r2=373677&view=diff
==============================================================================
--- directory/trunks/apacheds/standalone/installers/test/src/main/installers/log4j.properties
(original)
+++ directory/trunks/apacheds/standalone/installers/test/src/main/installers/log4j.properties
Mon Jan 30 18:57:18 2006
@@ -8,3 +8,5 @@
 log4j.logger.org.apache.ldap.common.name=WARN
 log4j.logger.org.springframework=WARN
 log4j.logger.org.apache.ldap.common.codec=WARN
+log4j.logger.org.apache.asn1=WARN
+

Propchange: directory/trunks/apacheds/standalone/simple/jndi/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon Jan 30 18:57:18 2006
@@ -1,4 +1,5 @@
 target
+.cdtproject
 *.ipr
 *.iws
 *.iml

Modified: directory/trunks/apacheds/standalone/simple/jndi/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/standalone/simple/jndi/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java?rev=373677&r1=373676&r2=373677&view=diff
==============================================================================
--- directory/trunks/apacheds/standalone/simple/jndi/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java
(original)
+++ directory/trunks/apacheds/standalone/simple/jndi/src/main/java/org/apache/ldap/server/jndi/ServerContextFactory.java
Mon Jan 30 18:57:18 2006
@@ -48,6 +48,7 @@
 import org.apache.ldap.server.protocol.ExtendedOperationHandler;
 import org.apache.ldap.server.protocol.LdapProtocolProvider;
 import org.apache.ldap.server.protocol.support.extended.GracefulShutdownHandler;
+import org.apache.ldap.server.protocol.support.extended.LaunchDiagnosticUiHandler;
 import org.apache.mina.common.DefaultIoFilterChainBuilder;
 import org.apache.mina.common.IoAcceptor;
 import org.apache.mina.common.IoFilterChainBuilder;
@@ -409,9 +410,16 @@
             
             if ( h instanceof GracefulShutdownHandler )
             {
-                GracefulShutdownHandler gsh = ( GracefulShutdownHandler ) h;
-                gsh.setLdapService( service );
-                gsh.setServiceRegistry( minaRegistry );
+                GracefulShutdownHandler graceful = ( GracefulShutdownHandler ) h;
+                graceful.setLdapService( service );
+                graceful.setServiceRegistry( minaRegistry );
+            }
+            else if ( h instanceof LaunchDiagnosticUiHandler )
+            {
+                LaunchDiagnosticUiHandler diagnostic = ( LaunchDiagnosticUiHandler ) h;
+                diagnostic.setLdapService( service );
+                diagnostic.setServiceRegistry( minaRegistry );
+                diagnostic.setLdapProvider( protocolProvider );
             }
         }
         

Modified: directory/trunks/apacheds/tools/src/main/java/org/apache/ldap/server/dumptool/GracefulShutdown.java
URL: http://svn.apache.org/viewcvs/directory/trunks/apacheds/tools/src/main/java/org/apache/ldap/server/dumptool/GracefulShutdown.java?rev=373677&r1=373676&r2=373677&view=diff
==============================================================================
--- directory/trunks/apacheds/tools/src/main/java/org/apache/ldap/server/dumptool/GracefulShutdown.java
(original)
+++ directory/trunks/apacheds/tools/src/main/java/org/apache/ldap/server/dumptool/GracefulShutdown.java
Mon Jan 30 18:57:18 2006
@@ -47,7 +47,7 @@
         env.put( "java.naming.security.authentication", "simple" );
 
         LdapContext ctx = new InitialLdapContext( env, null );
-        ctx.extendedOperation( new GracefulShutdownRequest( 0, 10, 5 ) );
+        ctx.extendedOperation( new GracefulShutdownRequest( 0, 10, 10 ) );
         ctx.close();
     }
 

Modified: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/extended/GracefulDisconnect.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/extended/GracefulDisconnect.java?rev=373677&r1=373676&r2=373677&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/extended/GracefulDisconnect.java
(original)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/extended/GracefulDisconnect.java
Mon Jan 30 18:57:18 2006
@@ -109,6 +109,7 @@
         catch ( DecoderException e )
         {
             log.error( "Failed to decode response value", e );
+            throw new RuntimeException( e );
         }
     }
     
@@ -142,6 +143,7 @@
         catch ( EncoderException e )
         {
             log.error( "Failed to encode message value.", e );
+            throw new RuntimeException( e );
         }
     }
     

Modified: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/extended/GracefulShutdownRequest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/extended/GracefulShutdownRequest.java?rev=373677&r1=373676&r2=373677&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/extended/GracefulShutdownRequest.java
(original)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/message/extended/GracefulShutdownRequest.java
Mon Jan 30 18:57:18 2006
@@ -96,7 +96,8 @@
         }
         catch ( DecoderException e )
         {
-            log.error( "failed to decode payload" );
+            log.error( "failed to decode payload", e );
+            throw new RuntimeException( e );
         }
     }
     
@@ -125,6 +126,7 @@
             catch ( EncoderException e )
             {
                 log.error( "Failed to encode payload GracefulShutdownRequest", e );
+                throw new RuntimeException( e );
             }
         }
         



Mime
View raw message