diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6465a7e..13ff52d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ ubuntu-latest ] + os: [ ubuntu-latest, windows-latest, macos-latest ] java: [ 17 ] steps: - name: Checkout diff --git a/load-balancing-demo/client/src/main/java/org/jboss/modcluster/demo/client/ChartManager.java b/load-balancing-demo/client/src/main/java/org/jboss/modcluster/demo/client/ChartManager.java index b8cb226..93bde53 100755 --- a/load-balancing-demo/client/src/main/java/org/jboss/modcluster/demo/client/ChartManager.java +++ b/load-balancing-demo/client/src/main/java/org/jboss/modcluster/demo/client/ChartManager.java @@ -20,9 +20,9 @@ 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 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; @@ -81,7 +81,7 @@ public void updateStats() { last = 0; } - int perSec = (int) ((current.intValue() - last.intValue()) / elapsed); + int perSec = (int) ((current - last) / elapsed); XYSeries series = requestSeries.get(key); if (series == null) { diff --git a/load-balancing-demo/client/src/main/java/org/jboss/modcluster/demo/client/ModClusterDemo.java b/load-balancing-demo/client/src/main/java/org/jboss/modcluster/demo/client/ModClusterDemo.java index 8493998..28d0122 100755 --- a/load-balancing-demo/client/src/main/java/org/jboss/modcluster/demo/client/ModClusterDemo.java +++ b/load-balancing-demo/client/src/main/java/org/jboss/modcluster/demo/client/ModClusterDemo.java @@ -159,10 +159,10 @@ public void windowClosed(WindowEvent e) { public void stateChanged(ChangeEvent e) { if (loadPanel.equals(tabbedPane.getSelectedComponent())) { String text = targetHostNameField.getText(); - if (text == null || text.length() == 0) + if (text == null || text.isEmpty()) targetHostNameField.setText(proxyHostNameField.getText()); text = targetPortField.getText(); - if (text == null || text.length() == 0) + if (text == null || text.isEmpty()) targetPortField.setText(proxyPortField.getText()); } } @@ -172,8 +172,8 @@ public void stateChanged(ChangeEvent e) { 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 }; + 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(); @@ -279,7 +279,7 @@ private JPanel createClientControlPanel() { controlPanel.add(sessionTimeoutLabel, gridBagConstraints); sessionTimeoutField = new JTextField(); - sessionTimeoutField.setText(String.valueOf(DEFAULT_SESSION_TIMEOUT)); + sessionTimeoutField.setText(DEFAULT_SESSION_TIMEOUT); sessionTimeoutField.setEnabled(destroySessionField.isSelected()); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridy = 4; @@ -382,8 +382,8 @@ public void actionPerformed(final ActionEvent e) { controlPanel.add(statusPanel, gridBagConstraints); gridBagLayout = new GridBagLayout(); - gridBagLayout.columnWidths = new int[] { 0, 0, 7 }; - gridBagLayout.rowHeights = new int[] { 0, 7, 0, 0 }; + gridBagLayout.columnWidths = new int[] {0, 0, 7}; + gridBagLayout.rowHeights = new int[] {0, 7, 0, 0}; statusPanel.setLayout(gridBagLayout); label = new JLabel(); @@ -405,7 +405,7 @@ public void actionPerformed(final ActionEvent e) { statusPanel.add(label, gridBagConstraints); totalClientsLabel = new JLabel(); - totalClientsLabel.setText(String.valueOf("0")); + totalClientsLabel.setText("0"); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridy = 2; gridBagConstraints.gridx = 3; @@ -421,7 +421,7 @@ public void actionPerformed(final ActionEvent e) { statusPanel.add(label, gridBagConstraints); liveClientsLabel = new JLabel(); - liveClientsLabel.setText(String.valueOf("0")); + liveClientsLabel.setText("0"); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridy = 3; gridBagConstraints.gridx = 3; @@ -437,7 +437,7 @@ public void actionPerformed(final ActionEvent e) { statusPanel.add(label, gridBagConstraints); failedClientsLabel = new JLabel(); - failedClientsLabel.setText(String.valueOf("0")); + failedClientsLabel.setText("0"); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridy = 4; gridBagConstraints.gridx = 3; @@ -450,8 +450,8 @@ public void actionPerformed(final ActionEvent e) { 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 }; + 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(); @@ -603,8 +603,8 @@ public void actionPerformed(final ActionEvent e) { private JPanel createRequestBalancingPanel() { final JPanel requestBalancingPanel = new JPanel(); GridBagLayout gridBagLayout = new GridBagLayout(); - gridBagLayout.columnWidths = new int[] { 0 }; - gridBagLayout.rowHeights = new int[] { 0, 0 }; + gridBagLayout.columnWidths = new int[] {0}; + gridBagLayout.rowHeights = new int[] {0, 0}; requestBalancingPanel.setLayout(gridBagLayout); final JPanel requestChart = new ChartPanel(this.chartManager.getRequestBalancingChart(), true); @@ -618,8 +618,8 @@ private JPanel createRequestBalancingPanel() { 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 }; + 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(); @@ -638,7 +638,7 @@ private JPanel createRequestBalancingPanel() { clientStatusPanel.add(label, gridBagConstraints); totalClientsLabelReq = new JLabel(); - totalClientsLabelReq.setText(String.valueOf("0")); + totalClientsLabelReq.setText("0"); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridy = 0; gridBagConstraints.gridx = 3; @@ -654,7 +654,7 @@ private JPanel createRequestBalancingPanel() { clientStatusPanel.add(label, gridBagConstraints); liveClientsLabelReq = new JLabel(); - liveClientsLabelReq.setText(String.valueOf("0")); + liveClientsLabelReq.setText("0"); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridy = 0; gridBagConstraints.gridx = 7; @@ -670,7 +670,7 @@ private JPanel createRequestBalancingPanel() { clientStatusPanel.add(label, gridBagConstraints); failedClientsLabelReq = new JLabel(); - failedClientsLabelReq.setText(String.valueOf("0")); + failedClientsLabelReq.setText("0"); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridy = 0; gridBagConstraints.gridx = 11; @@ -683,8 +683,8 @@ private JPanel createRequestBalancingPanel() { private JPanel createSessionBalancingPanel() { final JPanel sessionBalancingPanel = new JPanel(); GridBagLayout gridBagLayout = new GridBagLayout(); - gridBagLayout.columnWidths = new int[] { 0 }; - gridBagLayout.rowHeights = new int[] { 0, 0 }; + gridBagLayout.columnWidths = new int[] {0}; + gridBagLayout.rowHeights = new int[] {0, 0}; sessionBalancingPanel.setLayout(gridBagLayout); JPanel sessionBalancingChart = new ChartPanel(this.chartManager.getSessionBalancingChart(), true); @@ -699,8 +699,8 @@ private JPanel createSessionBalancingPanel() { 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 }; + 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(); @@ -719,7 +719,7 @@ private JPanel createSessionBalancingPanel() { clientStatusPanel.add(label, gridBagConstraints); totalClientsLabelSess = new JLabel(); - totalClientsLabelSess.setText(String.valueOf("0")); + totalClientsLabelSess.setText("0"); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridy = 0; gridBagConstraints.gridx = 3; @@ -735,7 +735,7 @@ private JPanel createSessionBalancingPanel() { clientStatusPanel.add(label, gridBagConstraints); liveClientsLabelSess = new JLabel(); - liveClientsLabelSess.setText(String.valueOf("0")); + liveClientsLabelSess.setText("0"); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridy = 0; gridBagConstraints.gridx = 7; @@ -751,7 +751,7 @@ private JPanel createSessionBalancingPanel() { clientStatusPanel.add(label, gridBagConstraints); failedClientsLabelSess = new JLabel(); - failedClientsLabelSess.setText(String.valueOf("0")); + failedClientsLabelSess.setText("0"); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridy = 0; gridBagConstraints.gridx = 11; @@ -770,7 +770,7 @@ private JPanel createSessionBalancingPanel() { private void start() { String sessionTimeoutText = sessionTimeoutField.getText(); int sessionTimeout = -1; - if (sessionTimeoutText != null && sessionTimeoutText.trim().length() > 0) { + if (sessionTimeoutText != null && !sessionTimeoutText.trim().isEmpty()) { try { sessionTimeout = Integer.parseInt(sessionTimeoutText); } catch (NumberFormatException e) { @@ -787,7 +787,7 @@ private void start() { requestURL = new URL(tmp); destroyURL = new URL(tmp + "?destroy=true"); } else { - String timeoutParam = (sessionTimeout > 0) ? "?timeout=" + String.valueOf(sessionTimeout) : ""; + String timeoutParam = (sessionTimeout > 0) ? "?timeout=" + sessionTimeout : ""; requestURL = new URL(tmp + timeoutParam); destroyURL = requestURL; } @@ -798,25 +798,25 @@ private void start() { int num_threads = DEFAULT_NUM_THREADS; String numT = numThreadsField.getText(); - if (numT != null && numT.trim().length() > 0) { + if (numT != null && !numT.trim().isEmpty()) { num_threads = Integer.parseInt(numT); } int session_life = DEFAULT_SESSION_LIFE; String sessL = sessionLifeField.getText(); - if (sessL != null && sessL.trim().length() > 0) { + if (sessL != null && !sessL.trim().isEmpty()) { session_life = Integer.parseInt(sessL); } int sleep_time = DEFAULT_SLEEP_TIME; String sleepT = sleepTimeField.getText(); - if (sleepT != null && sleepT.trim().length() > 0) { + if (sleepT != null && !sleepT.trim().isEmpty()) { sleep_time = Integer.parseInt(sleepT); } int startup_time = DEFAULT_STARTUP_TIME; String startT = startupTimeField.getText(); - if (startT != null && startT.trim().length() > 0) { + if (startT != null && !startT.trim().isEmpty()) { startup_time = Integer.parseInt(startT); } @@ -842,7 +842,7 @@ private void createLoad() { String tmp = createBaseURL(targetHostNameField.getText(), targetPortField.getText()) + selectedLoadServlet.getServletPath(); List params = selectedLoadServlet.getParams(); - if (params.size() > 0) { + if (!params.isEmpty()) { String val = targetServletParamField1.getText(); params.get(0).setValue(val); tmp += "?" + params.get(0).getName() + "=" + val; @@ -887,7 +887,7 @@ public void run() { } private String createBaseURL(String hostText, String portText) { - if (portText == null || portText.trim().length() == 0) + if (portText == null || portText.trim().isEmpty()) portText = "80"; portText = portText.trim(); @@ -895,9 +895,9 @@ private String createBaseURL(String hostText, String portText) { if (contextPath == null) contextPath = ""; contextPath = contextPath.trim(); - if (contextPath.length() > 0 && '/' == contextPath.charAt(0)) + if (!contextPath.isEmpty() && '/' == contextPath.charAt(0)) contextPath = contextPath.length() == 1 ? "" : contextPath.substring(1); - if (contextPath.length() > 0 && '/' == contextPath.charAt(contextPath.length() - 1)) + if (!contextPath.isEmpty() && '/' == contextPath.charAt(contextPath.length() - 1)) contextPath = contextPath.length() == 1 ? "" : contextPath.substring(0, contextPath.length() - 1); return "http://" + hostText + ":" + portText + "/" + contextPath + "/"; @@ -938,7 +938,7 @@ private class ServerLoadServletCellRenderer extends JLabel implements ListCellRe @Override public Component getListCellRendererComponent(JList list, ServerLoadServlets value, int index, boolean isSelected, boolean cellHasFocus) { this.setText(value.toString()); - this.setToolTipText(((ServerLoadServlets) value).getDescription()); + this.setToolTipText(value.getDescription()); return this; } } diff --git a/load-balancing-demo/client/src/main/java/org/jboss/modcluster/demo/client/RequestDriver.java b/load-balancing-demo/client/src/main/java/org/jboss/modcluster/demo/client/RequestDriver.java index 553c2f0..cfb1d2b 100755 --- a/load-balancing-demo/client/src/main/java/org/jboss/modcluster/demo/client/RequestDriver.java +++ b/load-balancing-demo/client/src/main/java/org/jboss/modcluster/demo/client/RequestDriver.java @@ -21,8 +21,8 @@ public class RequestDriver { private Client[] clients; - private final ConcurrentMap requestCounts = new ConcurrentHashMap(); - private final ConcurrentMap sessionCounts = new ConcurrentHashMap(); + private final ConcurrentMap requestCounts = new ConcurrentHashMap<>(); + private final ConcurrentMap sessionCounts = new ConcurrentHashMap<>(); private final AtomicBoolean stopped = new AtomicBoolean(false); private Thread startThread; @@ -66,7 +66,8 @@ public void stop() { if (this.startThread != null && this.startThread.isAlive()) { try { this.startThread.join(2000); - } catch (InterruptedException e) { + } catch (InterruptedException ignored) { + // Ignored. } if (this.startThread.isAlive()) { @@ -162,7 +163,8 @@ public void run() { if (cookie != null && destroy_url != null) { executeRequest(destroy_url); } - } catch (IOException e) { + } catch (IOException ignored) { + // Ignored. } finally { // If we haven't already cleaned up this thread's // session info, do so now @@ -182,7 +184,8 @@ private void terminate() { if (this.isAlive()) { this.interrupt(); } - } catch (InterruptedException e) { + } catch (InterruptedException ignored) { + // Ignored. } } } diff --git a/load-balancing-demo/client/src/main/java/org/jboss/modcluster/demo/client/load/ServerLoadServlets.java b/load-balancing-demo/client/src/main/java/org/jboss/modcluster/demo/client/load/ServerLoadServlets.java index cdcdc47..17a9e8e 100755 --- a/load-balancing-demo/client/src/main/java/org/jboss/modcluster/demo/client/load/ServerLoadServlets.java +++ b/load-balancing-demo/client/src/main/java/org/jboss/modcluster/demo/client/load/ServerLoadServlets.java @@ -4,7 +4,6 @@ */ package org.jboss.modcluster.demo.client.load; -import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -24,7 +23,7 @@ public enum ServerLoadServlets { "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", + "Generates server load by tying 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")), @@ -49,7 +48,7 @@ public enum ServerLoadServlets { 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")); + "requests", new ServerLoadParam("count", "Number of Requests", "Number of requests to make", "50")); private final String label; private final String description; @@ -61,7 +60,7 @@ public enum ServerLoadServlets { this.description = description; this.servletPath = servletPath; if (params != null) { - this.params = Collections.unmodifiableList(Arrays.asList(params)); + this.params = List.of(params); } else { this.params = Collections.emptyList(); } diff --git a/load-balancing-demo/pom.xml b/load-balancing-demo/pom.xml index a68ff1c..c3b60d8 100644 --- a/load-balancing-demo/pom.xml +++ b/load-balancing-demo/pom.xml @@ -10,44 +10,30 @@ mod_cluster-examples-parent 2.1.0.Final-SNAPSHOT + mod_cluster-demo mod_cluster Examples: Demo (parent) pom + client server - - 3.5.3.Final - 2.2.1.Final - - + 6.0.0 4.5.14 1.0.13 1.0 4.13.2 - 5.8.0 - 1.0.2.Final - org.jboss.spec.javax.servlet - jboss-servlet-api_3.0_spec - ${version.javax.servlet-3.0} - - - org.jboss.logging - jboss-logging - ${version.jboss-logging} - - - org.jboss.logging - jboss-logging-processor - ${version.jboss-logging-processor} + jakarta.servlet + jakarta.servlet-api + ${version.jakarta.servlet-api} org.apache.httpcomponents @@ -59,37 +45,9 @@ jfreechart ${version.jfreechart} - - net.jcip - jcip-annotations - ${version.jcip-annotations} - - - junit - junit - ${version.junit} - - - org.mockito - mockito-core - ${version.mockito} - - - - junit - junit - test - - - org.mockito - mockito-core - test - - - @@ -103,89 +61,6 @@ true - - - org.apache.maven.plugins - maven-compiler-plugin - - - default-compile - compile - - compile - - - ${jdk.release.version} - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - - - - javax.annotation - javax.annotation-api - 1.3.2 - - - ${jdk.release.version} - - - - org.apache.maven.plugins - maven-release-plugin - - true - @{project.version} - - - - org.codehaus.mojo - versions-maven-plugin - 2.16.2 - - - org.apache.maven.plugins - maven-checkstyle-plugin - - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - - - check-style - compile - - checkstyle - - - - - - org.wildfly.checkstyle - wildfly-checkstyle-config - ${version.org.wildfly.checkstyle-config} - - - - false - wildfly-checkstyle/checkstyle.xml - true - true - true - **/*$logger.java,**/*$bundle.java - - - - - + \ No newline at end of file diff --git a/load-balancing-demo/server/pom.xml b/load-balancing-demo/server/pom.xml index 3e0859f..d1ad80e 100644 --- a/load-balancing-demo/server/pom.xml +++ b/load-balancing-demo/server/pom.xml @@ -10,13 +10,15 @@ mod_cluster-demo 2.1.0.Final-SNAPSHOT + mod_cluster-demo-server mod_cluster Examples: Demo - Server war + - org.jboss.spec.javax.servlet - jboss-servlet-api_3.0_spec + jakarta.servlet + jakarta.servlet-api provided @@ -24,4 +26,5 @@ httpclient + \ No newline at end of file diff --git a/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/ContextParamConfig.java b/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/ContextParamConfig.java new file mode 100644 index 0000000..a1691f2 --- /dev/null +++ b/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/ContextParamConfig.java @@ -0,0 +1,23 @@ +/* + * Copyright The mod_cluster Project Authors + * SPDX-License-Identifier: Apache-2.0 + */ +package org.jboss.modcluster.demo; + +import jakarta.servlet.ServletContextEvent; +import jakarta.servlet.ServletContextListener; +import jakarta.servlet.annotation.WebListener; + +/** + * @author Radoslav Husar + */ +@WebListener +public class ContextParamConfig implements ServletContextListener { + + @Override + public void contextInitialized(ServletContextEvent sce) { + // Set the context parameter programmatically + sce.getServletContext().setInitParameter("duration", "15"); + } + +} diff --git a/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/ActiveSessionsLoadServlet.java b/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/ActiveSessionsLoadServlet.java index 21e9b9d..f64c25a 100755 --- a/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/ActiveSessionsLoadServlet.java +++ b/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/ActiveSessionsLoadServlet.java @@ -4,12 +4,16 @@ */ 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.io.Serial; import java.net.URI; +import jakarta.servlet.annotation.WebInitParam; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; + import org.apache.http.client.methods.HttpHead; import org.apache.http.client.utils.HttpClientUtils; import org.apache.http.impl.client.CloseableHttpClient; @@ -19,8 +23,16 @@ * @author Paul Ferraro * @author Radoslav Husar */ +@WebServlet( + name = "sessions", + urlPatterns = {"/sessions"}, + initParams = { + @WebInitParam(name = "count", value = "20") + } +) public class ActiveSessionsLoadServlet extends LoadServlet { + @Serial private static final long serialVersionUID = -946741803216943778L; @Override diff --git a/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/BusyConnectorsLoadServlet.java b/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/BusyConnectorsLoadServlet.java index 314a386..d0a8d7d 100755 --- a/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/BusyConnectorsLoadServlet.java +++ b/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/BusyConnectorsLoadServlet.java @@ -4,12 +4,16 @@ */ package org.jboss.modcluster.demo.servlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.io.Serial; import java.net.URI; import java.util.Collections; +import jakarta.servlet.annotation.WebInitParam; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + import org.apache.http.HttpResponse; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpHead; @@ -19,10 +23,18 @@ /** * @author Paul Ferraro - * + * @author Radoslav Husar */ +@WebServlet( + name = "connectors", + urlPatterns = {"/connectors"}, + initParams = { + @WebInitParam(name = "count", value = "50") + } +) public class BusyConnectorsLoadServlet extends LoadServlet { + @Serial private static final long serialVersionUID = -946741803216943778L; private static final String END = "end"; diff --git a/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/HeapMemoryLoadServlet.java b/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/HeapMemoryLoadServlet.java index e8dc679..59daa52 100755 --- a/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/HeapMemoryLoadServlet.java +++ b/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/HeapMemoryLoadServlet.java @@ -5,19 +5,27 @@ package org.jboss.modcluster.demo.servlet; import java.io.IOException; +import java.io.Serial; 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; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; /** * @author Paul Ferraro + * @author Radoslav Husar */ +@WebServlet( + name = "heap", + urlPatterns = {"/heap"} +) public class HeapMemoryLoadServlet extends LoadServlet { - /** The serialVersionUID */ + + @Serial private static final long serialVersionUID = -8183119455180366670L; private static final String RATIO = "ratio"; @@ -44,7 +52,7 @@ protected void service(HttpServletRequest request, HttpServletResponse response) this.log((free / MB) + "MB free memory"); this.log("Reserving " + (reserve / MB) + "MB (" + ((int) (ratio * 100)) + "%) of memory"); - List list = new ArrayList(2); + List list = new ArrayList<>(2); if (free > Integer.MAX_VALUE) { list.add(new byte[(int) (reserve / Integer.MAX_VALUE)][Integer.MAX_VALUE]); @@ -53,7 +61,6 @@ protected void service(HttpServletRequest request, HttpServletResponse response) list.add(new byte[(int) (reserve % Integer.MAX_VALUE)]); try { - Thread.sleep(duration); } catch (InterruptedException e) { Thread.currentThread().interrupt(); diff --git a/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/LoadServlet.java b/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/LoadServlet.java index 531f6b2..9e0e69c 100755 --- a/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/LoadServlet.java +++ b/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/LoadServlet.java @@ -5,26 +5,29 @@ package org.jboss.modcluster.demo.servlet; import java.io.IOException; +import java.io.Serial; import java.lang.management.ManagementFactory; import java.net.URI; import java.net.URISyntaxException; import java.util.Iterator; import java.util.Map; - import javax.management.JMException; import javax.management.MBeanServer; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; + +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; /** * @author Paul Ferraro + * @author Radoslav Husar */ public class LoadServlet extends HttpServlet { - /** The serialVersionUID */ + + @Serial private static final long serialVersionUID = 5665079393261425098L; protected static final String DURATION = "duration"; @@ -37,8 +40,15 @@ public class LoadServlet extends HttpServlet { @Override public void init() throws ServletException { + // Set manually via 'jboss.mod_cluster.jvmRoute' this.jvmRoute = System.getProperty(JVM_ROUTE_SYSTEM_PROPERTY); + // WildFly + if (this.jvmRoute == null) { + this.jvmRoute = System.getProperty("jboss.node.name"); + } + + // TODO Adapt for Tomcat if (this.jvmRoute == null) { try { MBeanServer server = ManagementFactory.getPlatformMBeanServer(); @@ -57,7 +67,7 @@ public void init() throws ServletException { } private ObjectName findObjectName(MBeanServer server, String key, String value, String... domains) throws MalformedObjectNameException { - for (String domain: domains) { + for (String domain : domains) { ObjectName name = ObjectName.getInstance(domain, key, value); if (server.isRegistered(name)) { return name; diff --git a/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/ReceiveTrafficLoadServlet.java b/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/ReceiveTrafficLoadServlet.java index a0502ca..20d43a8 100755 --- a/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/ReceiveTrafficLoadServlet.java +++ b/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/ReceiveTrafficLoadServlet.java @@ -4,11 +4,15 @@ */ package org.jboss.modcluster.demo.servlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.io.Serial; import java.net.URI; +import jakarta.servlet.annotation.WebInitParam; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + import org.apache.http.HttpEntity; import org.apache.http.client.methods.HttpPut; import org.apache.http.client.utils.HttpClientUtils; @@ -18,9 +22,18 @@ /** * @author Paul Ferraro + * @author Radoslav Husar */ +@WebServlet( + name = "receive", + urlPatterns = {"/receive"}, + initParams = { + @WebInitParam(name = "size", value = "100") + } +) public class ReceiveTrafficLoadServlet extends LoadServlet { + @Serial private static final long serialVersionUID = 2344830128026153418L; private static final String SIZE = "size"; diff --git a/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/RecordServlet.java b/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/RecordServlet.java index 22d9ad3..ac64e32 100755 --- a/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/RecordServlet.java +++ b/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/RecordServlet.java @@ -5,17 +5,26 @@ package org.jboss.modcluster.demo.servlet; import java.io.IOException; +import java.io.Serial; +import java.util.Collections; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import jakarta.servlet.http.HttpSession; /** * @author Paul Ferraro + * @author Radoslav Husar */ +@WebServlet( + name = "record", + urlPatterns = {"/record"} +) public class RecordServlet extends LoadServlet { - /** The serialVersionUID */ + + @Serial private static final long serialVersionUID = -4143320241936636855L; private static final String DESTROY = "destroy"; @@ -25,7 +34,7 @@ public class RecordServlet extends LoadServlet { protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(true); - boolean destroy = Boolean.valueOf(request.getParameter(DESTROY)); + boolean destroy = Boolean.parseBoolean(request.getParameter(DESTROY)); if (destroy) { session.invalidate(); @@ -33,14 +42,14 @@ protected void service(HttpServletRequest request, HttpServletResponse response) String timeout = request.getParameter(TIMEOUT); if (timeout != null) { - session.setMaxInactiveInterval(Integer.valueOf(timeout)); + session.setMaxInactiveInterval(Integer.parseInt(timeout)); } } if (!request.getAttributeNames().hasMoreElements()) { System.out.println("No request attributes"); } - for (String attribute: java.util.Collections.list(request.getAttributeNames())) { + for (String attribute : Collections.list(request.getAttributeNames())) { System.out.println(attribute + " = " + request.getAttribute(attribute)); } response.setHeader("X-ClusterNode", this.getJvmRoute()); diff --git a/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/RequestCountLoadServlet.java b/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/RequestCountLoadServlet.java index 4d1f1d0..dff1b66 100755 --- a/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/RequestCountLoadServlet.java +++ b/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/RequestCountLoadServlet.java @@ -4,12 +4,16 @@ */ package org.jboss.modcluster.demo.servlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.io.Serial; import java.net.URI; import java.util.Collections; +import jakarta.servlet.annotation.WebInitParam; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + import org.apache.http.client.methods.HttpGet; import org.apache.http.client.utils.HttpClientUtils; import org.apache.http.impl.client.CloseableHttpClient; @@ -17,9 +21,18 @@ /** * @author Paul Ferraro + * @author Radoslav Husar */ +@WebServlet( + name = "requests", + urlPatterns = {"/requests"}, + initParams = { + @WebInitParam(name = "count", value = "50") + } +) public class RequestCountLoadServlet extends LoadServlet { + @Serial private static final long serialVersionUID = -5001091954463802789L; @Override diff --git a/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/SendTrafficLoadServlet.java b/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/SendTrafficLoadServlet.java index 77a0eb5..ae6f655 100755 --- a/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/SendTrafficLoadServlet.java +++ b/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/SendTrafficLoadServlet.java @@ -4,13 +4,17 @@ */ package org.jboss.modcluster.demo.servlet; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.io.Serial; import java.net.URI; import java.util.Collections; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebInitParam; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + import org.apache.http.client.methods.HttpPost; import org.apache.http.client.utils.HttpClientUtils; import org.apache.http.impl.client.CloseableHttpClient; @@ -18,9 +22,18 @@ /** * @author Paul Ferraro + * @author Radoslav Husar */ +@WebServlet( + name = "send", + urlPatterns = {"/send"}, + initParams = { + @WebInitParam(name = "size", value = "100") + } +) public class SendTrafficLoadServlet extends LoadServlet { + @Serial private static final long serialVersionUID = -8586013739155819909L; private static final String SIZE = "size"; diff --git a/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/SystemLoadServlet.java b/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/SystemLoadServlet.java index b9b2ede..7429d54 100755 --- a/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/SystemLoadServlet.java +++ b/load-balancing-demo/server/src/main/java/org/jboss/modcluster/demo/servlet/SystemLoadServlet.java @@ -5,15 +5,23 @@ package org.jboss.modcluster.demo.servlet; import java.io.IOException; +import java.io.Serial; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; /** * @author Paul Ferraro + * @author Radoslav Husar */ +@WebServlet( + name = "cpu", + urlPatterns = {"/cpu"} +) public class SystemLoadServlet extends LoadServlet { - /** The serialVersionUID */ + + @Serial private static final long serialVersionUID = 5665079393261425098L; @Override diff --git a/load-balancing-demo/server/src/main/webapp/WEB-INF/jboss-web.xml b/load-balancing-demo/server/src/main/webapp/WEB-INF/jboss-web.xml new file mode 100644 index 0000000..517e2df --- /dev/null +++ b/load-balancing-demo/server/src/main/webapp/WEB-INF/jboss-web.xml @@ -0,0 +1,13 @@ + + + + + /load-demo + + diff --git a/load-balancing-demo/server/src/main/webapp/WEB-INF/web.xml b/load-balancing-demo/server/src/main/webapp/WEB-INF/web.xml index 5d49e5b..561dc5f 100755 --- a/load-balancing-demo/server/src/main/webapp/WEB-INF/web.xml +++ b/load-balancing-demo/server/src/main/webapp/WEB-INF/web.xml @@ -3,108 +3,15 @@ ~ Copyright The mod_cluster Project Authors ~ SPDX-License-Identifier: Apache-2.0 --> - - - - - - duration - 15 - - - - record - org.jboss.modcluster.demo.servlet.RecordServlet - - - record - /record - - - - sessions - org.jboss.modcluster.demo.servlet.ActiveSessionsLoadServlet - - count - 20 - - - - sessions - /sessions - + - - connectors - org.jboss.modcluster.demo.servlet.BusyConnectorsLoadServlet - - count - 50 - - - - connectors - /connectors - - - - heap - org.jboss.modcluster.demo.servlet.HeapMemoryLoadServlet - - - heap - /heap - - - - receive - org.jboss.modcluster.demo.servlet.ReceiveTrafficLoadServlet - - size - 100 - - - - receive - /receive - - - - requests - org.jboss.modcluster.demo.servlet.RequestCountLoadServlet - - count - 50 - - - - requests - /requests - - - - send - org.jboss.modcluster.demo.servlet.SendTrafficLoadServlet - - size - 100 - - - - send - /send - - - - cpu - org.jboss.modcluster.demo.servlet.SystemLoadServlet - - - cpu - /cpu - + + + + 1 + - - 1 - diff --git a/load-balancing-demo/server/src/main/webapp/index.html b/load-balancing-demo/server/src/main/webapp/index.html new file mode 100644 index 0000000..325b0be --- /dev/null +++ b/load-balancing-demo/server/src/main/webapp/index.html @@ -0,0 +1,46 @@ + + + + + + Notice + + + +
+

mod_cluster Load Demo Application

+

+ This application is not intended to be accessed through a web browser. For further information and proper usage + instructions, please refer to the documentation. +

+
+ + diff --git a/pom.xml b/pom.xml index 38315ca..2f3d94c 100644 --- a/pom.xml +++ b/pom.xml @@ -95,4 +95,54 @@ + + + + org.apache.maven.plugins + maven-release-plugin + + true + @{project.version} + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + check-style + compile + + checkstyle + + + + + + org.wildfly.checkstyle + wildfly-checkstyle-config + ${version.org.wildfly.checkstyle-config} + + + + false + wildfly-checkstyle/checkstyle.xml + true + true + true + **/*$logger.java,**/*$bundle.java + + + + + + +