Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ Using jetty-test-helper 3.0 + Adding jetty-perf-helper (replacement for BenchmarkHelper) + Adding JmxServiceConnection to jetty-deploy (formerly part of jetty-test-helper)
- Loading branch information
Showing
5 changed files
with
172 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
jetty-deploy/src/test/java/org/eclipse/jetty/deploy/JmxServiceConnection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995-2012 Mort Bay Consulting Pty. Ltd. | ||
// ------------------------------------------------------------------------ | ||
// All rights reserved. This program and the accompanying materials | ||
// are made available under the terms of the Eclipse Public License v1.0 | ||
// and Apache License v2.0 which accompanies this distribution. | ||
// | ||
// The Eclipse Public License is available at | ||
// http://www.eclipse.org/legal/epl-v10.html | ||
// | ||
// The Apache License v2.0 is available at | ||
// http://www.opensource.org/licenses/apache2.0.php | ||
// | ||
// You may elect to redistribute this code under either of these licenses. | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.deploy; | ||
|
||
import java.io.IOException; | ||
import java.lang.management.ManagementFactory; | ||
|
||
import javax.management.MBeanServer; | ||
import javax.management.MBeanServerConnection; | ||
import javax.management.remote.JMXConnector; | ||
import javax.management.remote.JMXConnectorFactory; | ||
import javax.management.remote.JMXConnectorServer; | ||
import javax.management.remote.JMXConnectorServerFactory; | ||
import javax.management.remote.JMXServiceURL; | ||
|
||
import org.eclipse.jetty.toolchain.test.IO; | ||
|
||
/** | ||
* JmxServiceConnection | ||
* | ||
* Provides ability to create a connection to either an external | ||
* JMX server, or a loopback connection to the internal one. | ||
*/ | ||
public class JmxServiceConnection | ||
{ | ||
private String serviceUrl; | ||
private MBeanServer server; | ||
private JMXConnectorServer connectorServer; | ||
private JMXConnector serverConnector; | ||
private MBeanServerConnection serviceConnection; | ||
|
||
/** | ||
* Construct a loopback connection to an internal server | ||
*/ | ||
public JmxServiceConnection() | ||
{ | ||
this(null); | ||
} | ||
|
||
/** | ||
* Construct a connection to specified server | ||
* | ||
* @param url | ||
* URL of JMX server | ||
*/ | ||
public JmxServiceConnection(String url) | ||
{ | ||
serviceUrl = url; | ||
} | ||
|
||
/** | ||
* Retrieve an external URL for the JMX server | ||
* | ||
* @return service URL | ||
*/ | ||
public String getServiceUrl() | ||
{ | ||
return serviceUrl; | ||
} | ||
|
||
/* ------------------------------------------------------------ */ | ||
/** | ||
* Retrieve a connection to MBean server | ||
* | ||
* @return connection to MBean server | ||
*/ | ||
public MBeanServerConnection getConnection() | ||
{ | ||
return serviceConnection; | ||
} | ||
|
||
public void connect() throws IOException | ||
{ | ||
if (serviceConnection == null) | ||
{ | ||
if (serviceUrl == null) | ||
{ | ||
openLoopbackConnection(); | ||
} | ||
else | ||
{ | ||
openServerConnection(serviceUrl); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Open a loopback connection to local JMX server | ||
* | ||
* @throws IOException | ||
*/ | ||
private void openLoopbackConnection() throws IOException | ||
{ | ||
server = ManagementFactory.getPlatformMBeanServer(); | ||
|
||
JMXServiceURL serviceUrl = new JMXServiceURL("service:jmx:rmi://"); | ||
connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(serviceUrl,null,server); | ||
connectorServer.start(); | ||
|
||
this.serviceUrl = connectorServer.getAddress().toString(); | ||
|
||
serverConnector = JMXConnectorFactory.connect(connectorServer.getAddress()); | ||
serviceConnection = serverConnector.getMBeanServerConnection(); | ||
} | ||
|
||
/** | ||
* Open a connection to remote JMX server | ||
* | ||
* @param url | ||
* @throws IOException | ||
*/ | ||
private void openServerConnection(String url) throws IOException | ||
{ | ||
serviceUrl = url; | ||
serverConnector = JMXConnectorFactory.connect(new JMXServiceURL(serviceUrl)); | ||
serviceConnection = serverConnector.getMBeanServerConnection(); | ||
} | ||
|
||
/** | ||
* Close the connections | ||
*/ | ||
public void disconnect() | ||
{ | ||
IO.close(serverConnector); | ||
|
||
if (connectorServer != null) | ||
{ | ||
try | ||
{ | ||
connectorServer.stop(); | ||
} | ||
catch (Exception ignore) | ||
{ | ||
/* ignore */ | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters