use of javax.management.MBeanServerConnection in project jetty.project by eclipse.
the class JavaMonitorAction method getHttpPort.
/* ------------------------------------------------------------ */
public Integer getHttpPort() {
Collection<ObjectName> connectors = null;
MBeanServerConnection service;
try {
service = JMXMonitor.getServiceConnection();
connectors = service.queryNames(new ObjectName("org.eclipse.jetty.nio:type=selectchannelconnector,*"), null);
if (connectors != null && connectors.size() > 0) {
Integer lowest = Integer.MAX_VALUE;
for (final ObjectName connector : connectors) {
lowest = (Integer) service.getAttribute(connector, "port");
}
if (lowest < Integer.MAX_VALUE)
return lowest;
}
} catch (Exception ex) {
LOG.debug(ex);
}
return 0;
}
use of javax.management.MBeanServerConnection in project jetty.project by eclipse.
the class AttrEventTrigger method match.
/* ------------------------------------------------------------ */
/**
* Verify if the event trigger conditions are in the
* appropriate state for an event to be triggered.
* This event trigger uses the match(Comparable<TYPE>)
* method to compare the value of the MXBean attribute
* to the conditions specified by the subclasses.
*
* @see org.eclipse.jetty.monitor.jmx.EventTrigger#match(long)
*/
@SuppressWarnings("unchecked")
public final boolean match(long timestamp) throws Exception {
MBeanServerConnection serverConnection = JMXMonitor.getServiceConnection();
TYPE value = null;
try {
int pos = _attributeName.indexOf('.');
if (pos < 0)
value = (TYPE) serverConnection.getAttribute(_nameObject, _attributeName);
else
value = getValue((CompositeData) serverConnection.getAttribute(_nameObject, _attributeName.substring(0, pos)), _attributeName.substring(pos + 1));
} catch (Exception ex) {
LOG.debug(ex);
}
boolean result = false;
if (value != null) {
result = match(value);
if (result || getSaveAll()) {
_states.put(timestamp, new EventState<TYPE>(this.getID(), this.getNameString(), value));
}
}
return result;
}
use of javax.management.MBeanServerConnection in project jetty.project by eclipse.
the class JavaMonitorAction method queryNames.
/* ------------------------------------------------------------ */
/**
* @param param
* @return
* @throws IOException
* @throws NullPointerException
* @throws MalformedObjectNameException
*/
private ObjectName[] queryNames(ObjectName param) throws IOException, MalformedObjectNameException {
ObjectName[] result = null;
MBeanServerConnection connection = JMXMonitor.getServiceConnection();
Set names = connection.queryNames(param, null);
if (names != null && names.size() > 0) {
result = new ObjectName[names.size()];
int idx = 0;
for (Object name : names) {
if (name instanceof ObjectName)
result[idx++] = (ObjectName) name;
else
result[idx++] = new ObjectName(name.toString());
}
}
return result;
}
use of javax.management.MBeanServerConnection in project jetty.project by eclipse.
the class DeploymentManagerLifeCyclePathTest method testStateTransition_DeployedToUndeployed.
@Test
public void testStateTransition_DeployedToUndeployed() throws Exception {
DeploymentManager depman = new DeploymentManager();
// no default
depman.setDefaultLifeCycleGoal(null);
AppLifeCyclePathCollector pathtracker = new AppLifeCyclePathCollector();
MockAppProvider mockProvider = new MockAppProvider();
// Setup JMX
MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
depman.addBean(mbContainer);
depman.addLifeCycleBinding(pathtracker);
depman.addAppProvider(mockProvider);
depman.setContexts(new ContextHandlerCollection());
// Start DepMan
depman.start();
// Trigger new App
mockProvider.findWebapp("foo-webapp-1.war");
App app = depman.getAppByOriginId("mock-foo-webapp-1.war");
// Request Deploy of App
depman.requestAppGoal(app, "deployed");
JmxServiceConnection jmxConnection = new JmxServiceConnection();
jmxConnection.connect();
MBeanServerConnection mbsConnection = jmxConnection.getConnection();
ObjectName dmObjName = new ObjectName("org.eclipse.jetty.deploy:type=deploymentmanager,id=0");
String[] params = new String[] { "mock-foo-webapp-1.war", "undeployed" };
String[] signature = new String[] { "java.lang.String", "java.lang.String" };
mbsConnection.invoke(dmObjName, "requestAppGoal", params, signature);
// Setup Expectations.
List<String> expected = new ArrayList<String>();
// SHOULD NOT SEE THIS NODE VISITED - expected.add("undeployed");
expected.add("deploying");
expected.add("deployed");
expected.add("undeploying");
expected.add("undeployed");
pathtracker.assertExpected("Test JMX StateTransition / Deployed -> Undeployed", expected);
}
use of javax.management.MBeanServerConnection in project jmxtrans by jmxtrans.
the class JMXConnectionTest method nullConnectorIsNotClosed.
@Test
public void nullConnectorIsNotClosed() throws IOException {
MBeanServerConnection mBeanServerConnection = mock(MBeanServerConnection.class);
JMXConnection jmxConnection = new JMXConnection(null, mBeanServerConnection);
jmxConnection.close();
}
Aggregations