diff --git a/README.md b/README.md
index ac8ab794..fe1422f5 100644
--- a/README.md
+++ b/README.md
@@ -64,9 +64,6 @@ container
tomcat-9.0 (Tomcat 9.0 container implementation)
tomcat-10.1 (Tomcat 10.1 container implementation)
load-spi (SPI classes for load metric computation)
-demo
- client
- server
```
@@ -90,7 +87,7 @@ When building from source, first ensure that Maven version 3.2.5 or newer (run `
mvn clean install
```
-Distribution files for Tomcat and a demo application will be built in the `dist/target/` directory.
+Distribution files for Tomcat will be built in the `dist/target/` directory.
### Code Coverage Report
diff --git a/demo/client/pom.xml b/demo/client/pom.xml
deleted file mode 100644
index 55d97ca4..00000000
--- a/demo/client/pom.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-
-
-
- 4.0.0
-
- org.jboss.mod_cluster
- mod_cluster-demo
- 2.0.4.Final-SNAPSHOT
-
- mod_cluster-demo-client
- mod_cluster: Demo - Client
- jar
-
-
- jfree
- jfreechart
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-dependency-plugin
-
-
- copy-dependencies-demo
- process-resources
-
- copy-dependencies
-
-
- true
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/demo/client/src/main/java/org/jboss/modcluster/demo/client/ChartManager.java b/demo/client/src/main/java/org/jboss/modcluster/demo/client/ChartManager.java
deleted file mode 100755
index a8862936..00000000
--- a/demo/client/src/main/java/org/jboss/modcluster/demo/client/ChartManager.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright The mod_cluster Project Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-package org.jboss.modcluster.demo.client;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.jfree.chart.ChartFactory;
-import org.jfree.chart.JFreeChart;
-import org.jfree.chart.plot.PlotOrientation;
-import org.jfree.data.xy.XYSeries;
-import org.jfree.data.xy.XYSeriesCollection;
-
-/**
- * @author Brian Stansberry
- */
-public class ChartManager {
- private final Map requestCounts;
- private final Map sessionCounts;
- private final Map lastRequestCounts = new HashMap();
- private final Map requestSeries = new HashMap();
- private final Map sessionSeries = new HashMap();
- private final XYSeriesCollection requestSeriesCollection = new XYSeriesCollection();
- private final XYSeriesCollection sessionSeriesCollection = new XYSeriesCollection();
- private final JFreeChart requestBalancingChart;
- private final JFreeChart sessionBalancingChart;
- private long lastUpdateTime = 0;
- private int seriesCount;
-
- public ChartManager(Map requestCounts, Map sessionCounts) {
- this.requestCounts = requestCounts;
- this.sessionCounts = sessionCounts;
-
- requestBalancingChart = ChartFactory.createXYLineChart("Request Balancing", "Sample", "Requests / Second",
- requestSeriesCollection, PlotOrientation.VERTICAL, true, true, false);
- sessionBalancingChart = ChartFactory.createXYLineChart("Session Balancing", "Sample", "Session Count",
- sessionSeriesCollection, PlotOrientation.VERTICAL, true, true, false);
-
- // for (int i = 1; i < 9; i++)
- // {
- // String key = "cluster0" + i;
- // createRequestSeries(key);
- // createSessionSeries(key);
- // }
- }
-
- public JFreeChart getRequestBalancingChart() {
- return this.requestBalancingChart;
- }
-
- public JFreeChart getSessionBalancingChart() {
- return this.sessionBalancingChart;
- }
-
- public void start() {
- this.lastRequestCounts.clear();
- this.lastUpdateTime = System.currentTimeMillis();
- }
-
- public void updateStats() {
- Integer xValue = new Integer(++seriesCount);
-
- long now = System.currentTimeMillis();
- long elapsed = (now - lastUpdateTime) / 1000L;
- // I once saw a DivideByZeroException below
- if (elapsed == 0) {
- seriesCount--;
- return;
- }
-
- this.lastUpdateTime = now;
-
- for (Map.Entry entry : requestCounts.entrySet()) {
- String key = entry.getKey();
- Integer current = new Integer(entry.getValue().get());
- Integer last = lastRequestCounts.put(key, current);
- if (last == null) {
- last = new Integer(0);
- }
-
- int perSec = (int) ((current.intValue() - last.intValue()) / elapsed);
-
- XYSeries series = requestSeries.get(key);
- if (series == null) {
- series = createRequestSeries(key);
- }
-
- series.add(xValue, new Integer(perSec));
- }
-
- for (Map.Entry entry : sessionCounts.entrySet()) {
- String key = entry.getKey();
- XYSeries series = sessionSeries.get(key);
- if (series == null) {
- series = createSessionSeries(key);
- }
-
- series.add(xValue, new Integer(entry.getValue().get()));
- }
- }
-
- private XYSeries createSessionSeries(String key) {
- XYSeries series = new XYSeries(key);
- series.setMaximumItemCount(20);
- sessionSeries.put(key, series);
- sessionSeriesCollection.addSeries(series);
- return series;
- }
-
- private XYSeries createRequestSeries(String key) {
- XYSeries series = new XYSeries(key);
- series.setMaximumItemCount(20);
- requestSeries.put(key, series);
- requestSeriesCollection.addSeries(series);
- return series;
- }
-
-}
diff --git a/demo/client/src/main/java/org/jboss/modcluster/demo/client/ModClusterDemo.java b/demo/client/src/main/java/org/jboss/modcluster/demo/client/ModClusterDemo.java
deleted file mode 100755
index 8493998e..00000000
--- a/demo/client/src/main/java/org/jboss/modcluster/demo/client/ModClusterDemo.java
+++ /dev/null
@@ -1,946 +0,0 @@
-/*
- * Copyright The mod_cluster Project Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-package org.jboss.modcluster.demo.client;
-
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Component;
-import java.awt.EventQueue;
-import java.awt.GridBagConstraints;
-import java.awt.GridBagLayout;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.EnumSet;
-import java.util.List;
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.Vector;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-import javax.swing.JButton;
-import javax.swing.JCheckBox;
-import javax.swing.JComboBox;
-import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JList;
-import javax.swing.JPanel;
-import javax.swing.JTabbedPane;
-import javax.swing.JTextField;
-import javax.swing.ListCellRenderer;
-import javax.swing.event.ChangeEvent;
-import javax.swing.event.ChangeListener;
-
-import org.jboss.modcluster.demo.client.RequestDriver.ClientStatus;
-import org.jboss.modcluster.demo.client.load.ServerLoadParam;
-import org.jboss.modcluster.demo.client.load.ServerLoadServlets;
-import org.jfree.chart.ChartPanel;
-
-/**
- * Client application for demonstrating load balancing with mod_cluster.
- *
- * @author Brian Stansberry
- */
-public class ModClusterDemo {
- private static final String DEFAULT_HOST_NAME = System.getProperty("mod_cluster.proxy.host", "localhost");
- private static final String DEFAULT_PROXY_PORT = System.getProperty("mod_cluster.proxy.port", "8000");
- private static final String DEFAULT_CONTEXT_PATH = "load-demo";
- private static final String DEFAULT_SESSION_TIMEOUT = "20";
- private static final int DEFAULT_NUM_THREADS = 80;
- private static final int DEFAULT_SESSION_LIFE = 120;
- private static final int DEFAULT_SLEEP_TIME = 100;
- private static final int DEFAULT_STARTUP_TIME = 120;
-
- private final RequestDriver requestDriver;
- private final ChartManager chartManager;
- private final Timer timer;
- private TimerTask currentTask;
- private JFrame frame;
- private JTextField proxyHostNameField;
- private JTextField proxyPortField;
- private JTextField contextPathField;
- private JCheckBox destroySessionField;
- private JTextField numThreadsField;
- private JTextField sessionLifeField;
- private JLabel sessionTimeoutLabel;
- private JTextField sessionTimeoutField;
- private JTextField sleepTimeField;
- private JTextField startupTimeField;
- private JTextField targetHostNameField;
- private JTextField targetPortField;
- private JLabel totalClientsLabel;
- private JLabel liveClientsLabel;
- private JLabel failedClientsLabel;
- private JLabel totalClientsLabelReq;
- private JLabel liveClientsLabelReq;
- private JLabel failedClientsLabelReq;
- private JLabel totalClientsLabelSess;
- private JLabel liveClientsLabelSess;
- private JLabel failedClientsLabelSess;
-
- private ServerLoadServlets selectedLoadServlet;
- private JLabel targetServletParamLabel1;
- private JTextField targetServletParamField1;
- private JLabel targetServletParamLabel2;
- private JTextField targetServletParamField2;
-
- /**
- * Launch the application
- *
- * @param args
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- ModClusterDemo window = new ModClusterDemo();
- window.frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
-
- /**
- * Create the application
- */
- public ModClusterDemo() {
- this.requestDriver = new RequestDriver();
- this.chartManager = new ChartManager(this.requestDriver.getRequestCounts(), this.requestDriver.getSessionCounts());
- this.timer = new Timer("ModClusterDemoTimer", false);
-
- // Set up GUI
- createContents();
- }
-
- /**
- * Initialize the contents of the frame
- */
- private void createContents() {
- frame = new JFrame();
- frame.setBounds(100, 100, 675, 422);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setTitle("Load Balancing Demonstration");
- frame.addWindowListener(new WindowAdapter() {
- @Override
- public void windowClosed(WindowEvent e) {
- ModClusterDemo.this.stop();
- ModClusterDemo.this.timer.cancel();
- }
- });
-
- final JTabbedPane tabbedPane = new JTabbedPane();
- frame.getContentPane().add(tabbedPane, BorderLayout.CENTER);
-
- tabbedPane.addTab("Client Control", null, createClientControlPanel(), null);
-
- final JPanel loadPanel = createServerLoadControlPanel();
- tabbedPane.addTab("Server Load Control", null, loadPanel, null);
-
- tabbedPane.addTab("Request Balancing", null, createRequestBalancingPanel(), null);
-
- tabbedPane.addTab("Session Balancing", null, createSessionBalancingPanel(), null);
-
- // Load the target host/proxy fields from the client control panel
- // the first time their panel gets focus
- tabbedPane.addChangeListener(new ChangeListener() {
- public void stateChanged(ChangeEvent e) {
- if (loadPanel.equals(tabbedPane.getSelectedComponent())) {
- String text = targetHostNameField.getText();
- if (text == null || text.length() == 0)
- targetHostNameField.setText(proxyHostNameField.getText());
- text = targetPortField.getText();
- if (text == null || text.length() == 0)
- targetPortField.setText(proxyPortField.getText());
- }
- }
- });
- }
-
- private JPanel createClientControlPanel() {
- final JPanel controlPanel = new JPanel();
- GridBagLayout gridBagLayout = new GridBagLayout();
- gridBagLayout.columnWidths = new int[] { 7, 0, 7, 0, 7, 0, 7, 7, 0, 0, 7 };
- gridBagLayout.rowHeights = new int[] { 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0 };
- controlPanel.setLayout(gridBagLayout);
-
- JLabel label = new JLabel();
- label.setText("Proxy Hostname:");
- label.setToolTipText("Hostname clients should request");
- GridBagConstraints gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 0;
- gridBagConstraints.gridx = 1;
- gridBagConstraints.weighty = 1;
- gridBagConstraints.anchor = GridBagConstraints.SOUTH;
- controlPanel.add(label, gridBagConstraints);
-
- proxyHostNameField = new JTextField();
- proxyHostNameField.setText(DEFAULT_HOST_NAME);
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 0;
- gridBagConstraints.gridx = 3;
- gridBagConstraints.weightx = 1;
- gridBagConstraints.weighty = 1;
- gridBagConstraints.anchor = GridBagConstraints.SOUTH;
- gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
- controlPanel.add(proxyHostNameField, gridBagConstraints);
-
- label = new JLabel();
- label.setText("Proxy Port:");
- label.setToolTipText("Port clients should request");
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 0;
- gridBagConstraints.gridx = 6;
- gridBagConstraints.weighty = 1;
- gridBagConstraints.anchor = GridBagConstraints.SOUTH;
- controlPanel.add(label, gridBagConstraints);
-
- proxyPortField = new JTextField();
- proxyPortField.setText(DEFAULT_PROXY_PORT);
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 0;
- gridBagConstraints.gridx = 9;
- gridBagConstraints.weightx = 1;
- gridBagConstraints.weighty = 1;
- gridBagConstraints.anchor = GridBagConstraints.SOUTH;
- gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
- controlPanel.add(proxyPortField, gridBagConstraints);
-
- label = new JLabel();
- label.setText("Context Path:");
- label.setToolTipText("Context path of the demo war");
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 2;
- gridBagConstraints.gridx = 1;
- controlPanel.add(label, gridBagConstraints);
-
- contextPathField = new JTextField();
- contextPathField.setText(DEFAULT_CONTEXT_PATH);
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 2;
- gridBagConstraints.gridx = 3;
- gridBagConstraints.weightx = 1;
- gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
- controlPanel.add(contextPathField, gridBagConstraints);
-
- label = new JLabel();
- label.setText("Session Life (s):");
- label.setToolTipText("Number of seconds client should use session before invalidating or abandoning it");
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 2;
- gridBagConstraints.gridx = 6;
- controlPanel.add(label, gridBagConstraints);
-
- sessionLifeField = new JTextField();
- sessionLifeField.setText(String.valueOf(DEFAULT_SESSION_LIFE));
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 2;
- gridBagConstraints.gridx = 9;
- gridBagConstraints.weightx = 1;
- gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
- controlPanel.add(sessionLifeField, gridBagConstraints);
-
- label = new JLabel();
- label.setText("Invalidate:");
- label.setToolTipText("Check if session should be invalidated at end of life; uncheck to abandon session");
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 4;
- gridBagConstraints.gridx = 1;
- controlPanel.add(label, gridBagConstraints);
-
- destroySessionField = new JCheckBox();
- destroySessionField.setSelected(true);
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 4;
- gridBagConstraints.gridx = 3;
- gridBagConstraints.weightx = 1;
- gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
- controlPanel.add(destroySessionField, gridBagConstraints);
-
- sessionTimeoutLabel = new JLabel();
- sessionTimeoutLabel.setText("Session Timeout (s):");
- sessionTimeoutLabel.setToolTipText("Session maxInactiveInterval if abandoned, in seconds");
- sessionTimeoutLabel.setEnabled(destroySessionField.isSelected());
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 4;
- gridBagConstraints.gridx = 6;
- controlPanel.add(sessionTimeoutLabel, gridBagConstraints);
-
- sessionTimeoutField = new JTextField();
- sessionTimeoutField.setText(String.valueOf(DEFAULT_SESSION_TIMEOUT));
- sessionTimeoutField.setEnabled(destroySessionField.isSelected());
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 4;
- gridBagConstraints.gridx = 9;
- gridBagConstraints.weightx = 1;
- gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
- controlPanel.add(sessionTimeoutField, gridBagConstraints);
-
- label = new JLabel();
- label.setText("Num Threads:");
- label.setToolTipText("Number of client threads to launch; max number of concurrent requests");
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 6;
- gridBagConstraints.gridx = 1;
- controlPanel.add(label, gridBagConstraints);
-
- numThreadsField = new JTextField();
- numThreadsField.setText(String.valueOf(DEFAULT_NUM_THREADS));
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 6;
- gridBagConstraints.gridx = 3;
- gridBagConstraints.weightx = 1;
- gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
- controlPanel.add(numThreadsField, gridBagConstraints);
-
- label = new JLabel();
- label.setText("Sleep Time (ms):");
- label.setToolTipText("Number of ms each client should sleep between requests");
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 6;
- gridBagConstraints.gridx = 6;
- controlPanel.add(label, gridBagConstraints);
-
- sleepTimeField = new JTextField();
- sleepTimeField.setText(String.valueOf(DEFAULT_SLEEP_TIME));
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 6;
- gridBagConstraints.gridx = 9;
- gridBagConstraints.weightx = 1;
- gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
- controlPanel.add(sleepTimeField, gridBagConstraints);
-
- label = new JLabel();
- label.setText("Startup Time (s):");
- label.setToolTipText("Number of seconds over which client threads should be launched");
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 8;
- gridBagConstraints.gridx = 1;
- controlPanel.add(label, gridBagConstraints);
-
- startupTimeField = new JTextField();
- startupTimeField.setText(String.valueOf(DEFAULT_STARTUP_TIME));
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 8;
- gridBagConstraints.gridx = 3;
- gridBagConstraints.weightx = 1;
- gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
- controlPanel.add(startupTimeField, gridBagConstraints);
-
- JButton startButton = new JButton();
- startButton.addActionListener(new ActionListener() {
- public void actionPerformed(final ActionEvent e) {
- start();
- }
- });
- startButton.setText("Start");
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 10;
- gridBagConstraints.gridx = 1;
- gridBagConstraints.weighty = 3;
- gridBagConstraints.weightx = 1;
- gridBagConstraints.gridwidth = 3;
- gridBagConstraints.anchor = GridBagConstraints.EAST;
- controlPanel.add(startButton, gridBagConstraints);
-
- JButton stopButton = new JButton();
- stopButton.addActionListener(new ActionListener() {
- public void actionPerformed(final ActionEvent e) {
- stop();
- }
- });
- stopButton.setText("Stop");
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 10;
- gridBagConstraints.gridx = 6;
- gridBagConstraints.weighty = 2;
- gridBagConstraints.weightx = 1;
- gridBagConstraints.gridwidth = 4;
- gridBagConstraints.anchor = GridBagConstraints.WEST;
- controlPanel.add(stopButton, gridBagConstraints);
-
- JPanel statusPanel = new JPanel();
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 11;
- gridBagConstraints.gridx = 1;
- gridBagConstraints.weighty = 2;
- gridBagConstraints.weightx = 1;
- gridBagConstraints.gridwidth = 9;
- gridBagConstraints.fill = GridBagConstraints.BOTH;
- controlPanel.add(statusPanel, gridBagConstraints);
-
- gridBagLayout = new GridBagLayout();
- gridBagLayout.columnWidths = new int[] { 0, 0, 7 };
- gridBagLayout.rowHeights = new int[] { 0, 7, 0, 0 };
- statusPanel.setLayout(gridBagLayout);
-
- label = new JLabel();
- label.setText("Client Status");
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 0;
- gridBagConstraints.gridx = 0;
- gridBagConstraints.gridwidth = 4;
- gridBagConstraints.weightx = 1;
- gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
- statusPanel.add(label, gridBagConstraints);
-
- label = new JLabel();
- label.setText("Total clients:");
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 2;
- gridBagConstraints.gridx = 1;
- gridBagConstraints.anchor = GridBagConstraints.WEST;
- statusPanel.add(label, gridBagConstraints);
-
- totalClientsLabel = new JLabel();
- totalClientsLabel.setText(String.valueOf("0"));
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 2;
- gridBagConstraints.gridx = 3;
- gridBagConstraints.anchor = GridBagConstraints.WEST;
- statusPanel.add(totalClientsLabel, gridBagConstraints);
-
- label = new JLabel();
- label.setText("Live clients:");
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 3;
- gridBagConstraints.gridx = 1;
- gridBagConstraints.anchor = GridBagConstraints.WEST;
- statusPanel.add(label, gridBagConstraints);
-
- liveClientsLabel = new JLabel();
- liveClientsLabel.setText(String.valueOf("0"));
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 3;
- gridBagConstraints.gridx = 3;
- gridBagConstraints.anchor = GridBagConstraints.WEST;
- statusPanel.add(liveClientsLabel, gridBagConstraints);
-
- label = new JLabel();
- label.setText("Failed clients:");
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 4;
- gridBagConstraints.gridx = 1;
- gridBagConstraints.anchor = GridBagConstraints.WEST;
- statusPanel.add(label, gridBagConstraints);
-
- failedClientsLabel = new JLabel();
- failedClientsLabel.setText(String.valueOf("0"));
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 4;
- gridBagConstraints.gridx = 3;
- gridBagConstraints.anchor = GridBagConstraints.WEST;
- statusPanel.add(failedClientsLabel, gridBagConstraints);
-
- return controlPanel;
- }
-
- private JPanel createServerLoadControlPanel() {
- final JPanel loadPanel = new JPanel();
- GridBagLayout gridBagLayout = new GridBagLayout();
- gridBagLayout.columnWidths = new int[] { 7, 0, 7, 0, 7, 0, 7, 7, 0, 0, 7 };
- gridBagLayout.rowHeights = new int[] { 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0 };
- loadPanel.setLayout(gridBagLayout);
-
- JLabel label = new JLabel();
- label.setText("Target Hostname:");
- label.setToolTipText("Hostname clients should request");
- GridBagConstraints gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 0;
- gridBagConstraints.gridx = 1;
- gridBagConstraints.weighty = 1;
- gridBagConstraints.anchor = GridBagConstraints.SOUTH;
- loadPanel.add(label, gridBagConstraints);
-
- targetHostNameField = new JTextField();
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 0;
- gridBagConstraints.gridx = 3;
- gridBagConstraints.weightx = 1;
- gridBagConstraints.weighty = 1;
- gridBagConstraints.anchor = GridBagConstraints.SOUTH;
- gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
- loadPanel.add(targetHostNameField, gridBagConstraints);
-
- label = new JLabel();
- label.setText("Target Port:");
- label.setToolTipText("Port clients should request");
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 0;
- gridBagConstraints.gridx = 6;
- gridBagConstraints.weighty = 1;
- gridBagConstraints.anchor = GridBagConstraints.SOUTH;
- loadPanel.add(label, gridBagConstraints);
-
- targetPortField = new JTextField();
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 0;
- gridBagConstraints.gridx = 9;
- gridBagConstraints.weightx = 1;
- gridBagConstraints.weighty = 1;
- gridBagConstraints.anchor = GridBagConstraints.SOUTH;
- gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
- loadPanel.add(targetPortField, gridBagConstraints);
-
- label = new JLabel();
- label.setText("Load Creation Action:");
- label.setToolTipText("Action to invoke on target server to simulate server load");
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 2;
- gridBagConstraints.gridx = 1;
- loadPanel.add(label, gridBagConstraints);
-
- EnumSet es = EnumSet.allOf(ServerLoadServlets.class);
- Vector v = new Vector(es);
- final JComboBox targetLoadServletCombo = new JComboBox(v);
- targetLoadServletCombo.setRenderer(new ServerLoadServletCellRenderer());
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 2;
- gridBagConstraints.gridx = 3;
- gridBagConstraints.weightx = 1;
- gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
- loadPanel.add(targetLoadServletCombo, gridBagConstraints);
-
- targetLoadServletCombo.setSelectedItem(ServerLoadServlets.CONNECTOR_THREAD_USAGE);
- selectedLoadServlet = ServerLoadServlets.CONNECTOR_THREAD_USAGE;
-
- ServerLoadParam param = ServerLoadServlets.CONNECTOR_THREAD_USAGE.getParams().get(0);
-
- targetServletParamLabel1 = new JLabel();
- targetServletParamLabel1.setText(param.getLabel() + ":");
- targetServletParamLabel1.setToolTipText(param.getDescription());
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 4;
- gridBagConstraints.gridx = 1;
- loadPanel.add(targetServletParamLabel1, gridBagConstraints);
-
- targetServletParamField1 = new JTextField();
- targetServletParamField1.setText(param.getValue());
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 4;
- gridBagConstraints.gridx = 3;
- gridBagConstraints.weightx = 1;
- gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
- loadPanel.add(targetServletParamField1, gridBagConstraints);
-
- param = ServerLoadServlets.CONNECTOR_THREAD_USAGE.getParams().get(1);
-
- targetServletParamLabel2 = new JLabel();
- targetServletParamLabel2.setText(param.getLabel() + ":");
- targetServletParamLabel2.setToolTipText(param.getDescription());
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 6;
- gridBagConstraints.gridx = 1;
- loadPanel.add(targetServletParamLabel2, gridBagConstraints);
-
- targetServletParamField2 = new JTextField();
- targetServletParamField2.setText(param.getValue());
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 6;
- gridBagConstraints.gridx = 3;
- gridBagConstraints.weightx = 1;
- gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
- loadPanel.add(targetServletParamField2, gridBagConstraints);
-
- targetLoadServletCombo.addItemListener(new ItemListener() {
- public void itemStateChanged(ItemEvent e) {
- if (ItemEvent.SELECTED == e.getStateChange()) {
- selectedLoadServlet = (ServerLoadServlets) e.getItem();
- List params = selectedLoadServlet.getParams();
- if (params.size() > 0) {
- targetServletParamLabel1.setText(params.get(0).getLabel() + ":");
- targetServletParamLabel1.setToolTipText(params.get(0).getDescription());
- targetServletParamField1.setVisible(true);
- targetServletParamField1.setText(params.get(0).getValue());
- } else {
- targetServletParamLabel1.setText(" ");
- targetServletParamField1.setVisible(false);
- }
- if (params.size() > 1) {
- targetServletParamLabel2.setText(params.get(1).getLabel() + ":");
- targetServletParamLabel2.setToolTipText(params.get(1).getDescription());
- targetServletParamField2.setVisible(true);
- targetServletParamField2.setText(params.get(1).getValue());
- } else {
- targetServletParamLabel2.setText(" ");
- targetServletParamField2.setVisible(false);
- }
- }
- }
- });
-
- JButton createLoadButton = new JButton();
- createLoadButton.addActionListener(new ActionListener() {
- public void actionPerformed(final ActionEvent e) {
- createLoad();
- }
- });
- createLoadButton.setText("Create Load");
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 8;
- gridBagConstraints.gridx = 1;
- gridBagConstraints.weighty = 3;
- gridBagConstraints.weightx = 1;
- gridBagConstraints.gridwidth = 9;
- gridBagConstraints.anchor = GridBagConstraints.NORTH;
- loadPanel.add(createLoadButton, gridBagConstraints);
-
- return loadPanel;
- }
-
- private JPanel createRequestBalancingPanel() {
- final JPanel requestBalancingPanel = new JPanel();
- GridBagLayout gridBagLayout = new GridBagLayout();
- gridBagLayout.columnWidths = new int[] { 0 };
- gridBagLayout.rowHeights = new int[] { 0, 0 };
- requestBalancingPanel.setLayout(gridBagLayout);
-
- final JPanel requestChart = new ChartPanel(this.chartManager.getRequestBalancingChart(), true);
- GridBagConstraints gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 0;
- gridBagConstraints.gridx = 0;
- gridBagConstraints.weightx = 1;
- gridBagConstraints.weighty = 1;
- gridBagConstraints.fill = GridBagConstraints.BOTH;
- requestBalancingPanel.add(requestChart, gridBagConstraints);
-
- JPanel clientStatusPanel = new JPanel();
- gridBagLayout = new GridBagLayout();
- gridBagLayout.columnWidths = new int[] { 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7 };
- gridBagLayout.rowHeights = new int[] { 7, 0 };
- clientStatusPanel.setLayout(gridBagLayout);
-
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 1;
- gridBagConstraints.gridx = 0;
- gridBagConstraints.weightx = 1;
- gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
- requestBalancingPanel.add(clientStatusPanel, gridBagConstraints);
-
- JLabel label = new JLabel();
- label.setText("Total clients:");
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 0;
- gridBagConstraints.gridx = 1;
- gridBagConstraints.anchor = GridBagConstraints.WEST;
- clientStatusPanel.add(label, gridBagConstraints);
-
- totalClientsLabelReq = new JLabel();
- totalClientsLabelReq.setText(String.valueOf("0"));
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 0;
- gridBagConstraints.gridx = 3;
- gridBagConstraints.anchor = GridBagConstraints.WEST;
- clientStatusPanel.add(totalClientsLabelReq, gridBagConstraints);
-
- label = new JLabel();
- label.setText("Live clients:");
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 0;
- gridBagConstraints.gridx = 5;
- gridBagConstraints.anchor = GridBagConstraints.WEST;
- clientStatusPanel.add(label, gridBagConstraints);
-
- liveClientsLabelReq = new JLabel();
- liveClientsLabelReq.setText(String.valueOf("0"));
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 0;
- gridBagConstraints.gridx = 7;
- gridBagConstraints.anchor = GridBagConstraints.WEST;
- clientStatusPanel.add(liveClientsLabelReq, gridBagConstraints);
-
- label = new JLabel();
- label.setText("Failed clients:");
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 0;
- gridBagConstraints.gridx = 9;
- gridBagConstraints.anchor = GridBagConstraints.WEST;
- clientStatusPanel.add(label, gridBagConstraints);
-
- failedClientsLabelReq = new JLabel();
- failedClientsLabelReq.setText(String.valueOf("0"));
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 0;
- gridBagConstraints.gridx = 11;
- gridBagConstraints.anchor = GridBagConstraints.WEST;
- clientStatusPanel.add(failedClientsLabelReq, gridBagConstraints);
-
- return requestBalancingPanel;
- }
-
- private JPanel createSessionBalancingPanel() {
- final JPanel sessionBalancingPanel = new JPanel();
- GridBagLayout gridBagLayout = new GridBagLayout();
- gridBagLayout.columnWidths = new int[] { 0 };
- gridBagLayout.rowHeights = new int[] { 0, 0 };
- sessionBalancingPanel.setLayout(gridBagLayout);
-
- JPanel sessionBalancingChart = new ChartPanel(this.chartManager.getSessionBalancingChart(), true);
-
- GridBagConstraints gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 0;
- gridBagConstraints.gridx = 0;
- gridBagConstraints.weightx = 1;
- gridBagConstraints.weighty = 1;
- gridBagConstraints.fill = GridBagConstraints.BOTH;
- sessionBalancingPanel.add(sessionBalancingChart, gridBagConstraints);
-
- JPanel clientStatusPanel = new JPanel();
- gridBagLayout = new GridBagLayout();
- gridBagLayout.columnWidths = new int[] { 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7, 0, 7 };
- gridBagLayout.rowHeights = new int[] { 7, 0 };
- clientStatusPanel.setLayout(gridBagLayout);
-
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 1;
- gridBagConstraints.gridx = 0;
- gridBagConstraints.weightx = 1;
- gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
- sessionBalancingPanel.add(clientStatusPanel, gridBagConstraints);
-
- JLabel label = new JLabel();
- label.setText("Total clients:");
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 0;
- gridBagConstraints.gridx = 1;
- gridBagConstraints.anchor = GridBagConstraints.WEST;
- clientStatusPanel.add(label, gridBagConstraints);
-
- totalClientsLabelSess = new JLabel();
- totalClientsLabelSess.setText(String.valueOf("0"));
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 0;
- gridBagConstraints.gridx = 3;
- gridBagConstraints.anchor = GridBagConstraints.WEST;
- clientStatusPanel.add(totalClientsLabelSess, gridBagConstraints);
-
- label = new JLabel();
- label.setText("Live clients:");
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 0;
- gridBagConstraints.gridx = 5;
- gridBagConstraints.anchor = GridBagConstraints.WEST;
- clientStatusPanel.add(label, gridBagConstraints);
-
- liveClientsLabelSess = new JLabel();
- liveClientsLabelSess.setText(String.valueOf("0"));
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 0;
- gridBagConstraints.gridx = 7;
- gridBagConstraints.anchor = GridBagConstraints.WEST;
- clientStatusPanel.add(liveClientsLabelSess, gridBagConstraints);
-
- label = new JLabel();
- label.setText("Failed clients:");
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 0;
- gridBagConstraints.gridx = 9;
- gridBagConstraints.anchor = GridBagConstraints.WEST;
- clientStatusPanel.add(label, gridBagConstraints);
-
- failedClientsLabelSess = new JLabel();
- failedClientsLabelSess.setText(String.valueOf("0"));
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 0;
- gridBagConstraints.gridx = 11;
- gridBagConstraints.anchor = GridBagConstraints.WEST;
- clientStatusPanel.add(failedClientsLabelSess, gridBagConstraints);
-
- gridBagConstraints = new GridBagConstraints();
- gridBagConstraints.gridy = 1;
- gridBagConstraints.gridx = 0;
- gridBagConstraints.weightx = 1;
- gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
- sessionBalancingPanel.add(clientStatusPanel, gridBagConstraints);
- return sessionBalancingPanel;
- }
-
- private void start() {
- String sessionTimeoutText = sessionTimeoutField.getText();
- int sessionTimeout = -1;
- if (sessionTimeoutText != null && sessionTimeoutText.trim().length() > 0) {
- try {
- sessionTimeout = Integer.parseInt(sessionTimeoutText);
- } catch (NumberFormatException e) {
- e.printStackTrace();
- }
- }
-
- boolean invalidate = destroySessionField.isSelected();
-
- String tmp = createBaseURL(proxyHostNameField.getText(), proxyPortField.getText()) + "record";
- URL requestURL, destroyURL;
- try {
- if (invalidate) {
- requestURL = new URL(tmp);
- destroyURL = new URL(tmp + "?destroy=true");
- } else {
- String timeoutParam = (sessionTimeout > 0) ? "?timeout=" + String.valueOf(sessionTimeout) : "";
- requestURL = new URL(tmp + timeoutParam);
- destroyURL = requestURL;
- }
- } catch (MalformedURLException e) {
- e.printStackTrace(System.err);
- return;
- }
-
- int num_threads = DEFAULT_NUM_THREADS;
- String numT = numThreadsField.getText();
- if (numT != null && numT.trim().length() > 0) {
- num_threads = Integer.parseInt(numT);
- }
-
- int session_life = DEFAULT_SESSION_LIFE;
- String sessL = sessionLifeField.getText();
- if (sessL != null && sessL.trim().length() > 0) {
- session_life = Integer.parseInt(sessL);
- }
-
- int sleep_time = DEFAULT_SLEEP_TIME;
- String sleepT = sleepTimeField.getText();
- if (sleepT != null && sleepT.trim().length() > 0) {
- sleep_time = Integer.parseInt(sleepT);
- }
-
- int startup_time = DEFAULT_STARTUP_TIME;
- String startT = startupTimeField.getText();
- if (startT != null && startT.trim().length() > 0) {
- startup_time = Integer.parseInt(startT);
- }
-
- // Start the components
- this.currentTask = new GUIUpdateTimerTask();
- this.chartManager.start();
- this.timer.schedule(this.currentTask, 2000, 2000);
- this.requestDriver.start(requestURL, destroyURL, num_threads, session_life, sleep_time, startup_time);
- }
-
- private void stop() {
- if (this.currentTask != null) {
- this.currentTask.cancel();
- }
-
- this.requestDriver.stop();
-
- // Update the client status panel
- updateStatusPanel();
- }
-
- private void createLoad() {
- String tmp = createBaseURL(targetHostNameField.getText(), targetPortField.getText())
- + selectedLoadServlet.getServletPath();
- List params = selectedLoadServlet.getParams();
- if (params.size() > 0) {
- String val = targetServletParamField1.getText();
- params.get(0).setValue(val);
- tmp += "?" + params.get(0).getName() + "=" + val;
- }
- if (params.size() > 1) {
- String val = targetServletParamField2.getText();
- params.get(1).setValue(val);
- tmp += "&" + params.get(1).getName() + "=" + val;
- }
-
- final URL requestURL;
- try {
- requestURL = new URL(tmp);
- } catch (MalformedURLException e) {
- e.printStackTrace(System.err);
- return;
- }
-
- // Send the request in another thread
- Runnable r = new Runnable() {
- private final byte[] buffer = new byte[1024];
-
- public void run() {
- System.out.println("Sending load generation request " + requestURL);
- InputStream input = null;
- HttpURLConnection conn = null;
- try {
- conn = (HttpURLConnection) requestURL.openConnection(); // not yet connected
- input = conn.getInputStream(); // NOW it is connected
- while (input.read(buffer) > 0) {
- }
- input.close(); // discard data
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- };
-
- ExecutorService exec = Executors.newSingleThreadExecutor();
- exec.execute(r);
- exec.shutdown();
- }
-
- private String createBaseURL(String hostText, String portText) {
- if (portText == null || portText.trim().length() == 0)
- portText = "80";
- portText = portText.trim();
-
- String contextPath = contextPathField.getText();
- if (contextPath == null)
- contextPath = "";
- contextPath = contextPath.trim();
- if (contextPath.length() > 0 && '/' == contextPath.charAt(0))
- contextPath = contextPath.length() == 1 ? "" : contextPath.substring(1);
- if (contextPath.length() > 0 && '/' == contextPath.charAt(contextPath.length() - 1))
- contextPath = contextPath.length() == 1 ? "" : contextPath.substring(0, contextPath.length() - 1);
-
- return "http://" + hostText + ":" + portText + "/" + contextPath + "/";
- }
-
- private void updateStatusPanel() {
- ClientStatus status = requestDriver.getClientStatus();
- totalClientsLabel.setText(String.valueOf(status.clientCount));
- liveClientsLabel.setText(String.valueOf(status.liveClientCount));
- totalClientsLabelReq.setText(String.valueOf(status.clientCount));
- liveClientsLabelReq.setText(String.valueOf(status.liveClientCount));
- totalClientsLabelSess.setText(String.valueOf(status.clientCount));
- liveClientsLabelSess.setText(String.valueOf(status.liveClientCount));
- int failedCount = status.clientCount - status.successfulClientCount;
- failedClientsLabel.setText(String.valueOf(failedCount));
- failedClientsLabel.setForeground(failedCount == 0 ? Color.BLACK : Color.RED);
- failedClientsLabelReq.setText(String.valueOf(failedCount));
- failedClientsLabelReq.setForeground(failedCount == 0 ? Color.BLACK : Color.RED);
- failedClientsLabelSess.setText(String.valueOf(failedCount));
- failedClientsLabelSess.setForeground(failedCount == 0 ? Color.BLACK : Color.RED);
- }
-
- private class GUIUpdateTimerTask extends TimerTask {
- @Override
- public void run() {
- // Update the chart
- chartManager.updateStats();
-
- // Update the client status panel
- updateStatusPanel();
- }
-
- }
-
- private class ServerLoadServletCellRenderer extends JLabel implements ListCellRenderer {
- private static final long serialVersionUID = -8010662328204072428L;
-
- @Override
- public Component getListCellRendererComponent(JList extends ServerLoadServlets> list, ServerLoadServlets value, int index, boolean isSelected, boolean cellHasFocus) {
- this.setText(value.toString());
- this.setToolTipText(((ServerLoadServlets) value).getDescription());
- return this;
- }
- }
-
-}
diff --git a/demo/client/src/main/java/org/jboss/modcluster/demo/client/RequestDriver.java b/demo/client/src/main/java/org/jboss/modcluster/demo/client/RequestDriver.java
deleted file mode 100755
index 553c2f0c..00000000
--- a/demo/client/src/main/java/org/jboss/modcluster/demo/client/RequestDriver.java
+++ /dev/null
@@ -1,310 +0,0 @@
-/*
- * Copyright The mod_cluster Project Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-package org.jboss.modcluster.demo.client;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * @author Brian Stansberry
- */
-public class RequestDriver {
- private Client[] clients;
-
- private final ConcurrentMap requestCounts = new ConcurrentHashMap();
- private final ConcurrentMap sessionCounts = new ConcurrentHashMap();
-
- private final AtomicBoolean stopped = new AtomicBoolean(false);
- private Thread startThread;
-
- public void start(final URL request_url, final URL destroy_url, int num_threads, final int session_life, final int sleep_time, int startup_time) {
- this.requestCounts.clear();
- this.sessionCounts.clear();
-
- this.clients = new Client[num_threads];
-
- this.stopped.set(false);
- final int startupPause = startup_time > 0 ? (startup_time * 1000 / num_threads) : 0;
-
- System.out.println("Request URL is " + request_url);
- System.out.println("Terminal URL is " + destroy_url);
- System.out.println("Starting " + num_threads + " clients");
- Runnable r = new Runnable() {
- public void run() {
- for (int i = 0; i < clients.length & !stopped.get(); i++) {
- Client client = new Client(request_url, destroy_url, session_life, sleep_time, requestCounts, sessionCounts, stopped);
- clients[i] = client;
- client.start();
- try {
- Thread.sleep(startupPause);
- } catch (InterruptedException e) {
- e.printStackTrace(System.err);
- return;
- }
- }
-
- }
- };
-
- this.startThread = new Thread(r, "RequestDriverStartThread");
- this.startThread.start();
- }
-
- public void stop() {
- // Stop creating new clients (if we still are)
- this.stopped.set(true);
- if (this.startThread != null && this.startThread.isAlive()) {
- try {
- this.startThread.join(2000);
- } catch (InterruptedException e) {
- }
-
- if (this.startThread.isAlive()) {
- this.startThread.interrupt();
- }
- }
-
- // Stop the clients we've created
- if (this.clients != null) {
- for (Client client : this.clients) {
- if (client != null && client.isAlive()) {
- client.terminate();
- }
- }
- }
- }
-
- public ConcurrentMap getRequestCounts() {
- return requestCounts;
- }
-
- public ConcurrentMap getSessionCounts() {
- return sessionCounts;
- }
-
- public ClientStatus getClientStatus() {
- ClientStatus result = new ClientStatus();
- if (this.clients != null) {
- for (Client client : this.clients) {
- if (client != null) {
- result.clientCount++;
- if (client.isAlive()) {
- result.liveClientCount++;
- }
- if (client.isSuccessful()) {
- result.successfulClientCount++;
- }
- }
- }
- }
- return result;
- }
-
- public static class ClientStatus {
- public int clientCount;
- public int liveClientCount;
- public int successfulClientCount;
- }
-
- private static class Client extends Thread {
- private final URL request_url, destroy_url;
-
- private final long sessionLife;
-
- private final long sleepTime;
-
- private boolean successful = true;
-
- private final byte[] buffer = new byte[1024];
-
- private String cookie = null;
-
- private String lastHandler = null;
-
- private final AtomicBoolean stopped;
-
- private final ConcurrentMap requests;
-
- private final ConcurrentMap sessions;
-
- private Client(URL request_url, URL destroy_url, long sessionLife, int sleepTime, ConcurrentMap requests, ConcurrentMap sessions, AtomicBoolean stopped) {
- this.request_url = request_url;
- this.destroy_url = (request_url.equals(destroy_url)) ? null : destroy_url;
- this.sessionLife = sessionLife * 1000;
- this.sleepTime = sleepTime;
- this.requests = requests;
- this.sessions = sessions;
- this.stopped = stopped;
- // Don't keep the VM alive
- setDaemon(false);
- }
-
- public void run() {
- try {
- loop();
- } catch (Exception e) {
- error("failure", e);
- successful = false;
- } finally {
- try {
- // Make an attempt to terminate any ongoing session
- // Only bother if our destroy
- if (cookie != null && destroy_url != null) {
- executeRequest(destroy_url);
- }
- } catch (IOException e) {
- } finally {
- // If we haven't already cleaned up this thread's
- // session info, do so now
- handleSessionTermination();
- }
- }
- }
-
- public boolean isSuccessful() {
- return successful;
- }
-
- private void terminate() {
- if (this.isAlive()) {
- try {
- this.join(5000);
- if (this.isAlive()) {
- this.interrupt();
- }
- } catch (InterruptedException e) {
- }
- }
- }
-
- private void loop() throws IOException {
- int rc;
-
- while (!stopped.get()) {
- long sessionStart = System.currentTimeMillis();
- long elapsed = 0;
- boolean failed = false;
- while ((elapsed < sessionLife) && !stopped.get()) {
- try {
- Thread.sleep(sleepTime);
- } catch (InterruptedException e) {
- break;
- }
-
- rc = executeRequest(request_url);
- if (rc == 200) {
- elapsed = System.currentTimeMillis() - sessionStart;
- } else {
- failed = true;
- break;
- }
- }
-
- if (!failed && destroy_url != null) {
- // Send invalidation request
- executeRequest(destroy_url);
- }
-
- handleSessionTermination();
- }
- }
-
- private int executeRequest(URL url) throws IOException {
- InputStream input = null;
- HttpURLConnection conn = null;
- try {
- conn = (HttpURLConnection) url.openConnection(); // not yet connected
- if (cookie != null)
- conn.setRequestProperty("Cookie", cookie);
-
- input = conn.getInputStream(); // NOW it is connected
- while (input.read(buffer) > 0) {
- }
- input.close(); // discard data
-
- String handlerNode = conn.getHeaderField("X-ClusterNode");
-
- modifyCount(handlerNode, requests, true);
-
- String tmp_cookie = conn.getHeaderField("set-cookie");
-
- if (tmp_cookie != null && cookie == null) {
- // New session -- track it and its handler
- cookie = tmp_cookie;
- modifyCount(handlerNode, sessions, true);
- // Track this handler so we can decrement the session
- // count in case of failover or error
- lastHandler = handlerNode;
- } else if (lastHandler != null && !lastHandler.equals(handlerNode)) {
- // Ongoing session has failed over in an unplanned way,
- // so decrement the previous handler's count.
- modifyCount(lastHandler, sessions, false);
- lastHandler = null;
- }
-
- return conn.getResponseCode();
- } catch (Exception e) {
- handleSessionTermination();
-
- if (e instanceof IOException)
- throw (IOException) e;
- else
- throw (RuntimeException) e;
- } finally {
- if (conn != null)
- conn.disconnect();
- }
- }
-
- private void handleSessionTermination() {
- cookie = null;
- String last = lastHandler;
- lastHandler = null;
- if (last != null) {
- // Decrement the session count for whoever last handled a request
- modifyCount(last, sessions, false);
- }
- }
-
- private static void modifyCount(String handlerNode, ConcurrentMap map, boolean increment) {
- if (handlerNode != null) {
- AtomicInteger count = map.get(handlerNode);
- if (count == null) {
- count = new AtomicInteger();
- AtomicInteger existing = map.putIfAbsent(handlerNode, count);
- if (existing != null) {
- count = existing;
- }
- }
-
- if (increment)
- count.incrementAndGet();
- else
- count.decrementAndGet();
- }
- }
-
- private static void error(String msg, Throwable th) {
- String tmp = "[thread-" + Thread.currentThread().getId() + "]: " + msg;
- if (th != null) {
- tmp += ", ex: " + th + "\n";
- StringWriter writer = new StringWriter();
- PrintWriter pw = new PrintWriter(writer);
- th.printStackTrace(pw);
- pw.flush();
- tmp += writer.toString();
- }
- System.err.println(tmp);
- }
- }
-}
\ No newline at end of file
diff --git a/demo/client/src/main/java/org/jboss/modcluster/demo/client/load/ServerLoadParam.java b/demo/client/src/main/java/org/jboss/modcluster/demo/client/load/ServerLoadParam.java
deleted file mode 100755
index 13630523..00000000
--- a/demo/client/src/main/java/org/jboss/modcluster/demo/client/load/ServerLoadParam.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright The mod_cluster Project Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-package org.jboss.modcluster.demo.client.load;
-
-/**
- * @author Brian Stansberry
- */
-public class ServerLoadParam {
- private final String name;
- private final String label;
- private final String description;
- private String value;
-
- public ServerLoadParam(String name, String label, String description, String value) {
- this.name = name;
- this.label = label;
- this.description = description;
- this.value = value;
- }
-
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
-
- public String getName() {
- return name;
- }
-
- public String getLabel() {
- return label;
- }
-
- public String getDescription() {
- return description;
- }
-}
diff --git a/demo/client/src/main/java/org/jboss/modcluster/demo/client/load/ServerLoadServlets.java b/demo/client/src/main/java/org/jboss/modcluster/demo/client/load/ServerLoadServlets.java
deleted file mode 100755
index cdcdc470..00000000
--- a/demo/client/src/main/java/org/jboss/modcluster/demo/client/load/ServerLoadServlets.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright The mod_cluster Project Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-package org.jboss.modcluster.demo.client.load;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-/**
- * @author Brian Stansberry
- */
-public enum ServerLoadServlets {
- ACTIVE_SESSIONS("Active Sessions", "Generates server load by causing session creation on the target server.", "sessions",
- new ServerLoadParam("count", "Number of Sessions", "Number of sessions to create", "20")),
-
- DATASOURCE_USAGE(
- "Datasource Use",
- "Generates server load by taking connections from the java:DefaultDS datasource for a period",
- "database",
- new ServerLoadParam("count", "Number of Connections", "Number of connections to request from the datasource", "20"),
- new ServerLoadParam("duration", "Duration",
- "Number of seconds to hold the connections before returning to datasource", "15")),
-
- CONNECTOR_THREAD_USAGE("Connector Thread Use",
- "Generates server load by tieing up threads in the webserver connections pool for a period", "connectors",
- new ServerLoadParam("count", "Number of Connections", "Number of connection pool threads to tie up", "50"),
- new ServerLoadParam("duration", "Duration", "Number of seconds to tie up the connections", "15")),
-
- HEAP_MEMORY_USAGE("Heap Memory Use", "Generates server load by filling a percentage of free heap memory for a period",
- "heap", new ServerLoadParam("duration", "Duration", "Number of seconds to maintain memory usage", "15"),
- new ServerLoadParam("ratio", "Ratio", "Percentage of heap memory to reserve", "0.9")),
-
- CPU_USAGE("CPU Use", "Generates server CPU load by initiating a tight loop in a thread", "cpu", new ServerLoadParam(
- "duration", "Duration", "Number of seconds to maintain CPU usage", "15")),
-
- RECEIVE_TRAFFIC_USAGE("Server Receive Traffic",
- "Generates server traffic receipt load by POSTing a large byte array to the server once per second for a period",
- "receive", new ServerLoadParam("size", "POST size", "Number of bytes to POST, divided by 1000", "100"),
- new ServerLoadParam("duration", "Duration", "Number of seconds to continue POSTing", "15")),
-
- SEND_TRAFFIC_USAGE(
- "Server Send Traffic",
- "Generates server traffic send load by making a request once per second to which the server responds with a large byte array",
- "send",
- new ServerLoadParam("size", "Response size", "Size of the server response in bytes, divided by 1000", "100"),
- new ServerLoadParam("duration", "Duration", "Number of seconds to continue POSTing", "15")),
-
- REQUEST_COUNT_USAGE("Request Count",
- "Generates server load by making numerous requests, increasing the request count on the target server.",
- "requests", new ServerLoadParam("count", "Number of Requests", "Number of requestss to make", "50"));
-
- private final String label;
- private final String description;
- private final String servletPath;
- private final List params;
-
- ServerLoadServlets(String label, String description, String servletPath, ServerLoadParam... params) {
- this.label = label;
- this.description = description;
- this.servletPath = servletPath;
- if (params != null) {
- this.params = Collections.unmodifiableList(Arrays.asList(params));
- } else {
- this.params = Collections.emptyList();
- }
- }
-
- public String getLabel() {
- return label;
- }
-
- public String getDescription() {
- return description;
- }
-
- public String getServletPath() {
- return servletPath;
- }
-
- public List getParams() {
- return params;
- }
-
- @Override
- public String toString() {
- return label;
- }
-}
diff --git a/demo/client/src/main/resources/run-demo.bat b/demo/client/src/main/resources/run-demo.bat
deleted file mode 100755
index 668da1f4..00000000
--- a/demo/client/src/main/resources/run-demo.bat
+++ /dev/null
@@ -1,34 +0,0 @@
-@echo off
-setlocal ENABLEDELAYEDEXPANSION
-
-REM
-REM Copyright The mod_cluster Project Authors
-REM SPDX-License-Identifier: Apache-2.0
-REM
-
-set CP=
-
-for %%i in (lib\*.jar) do call :concatsep %%i
-
-REM Uncomment the following line for enabling JVM performance options
-REM set "OPTS=-Xmn200M -Xmx300M -Xms300M -Xss8K -XX:ThreadStackSize=8k -XX:CompileThreshold=100 -XX:SurvivorRatio=8 -XX:TargetSurvivorRatio=90 -XX:MaxTenuringThreshold=15"
-
-REM Tell the HttpURLConnection pool to maintain 400 connections max
-set "OPTS=%OPTS% -Dhttp.maxConnections=400"
-
-REM Set defaults for the load balancer
-set "OPTS=%OPTS% -Dmod_cluster.proxy.host=localhost -Dmod_cluster.proxy.port=8000"
-
-java -cp %CP% %OPTS% org.jboss.modcluster.demo.client.ModClusterDemo
-
-goto end
-
-:concatsep
-
-if "%CP%" == "" (
-set CP=%1
-)else (
-set CP=%CP%;%1
-)
-
-:end
diff --git a/demo/client/src/main/resources/run-demo.sh b/demo/client/src/main/resources/run-demo.sh
deleted file mode 100755
index c9776dc5..00000000
--- a/demo/client/src/main/resources/run-demo.sh
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/usr/bin/env bash
-
-#
-# Copyright The mod_cluster Project Authors
-# SPDX-License-Identifier: Apache-2.0
-#
-
-CP=
-
-for i in lib/*.jar
-do
- CP=${CP}:./${i}
-done
-
-# Uncomment the following line for enabling JVM performance options; note -Xss8K may cause troubles check ulimit -s should be >= 8192
-#OPTS="-Xmn200M -Xmx300M -Xms300M -Xss8K -XX:ThreadStackSize=8k -XX:CompileThreshold=100 -XX:SurvivorRatio=8 -XX:TargetSurvivorRatio=90 -XX:MaxTenuringThreshold=15"
-
-# Tell the HttpURLConnection pool to maintain 400 connections max
-OPTS="$OPTS -Dhttp.maxConnections=400"
-
-# Set defaults for the load balancer
-OPTS="$OPTS -Dmod_cluster.proxy.host=localhost -Dmod_cluster.proxy.port=8000"
-
-java -classpath $CP $OPTS org.jboss.modcluster.demo.client.ModClusterDemo
diff --git a/demo/pom.xml b/demo/pom.xml
deleted file mode 100644
index 13e6733c..00000000
--- a/demo/pom.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
- 4.0.0
-
- org.jboss.mod_cluster
- mod_cluster-parent
- 2.0.4.Final-SNAPSHOT
-
- mod_cluster-demo
- mod_cluster: Demo (parent)
- pom
-
- client
- server
-
-
\ No newline at end of file
diff --git a/demo/server/pom.xml b/demo/server/pom.xml
deleted file mode 100644
index 66364da7..00000000
--- a/demo/server/pom.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
-
- 4.0.0
-
- org.jboss.mod_cluster
- mod_cluster-demo
- 2.0.4.Final-SNAPSHOT
-
- mod_cluster-demo-server
- mod_cluster: Demo - Server
- war
-
-
- org.jboss.spec.javax.servlet
- jboss-servlet-api_3.0_spec
- provided
-
-
- org.apache.httpcomponents
- httpclient
-
-
-
\ No newline at end of file
diff --git a/demo/server/src/main/java/org/jboss/modcluster/demo/servlet/ActiveSessionsLoadServlet.java b/demo/server/src/main/java/org/jboss/modcluster/demo/servlet/ActiveSessionsLoadServlet.java
deleted file mode 100755
index 21e9b9d4..00000000
--- a/demo/server/src/main/java/org/jboss/modcluster/demo/servlet/ActiveSessionsLoadServlet.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright The mod_cluster Project Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-package org.jboss.modcluster.demo.servlet;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
-import java.io.IOException;
-import java.net.URI;
-
-import org.apache.http.client.methods.HttpHead;
-import org.apache.http.client.utils.HttpClientUtils;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
-
-/**
- * @author Paul Ferraro
- * @author Radoslav Husar
- */
-public class ActiveSessionsLoadServlet extends LoadServlet {
-
- private static final long serialVersionUID = -946741803216943778L;
-
- @Override
- protected void doHead(HttpServletRequest request, HttpServletResponse response) {
- HttpSession session = request.getSession(true);
- this.log("Handling session load request from: " + request.getRequestURL().toString() + ", using session id: " + session.getId());
- }
-
- @Override
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
- int count = Integer.parseInt(this.getParameter(request, COUNT, "20"));
-
- URI uri = this.createLocalURI(request, null);
-
- this.log("Sending " + count + " requests to: " + uri);
-
- try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
- for (int i = 0; i < count; ++i) {
- HttpClientUtils.closeQuietly(client.execute(new HttpHead(uri)));
- }
- }
-
- this.writeLocalName(request, response);
- }
-}
diff --git a/demo/server/src/main/java/org/jboss/modcluster/demo/servlet/BusyConnectorsLoadServlet.java b/demo/server/src/main/java/org/jboss/modcluster/demo/servlet/BusyConnectorsLoadServlet.java
deleted file mode 100755
index 314a386c..00000000
--- a/demo/server/src/main/java/org/jboss/modcluster/demo/servlet/BusyConnectorsLoadServlet.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * Copyright The mod_cluster Project Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-package org.jboss.modcluster.demo.servlet;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.net.URI;
-import java.util.Collections;
-
-import org.apache.http.HttpResponse;
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.client.methods.HttpHead;
-import org.apache.http.client.utils.HttpClientUtils;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
-
-/**
- * @author Paul Ferraro
- *
- */
-public class BusyConnectorsLoadServlet extends LoadServlet {
-
- private static final long serialVersionUID = -946741803216943778L;
-
- private static final String END = "end";
-
- @Override
- protected void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
- String parameter = request.getParameter(END);
-
- if (parameter == null) {
- int duration = Integer.parseInt(this.getParameter(request, DURATION, "15")) * 1000;
-
- long end = System.currentTimeMillis() + duration;
-
- URI uri = this.createLocalURI(request, Collections.singletonMap(END, String.valueOf(end)));
- Runnable task = new ExecuteMethodTask(uri);
-
- int count = Integer.parseInt(this.getParameter(request, COUNT, "50"));
-
- this.log("Sending " + count + " concurrent requests to: " + uri);
-
- Thread[] threads = new Thread[count];
-
- for (int i = 0; i < count; ++i) {
- threads[i] = new Thread(task);
- }
-
- for (int i = 0; i < count; ++i) {
- threads[i].start();
- }
-
- for (int i = 0; i < count; ++i) {
- try {
- threads[i].join();
- } catch (InterruptedException e) {
- Thread.currentThread().interrupt();
- }
- }
-
- this.writeLocalName(request, response);
- } else {
- long end = Long.parseLong(parameter);
-
- if (end > System.currentTimeMillis()) {
- URI uri = this.createLocalURI(request, Collections.singletonMap(END, String.valueOf(end)));
- response.setStatus(HttpServletResponse.SC_TEMPORARY_REDIRECT);
- response.setHeader("location", response.encodeRedirectURL(uri.toString()));
- }
- }
- }
-
- private class ExecuteMethodTask implements Runnable {
- private final URI uri;
-
- ExecuteMethodTask(URI uri) {
- this.uri = uri;
- }
-
- @Override
- public void run() {
- URI uri = this.uri;
-
- try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
- while (uri != null) {
- // Disable auto redirect following, to allow circular redirect
- RequestConfig requestConfig = RequestConfig.custom().setCircularRedirectsAllowed(true).build();
-
- HttpHead head = new HttpHead(uri);
- head.setConfig(requestConfig);
-
- HttpResponse response = client.execute(head);
- try {
- int code = response.getStatusLine().getStatusCode();
-
- uri = (code == HttpServletResponse.SC_TEMPORARY_REDIRECT) ? URI.create(response.getFirstHeader("location").getValue()) : null;
- } finally {
- HttpClientUtils.closeQuietly(response);
- }
- }
- } catch (IOException e) {
- BusyConnectorsLoadServlet.this.log(e.getLocalizedMessage(), e);
- }
- }
- }
-}
diff --git a/demo/server/src/main/java/org/jboss/modcluster/demo/servlet/HeapMemoryLoadServlet.java b/demo/server/src/main/java/org/jboss/modcluster/demo/servlet/HeapMemoryLoadServlet.java
deleted file mode 100755
index e8dc6798..00000000
--- a/demo/server/src/main/java/org/jboss/modcluster/demo/servlet/HeapMemoryLoadServlet.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright The mod_cluster Project Authors
- * SPDX-License-Identifier: Apache-2.0
- */
-package org.jboss.modcluster.demo.servlet;
-
-import java.io.IOException;
-import java.lang.management.ManagementFactory;
-import java.lang.management.MemoryUsage;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- * @author Paul Ferraro
- */
-public class HeapMemoryLoadServlet extends LoadServlet {
- /** The serialVersionUID */
- private static final long serialVersionUID = -8183119455180366670L;
-
- private static final String RATIO = "ratio";
- private static final String DEFAULT_RATIO = "0.9";
-
- private static final int MB = 1024 * 1024;
-
- @Override
- protected void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
- int duration = Integer.parseInt(this.getParameter(request, DURATION, DEFAULT_DURATION)) * 1000;
- float ratio = Float.parseFloat(this.getParameter(request, RATIO, DEFAULT_RATIO));
-
- System.gc();
-
- MemoryUsage usage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
-
- long max = usage.getMax();
- long total = (max >= 0) ? max : usage.getCommitted();
- long free = total - usage.getUsed();
-
- long reserve = (long) (free * ratio);
-
- this.log((total / MB) + "MB total memory");
- this.log((free / MB) + "MB free memory");
- this.log("Reserving " + (reserve / MB) + "MB (" + ((int) (ratio * 100)) + "%) of memory");
-
- List