From 39c1a97d2f879669121b081d73c82bc71b14b89a Mon Sep 17 00:00:00 2001 From: Pete Whelpton Date: Fri, 1 Apr 2022 17:53:48 +0100 Subject: [PATCH] Parameterize Tomcat startup/shutdown timeouts. Closes: #3898 --- .../tomcat5/customizer/Bundle.properties | 4 + .../customizer/CustomizerDataSupport.java | 40 +++++++ .../tomcat5/customizer/CustomizerStartup.form | 102 +++++++++++++++--- .../tomcat5/customizer/CustomizerStartup.java | 71 ++++++++++-- .../modules/tomcat5/optional/StartTomcat.java | 17 ++- .../tomcat5/util/TomcatProperties.java | 40 +++++++ 6 files changed, 250 insertions(+), 24 deletions(-) diff --git a/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/customizer/Bundle.properties b/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/customizer/Bundle.properties index bd8889b8ac96..91c7be4a849d 100644 --- a/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/customizer/Bundle.properties +++ b/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/customizer/Bundle.properties @@ -237,3 +237,7 @@ CustomizerDeployment.deplolymentTimeoutSpinner.accessible.description=Deployment CustomizerDeployment.deplolymentTimeoutLabel.tooltip=Time to wait before assuming a deployment has failed CustomizerDeployment.deplolymentTimeoutSpinner.tooltip=Time to wait before assuming a deployment has failed + +CustomizerStartup.timeoutsLabel.txt=Timeouts [s]\: +CustomizerStartup.startupTimeout.label=Startup: +CustomizerStartup.shutdownTimeout.label=Shutdown: \ No newline at end of file diff --git a/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/customizer/CustomizerDataSupport.java b/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/customizer/CustomizerDataSupport.java index 32b311c4ea46..87f03ee6799e 100644 --- a/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/customizer/CustomizerDataSupport.java +++ b/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/customizer/CustomizerDataSupport.java @@ -74,6 +74,8 @@ public class CustomizerDataSupport { private SpinnerNumberModel shutdownPortModel; private SpinnerNumberModel debugPortModel; private SpinnerNumberModel deploymentTimeoutModel; + private SpinnerNumberModel startupTimeoutModel; + private SpinnerNumberModel shutdownTimeoutModel; private ButtonModel driverDeploymentModel; // model dirty flags @@ -97,6 +99,8 @@ public class CustomizerDataSupport { private boolean debugPortModelFlag; private boolean deploymentTimeoutModelFlag; private boolean driverDeploymentModelFlag; + private boolean startupTimeoutModelFlag; + private boolean shutdownTimeoutModelFlag; private TomcatProperties tp; private TomcatManager tm; @@ -315,6 +319,24 @@ public void modelChanged() { store(); // This is just temporary until the server manager has OK and Cancel buttons } }); + + // startupTimeoutModel + startupTimeoutModel = new SpinnerNumberModel(tp.getStartupTimeout(), 1, Integer.MAX_VALUE, 1); + startupTimeoutModel.addChangeListener(new ModelChangeAdapter() { + public void modelChanged() { + startupTimeoutModelFlag = true; + store(); // This is just temporary until the server manager has OK and Cancel buttons + } + }); + + // shutdownTimeoutModel + shutdownTimeoutModel = new SpinnerNumberModel(tp.getShutdownTimeout(), 1, Integer.MAX_VALUE, 1); + shutdownTimeoutModel.addChangeListener(new ModelChangeAdapter() { + public void modelChanged() { + shutdownTimeoutModelFlag = true; + store(); // This is just temporary until the server manager has OK and Cancel buttons + } + }); } @@ -444,6 +466,14 @@ public SpinnerNumberModel getDeploymentTimeoutModel() { return deploymentTimeoutModel; } + public SpinnerNumberModel getStartupTimeoutModel() { + return startupTimeoutModel; + } + + public SpinnerNumberModel getShutdownTimeoutModel() { + return shutdownTimeoutModel; + } + public ButtonModel getDriverDeploymentModel() { return driverDeploymentModel; } @@ -554,6 +584,16 @@ private void store() { tp.setDriverDeployment(driverDeploymentModel.isSelected()); driverDeploymentModelFlag = false; } + + if (startupTimeoutModelFlag) { + tp.setStartupTimeout((Integer)startupTimeoutModel.getValue()); + startupTimeoutModelFlag = false; + } + + if (shutdownTimeoutModelFlag) { + tp.setShutdownTimeout((Integer)shutdownTimeoutModel.getValue()); + shutdownTimeoutModelFlag = false; + } } /** Create a Document initialized by the specified text parameter, which may be null */ diff --git a/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/customizer/CustomizerStartup.form b/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/customizer/CustomizerStartup.form index b1ae6c4b3c8e..ec6f4d9af390 100644 --- a/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/customizer/CustomizerStartup.form +++ b/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/customizer/CustomizerStartup.form @@ -21,13 +21,15 @@ --> -
+ + + @@ -84,12 +86,12 @@ - - - + + + @@ -133,12 +135,12 @@ - - - + + + @@ -159,15 +161,15 @@ + + + - - - @@ -188,15 +190,15 @@ + + + - - - @@ -273,7 +275,7 @@ - + @@ -295,5 +297,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/customizer/CustomizerStartup.java b/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/customizer/CustomizerStartup.java index 8e99d29b5172..b43ec79f649d 100644 --- a/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/customizer/CustomizerStartup.java +++ b/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/customizer/CustomizerStartup.java @@ -23,6 +23,7 @@ import javax.accessibility.AccessibleContext; import javax.swing.JFileChooser; import javax.swing.JSpinner; +import javax.swing.JSpinner.NumberEditor; import javax.swing.JTextField; import javax.swing.SwingUtilities; import org.openide.util.NbBundle; @@ -82,7 +83,7 @@ public CustomizerStartup(CustomizerDataSupport custData, File catalinaHome) { * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ - // //GEN-BEGIN:initComponents + // //GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; @@ -98,6 +99,11 @@ private void initComponents() { browseButton = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); jSpinner1 = new javax.swing.JSpinner(); + timeoutsLabel = new javax.swing.JLabel(); + startupTimeoutLabel = new javax.swing.JLabel(); + startupTimeoutSpinner = new javax.swing.JSpinner(); + shutdownTimeoutLabel = new javax.swing.JLabel(); + shutdownTimeoutSpinner = new javax.swing.JSpinner(); setLayout(new java.awt.GridBagLayout()); @@ -126,8 +132,8 @@ private void initComponents() { jTextField1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(CustomizerStartup.class, "ASCN_Script")); // NOI18N jTextField1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CustomizerStartup.class, "ASCD_Script")); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(jCheckBox1, org.openide.util.NbBundle.getMessage(CustomizerStartup.class, "TXT_CustomScript")); // NOI18N jCheckBox1.setModel(custData.getCustomScriptModel()); + org.openide.awt.Mnemonics.setLocalizedText(jCheckBox1, org.openide.util.NbBundle.getMessage(CustomizerStartup.class, "TXT_CustomScript")); // NOI18N jCheckBox1.addChangeListener(new javax.swing.event.ChangeListener() { public void stateChanged(javax.swing.event.ChangeEvent evt) { jCheckBox1StateChanged(evt); @@ -154,8 +160,8 @@ public void stateChanged(javax.swing.event.ChangeEvent evt) { jLabel4.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(CustomizerStartup.class, "ACSN_DebugTrans")); // NOI18N jLabel4.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CustomizerStartup.class, "ACSN_DebugTrans")); // NOI18N - org.openide.awt.Mnemonics.setLocalizedText(jCheckBox4, org.openide.util.NbBundle.getMessage(CustomizerStartup.class, "TXT_ForceShutdown")); // NOI18N jCheckBox4.setModel(custData.getForceStopModel()); + org.openide.awt.Mnemonics.setLocalizedText(jCheckBox4, org.openide.util.NbBundle.getMessage(CustomizerStartup.class, "TXT_ForceShutdown")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; @@ -166,9 +172,9 @@ public void stateChanged(javax.swing.event.ChangeEvent evt) { jCheckBox4.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(CustomizerStartup.class, "ASCN_ForceStop")); // NOI18N jCheckBox4.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CustomizerStartup.class, "ASCD_ForceStop")); // NOI18N + jRadioButton1.setModel(custData.getSharedMemModel()); buttonGroup1.add(jRadioButton1); org.openide.awt.Mnemonics.setLocalizedText(jRadioButton1, org.openide.util.NbBundle.getMessage(CustomizerStartup.class, "TXT_SharedMemName")); // NOI18N - jRadioButton1.setModel(custData.getSharedMemModel()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 4; @@ -179,9 +185,9 @@ public void stateChanged(javax.swing.event.ChangeEvent evt) { jRadioButton1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(CustomizerStartup.class, "ACSN_SharedMem")); // NOI18N jRadioButton1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CustomizerStartup.class, "ACSD_SharedMem")); // NOI18N + jRadioButton2.setModel(custData.getSocketModel()); buttonGroup1.add(jRadioButton2); org.openide.awt.Mnemonics.setLocalizedText(jRadioButton2, org.openide.util.NbBundle.getMessage(CustomizerStartup.class, "TXT_SocketPort")); // NOI18N - jRadioButton2.setModel(custData.getSocketModel()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 5; @@ -222,7 +228,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(CustomizerStartup.class, "TXT_NoteChangesTakeAffect")); // NOI18N gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; - gridBagConstraints.gridy = 6; + gridBagConstraints.gridy = 9; gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST; @@ -232,7 +238,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { jLabel2.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(CustomizerStartup.class, "ASCN_Note")); // NOI18N jLabel2.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CustomizerStartup.class, "ASCD_Note")); // NOI18N - jSpinner1.setFont(new java.awt.Font("Dialog", 0, 12)); + jSpinner1.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N jSpinner1.setModel(custData.getDebugPortModel()); jSpinner1.setEditor(new JSpinner.NumberEditor(jSpinner1, "#")); gridBagConstraints = new java.awt.GridBagConstraints(); @@ -241,6 +247,52 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(5, 5, 0, 0); add(jSpinner1, gridBagConstraints); + + org.openide.awt.Mnemonics.setLocalizedText(timeoutsLabel, org.openide.util.NbBundle.getMessage(CustomizerStartup.class, "CustomizerStartup.timeoutsLabel.txt")); // NOI18N + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 6; + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.insets = new java.awt.Insets(11, 12, 0, 0); + add(timeoutsLabel, gridBagConstraints); + + startupTimeoutLabel.setLabelFor(startupTimeoutSpinner); + org.openide.awt.Mnemonics.setLocalizedText(startupTimeoutLabel, org.openide.util.NbBundle.getMessage(CustomizerStartup.class, "CustomizerStartup.startupTimeout.label")); // NOI18N + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 7; + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.insets = new java.awt.Insets(5, 34, 0, 0); + add(startupTimeoutLabel, gridBagConstraints); + + startupTimeoutSpinner.setModel(custData.getStartupTimeoutModel()); + startupTimeoutSpinner.setEditor(new NumberEditor(startupTimeoutSpinner, "#")); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 2; + gridBagConstraints.gridy = 7; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 0, 0); + add(startupTimeoutSpinner, gridBagConstraints); + + shutdownTimeoutLabel.setLabelFor(shutdownTimeoutSpinner); + org.openide.awt.Mnemonics.setLocalizedText(shutdownTimeoutLabel, org.openide.util.NbBundle.getMessage(CustomizerStartup.class, "CustomizerStartup.shutdownTimeout.label")); // NOI18N + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 0; + gridBagConstraints.gridy = 8; + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.insets = new java.awt.Insets(5, 34, 0, 0); + add(shutdownTimeoutLabel, gridBagConstraints); + + shutdownTimeoutSpinner.setModel(custData.getShutdownTimeoutModel()); + shutdownTimeoutSpinner.setEditor(new NumberEditor(shutdownTimeoutSpinner, "#")); + gridBagConstraints = new java.awt.GridBagConstraints(); + gridBagConstraints.gridx = 2; + gridBagConstraints.gridy = 8; + gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; + gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; + gridBagConstraints.insets = new java.awt.Insets(5, 5, 0, 0); + add(shutdownTimeoutSpinner, gridBagConstraints); }// //GEN-END:initComponents private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed @@ -287,6 +339,11 @@ private void updateCustomScriptComponents() { private javax.swing.JSpinner jSpinner1; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField4; + private javax.swing.JLabel shutdownTimeoutLabel; + private javax.swing.JSpinner shutdownTimeoutSpinner; + private javax.swing.JLabel startupTimeoutLabel; + private javax.swing.JSpinner startupTimeoutSpinner; + private javax.swing.JLabel timeoutsLabel; // End of variables declaration//GEN-END:variables } diff --git a/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/optional/StartTomcat.java b/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/optional/StartTomcat.java index b8758153ef7c..4b3ba7162010 100644 --- a/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/optional/StartTomcat.java +++ b/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/optional/StartTomcat.java @@ -110,7 +110,7 @@ public final class StartTomcat extends StartServer implements ProgressObject { private static final int MODE_PROFILE = 2; /** For how long should we keep trying to get response from the server. */ - private static final long TIMEOUT_DELAY = 180000; + private static final long DEFAULT_TIMEOUT_DELAY = 180000; private static final Pattern WINDOWS_ESCAPED_JAVA_OPTS = Pattern.compile("^set\\s\"JAVA_OPTS.*$"); @@ -583,8 +583,19 @@ private void fireCmdExecProgressEvent(String resName, Object arg1, StateType sta * @return true if START/STOP command completion was verified, * false if time-out ran out. */ - private boolean hasCommandSucceeded() { - long timeout = System.currentTimeMillis() + TIMEOUT_DELAY; + private boolean hasCommandSucceeded() { + long timeout = System.currentTimeMillis(); + + if (command == CommandType.START) { + timeout += tm.getTomcatProperties().getStartupTimeout() * 1000l; + } + else if (command == CommandType.STOP) { + timeout += tm.getTomcatProperties().getShutdownTimeout() * 1000l; + } + else { + timeout += DEFAULT_TIMEOUT_DELAY; + } + while (true) { boolean isRunning = isRunning(); if (command == CommandType.START) { diff --git a/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/util/TomcatProperties.java b/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/util/TomcatProperties.java index a806823ede31..b3db3253029f 100644 --- a/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/util/TomcatProperties.java +++ b/enterprise/tomcat5/src/org/netbeans/modules/tomcat5/util/TomcatProperties.java @@ -124,6 +124,8 @@ public class TomcatProperties { NbBundle.getMessage(TomcatProperties.class, "LBL_DefaultDisplayName"); private static final boolean DEF_VALUE_DRIVER_DEPLOYMENT = true; private static final int DEF_VALUE_DEPLOYMENT_TIMEOUT = 120; + private static final int DEF_VALUE_STARTUP_TIMEOUT = 120; + private static final int DEF_VALUE_SHUTDOWN_TIMEOUT = 120; private TomcatManager tm; private InstanceProperties ip; @@ -594,6 +596,44 @@ public void setDeploymentTimeout(int timeout) { ip.setProperty(InstanceProperties.DEPLOYMENT_TIMEOUT, Integer.toString(timeout)); } + public int getStartupTimeout() { + String val = ip.getProperty(InstanceProperties.STARTUP_TIMEOUT); + if (val != null) { + try { + int timeout = Integer.parseInt(val); + if (timeout >= 1) { + return timeout; + } + } catch (NumberFormatException nfe) { + Logger.getLogger(TomcatProperties.class.getName()).log(Level.INFO, null, nfe); + } + } + return DEF_VALUE_STARTUP_TIMEOUT; + } + + public void setStartupTimeout(int timeout) { + ip.setProperty(InstanceProperties.STARTUP_TIMEOUT, Integer.toString(timeout)); + } + + public int getShutdownTimeout() { + String val = ip.getProperty(InstanceProperties.SHUTDOWN_TIMEOUT); + if (val != null) { + try { + int timeout = Integer.parseInt(val); + if (timeout >= 1) { + return timeout; + } + } catch (NumberFormatException nfe) { + Logger.getLogger(TomcatProperties.class.getName()).log(Level.INFO, null, nfe); + } + } + return DEF_VALUE_SHUTDOWN_TIMEOUT; + } + + public void setShutdownTimeout(int timeout) { + ip.setProperty(InstanceProperties.SHUTDOWN_TIMEOUT, Integer.toString(timeout)); + } + public boolean getDriverDeployment() { String val = ip.getProperty(PROP_DRIVER_DEPLOYMENT); return val != null ? Boolean.valueOf(val)