下面列出了怎么用javax.management.InstanceAlreadyExistsException的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Call <code>checkCreate(className)</code>, then forward this method to the
* wrapped object.
*/
public ObjectInstance createMBean(String className,
ObjectName name,
ObjectName loaderName)
throws
ReflectionException,
InstanceAlreadyExistsException,
MBeanRegistrationException,
MBeanException,
NotCompliantMBeanException,
InstanceNotFoundException {
checkCreate(className);
SecurityManager sm = System.getSecurityManager();
if (sm == null) {
Object object = getMBeanServer().instantiate(className,
loaderName);
checkClassLoader(object);
return getMBeanServer().registerMBean(object, name);
} else {
return getMBeanServer().createMBean(className, name, loaderName);
}
}
public ObjectInstance createMBean(String className, ObjectName name,
Object[] params, String[] signature)
throws ReflectionException, InstanceAlreadyExistsException,
MBeanRegistrationException, MBeanException,
NotCompliantMBeanException {
try {
return createMBean(className, name, null, true,
params, signature);
} catch (InstanceNotFoundException e) {
/* Can only happen if loaderName doesn't exist, but we just
passed null, so we shouldn't get this exception. */
throw EnvHelp.initCause(
new IllegalArgumentException("Unexpected exception: " + e), e);
}
}
public ObjectInstance createMBean(String className, ObjectName name,
Object[] params, String[] signature)
throws ReflectionException, InstanceAlreadyExistsException,
MBeanRegistrationException, MBeanException,
NotCompliantMBeanException {
try {
return createMBean(className, name, null, true,
params, signature);
} catch (InstanceNotFoundException e) {
/* Can only happen if loaderName doesn't exist, but we just
passed null, so we shouldn't get this exception. */
throw EnvHelp.initCause(
new IllegalArgumentException("Unexpected exception: " + e), e);
}
}
public ObjectInstance createMBean(String className, ObjectName name,
Object[] params, String[] signature)
throws ReflectionException, InstanceAlreadyExistsException,
MBeanRegistrationException, MBeanException,
NotCompliantMBeanException {
try {
return createMBean(className, name, null, true,
params, signature);
} catch (InstanceNotFoundException e) {
/* Can only happen if loaderName doesn't exist, but we just
passed null, so we shouldn't get this exception. */
throw EnvHelp.initCause(
new IllegalArgumentException("Unexpected exception: " + e), e);
}
}
@Override
public ObjectInstance createMBean(String className, ObjectName name, Object[] params, String[] signature)
throws ReflectionException, InstanceAlreadyExistsException, MBeanException,
NotCompliantMBeanException {
params = nullAsEmpty(params);
signature = nullAsEmpty(signature);
Throwable error = null;
MBeanServerPlugin delegate = null;
final boolean readOnly = false;
try {
delegate = findDelegateForNewObject(name);
authorizeMBeanOperation(delegate, name, CREATE_MBEAN, null, JmxAction.Impact.WRITE);
return checkNotAReservedDomainRegistrationIfObjectNameWasChanged(name, delegate.createMBean(className, name, params, signature), delegate);
} catch (Exception e) {
error = e;
if (e instanceof ReflectionException) throw (ReflectionException)e;
if (e instanceof InstanceAlreadyExistsException) throw (InstanceAlreadyExistsException)e;
if (e instanceof MBeanException) throw (MBeanException)e;
if (e instanceof NotCompliantMBeanException) throw (NotCompliantMBeanException)e;
throw makeRuntimeException(e);
} finally {
if (shouldAuditLog(delegate, readOnly)) {
new MBeanServerAuditLogRecordFormatter(this, error, readOnly).createMBean(className, name, params, signature);
}
}
}
/**
* 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 register(String serviceName, String nameName,
Object theMbean) {
final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName name = getMBeanName(serviceName, nameName);
try {
mbs.registerMBean(theMbean, name);
LOG.debug("Registered "+ name);
return name;
} catch (InstanceAlreadyExistsException iaee) {
if (LOG.isTraceEnabled()) {
LOG.trace("Failed to register MBean \""+ name + "\"", iaee);
} else {
LOG.warn("Failed to register MBean \""+ name
+ "\": Instance already exists.");
}
} catch (Exception e) {
LOG.warn("Failed to register MBean \""+ name + "\"", e);
}
return null;
}
/**
* Initialization of the MIB with AUTOMATIC REGISTRATION in Java DMK.
*/
public ObjectName preRegister(MBeanServer server, ObjectName name)
throws Exception {
// Allow only one initialization of the MIB.
//
if (isInitialized == true) {
throw new InstanceAlreadyExistsException();
}
// Initialize MBeanServer information.
//
this.server = server;
populate(server, name);
isInitialized = true;
return name;
}
/**
* Initialization of the MIB with AUTOMATIC REGISTRATION in Java DMK.
*/
public ObjectName preRegister(MBeanServer server, ObjectName name)
throws Exception {
// Allow only one initialization of the MIB.
//
if (isInitialized == true) {
throw new InstanceAlreadyExistsException();
}
// Initialize MBeanServer information.
//
this.server = server;
populate(server, name);
isInitialized = true;
return name;
}
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;
}
private boolean shouldRetryOn(Exception e) {
// Expect SecurityException, IOException, etc.
// But can also see things like javax.naming.ServiceUnavailableException with WSO2 app-servers.
// So let's not try to second guess strange behaviours that future entities will exhibit.
//
// However, if it was our request that was invalid then not worth retrying.
if (e instanceof AttributeNotFoundException) return false;
if (e instanceof InstanceAlreadyExistsException) return false;
if (e instanceof InstanceNotFoundException) return false;
if (e instanceof InvalidAttributeValueException) return false;
if (e instanceof ListenerNotFoundException) return false;
if (e instanceof MalformedObjectNameException) return false;
if (e instanceof NotCompliantMBeanException) return false;
if (e instanceof InterruptedException) return false;
if (e instanceof RuntimeInterruptedException) return false;
return true;
}
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);
}
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);
}
/**
* Call <code>checkCreate(className)</code>, then forward this method to the
* wrapped object.
*/
public ObjectInstance createMBean(String className, ObjectName name)
throws
ReflectionException,
InstanceAlreadyExistsException,
MBeanRegistrationException,
MBeanException,
NotCompliantMBeanException {
checkCreate(className);
SecurityManager sm = System.getSecurityManager();
if (sm == null) {
Object object = getMBeanServer().instantiate(className);
checkClassLoader(object);
return getMBeanServer().registerMBean(object, name);
} else {
return getMBeanServer().createMBean(className, name);
}
}
/**
* Call <code>checkCreate(className)</code>, then forward this method to the
* wrapped object.
*/
public ObjectInstance createMBean(String className, ObjectName name)
throws
ReflectionException,
InstanceAlreadyExistsException,
MBeanRegistrationException,
MBeanException,
NotCompliantMBeanException {
checkCreate(className);
SecurityManager sm = System.getSecurityManager();
if (sm == null) {
Object object = getMBeanServer().instantiate(className);
checkClassLoader(object);
return getMBeanServer().registerMBean(object, name);
} else {
return getMBeanServer().createMBean(className, name);
}
}
/**
* Initialization of the MIB with AUTOMATIC REGISTRATION in Java DMK.
*/
public ObjectName preRegister(MBeanServer server, ObjectName name)
throws Exception {
// Allow only one initialization of the MIB.
//
if (isInitialized == true) {
throw new InstanceAlreadyExistsException();
}
// Initialize MBeanServer information.
//
this.server = server;
populate(server, name);
isInitialized = true;
return name;
}
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);
}
public ObjectInstance createMBean(String className, ObjectName name,
Object[] params, String[] signature)
throws ReflectionException, InstanceAlreadyExistsException,
MBeanRegistrationException, MBeanException,
NotCompliantMBeanException {
try {
return createMBean(className, name, null, true,
params, signature);
} catch (InstanceNotFoundException e) {
/* Can only happen if loaderName doesn't exist, but we just
passed null, so we shouldn't get this exception. */
throw EnvHelp.initCause(
new IllegalArgumentException("Unexpected exception: " + e), e);
}
}
/**
* Call <code>checkCreate(className)</code>, then forward this method to the
* wrapped object.
*/
public ObjectInstance createMBean(String className,
ObjectName name,
ObjectName loaderName)
throws
ReflectionException,
InstanceAlreadyExistsException,
MBeanRegistrationException,
MBeanException,
NotCompliantMBeanException,
InstanceNotFoundException {
checkCreate(className);
SecurityManager sm = System.getSecurityManager();
if (sm == null) {
Object object = getMBeanServer().instantiate(className,
loaderName);
checkClassLoader(object);
return getMBeanServer().registerMBean(object, name);
} else {
return getMBeanServer().createMBean(className, name, loaderName);
}
}
/**
* Register the status MBean for the specified client cache on the platform mbean server.
*
* @param client the cache client on which status provided by the mbean refer to
* @param bean the mbean providing cache client status
*/
public static void registerClientStatusMXBean(final CacheClient client, final CacheClientStatusMXBean bean) {
if (platformMBeanServer == null) {
throw new BlazingCacheManagementException("PlatformMBeanServer not available", mBeanServerLookupError);
}
final String cacheClientId = safeName(client.getClientId());
try {
final ObjectName name = new ObjectName("blazingcache.client.management:type=CacheClientStatus,CacheClient=" + cacheClientId);
if (platformMBeanServer.isRegistered(name)) {
try {
platformMBeanServer.unregisterMBean(name);
} catch (InstanceNotFoundException noProblem) {
LOGGER.warning("Impossible to unregister non-registered mbean: " + name + ". Cause: " + noProblem);
}
}
platformMBeanServer.registerMBean(bean, name);
} catch (MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) {
throw new BlazingCacheManagementException(REGISTRATION_FAILURE_MSG + e);
}
}
public ObjectInstance createMBean(
String className, ObjectName name, ObjectName loaderName,
Object[] params, String[] signature)
throws ReflectionException, InstanceAlreadyExistsException,
MBeanRegistrationException, MBeanException,
NotCompliantMBeanException, InstanceNotFoundException {
Object mbean = instantiate(className, loaderName, params, signature);
return registerMBean(mbean, name);
}
synchronized void addReference(ObjectName name, Object mxbean)
throws InstanceAlreadyExistsException {
ObjectName existing = mxbeanToObjectName.get(mxbean);
if (existing != null) {
String multiname = AccessController.doPrivileged(
new GetPropertyAction("jmx.mxbean.multiname"));
if (!"true".equalsIgnoreCase(multiname)) {
throw new InstanceAlreadyExistsException(
"MXBean already registered with name " + existing);
}
}
mxbeanToObjectName.put(mxbean, name);
}
@Override
public ObjectInstance createMBean(String className, ObjectName name) throws ReflectionException,
InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException {
Boolean originalValue = AUTHORIZING.get();
try {
AUTHORIZING.set(Boolean.TRUE);
return delegate.createMBean(className, name);
} finally {
AUTHORIZING.set(originalValue);
}
}
public ObjectInstance createMBean(String className,
ObjectName name,
ObjectName loaderName,
Object params[],
String signature[])
throws ReflectionException,
InstanceAlreadyExistsException,
MBeanRegistrationException,
MBeanException,
NotCompliantMBeanException,
InstanceNotFoundException,
IOException {
if (logger.debugOn()) logger.debug(
"createMBean(String,ObjectName,ObjectName,Object[],String[])",
"className=" + className + ", name=" + name + ", loaderName="
+ loaderName + ", signature=" + strings(signature));
final MarshalledObject<Object[]> sParams =
new MarshalledObject<Object[]>(params);
final ClassLoader old = pushDefaultClassLoader();
try {
return connection.createMBean(className,
name,
loaderName,
sParams,
signature,
delegationSubject);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
return connection.createMBean(className,
name,
loaderName,
sParams,
signature,
delegationSubject);
} finally {
popDefaultClassLoader(old);
}
}
public ObjectInstance createMBean(String className, ObjectName name,
ObjectName loaderName)
throws ReflectionException, InstanceAlreadyExistsException,
MBeanRegistrationException, MBeanException,
NotCompliantMBeanException, InstanceNotFoundException {
return createMBean(className, name, loaderName, (Object[]) null,
(String[]) null);
}
/**
* Adds a MBean in the repository,
* sends MBeanServerNotification.REGISTRATION_NOTIFICATION,
* returns ResourceContext for special resources such as ClassLoaders
* or JMXNamespaces. For regular MBean this method returns
* ResourceContext.NONE.
* @return a ResourceContext for special resources such as ClassLoaders
* or JMXNamespaces.
*/
private ResourceContext registerWithRepository(
final Object resource,
final DynamicMBean object,
final ObjectName logicalName)
throws InstanceAlreadyExistsException,
MBeanRegistrationException {
// Creates a registration context, if needed.
//
final ResourceContext context =
makeResourceContextFor(resource, logicalName);
repository.addMBean(object, logicalName, context);
// May throw InstanceAlreadyExistsException
// ---------------------
// Send create event
// ---------------------
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
MBEANSERVER_LOGGER.logp(Level.FINER,
DefaultMBeanServerInterceptor.class.getName(),
"addObject", "Send create notification of object " +
logicalName.getCanonicalName());
}
sendNotification(
MBeanServerNotification.REGISTRATION_NOTIFICATION,
logicalName);
return context;
}
public ObjectInstance createMBean(
String className, ObjectName name, ObjectName loaderName,
Object[] params, String[] signature)
throws ReflectionException, InstanceAlreadyExistsException,
MBeanRegistrationException, MBeanException,
NotCompliantMBeanException, InstanceNotFoundException {
Object mbean = instantiate(className, loaderName, params, signature);
return registerMBean(mbean, name);
}
@Override
public void register(MBeanServer server, ObjectName name)
throws InstanceAlreadyExistsException {
if (name == null)
throw new IllegalArgumentException("Null object name");
// eventually we could have some logic to supply a default name
synchronized (lock) {
this.mxbeanLookup = MXBeanLookup.lookupFor(server);
this.mxbeanLookup.addReference(name, getResource());
this.objectName = name;
}
}
public ObjectInstance createMBean(
String className, ObjectName name, Object[] params, String[] signature)
throws ReflectionException, InstanceAlreadyExistsException,
MBeanRegistrationException, MBeanException,
NotCompliantMBeanException {
try {
return createMBean(className, name, clrName, params, signature);
} catch (InstanceNotFoundException ex) {
throw new RuntimeException(ex); // can't happen
}
}
public FaweForge(ForgeMain plugin, Logger logger, ModMetadata mod, File directory) {
this.parent = plugin;
this.logger = logger;
this.directory = directory;
this.mod = mod;
try {
Fawe.set(this);
setupInjector();
} catch (InstanceAlreadyExistsException e) {
MainUtil.handleError(e);
}
}
public void startup() throws MalformedObjectNameException, NullPointerException, InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException {
mBeanServer = ManagementFactory.getPlatformMBeanServer();
register(mBeanServer, getWorkflowRepositoryMXBeans(), "copper.workflowrepo");
register(mBeanServer, getProcessingEngineMXBeans(), "copper.engine");
register(mBeanServer, getProcessorPoolMXBeans(), "copper.processorpool");
register(mBeanServer, getStatisticsCollectorMXBeans(), "copper.monitoring.statistics");
register(mBeanServer, getAuditTrailMXBeans(), "copper.db");
register(mBeanServer, getBatcherMXBeans(), "copper.db");
register(mBeanServer, getDBStorageMXBeans(), "copper.db");
register(mBeanServer, getDatabaseDialectMXBeans(), "copper.db");
register(mBeanServer, getAuditTrailQueryMXBeans(), "copper.audittrail");
}