/**
* Register the MBean using our standard MBeanName format
* "hadoop:service=<serviceName>,name=<nameName>"
* Where the <serviceName> and <nameName> are the supplied parameters
*
* @param serviceName
* @param nameName
* @param theMbean - the MBean to register
* @return the named used to register the MBean
*/
static public ObjectName registerMBean(final String serviceName,
final String nameName,
final Object theMbean) {
final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName name = getMBeanName(serviceName, nameName);
try {
mbs.registerMBean(theMbean, name);
return name;
} catch (InstanceAlreadyExistsException ie) {
// Ignore if instance already exists
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
java类javax.management.ObjectName的实例源码
MBeanUtil.java 文件源码
项目:hadoop-oss
阅读 27
收藏 0
点赞 0
评论 0
TestMonitoredCounterGroup.java 文件源码
项目:flume-release-1.7.0
阅读 21
收藏 0
点赞 0
评论 0
private void assertChCounterState(ObjectName on, long channelSize,
long eventPutAttempt, long eventTakeAttempt, long eventPutSuccess,
long eventTakeSuccess) throws Exception {
Assert.assertEquals("ChChannelSize",
getChChannelSize(on),
channelSize);
Assert.assertEquals("ChEventPutAttempt",
getChEventPutAttempt(on),
eventPutAttempt);
Assert.assertEquals("ChEventTakeAttempt",
getChEventTakeAttempt(on),
eventTakeAttempt);
Assert.assertEquals("ChEventPutSuccess",
getChEventPutSuccess(on),
eventPutSuccess);
Assert.assertEquals("ChEventTakeSuccess",
getChEventTakeSuccess(on),
eventTakeSuccess);
}
DynamicWritableWrapperTest.java 文件源码
项目:hashsdn-controller
阅读 25
收藏 0
点赞 0
评论 0
@Test
public void testObjectNameSetterWithONContainingTransaction_shouldBeTranslatedToReadOnlyON() throws Exception {
TestingParallelAPSPModuleFactory testingParallelAPSPConfigBeanFactory = new TestingParallelAPSPModuleFactory();
TestingParallelAPSPModule apspConfigBean = testingParallelAPSPConfigBeanFactory.createModule("", null, null);
ModuleIdentifier moduleIdentifier2 = new ModuleIdentifier("apsp", "parallel");
ObjectName dynON2 = ObjectNameUtil.createReadOnlyModuleON(moduleIdentifier2);
AbstractDynamicWrapper dyn = getDynamicWrapper(apspConfigBean, moduleIdentifier2);
platformMBeanServer.registerMBean(dyn, dynON2);
try {
TestingParallelAPSPConfigMXBean proxy = JMX.newMBeanProxy(platformMBeanServer, dynON2,
TestingParallelAPSPConfigMXBean.class);
ObjectName withTransactionName = ObjectNameUtil.createTransactionModuleON("transaction1", "moduleName",
"instanceName");
proxy.setThreadPool(withTransactionName);
ObjectName withoutTransactionName = ObjectNameUtil.withoutTransactionName(withTransactionName);
assertEquals(withoutTransactionName, proxy.getThreadPool());
} finally {
platformMBeanServer.unregisterMBean(dynON2);
}
}
DefaultMBeanServerInterceptor.java 文件源码
项目:openjdk-jdk10
阅读 28
收藏 0
点赞 0
评论 0
private static ObjectName preRegister(
DynamicMBean mbean, MBeanServer mbs, ObjectName name)
throws InstanceAlreadyExistsException, MBeanRegistrationException {
ObjectName newName = null;
try {
if (mbean instanceof MBeanRegistration)
newName = ((MBeanRegistration) mbean).preRegister(mbs, name);
} catch (Throwable t) {
throwMBeanRegistrationException(t, "in preRegister method");
}
if (newName != null) return newName;
else return name;
}
MBeanUtils.java 文件源码
项目:jerrydog
阅读 26
收藏 0
点赞 0
评论 0
/**
* Create, register, and return an MBean for this
* <code>UserDatabase</code> object.
*
* @param userDatabase The UserDatabase to be managed
*
* @exception Exception if an MBean cannot be created or registered
*/
public static ModelMBean createMBean(UserDatabase userDatabase)
throws Exception {
String mname = createManagedName(userDatabase);
ManagedBean managed = registry.findManagedBean(mname);
if (managed == null) {
Exception e = new Exception("ManagedBean is not found with "+mname);
throw new MBeanException(e);
}
String domain = managed.getDomain();
if (domain == null)
domain = mserver.getDefaultDomain();
ModelMBean mbean = managed.createMBean(userDatabase);
ObjectName oname = createObjectName(domain, userDatabase);
mserver.registerMBean(mbean, oname);
return (mbean);
}
MBeanExporter.java 文件源码
项目:lams
阅读 29
收藏 0
点赞 0
评论 0
/**
* Unregister the configured {@link NotificationListener NotificationListeners}
* from the {@link MBeanServer}.
*/
private void unregisterNotificationListeners() {
for (Map.Entry<NotificationListenerBean, ObjectName[]> entry : this.registeredNotificationListeners.entrySet()) {
NotificationListenerBean bean = entry.getKey();
ObjectName[] mappedObjectNames = entry.getValue();
for (ObjectName mappedObjectName : mappedObjectNames) {
try {
this.server.removeNotificationListener(mappedObjectName, bean.getNotificationListener(),
bean.getNotificationFilter(), bean.getHandback());
}
catch (Exception ex) {
if (logger.isDebugEnabled()) {
logger.debug("Unable to unregister NotificationListener", ex);
}
}
}
}
this.registeredNotificationListeners.clear();
}
Registry.java 文件源码
项目:tomcat7
阅读 31
收藏 0
点赞 0
评论 0
/** Find the operation info for a method
*
* @param oname
* @param opName
* @return the operation info for the specified operation
*/
public MBeanOperationInfo getMethodInfo( ObjectName oname, String opName )
{
MBeanInfo info=null;
try {
info=server.getMBeanInfo(oname);
} catch (Exception e) {
log.info( "Can't find metadata " + oname );
return null;
}
MBeanOperationInfo attInfo[]=info.getOperations();
for( int i=0; i<attInfo.length; i++ ) {
if( opName.equals(attInfo[i].getName())) {
return attInfo[i];
}
}
return null;
}
TestJMXGet.java 文件源码
项目:hadoop
阅读 27
收藏 0
点赞 0
评论 0
/**
* test JMX connection to DataNode..
* @throws Exception
*/
@Test
public void testDataNode() throws Exception {
int numDatanodes = 2;
cluster = new MiniDFSCluster.Builder(config).numDataNodes(numDatanodes).build();
cluster.waitActive();
writeFile(cluster.getFileSystem(), new Path("/test"), 2);
JMXGet jmx = new JMXGet();
String serviceName = "DataNode";
jmx.setService(serviceName);
jmx.init();
assertEquals(fileSize, Integer.parseInt(jmx.getValue("BytesWritten")));
cluster.shutdown();
MBeanServerConnection mbsc = ManagementFactory.getPlatformMBeanServer();
ObjectName query = new ObjectName("Hadoop:service=" + serviceName + ",*");
Set<ObjectName> names = mbsc.queryNames(query, null);
assertTrue("No beans should be registered for " + serviceName, names.isEmpty());
}
StandardPipeline.java 文件源码
项目:apache-tomcat-7.0.73-with-comment
阅读 37
收藏 0
点赞 0
评论 0
public ObjectName[] getValveObjectNames() {
ArrayList<ObjectName> valveList = new ArrayList<ObjectName>();
Valve current = first;
if (current == null) {
current = basic;
}
while (current != null) {
if (current instanceof ValveBase) {
valveList.add(((ValveBase) current).getObjectName());
}
current = current.getNext();
}
return valveList.toArray(new ObjectName[0]);
}
DefaultMBeanServerInterceptor.java 文件源码
项目:OpenJSharp
阅读 73
收藏 0
点赞 0
评论 0
/**
* <p>Return the named {@link java.lang.ClassLoader}.
* @param loaderName The ObjectName of the ClassLoader.
* @return The named ClassLoader.
* @exception InstanceNotFoundException if the named ClassLoader
* is not found.
*/
public ClassLoader getClassLoader(ObjectName loaderName)
throws InstanceNotFoundException {
if (loaderName == null) {
checkMBeanPermission((String) null, null, null, "getClassLoader");
return server.getClass().getClassLoader();
}
DynamicMBean instance = getMBean(loaderName);
checkMBeanPermission(instance, null, loaderName, "getClassLoader");
Object resource = getResource(instance);
/* Check if the given MBean is a ClassLoader */
if (!(resource instanceof ClassLoader))
throw new InstanceNotFoundException(loaderName.toString() +
" is not a classloader");
return (ClassLoader) resource;
}
MemoryUserDatabaseMBean.java 文件源码
项目:jerrydog
阅读 23
收藏 0
点赞 0
评论 0
/**
* Return the MBean Name for the specified role name (if any);
* otherwise return <code>null</code>.
*
* @param rolename Role name to look up
*/
public String findRole(String rolename) {
UserDatabase database = (UserDatabase) this.resource;
Role role = database.findRole(rolename);
if (role == null) {
return (null);
}
try {
ObjectName oname =
MBeanUtils.createObjectName(managedRole.getDomain(), role);
return (oname.toString());
} catch (MalformedObjectNameException e) {
throw new IllegalArgumentException
("Cannot create object name for role " + role);
}
}
MBeanUtils.java 文件源码
项目:jerrydog
阅读 29
收藏 0
点赞 0
评论 0
/**
* Create, register, and return an MBean for this
* <code>Context</code> object.
*
* @param context The Context to be managed
*
* @exception Exception if an MBean cannot be created or registered
*/
public static ModelMBean createMBean(Context context)
throws Exception {
String mname = createManagedName(context);
ManagedBean managed = registry.findManagedBean(mname);
if (managed == null) {
Exception e = new Exception("ManagedBean is not found with "+mname);
throw new MBeanException(e);
}
String domain = managed.getDomain();
if (domain == null)
domain = mserver.getDefaultDomain();
ModelMBean mbean = managed.createMBean(context);
ObjectName oname = createObjectName(domain, context);
mserver.registerMBean(mbean, oname);
return (mbean);
}
PogamutMBeanServer.java 文件源码
项目:Pogamut3
阅读 39
收藏 0
点赞 0
评论 0
@Override
public synchronized void removeNotificationListener(ObjectName name,
NotificationListener listener) throws InstanceNotFoundException,
ListenerNotFoundException {
mbs.removeNotificationListener(name, listener);
// TODO: slow implementation ... but fast one takes a lot of time to do :-)
Iterator<Listener2> iter = listeners2.iterator();
while(iter.hasNext()) {
Listener2 l = iter.next();
if (SafeEquals.equals(name, l.name) && SafeEquals.equals(listener, l.listener)) {
listeners.remove(l);
unregisteredListeners.remove(l);
iter.remove();
}
}
}
MBeanFactory.java 文件源码
项目:lams
阅读 30
收藏 0
点赞 0
评论 0
/**
* Create a new JNDI Realm.
*
* @param parent MBean Name of the associated parent component
*
* @exception Exception if an MBean cannot be created or registered
*/
public String createJNDIRealm(String parent)
throws Exception {
// Create a new JNDIRealm instance
JNDIRealm realm = new JNDIRealm();
// Add the new instance to its parent component
ObjectName pname = new ObjectName(parent);
ContainerBase containerBase = getParentContainerFromParent(pname);
// Add the new instance to its parent component
containerBase.setRealm(realm);
// Return the corresponding MBean name
ObjectName oname = realm.getObjectName();
if (oname != null) {
return (oname.toString());
} else {
return null;
}
}
GroupMBean.java 文件源码
项目:lazycat
阅读 26
收藏 0
点赞 0
评论 0
/**
* Return the MBean Names of all users that are members of this group.
*/
public String[] getUsers() {
Group group = (Group) this.resource;
ArrayList<String> results = new ArrayList<String>();
Iterator<User> users = group.getUsers();
while (users.hasNext()) {
User user = null;
try {
user = users.next();
ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), user);
results.add(oname.toString());
} catch (MalformedObjectNameException e) {
IllegalArgumentException iae = new IllegalArgumentException(
"Cannot create object name for user " + user);
iae.initCause(e);
throw iae;
}
}
return results.toArray(new String[results.size()]);
}
DefaultMBeanServerInterceptor.java 文件源码
项目:OpenJSharp
阅读 30
收藏 0
点赞 0
评论 0
public ObjectInstance registerMBean(Object object, ObjectName name)
throws InstanceAlreadyExistsException, MBeanRegistrationException,
NotCompliantMBeanException {
// ------------------------------
// ------------------------------
Class<?> theClass = object.getClass();
Introspector.checkCompliance(theClass);
final String infoClassName = getNewMBeanClassName(object);
checkMBeanPermission(infoClassName, null, name, "registerMBean");
checkMBeanTrustPermission(theClass);
return registerObject(infoClassName, object, name);
}
ApplyWildcardTest.java 文件源码
项目:jdk8u-jdk
阅读 30
收藏 0
点赞 0
评论 0
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;
}
Repository.java 文件源码
项目:jdk8u-jdk
阅读 30
收藏 0
点赞 0
评论 0
/**
* Retrieves the named object contained in repository
* from the given objectname.
*/
private NamedObject retrieveNamedObject(ObjectName name) {
// No patterns inside reposit
if (name.isPattern()) return null;
// Extract the domain name.
String dom = name.getDomain().intern();
// Default domain case
if (dom.length() == 0) {
dom = domain;
}
Map<String,NamedObject> moiTb = domainTb.get(dom);
if (moiTb == null) {
return null; // No domain containing registered object names
}
return moiTb.get(name.getCanonicalKeyPropertyListString());
}
ClientHandler.java 文件源码
项目:OpenJSharp
阅读 32
收藏 0
点赞 0
评论 0
public ClientHandler(CommunicatorServer server, int id, MBeanServer f, ObjectName n) {
adaptorServer = server ;
requestId = id ;
mbs = f ;
objectName = n ;
interruptCalled = false ;
dbgTag = makeDebugTag() ;
//if (mbs == null ){
//thread = new Thread (this) ;
thread = createThread(this);
//} else {
//thread = mbs.getThreadAllocatorSrvIf().obtainThread(objectName,this) ;
//}
// Note: the thread will be started by the subclass.
}
JMXAccessorCondition.java 文件源码
项目:lams
阅读 30
收藏 0
点赞 0
评论 0
/**
* Get value from MBeans attribute
* @return The value
*/
protected String accessJMXValue() {
try {
Object result = getJMXConnection().getAttribute(
new ObjectName(name), attribute);
if(result != null)
return result.toString();
} catch (Exception e) {
// ignore access or connection open errors
}
return null;
}
StandardServer.java 文件源码
项目:lams
阅读 28
收藏 0
点赞 0
评论 0
public ObjectName preRegister(MBeanServer server,
ObjectName name) throws Exception {
oname=name;
mserver=server;
domain=name.getDomain();
return name;
}
StatusTransformer.java 文件源码
项目:lazycat
阅读 22
收藏 0
点赞 0
评论 0
/**
* Write detailed information about a manager.
*/
public static void writeManager(PrintWriter writer, ObjectName objectName, MBeanServer mBeanServer, int mode)
throws Exception {
if (mode == 0) {
writer.print("<br>");
writer.print(" Active sessions: ");
writer.print(mBeanServer.getAttribute(objectName, "activeSessions"));
writer.print(" Session count: ");
writer.print(mBeanServer.getAttribute(objectName, "sessionCounter"));
writer.print(" Max active sessions: ");
writer.print(mBeanServer.getAttribute(objectName, "maxActive"));
writer.print(" Rejected session creations: ");
writer.print(mBeanServer.getAttribute(objectName, "rejectedSessions"));
writer.print(" Expired sessions: ");
writer.print(mBeanServer.getAttribute(objectName, "expiredSessions"));
writer.print(" Longest session alive time: ");
writer.print(formatSeconds(mBeanServer.getAttribute(objectName, "sessionMaxAliveTime")));
writer.print(" Average session alive time: ");
writer.print(formatSeconds(mBeanServer.getAttribute(objectName, "sessionAverageAliveTime")));
writer.print(" Processing time: ");
writer.print(formatTime(mBeanServer.getAttribute(objectName, "processingTime"), false));
} else if (mode == 1) {
// for now we don't write out the wrapper details
}
}
AuthorizationTest.java 文件源码
项目:jdk8u-jdk
阅读 36
收藏 0
点赞 0
评论 0
protected int doInvokeRequest(MBeanServerConnection mbsc,
ObjectName on,
boolean expectedException) {
int errorCount = 0;
try {
Utils.debug(Utils.DEBUG_STANDARD,
"ClientSide::doInvokeRequest: Invoke operations on the MBean") ;
mbsc.invoke(on, "operation", null, null) ;
if (expectedException) {
System.out.println("ClientSide::doInvokeRequest: " +
"(ERROR) Invoke did not fail with expected SecurityException");
errorCount++;
} else {
System.out.println("ClientSide::doInvokeRequest: (OK) Invoke succeed") ;
}
} catch(Exception e) {
Utils.printThrowable(e, true) ;
if (expectedException) {
if (e instanceof java.lang.SecurityException) {
System.out.println("ClientSide::doInvokeRequest: " +
"(OK) Invoke failed with expected SecurityException") ;
} else {
System.out.println("ClientSide::doInvokeRequest: " +
" (ERROR) Invoke failed with " +
e.getClass() + " instead of expected SecurityException");
errorCount++;
}
} else {
System.out.println("ClientSide::doInvokeRequest: " +
"(ERROR) Invoke failed");
errorCount++;
}
}
return errorCount;
}
RelationNotification.java 文件源码
项目:openjdk-jdk10
阅读 22
收藏 0
点赞 0
评论 0
/**
* Returns old value of updated role (only for role update).
*
* @return the old value of the updated role.
*/
public List<ObjectName> getOldRoleValue() {
List<ObjectName> result;
if (oldRoleValue != null) {
result = new ArrayList<ObjectName>(oldRoleValue);
} else {
result = Collections.emptyList();
}
return result;
}
DistributedSystemBridge.java 文件源码
项目:monarch
阅读 27
收藏 0
点赞 0
评论 0
/**
* Removed the proxy from the map.
*
* @param objectName name of the proxy to be removed.
* @param proxy actual reference to the proxy object
* @return whether all proxies have been removed or not. In this case it will always be false.
* Kept it for consistency for MBeanAggregator.
*/
public boolean removeGatewaySenderFromSystem(ObjectName objectName, GatewaySenderMXBean proxy,
FederationComponent oldState) {
if (mapOfGatewaySenders != null) {
mapOfGatewaySenders.remove(objectName);
gatewaySenderSetSize = mapOfGatewaySenders.values().size();
if (mapOfGatewaySenders.values().size() == 0) {
gatewaySenderSetSize = 0;
return true;
}
}
updateGatewaySender(objectName, null, oldState);
return false;
}
RMIConnector.java 文件源码
项目:jdk8u-jdk
阅读 50
收藏 0
点赞 0
评论 0
public ObjectInstance createMBean(String className,
ObjectName name,
Object params[],
String signature[])
throws ReflectionException,
InstanceAlreadyExistsException,
MBeanRegistrationException,
MBeanException,
NotCompliantMBeanException,
IOException {
if (logger.debugOn())
logger.debug("createMBean(String,ObjectName,Object[],String[])",
"className=" + className + ", name="
+ name + ", signature=" + strings(signature));
final MarshalledObject<Object[]> sParams =
new MarshalledObject<Object[]>(params);
final ClassLoader old = pushDefaultClassLoader();
try {
return connection.createMBean(className,
name,
sParams,
signature,
delegationSubject);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
return connection.createMBean(className,
name,
sParams,
signature,
delegationSubject);
} finally {
popDefaultClassLoader(old);
}
}
ShellCommandsController.java 文件源码
项目:monarch
阅读 26
收藏 0
点赞 0
评论 0
@RequestMapping(method = RequestMethod.POST, value = "/mbean/query")
public ResponseEntity<?> queryNames(@RequestBody final QueryParameterSource query) {
try {
final Set<ObjectName> objectNames =
getMBeanServer().queryNames(query.getObjectName(), query.getQueryExpression());
return new ResponseEntity<byte[]>(IOUtils.serializeObject(objectNames), HttpStatus.OK);
} catch (IOException e) {
return new ResponseEntity<String>(printStackTrace(e), HttpStatus.INTERNAL_SERVER_ERROR);
}
}
ContainerBase.java 文件源码
项目:lams
阅读 40
收藏 0
点赞 0
评论 0
public ObjectName[] getChildren() {
ObjectName result[]=new ObjectName[children.size()];
Iterator it=children.values().iterator();
int i=0;
while( it.hasNext() ) {
Object next=it.next();
if( next instanceof ContainerBase ) {
result[i++]=((ContainerBase)next).getJmxName();
}
}
return result;
}
MX4JModelMBean.java 文件源码
项目:monarch
阅读 24
收藏 0
点赞 0
评论 0
public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception {
if (m_canBeRegistered) {
m_mbeanServer = server;
return name;
} else {
throw new MBeanRegistrationException(new IllegalStateException(
LocalizedStrings.MX4JModelMBean_MODELMBEAN_CANNOT_BE_REGISTERED_UNTIL_SETMODELMBEANINFO_HAS_BEEN_CALLED
.toLocalizedString()));
}
}
MonitoringRegionCacheListener.java 文件源码
项目:monarch
阅读 28
收藏 0
点赞 0
评论 0
@Override
public void afterUpdate(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 oldObject = (FederationComponent) event.getOldValue();
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.afterUpdateProxy(objectName, interfaceClass, null, newObject, oldObject);
} catch (Exception e) {
if (logger.isDebugEnabled()) {
logger.debug("Aggregation Failed failed for {} with exception {}", e);
}
}
}