本文整理汇总了Java中javax.management.ObjectName.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectName.getInstance方法的具体用法?Java ObjectName.getInstance怎么用?Java ObjectName.getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.management.ObjectName
的用法示例。
在下文中一共展示了ObjectName.getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getWorkManager
import javax.management.ObjectName; //导入方法依赖的package包/类
/**
* Obtain the default JBoss JCA WorkManager through a JMX lookup
* for the JBossWorkManagerMBean.
* @param mbeanName the JMX object name to use
* @see org.jboss.resource.work.JBossWorkManagerMBean
*/
public static WorkManager getWorkManager(String mbeanName) {
Assert.hasLength(mbeanName, "JBossWorkManagerMBean name must not be empty");
try {
Class<?> mbeanClass = JBossWorkManagerUtils.class.getClassLoader().loadClass(JBOSS_WORK_MANAGER_MBEAN_CLASS_NAME);
InitialContext jndiContext = new InitialContext();
MBeanServerConnection mconn = (MBeanServerConnection) jndiContext.lookup(MBEAN_SERVER_CONNECTION_JNDI_NAME);
ObjectName objectName = ObjectName.getInstance(mbeanName);
Object workManagerMBean = MBeanServerInvocationHandler.newProxyInstance(mconn, objectName, mbeanClass, false);
Method getInstanceMethod = workManagerMBean.getClass().getMethod("getInstance");
return (WorkManager) getInstanceMethod.invoke(workManagerMBean);
}
catch (Exception ex) {
throw new IllegalStateException(
"Could not initialize JBossWorkManagerTaskExecutor because JBoss API is not available", ex);
}
}
示例2: runPositiveTests
import javax.management.ObjectName; //导入方法依赖的package包/类
private static int runPositiveTests() {
int error = 0;
for (int i = 0; i < positiveTests.length; i++) {
System.out.println("----------------------------------------------");
try {
ObjectName on1 = ObjectName.getInstance(positiveTests[i][0]);
ObjectName on2 = ObjectName.getInstance(positiveTests[i][1]);
System.out.println("\"" + on1 + "\".apply(\"" + on2 + "\")");
boolean result = on1.apply(on2);
System.out.println("Result = " + result);
if (result == false) {
error++;
System.out.println("Test failed!");
} else {
System.out.println("Test passed!");
}
} catch (Exception e) {
error++;
System.out.println("Got Unexpected Exception = " + e.toString());
System.out.println("Test failed!");
}
System.out.println("----------------------------------------------");
}
return error;
}
示例3: getMemberMXBean
import javax.management.ObjectName; //导入方法依赖的package包/类
/**
* Gets the MemberMXBean from the JVM Platform MBeanServer for the specified member, identified by
* name or ID in the GemFire cluster.
*
* @param memberNameId a String indicating the name or ID of the GemFire member.
* @return a proxy to the GemFire member's MemberMXBean.
* @throws IllegalStateException if no MemberMXBean could be found for GemFire member with ID or
* name.
* @throws RuntimeException wrapping the MalformedObjectNameException if the ObjectName pattern is
* malformed.
* @see #getMBeanServer()
* @see #isMemberMXBeanFound(java.util.Collection)
* @see javax.management.ObjectName
* @see javax.management.QueryExp
* @see javax.management.MBeanServer#queryNames(javax.management.ObjectName,
* javax.management.QueryExp)
* @see javax.management.JMX#newMXBeanProxy(javax.management.MBeanServerConnection,
* javax.management.ObjectName, Class)
* @see org.apache.geode.management.MemberMXBean
*/
protected MemberMXBean getMemberMXBean(final String memberNameId) {
try {
final MBeanServer connection = getMBeanServer();
final String objectNamePattern =
ManagementConstants.OBJECTNAME__PREFIX.concat("type=Member,*");
// NOTE throws a MalformedObjectNameException, but this should not happen since we constructed
// the ObjectName above
final ObjectName objectName = ObjectName.getInstance(objectNamePattern);
final QueryExp query = Query.or(Query.eq(Query.attr("Name"), Query.value(memberNameId)),
Query.eq(Query.attr("Id"), Query.value(memberNameId)));
final Set<ObjectName> objectNames = connection.queryNames(objectName, query);
assertState(isMemberMXBeanFound(objectNames),
"No MemberMXBean with ObjectName (%1$s) based on Query (%2$s) was found in the Platform MBeanServer for member (%3$s)!",
objectName, query, memberNameId);
return JMX.newMXBeanProxy(connection, objectNames.iterator().next(), MemberMXBean.class);
} catch (MalformedObjectNameException e) {
throw new RuntimeException(e);
}
}
示例4: AgentJMXProxy
import javax.management.ObjectName; //导入方法依赖的package包/类
public AgentJMXProxy(String agentJmxAddress) {
// connect through RMI and get the proxy
String[] strs = agentJmxAddress.split("\\" + AgentJMXComponents.JMX_SERVER_AGENT_NAME_DELIM);
String jmxService = strs[0];
String objectName = strs[1];
try {
JMXServiceURL url = new JMXServiceURL(jmxService);
JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
mbsc = jmxc.getMBeanServerConnection();
agentName = ObjectName.getInstance(objectName);
proxy = new DynamicProxy(agentName, mbsc);
agentFlag = new FlagJMXProxy<IAgentState>(agentName, mbsc, AgentMBeanAdapter.AGENT_STATE_FLAG_NAME);
agentId = new AgentIdJMXProxy(this);
} catch (Exception e) {
throw new PogamutJMXException("Can't create AgentJMXProxy.", e, this);
}
}
示例5: monitorNotifications
import javax.management.ObjectName; //导入方法依赖的package包/类
/**
* Test the monitor notifications.
*/
public int monitorNotifications() throws Exception {
server = MBeanServerFactory.newMBeanServer();
MBeanServerForwarderInvocationHandler mbsfih =
(MBeanServerForwarderInvocationHandler)
Proxy.getInvocationHandler(server);
mbsfih.setGetAttributeException(
new RuntimeException("Test RuntimeException"));
domain = server.getDefaultDomain();
obsObjName = ObjectName.getInstance(domain + ":type=ObservedObject");
server.registerMBean(new ObservedObject(), obsObjName);
echo(">>> ----------------------------------------");
int error = counterMonitorNotification();
echo(">>> ----------------------------------------");
error += gaugeMonitorNotification();
echo(">>> ----------------------------------------");
error += stringMonitorNotification();
echo(">>> ----------------------------------------");
return error;
}
示例6: afterCreate
import javax.management.ObjectName; //导入方法依赖的package包/类
@Override
public void afterCreate(EntryEvent<String, Object> event) {
ObjectName objectName = null;
try {
if (!service.isStartedAndOpen() || !service.isManager()) {
// NO OP return; No work for Non Manager Nodes
return;
}
objectName = ObjectName.getInstance(event.getKey());
FederationComponent newObject = (FederationComponent) event.getNewValue();
String className = newObject.getMBeanInterfaceClass();
Class interfaceClass;
if (classRef.get(className) != null) {
interfaceClass = classRef.get(className);
} else {
interfaceClass = ClassLoadUtil.classFromName(className);
classRef.put(className, interfaceClass);
}
service.afterPseudoCreateProxy(objectName, interfaceClass, null, newObject);
} catch (Exception e) {
if (logger.isDebugEnabled()) {
logger.debug("{}: Aggregation Failed failed for {} With Exception {}", THIS_COMPONENT,
objectName, e);
}
}
}
示例7: monitorNotifications
import javax.management.ObjectName; //导入方法依赖的package包/类
/**
* Test the monitor notifications.
*/
public int monitorNotifications() throws Exception {
server = MBeanServerFactory.newMBeanServer();
MBeanServerForwarderInvocationHandler mbsfih =
(MBeanServerForwarderInvocationHandler)
Proxy.getInvocationHandler(server);
mbsfih.setGetAttributeException(
new ReflectionException(new RuntimeException(),
"Test ReflectionException"));
domain = server.getDefaultDomain();
obsObjName = ObjectName.getInstance(domain + ":type=ObservedObject");
server.registerMBean(new ObservedObject(), obsObjName);
echo(">>> ----------------------------------------");
int error = counterMonitorNotification();
echo(">>> ----------------------------------------");
error += gaugeMonitorNotification();
echo(">>> ----------------------------------------");
error += stringMonitorNotification();
echo(">>> ----------------------------------------");
return error;
}
示例8: beforeClass
import javax.management.ObjectName; //导入方法依赖的package包/类
@BeforeClass
public static void beforeClass() throws Exception {
// the server does not have a GAtewaySenderMXBean registered initially, has to register a mock
// one.
service = ManagementService.getManagementService(serverRule.getCache());
mockBeanName = ObjectName.getInstance("GemFire", "key", "value");
service.registerMBean(mock, mockBeanName);
}
示例9: setUp
import javax.management.ObjectName; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
pid = ProcessUtils.identifyPid();
final Process process = new Process(pid, true);
this.objectName = ObjectName
.getInstance(getClass().getSimpleName() + ":testName=" + testName.getMethodName());
this.server = ManagementFactory.getPlatformMBeanServer();
final ObjectInstance instance = this.server.registerMBean(process, objectName);
assertNotNull(instance);
}
示例10: newObjectName
import javax.management.ObjectName; //导入方法依赖的package包/类
public static ObjectName newObjectName(String name) {
try {
return ObjectName.getInstance(name);
} catch (MalformedObjectNameException e) {
throw new IllegalArgumentException(e);
}
}
示例11: cloneObjectName
import javax.management.ObjectName; //导入方法依赖的package包/类
/**
* Clone object name.
*/
private ObjectName cloneObjectName(ObjectName name) {
if (name != null) {
return ObjectName.getInstance(name);
}
return name;
}
示例12: removeAllProxies
import javax.management.ObjectName; //导入方法依赖的package包/类
/**
* Removes all proxies for a given member
*
* @param member {@link org.apache.geode.distributed.DistributedMember}
* @param monitoringRegion monitoring region containing the proxies
*/
public void removeAllProxies(DistributedMember member, Region<String, Object> monitoringRegion) {
Set<Entry<String, Object>> entries = monitoringRegion.entrySet();
Iterator<Entry<String, Object>> entriesIt = entries.iterator();
if (logger.isDebugEnabled()) {
logger.debug("Removing {} proxies for member {}", entries.size(), member.getId());
}
while (entriesIt.hasNext()) {
String key = null;
Object val = null;
try {
Entry<String, Object> entry = entriesIt.next();
key = entry.getKey();// MBean Name in String format.
val = entry.getValue(); // Federation Component
ObjectName mbeanName = ObjectName.getInstance(key);
removeProxy(member, mbeanName, val);
} catch (Exception e) {
if (!(e.getCause() instanceof InstanceNotFoundException)) {
logger.warn("Remove Proxy failed for {} due to {}", key, e.getMessage(), e);
}
continue;
}
}
}
示例13: safeGetObjectName
import javax.management.ObjectName; //导入方法依赖的package包/类
private ObjectName safeGetObjectName(ObjectName src){
ObjectName dest = null;
if (src != null) {
dest = ObjectName.getInstance(src);
}
return dest;
}
示例14: getMemberId
import javax.management.ObjectName; //导入方法依赖的package包/类
protected static String getMemberId(final String jmxManagerHost, final int jmxManagerPort,
final String memberName) throws Exception {
JMXConnector connector = null;
try {
connector = JMXConnectorFactory.connect(new JMXServiceURL(String.format(
"service:jmx:rmi://%1$s/jndi/rmi://%1$s:%2$d/jmxrmi", jmxManagerHost, jmxManagerPort)));
MBeanServerConnection connection = connector.getMBeanServerConnection();
ObjectName objectNamePattern = ObjectName.getInstance("GemFire:type=Member,*");
QueryExp query = Query.eq(Query.attr("Name"), Query.value(memberName));
Set<ObjectName> objectNames = connection.queryNames(objectNamePattern, query);
assertNotNull(objectNames);
assertFalse(objectNames.isEmpty());
assertEquals(1, objectNames.size());
// final ObjectName objectName = ObjectName.getInstance("GemFire:type=Member,Name=" +
// memberName);
ObjectName objectName = objectNames.iterator().next();
// System.err.printf("ObjectName for Member with Name (%1$s) is %2$s%n", memberName,
// objectName);
return ObjectUtils.toString(connection.getAttribute(objectName, "Id"));
} finally {
IOUtils.close(connector);
}
}
示例15: testInterface
import javax.management.ObjectName; //导入方法依赖的package包/类
private static <T> void testInterface(Class<T> c, boolean nullTest)
throws Exception {
System.out.println("Testing " + c.getName() +
(nullTest ? " for null values" : "") + "...");
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
JMXConnectorServer cs =
JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);
cs.start();
JMXServiceURL addr = cs.getAddress();
JMXConnector cc = JMXConnectorFactory.connect(addr);
MBeanServerConnection mbsc = cc.getMBeanServerConnection();
NamedMXBeans namedMXBeans = new NamedMXBeans(mbsc);
InvocationHandler ih =
nullTest ? new MXBeanNullImplInvocationHandler(c, namedMXBeans) :
new MXBeanImplInvocationHandler(c, namedMXBeans);
T impl = c.cast(Proxy.newProxyInstance(c.getClassLoader(),
new Class[] {c},
ih));
ObjectName on = new ObjectName("test:type=" + c.getName());
mbs.registerMBean(impl, on);
System.out.println("Register any MXBeans...");
Field[] fields = c.getFields();
for (Field field : fields) {
String n = field.getName();
if (n.endsWith("ObjectName")) {
String objectNameString = (String) field.get(null);
String base = n.substring(0, n.length() - 10);
Field f = c.getField(base);
Object mxbean = f.get(null);
ObjectName objectName =
ObjectName.getInstance(objectNameString);
mbs.registerMBean(mxbean, objectName);
namedMXBeans.put(objectName, mxbean);
}
}
try {
testInterface(c, mbsc, on, namedMXBeans, nullTest);
} finally {
try {
cc.close();
} finally {
cs.stop();
}
}
}