aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Becker2012-11-21 07:37:57 (EST)
committerThomas Becker2012-11-21 07:37:57 (EST)
commitac43fd4c63b429d4736ca654cf84ac53deef9dc1 (patch)
treeedd66ae4267405df905c34c0305c58791195e683
parent9e4ec32e587c7ae5d046951d26d99f0f42ee8029 (diff)
downloadorg.eclipse.jetty.project-ac43fd4c63b429d4736ca654cf84ac53deef9dc1.zip
org.eclipse.jetty.project-ac43fd4c63b429d4736ca654cf84ac53deef9dc1.tar.gz
org.eclipse.jetty.project-ac43fd4c63b429d4736ca654cf84ac53deef9dc1.tar.bz2
started to migrate java-monitor to jetty-9, however we decided to drop it. So I'll commit my unfinished status quo and then delete the module
-rw-r--r--jetty-monitor/pom.xml6
-rw-r--r--jetty-monitor/src/main/config/etc/jetty-monitor.xml2
-rw-r--r--jetty-monitor/src/main/java/org/eclipse/jetty/monitor/integration/JavaMonitorAction.java136
-rw-r--r--jetty-monitor/src/main/java/org/eclipse/jetty/monitor/integration/JavaMonitorTools.java11
-rw-r--r--jetty-monitor/src/test/java/org/eclipse/jetty/monitor/AttrEventTriggerTest.java20
-rw-r--r--pom.xml2
6 files changed, 67 insertions, 110 deletions
diff --git a/jetty-monitor/pom.xml b/jetty-monitor/pom.xml
index 229464e..7b5ac23 100644
--- a/jetty-monitor/pom.xml
+++ b/jetty-monitor/pom.xml
@@ -126,12 +126,6 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-websocket</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${project.version}</version>
<scope>test</scope>
diff --git a/jetty-monitor/src/main/config/etc/jetty-monitor.xml b/jetty-monitor/src/main/config/etc/jetty-monitor.xml
index dc97f88..bd461c4 100644
--- a/jetty-monitor/src/main/config/etc/jetty-monitor.xml
+++ b/jetty-monitor/src/main/config/etc/jetty-monitor.xml
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
-<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
+<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- Create Thread Monitor, and add to the Server as a lifecycle -->
diff --git a/jetty-monitor/src/main/java/org/eclipse/jetty/monitor/integration/JavaMonitorAction.java b/jetty-monitor/src/main/java/org/eclipse/jetty/monitor/integration/JavaMonitorAction.java
index fc83d93..9b557f1 100644
--- a/jetty-monitor/src/main/java/org/eclipse/jetty/monitor/integration/JavaMonitorAction.java
+++ b/jetty-monitor/src/main/java/org/eclipse/jetty/monitor/integration/JavaMonitorAction.java
@@ -18,28 +18,24 @@
package org.eclipse.jetty.monitor.integration;
-import static java.lang.Integer.parseInt;
-import static java.lang.System.getProperty;
-
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.URL;
+import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
-
import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
-import org.eclipse.jetty.client.ContentExchange;
import org.eclipse.jetty.client.HttpClient;
-import org.eclipse.jetty.http.HttpMethods;
+import org.eclipse.jetty.client.api.ContentResponse;
+import org.eclipse.jetty.client.util.ByteBufferContentProvider;
import org.eclipse.jetty.http.HttpStatus;
-import org.eclipse.jetty.io.ByteArrayBuffer;
import org.eclipse.jetty.monitor.JMXMonitor;
import org.eclipse.jetty.monitor.jmx.EventNotifier;
import org.eclipse.jetty.monitor.jmx.EventState;
@@ -47,9 +43,13 @@ import org.eclipse.jetty.monitor.jmx.EventState.TriggerState;
import org.eclipse.jetty.monitor.jmx.EventTrigger;
import org.eclipse.jetty.monitor.jmx.MonitorAction;
import org.eclipse.jetty.monitor.triggers.AggregateEventTrigger;
+import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
+import static java.lang.Integer.parseInt;
+import static java.lang.System.getProperty;
+
/* ------------------------------------------------------------ */
/**
@@ -69,8 +69,8 @@ public class JavaMonitorAction extends MonitorAction
/* ------------------------------------------------------------ */
/**
- * @param notifier
- * @param pollInterval
+ * @param notifier the event notifier
+ * @param pollInterval the poll interval
* @throws Exception
* @throws MalformedObjectNameException
*/
@@ -84,9 +84,9 @@ public class JavaMonitorAction extends MonitorAction
_appid = appid;
_client = new HttpClient();
- _client.setTimeout(60000);
- _client.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
-
+ _client.setConnectTimeout(2000);
+ _client.setIdleTimeout(30000);
+
try
{
_client.start();
@@ -107,16 +107,15 @@ public class JavaMonitorAction extends MonitorAction
@Override
public void execute(EventTrigger trigger, EventState<?> state, long timestamp)
{
- exec(trigger, state, timestamp);
+ exec(state);
}
/* ------------------------------------------------------------ */
/**
- * @param trigger
- * @param state
- * @param timestamp
+ * @param state the event state
+ *
*/
- private <T> void exec(EventTrigger trigger, EventState<T> state, long timestamp)
+ private <T> void exec(EventState<T> state)
{
Collection<TriggerState<T>> trs = state.values();
@@ -125,15 +124,15 @@ public class JavaMonitorAction extends MonitorAction
{
Object value = ts.getValue();
- StringBuffer buffer = new StringBuffer();
- buffer.append(value == null ? "" : value.toString());
- buffer.append("|");
- buffer.append(getClassID(value));
- buffer.append("||");
- buffer.append(ts.getDescription());
-
- data.setProperty(ts.getID(), buffer.toString());
-
+ StringBuilder stringBuilder = new StringBuilder();
+ stringBuilder.append(value == null ? "" : value.toString());
+ stringBuilder.append("|");
+ stringBuilder.append(getClassID(value));
+ stringBuilder.append("||");
+ stringBuilder.append(ts.getDescription());
+
+ data.setProperty(ts.getID(), stringBuilder.toString());
+
try
{
sendData(data);
@@ -147,7 +146,7 @@ public class JavaMonitorAction extends MonitorAction
/* ------------------------------------------------------------ */
/**
- * @param data
+ * @param data the properties to send
* @throws Exception
*/
private void sendData(Properties data)
@@ -170,53 +169,37 @@ public class JavaMonitorAction extends MonitorAction
/* ------------------------------------------------------------ */
/**
- * @param request
- * @return
+ * @param requestProperties the properties to send
+ * @return the response properties
* @throws Exception
*/
- private Properties sendRequest(Properties request)
- throws Exception
+ private Properties sendRequest(Properties requestProperties)
+ throws Exception
{
- ByteArrayOutputStream reqStream = null;
ByteArrayInputStream resStream = null;
- Properties response = null;
-
- try {
- ContentExchange reqEx = new ContentExchange();
- reqEx.setURL(_url);
- reqEx.setMethod(HttpMethods.POST);
- reqEx.addRequestHeader("Connection","close");
-
- reqStream = new ByteArrayOutputStream();
- request.storeToXML(reqStream,null);
- ByteArrayBuffer reqBuff = new ByteArrayBuffer(reqStream.toByteArray());
+ Properties responseProperties = null;
- reqEx.setRequestContent(reqBuff);
- _client.send(reqEx);
-
- reqEx.waitForDone();
-
- if (reqEx.getResponseStatus() == HttpStatus.OK_200)
+ ByteArrayOutputStream reqStream = new ByteArrayOutputStream();
+ requestProperties.storeToXML(reqStream, null);
+ try
+ {
+ ByteBuffer byteBuffer = BufferUtil.toBuffer(reqStream.toByteArray());
+ ContentResponse response = _client.POST(_url).header("Connection",
+ "close").content(new ByteBufferContentProvider(byteBuffer)).send().get();
+
+ if (response.getStatus() == HttpStatus.OK_200)
{
- response = new Properties();
- resStream = new ByteArrayInputStream(reqEx.getResponseContentBytes());
- response.loadFromXML(resStream);
+ responseProperties = new Properties();
+ response.getContentAsString();
+ resStream = new ByteArrayInputStream(response.getContent());
+ responseProperties.loadFromXML(resStream);
}
}
finally
{
try
{
- if (reqStream != null)
- reqStream.close();
- }
- catch (IOException ex)
- {
- LOG.ignore(ex);
- }
-
- try
- {
+ reqStream.close();
if (resStream != null)
resStream.close();
}
@@ -225,10 +208,9 @@ public class JavaMonitorAction extends MonitorAction
LOG.ignore(ex);
}
}
-
- return response;
+ return responseProperties;
}
-
+
/* ------------------------------------------------------------ */
private void parseResponse(Properties response)
{
@@ -262,15 +244,11 @@ public class JavaMonitorAction extends MonitorAction
{
queryResults = queryNames(queryString);
}
- catch (IOException e)
+ catch (IOException | MalformedObjectNameException e)
{
LOG.debug(e);
}
- catch (MalformedObjectNameException e)
- {
- LOG.debug(e);
- }
-
+
if (queryResults != null)
{
int idx = 0;
@@ -288,8 +266,8 @@ public class JavaMonitorAction extends MonitorAction
/* ------------------------------------------------------------ */
/**
- * @param value
- * @return
+ * @param value the value
+ * @return the classId
*/
private int getClassID(final Object value)
{
@@ -314,7 +292,7 @@ public class JavaMonitorAction extends MonitorAction
/* ------------------------------------------------------------ */
/**
- * @return
+ * @return the serverIp
* @throws Exception
*/
private String getServerIP()
@@ -354,9 +332,9 @@ public class JavaMonitorAction extends MonitorAction
}
/* ------------------------------------------------------------ */
- public Integer getHttpPort()
- {
- Collection<ObjectName> connectors = null;
+ public Integer getHttpPort()
+ {
+ Collection<ObjectName> connectors;
MBeanServerConnection service;
try
{
@@ -384,8 +362,8 @@ public class JavaMonitorAction extends MonitorAction
/* ------------------------------------------------------------ */
/**
- * @param param
- * @return
+ * @param param the param
+ * @return object names
* @throws IOException
* @throws NullPointerException
* @throws MalformedObjectNameException
diff --git a/jetty-monitor/src/main/java/org/eclipse/jetty/monitor/integration/JavaMonitorTools.java b/jetty-monitor/src/main/java/org/eclipse/jetty/monitor/integration/JavaMonitorTools.java
index 13fc99a..acb1fb5 100644
--- a/jetty-monitor/src/main/java/org/eclipse/jetty/monitor/integration/JavaMonitorTools.java
+++ b/jetty-monitor/src/main/java/org/eclipse/jetty/monitor/integration/JavaMonitorTools.java
@@ -57,11 +57,7 @@ public class JavaMonitorTools
{
findDeadlockMethod = ThreadMXBean.class.getMethod("findMonitorDeadlockedThreads");
}
- catch (SecurityException e)
- {
- e.printStackTrace();
- }
- catch (NoSuchMethodException e)
+ catch (SecurityException | NoSuchMethodException e)
{
e.printStackTrace();
}
@@ -79,8 +75,7 @@ public class JavaMonitorTools
return null;
}
- final ThreadInfo[] threads = threadMXBean.getThreadInfo(threadIds,Integer.MAX_VALUE);
- return threads;
+ return threadMXBean.getThreadInfo(threadIds,Integer.MAX_VALUE);
}
@ManagedAttribute("detailed report of deadlocked threads")
@@ -137,7 +132,7 @@ public class JavaMonitorTools
*/
private long lastSampled = 0L;
- private final Map<Thread.State, Integer> states = new HashMap<Thread.State, Integer>();
+ private final Map<Thread.State, Integer> states = new HashMap<>();
public int getThreadsBlocked()
{
diff --git a/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/AttrEventTriggerTest.java b/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/AttrEventTriggerTest.java
index d82bef7..875097c 100644
--- a/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/AttrEventTriggerTest.java
+++ b/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/AttrEventTriggerTest.java
@@ -32,6 +32,7 @@ import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.client.ContentExchange;
import org.eclipse.jetty.client.HttpClient;
+import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.client.security.Realm;
import org.eclipse.jetty.client.security.SimpleRealmResolver;
import org.eclipse.jetty.http.HttpMethods;
@@ -55,6 +56,7 @@ import org.eclipse.jetty.monitor.triggers.RangeAttrEventTrigger;
import org.eclipse.jetty.monitor.triggers.RangeInclAttrEventTrigger;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.nio.SelectChannelConnector;
import org.eclipse.jetty.util.log.Log;
@@ -88,7 +90,7 @@ public class AttrEventTriggerTest
System.setProperty("org.eclipse.jetty.util.log.DEBUG","");
_server = new Server();
- SelectChannelConnector connector = new SelectChannelConnector();
+ ServerConnector connector = new ServerConnector(_server);
_server.addConnector(connector);
_handler = new TestHandler();
@@ -363,21 +365,9 @@ public class AttrEventTriggerTest
{
try
{
- ContentExchange getExchange = new ContentExchange();
- getExchange.setURL(_requestUrl);
- getExchange.setMethod(HttpMethods.GET);
+ ContentResponse response = _client.GET(_requestUrl).get();
- _client.send(getExchange);
- int state = getExchange.waitForDone();
-
- String content = "";
- int responseStatus = getExchange.getResponseStatus();
- if (responseStatus == HttpStatus.OK_200)
- {
- content = getExchange.getResponseContent();
- }
-
- assertEquals(HttpStatus.OK_200,responseStatus);
+ assertEquals(HttpStatus.OK_200,response.getStatus());
Thread.sleep(interval);
}
catch (InterruptedException ex)
diff --git a/pom.xml b/pom.xml
index d1953d6..7a7c4d3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -416,10 +416,10 @@
<module>jetty-runner</module>
<module>jetty-rhttp</module>
- <module>jetty-monitor</module>
<module>jetty-nested</module>
<module>jetty-overlay-deployer</module>
<module>jetty-http-spi</module>
+ <module>jetty-monitor</module>
-->
</modules>
<dependencyManagement>