本文整理匯總了Java中javax.management.remote.JMXConnectorServerFactory.newJMXConnectorServer方法的典型用法代碼示例。如果您正苦於以下問題:Java JMXConnectorServerFactory.newJMXConnectorServer方法的具體用法?Java JMXConnectorServerFactory.newJMXConnectorServer怎麽用?Java JMXConnectorServerFactory.newJMXConnectorServer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.management.remote.JMXConnectorServerFactory
的用法示例。
在下文中一共展示了JMXConnectorServerFactory.newJMXConnectorServer方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: dotest
import javax.management.remote.JMXConnectorServerFactory; //導入方法依賴的package包/類
private static void dotest(JMXServiceURL url, MBeanServer mbs)
throws Exception {
JMXConnectorServer server = null;
JMXConnector client = null;
server = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
server.start();
JMXServiceURL outputAddr = server.getAddress();
System.out.println("Server started ["+ outputAddr+ "]");
client = JMXConnectorFactory.newJMXConnector(outputAddr, null);
client.connect();
System.out.println("Client connected");
MBeanServerConnection connection
= client.getMBeanServerConnection();
System.out.println(connection.getDefaultDomain());
}
示例2: main
import javax.management.remote.JMXConnectorServerFactory; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
if (Platform.isDebugBuild()) {
System.out.println("Running on a debug build. Performance test not applicable. Skipping.");
return;
}
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
Sender sender = new Sender();
mbs.registerMBean(sender, testObjectName);
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
JMXConnectorServer cs =
JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
cs.start();
JMXServiceURL addr = cs.getAddress();
JMXConnector cc = JMXConnectorFactory.connect(addr);
try {
test(mbs, cs, cc);
} finally {
cc.close();
cs.stop();
}
}
示例3: createConnectorServer
import javax.management.remote.JMXConnectorServerFactory; //導入方法依賴的package包/類
/**
* Maak een connector server instantie.
*
* @return connector server
* @throws IOException bij fouten
*/
private JMXConnectorServer createConnectorServer() throws IOException {
final Properties configuration = readConfiguration();
final MBeanServer server = locateMBeanServer();
final JMXServiceURL url = new JMXServiceURL(SimpleJmx.PROTOCOL,
configuration.getProperty("jmx.host", DEFAULT_HOST), Integer.parseInt(configuration.getProperty("jmx.port", DEFAULT_PORT)));
final Map<String,Object> environment = new HashMap<>();
Properties authentication = new Properties();
authentication.setProperty("admin", "admin");
environment.put("jmx.remote.authenticator", new PropertiesAuthenticator(authentication));
environment.put("jmx.remote.accesscontroller", new AllAccessController());
return JMXConnectorServerFactory.newJMXConnectorServer(url, environment, server);
}
示例4: main
import javax.management.remote.JMXConnectorServerFactory; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
Sender sender = new Sender();
mbs.registerMBean(sender, testObjectName);
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
JMXConnectorServer cs =
JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
cs.start();
JMXServiceURL addr = cs.getAddress();
JMXConnector cc = JMXConnectorFactory.connect(addr);
try {
test(mbs, cs, cc);
} finally {
cc.close();
cs.stop();
}
}
示例5: startServer
import javax.management.remote.JMXConnectorServerFactory; //導入方法依賴的package包/類
private JMXConnectorServer startServer(int rmiPort) throws Exception {
System.out.println("DEBUG: Create RMI registry on port " + rmiPort);
LocateRegistry.createRegistry(rmiPort);
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
HashMap<String,Object> env = new HashMap<String,Object>();
JMXServiceURL url =
new JMXServiceURL("service:jmx:rmi:///jndi/rmi://127.0.0.1:" + rmiPort + "/jmxrmi");
JMXConnectorServer cs =
JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);
cs.start();
System.out.println("DEBUG: Started the RMI connector server");
return cs;
}
示例6: createJSR160Server
import javax.management.remote.JMXConnectorServerFactory; //導入方法依賴的package包/類
private static void createJSR160Server() throws RemoteException, MalformedURLException,
IOException {
// Create RMI registry needed for JSR-160 connectors
LocateRegistry.createRegistry(8998);
// Create MBeanServer
final MBeanServer server = MBeanServerFactory.createMBeanServer();
// Create the JMXConnectorServer
final JMXServiceURL address =
new JMXServiceURL("service:jmx:rmi://localhost/jndi/rmi://localhost:8998/jmxconnector");
// The environment map
// Map environment = new HashMap();
// environment.put(JMXConnectorServer.AUTHENTICATOR, new
// FooAuthenticator());
final JMXConnectorServer connectorServer =
JMXConnectorServerFactory.newJMXConnectorServer(address, null, server);
// Start the JMXConnectorServer
connectorServer.start();
}
示例7: lifecycleEvent
import javax.management.remote.JMXConnectorServerFactory; //導入方法依賴的package包/類
@Override
public synchronized void lifecycleEvent(final LifecycleEvent event) {
try {
if (server == null && Lifecycle.START_EVENT.equals(event.getType())) {
serviceURL = new JMXServiceURL(protocol, host, port, urlPath);
server = JMXConnectorServerFactory.newJMXConnectorServer(serviceURL, null,
ManagementFactory.getPlatformMBeanServer());
server.start();
LOGGER.info("Started JMX server: " + serviceURL.toString());
} else if (server != null && Lifecycle.STOP_EVENT.equals(event.getType())) {
server.stop();
server = null;
LOGGER.info("Stopped JMX server: " + serviceURL.toString());
}
} catch (final Exception e) {
throw new JMXException(e);
}
}
示例8: assertJmxEquals
import javax.management.remote.JMXConnectorServerFactory; //導入方法依賴的package包/類
protected void assertJmxEquals(String attributeName, Object attributeValue) throws Exception {
JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(new JMXServiceURL("service:jmx:rmi://"),
null,
ManagementFactory.getPlatformMBeanServer());
cs.start();
JMXConnector cc = null;
try {
cc = JMXConnectorFactory.connect(cs.getAddress());
MBeanServerConnection mbsc = cc.getMBeanServerConnection();
ObjectName objectName = JmxUtils.createObjectName(JmxUtils.getPackageName(failureDetector.getClass()),
failureDetector.getClass()
.getSimpleName());
Object availableNodes = mbsc.getAttribute(objectName, attributeName);
assertEquals(attributeValue, availableNodes);
} finally {
if(cc != null)
cc.close();
cs.stop();
}
}
示例9: main
import javax.management.remote.JMXConnectorServerFactory; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
JMXServiceURL inputAddr =
new JMXServiceURL("service:jmx:iiop://");
JMXConnectorServer s;
try {
s = JMXConnectorServerFactory.newJMXConnectorServer(inputAddr, null, null);
} catch (java.net.MalformedURLException x) {
try {
Class.forName("javax.management.remote.rmi._RMIConnectionImpl_Tie");
throw new RuntimeException("MalformedURLException thrown but iiop appears to be supported");
} catch (ClassNotFoundException expected) { }
System.out.println("IIOP protocol not supported, test skipped");
return;
}
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
mbs.registerMBean(s, new ObjectName("a:b=c"));
s.start();
JMXServiceURL outputAddr = s.getAddress();
if (!outputAddr.getURLPath().startsWith("/ior/IOR:")) {
throw new RuntimeException("URL path should start with \"/ior/IOR:\": " +
outputAddr);
}
System.out.println("IIOP URL path looks OK: " + outputAddr);
JMXConnector c = JMXConnectorFactory.connect(outputAddr);
System.out.println("Successfully got default domain: " +
c.getMBeanServerConnection().getDefaultDomain());
c.close();
s.stop();
}
示例10: setUp
import javax.management.remote.JMXConnectorServerFactory; //導入方法依賴的package包/類
public static void setUp() throws IOException {
MBeanServer mbs = MBeanRegistry.getInstance().getPlatformMBeanServer();
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
cs.start();
JMXServiceURL addr = cs.getAddress();
cc = JMXConnectorFactory.connect(addr);
}
示例11: start
import javax.management.remote.JMXConnectorServerFactory; //導入方法依賴的package包/類
public static String start() throws Exception {
int serverPort = 12345;
ObjectName name = new ObjectName("test", "foo", "bar");
MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
SteMBean bean = new Ste();
jmxServer.registerMBean(bean, name);
boolean exported = false;
Random rnd = new Random(System.currentTimeMillis());
do {
try {
LocateRegistry.createRegistry(serverPort);
exported = true;
} catch (ExportException ee) {
if (ee.getCause() instanceof BindException) {
serverPort = rnd.nextInt(10000) + 4096;
} else {
throw ee;
}
}
} while (!exported);
JMXServiceURL serverUrl = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + serverPort + "/test");
JMXConnectorServer jmxConnector = JMXConnectorServerFactory.newJMXConnectorServer(serverUrl, null, jmxServer);
jmxConnector.start();
return serverUrl.toString();
}
示例12: buildJmxConnector
import javax.management.remote.JMXConnectorServerFactory; //導入方法依賴的package包/類
/**
* Create a JMXMP Connector.
* @param startPort startport to look for an open port
* @param maxRange maximum port scan range
* @param mbs desired mbean server to register to
* @return JmxConnectorServer that could be started
* @throws IOException io exception if something bad happens
*/
public static JMXConnectorServer buildJmxConnector(final int startPort, final int maxRange, final MBeanServer mbs)
throws IOException {
final int nextOpenPort = PortScanner.getNextPort(startPort,30);
log.log(Level.INFO, "[PORTSCAN]: using port " + nextOpenPort + " for next jmx interface");
final JMXServiceURL url = new JMXServiceURL("jmxmp",null, nextOpenPort);
final Map<String, Object> environment = new HashMap<>();
final JMXConnectorServer connector = JMXConnectorServerFactory.newJMXConnectorServer(url,environment,mbs);
return connector;
}
示例13: call
import javax.management.remote.JMXConnectorServerFactory; //導入方法依賴的package包/類
public MBeanServerConnection call() {
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
try {
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://");
JMXConnectorServer cs =
JMXConnectorServerFactory.newJMXConnectorServer(
url, null, mbs);
cs.start();
JMXServiceURL addr = cs.getAddress();
connector = JMXConnectorFactory.connect(addr);
return connector.getMBeanServerConnection();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例14: lifecycleEvent
import javax.management.remote.JMXConnectorServerFactory; //導入方法依賴的package包/類
@Override
public void lifecycleEvent(final LifecycleEvent event)
{
try
{
// START
if (Lifecycle.START_EVENT == event.getType())
{
log.debug("Start JMXMP");
cs = JMXConnectorServerFactory.newJMXConnectorServer(
new JMXServiceURL("jmxmp", "0.0.0.0", port),
null,
ManagementFactory.getPlatformMBeanServer()
);
cs.start();
log.info("Started JMXMP on port " + port);
}
// STOP
else if (Lifecycle.STOP_EVENT == event.getType())
{
log.debug("Stopp JMXMP");
cs.stop();
log.info("Stopped JMXMP");
}
}
catch (final Exception e)
{
throw new RuntimeException(e);
}
}
示例15: jmxConnectorServerFactoryTests
import javax.management.remote.JMXConnectorServerFactory; //導入方法依賴的package包/類
private int jmxConnectorServerFactoryTests() {
int errorCount = 0;
echo("");
echo(dashedMessage("Run JMXConnectorServerFactory Tests"));
for (int i = 0; i < maps.length - 1; i++) {
echo("\n>>> JMXConnectorServerFactory Test [" + i + "]");
try {
echo("\tMap = " + maps[i]);
echo("\tCreate the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
echo("\tCreate the RMI connector server");
JMXServiceURL url =
new JMXServiceURL("service:jmx:rmi:///jndi/rmi://:" +
port + "/JMXConnectorServerFactory" + i);
JMXConnectorServer jmxcs =
JMXConnectorServerFactory.newJMXConnectorServer(url,
maps[i],
mbs);
echo("\tStart the RMI connector server");
jmxcs.start();
echo("\tCall RMIConnectorServer.toJMXConnector(Map)");
jmxcs.toJMXConnector(maps[i]);
echo("\tStop the RMI connector server");
jmxcs.stop();
echo("\tTest [" + i + "] PASSED!");
} catch (Exception e) {
errorCount++;
echo("\tTest [" + i + "] FAILED!");
e.printStackTrace(System.out);
}
}
if (errorCount == 0) {
echo("");
echo(dashedMessage("JMXConnectorServerFactory Tests PASSED!"));
} else {
echo("");
echo(dashedMessage("JMXConnectorServerFactory Tests FAILED!"));
}
return errorCount;
}