use of javax.management.InstanceNotFoundException in project jdk8u_jdk by JetBrains.
the class RelationService method handleNotification.
//
// NotificationListener Interface
//
/**
* Invoked when a JMX notification occurs.
* Currently handles notifications for unregistration of MBeans, either
* referenced in a relation role or being a relation itself.
*
* @param notif The notification.
* @param handback An opaque object which helps the listener to
* associate information regarding the MBean emitter (can be null).
*/
public void handleNotification(Notification notif, Object handback) {
if (notif == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(), "handleNotification", notif);
if (notif instanceof MBeanServerNotification) {
MBeanServerNotification mbsNtf = (MBeanServerNotification) notif;
String ntfType = notif.getType();
if (ntfType.equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
ObjectName mbeanName = ((MBeanServerNotification) notif).getMBeanName();
// Note: use a flag to block access to
// myRefedMBeanObjName2RelIdsMap only for a quick access
boolean isRefedMBeanFlag = false;
synchronized (myRefedMBeanObjName2RelIdsMap) {
if (myRefedMBeanObjName2RelIdsMap.containsKey(mbeanName)) {
// Unregistration of a referenced MBean
synchronized (myUnregNtfList) {
myUnregNtfList.add(mbsNtf);
}
isRefedMBeanFlag = true;
}
if (isRefedMBeanFlag && myPurgeFlag) {
// but assume that will be fine :)
try {
purgeRelations();
} catch (Exception exc) {
throw new RuntimeException(exc.getMessage());
}
}
}
// Note: do both tests as a relation can be an MBean and be
// itself referenced in another relation :)
String relId;
synchronized (myRelMBeanObjName2RelIdMap) {
relId = myRelMBeanObjName2RelIdMap.get(mbeanName);
}
if (relId != null) {
// InstanceNotFoundException
try {
removeRelation(relId);
} catch (Exception exc) {
throw new RuntimeException(exc.getMessage());
}
}
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(), "handleNotification");
return;
}
use of javax.management.InstanceNotFoundException in project jdk8u_jdk by JetBrains.
the class RelationSupport method setRoleInt.
// Sets the role with given value
//
// This method is called in setRole() above.
// It is also called by the Relation Service setRole() method.
// It is also called in setRolesInt() method below (used in setRoles()
// above and in RelationService setRoles() method).
//
// Will check the role according to its corresponding role definition
// provided in relation's relation type
// Will send a notification (RelationNotification with type
// RELATION_BASIC_UPDATE or RELATION_MBEAN_UPDATE, depending if the
// relation is a MBean or not) if not initialization of role.
//
// -param aRole role to be set (name and new value)
// -param relationServCallFlg true if call from the Relation Service; this
// will happen if the current RelationSupport object has been created by
// the Relation Service (via createRelation()) method, so direct access is
// possible.
// -param relationServ reference to Relation Service object, if internal
// relation
// -param multiRoleFlg true if getting the role in the scope of a
// multiple retrieval.
//
// -return (except other "critical" exceptions):
// - for single role retrieval (multiRoleFlg false):
// - null if the role has been set
// - raise an InvalidRoleValueException
// else
// - for multi-role retrieval (multiRoleFlg true):
// - the Role object for given role name if role has been set
// - a RoleUnresolved object with problem else.
//
// -exception IllegalArgumentException if null parameter
// -exception RoleNotFoundException if multiRoleFlg is false and:
// - internal relation and the role does not exist
// or
// - existing role (i.e. not initializing it) and the role is not
// writable.
// -exception InvalidRoleValueException ifmultiRoleFlg is false and
// value provided for:
// - the number of referenced MBeans in given value is less than
// expected minimum degree
// or
// - the number of referenced MBeans in provided value exceeds expected
// maximum degree
// or
// - one referenced MBean in the value is not an Object of the MBean
// class expected for that role
// or
// - a MBean provided for that role does not exist
// -exception RelationServiceNotRegisteredException if the Relation
// Service is not registered in the MBean Server
// -exception RelationTypeNotFoundException if relation type unknown
// -exception RelationNotFoundException if a relation MBean has not been
// added in the Relation Service
Object setRoleInt(Role aRole, boolean relationServCallFlg, RelationService relationServ, boolean multiRoleFlg) throws IllegalArgumentException, RoleNotFoundException, InvalidRoleValueException, RelationServiceNotRegisteredException, RelationTypeNotFoundException, RelationNotFoundException {
if (aRole == null || (relationServCallFlg && relationServ == null)) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationSupport.class.getName(), "setRoleInt", new Object[] { aRole, relationServCallFlg, relationServ, multiRoleFlg });
String roleName = aRole.getRoleName();
int pbType = 0;
// Checks if role exists in the relation
// No error if the role does not exist in the relation, to be able to
// handle initialization of role when creating the relation
// (roles provided in the RoleList parameter are directly set but
// roles automatically initialized are set using setRole())
Role role;
synchronized (myRoleName2ValueMap) {
role = (myRoleName2ValueMap.get(roleName));
}
List<ObjectName> oldRoleValue;
Boolean initFlg;
if (role == null) {
initFlg = true;
oldRoleValue = new ArrayList<ObjectName>();
} else {
initFlg = false;
oldRoleValue = role.getRoleValue();
}
// initialization) and correct value
try {
Integer status;
if (relationServCallFlg) {
// Call from the Relation Service, so direct access to it,
// avoiding MBean Server
//
// Shall not raise a RelationTypeNotFoundException
status = relationServ.checkRoleWriting(aRole, myRelTypeName, initFlg);
} else {
// Call from setRole() method above
// So we have a MBean. We must access the Relation Service
// via the MBean Server.
Object[] params = new Object[3];
params[0] = aRole;
params[1] = myRelTypeName;
params[2] = initFlg;
String[] signature = new String[3];
signature[0] = "javax.management.relation.Role";
signature[1] = "java.lang.String";
signature[2] = "java.lang.Boolean";
// Can throw InstanceNotFoundException if the Relation Service
// is not registered (to be transformed into
// RelationServiceNotRegisteredException in any case).
//
// Can throw a MBeanException wrapping a
// RelationTypeNotFoundException:
// throw wrapped exception.
//
// Shall not throw a ReflectionException
status = (Integer) (myRelServiceMBeanServer.invoke(myRelServiceName, "checkRoleWriting", params, signature));
}
pbType = status.intValue();
} catch (MBeanException exc2) {
// Retrieves underlying exception
Exception wrappedExc = exc2.getTargetException();
if (wrappedExc instanceof RelationTypeNotFoundException) {
throw ((RelationTypeNotFoundException) wrappedExc);
} else {
throw new RuntimeException(wrappedExc.getMessage());
}
} catch (ReflectionException exc3) {
throw new RuntimeException(exc3.getMessage());
} catch (RelationTypeNotFoundException exc4) {
throw new RuntimeException(exc4.getMessage());
} catch (InstanceNotFoundException exc5) {
throw new RelationServiceNotRegisteredException(exc5.getMessage());
}
Object result = null;
if (pbType == 0) {
// Role can be set
if (!(initFlg.booleanValue())) {
// Not initializing the role
// If role being initialized:
// - do not send an update notification
// - do not try to update internal map of Relation Service
// listing referenced MBeans, as role is initialized to an
// empty list
// Sends a notification (RelationNotification)
// Can throw a RelationNotFoundException
sendRoleUpdateNotification(aRole, oldRoleValue, relationServCallFlg, relationServ);
// Updates the role map of the Relation Service
// Can throw RelationNotFoundException
updateRelationServiceMap(aRole, oldRoleValue, relationServCallFlg, relationServ);
}
// Sets the role
synchronized (myRoleName2ValueMap) {
myRoleName2ValueMap.put(roleName, (Role) (aRole.clone()));
}
if (multiRoleFlg) {
// Multi-roles retrieval: returns the role
result = aRole;
}
} else {
if (!(multiRoleFlg)) {
// Problem when setting a simple role: either role not
// found, not writable, or incorrect value:
// raises appropriate exception, RoleNotFoundException or
// InvalidRoleValueException
RelationService.throwRoleProblemException(pbType, roleName);
// To keep compiler happy :)
return null;
} else {
// Problem when retrieving a role in a multi-role retrieval:
// returns a RoleUnresolved object
result = new RoleUnresolved(roleName, aRole.getRoleValue(), pbType);
}
}
RELATION_LOGGER.exiting(RelationSupport.class.getName(), "setRoleInt");
return result;
}
use of javax.management.InstanceNotFoundException in project jdk8u_jdk by JetBrains.
the class RMIConnectorServer method start.
/**
* <p>Activates the connector server, that is starts listening for
* client connections. Calling this method when the connector
* server is already active has no effect. Calling this method
* when the connector server has been stopped will generate an
* <code>IOException</code>.</p>
*
* <p>The behavior of this method when called for the first time
* depends on the parameters that were supplied at construction,
* as described below.</p>
*
* <p>First, an object of a subclass of {@link RMIServerImpl} is
* required, to export the connector server through RMI:</p>
*
* <ul>
*
* <li>If an <code>RMIServerImpl</code> was supplied to the
* constructor, it is used.
*
* <li>Otherwise, if the protocol part of the
* <code>JMXServiceURL</code> supplied to the constructor was
* <code>iiop</code>, an object of type {@link RMIIIOPServerImpl}
* is created.
*
* <li>Otherwise, if the <code>JMXServiceURL</code>
* was null, or its protocol part was <code>rmi</code>, an object
* of type {@link RMIJRMPServerImpl} is created.
*
* <li>Otherwise, the implementation can create an
* implementation-specific {@link RMIServerImpl} or it can throw
* {@link MalformedURLException}.
*
* </ul>
*
* <p>If the given address includes a JNDI directory URL as
* specified in the package documentation for {@link
* javax.management.remote.rmi}, then this
* <code>RMIConnectorServer</code> will bootstrap by binding the
* <code>RMIServerImpl</code> to the given address.</p>
*
* <p>If the URL path part of the <code>JMXServiceURL</code> was
* empty or a single slash (<code>/</code>), then the RMI object
* will not be bound to a directory. Instead, a reference to it
* will be encoded in the URL path of the RMIConnectorServer
* address (returned by {@link #getAddress()}). The encodings for
* <code>rmi</code> and <code>iiop</code> are described in the
* package documentation for {@link
* javax.management.remote.rmi}.</p>
*
* <p>The behavior when the URL path is neither empty nor a JNDI
* directory URL, or when the protocol is neither <code>rmi</code>
* nor <code>iiop</code>, is implementation defined, and may
* include throwing {@link MalformedURLException} when the
* connector server is created or when it is started.</p>
*
* @exception IllegalStateException if the connector server has
* not been attached to an MBean server.
* @exception IOException if the connector server cannot be
* started, or in the case of the {@code iiop} protocol, that
* RMI/IIOP is not supported.
*/
public synchronized void start() throws IOException {
final boolean tracing = logger.traceOn();
if (state == STARTED) {
if (tracing)
logger.trace("start", "already started");
return;
} else if (state == STOPPED) {
if (tracing)
logger.trace("start", "already stopped");
throw new IOException("The server has been stopped.");
}
if (getMBeanServer() == null)
throw new IllegalStateException("This connector server is not " + "attached to an MBean server");
//
if (attributes != null) {
// Check if access file property is specified
//
String accessFile = (String) attributes.get("jmx.remote.x.access.file");
if (accessFile != null) {
// Access file property specified, create an instance
// of the MBeanServerFileAccessController class
//
MBeanServerForwarder mbsf;
try {
mbsf = new MBeanServerFileAccessController(accessFile);
} catch (IOException e) {
throw EnvHelp.initCause(new IllegalArgumentException(e.getMessage()), e);
}
// Set the MBeanServerForwarder
//
setMBeanServerForwarder(mbsf);
}
}
try {
if (tracing)
logger.trace("start", "setting default class loader");
defaultClassLoader = EnvHelp.resolveServerClassLoader(attributes, getMBeanServer());
} catch (InstanceNotFoundException infc) {
IllegalArgumentException x = new IllegalArgumentException("ClassLoader not found: " + infc);
throw EnvHelp.initCause(x, infc);
}
if (tracing)
logger.trace("start", "setting RMIServer object");
final RMIServerImpl rmiServer;
if (rmiServerImpl != null)
rmiServer = rmiServerImpl;
else
rmiServer = newServer();
rmiServer.setMBeanServer(getMBeanServer());
rmiServer.setDefaultClassLoader(defaultClassLoader);
rmiServer.setRMIConnectorServer(this);
rmiServer.export();
try {
if (tracing)
logger.trace("start", "getting RMIServer object to export");
final RMIServer objref = objectToBind(rmiServer, attributes);
if (address != null && address.getURLPath().startsWith("/jndi/")) {
final String jndiUrl = address.getURLPath().substring(6);
if (tracing)
logger.trace("start", "Using external directory: " + jndiUrl);
String stringBoolean = (String) attributes.get(JNDI_REBIND_ATTRIBUTE);
final boolean rebind = EnvHelp.computeBooleanFromString(stringBoolean);
if (tracing)
logger.trace("start", JNDI_REBIND_ATTRIBUTE + "=" + rebind);
try {
if (tracing)
logger.trace("start", "binding to " + jndiUrl);
final Hashtable<?, ?> usemap = EnvHelp.mapToHashtable(attributes);
bind(jndiUrl, usemap, objref, rebind);
boundJndiUrl = jndiUrl;
} catch (NamingException e) {
// fit e in the nested exception if we are on 1.4
throw newIOException("Cannot bind to URL [" + jndiUrl + "]: " + e, e);
}
} else {
// if jndiURL is null, we must encode the stub into the URL.
if (tracing)
logger.trace("start", "Encoding URL");
encodeStubInAddress(objref, attributes);
if (tracing)
logger.trace("start", "Encoded URL: " + this.address);
}
} catch (Exception e) {
try {
rmiServer.close();
} catch (Exception x) {
// OK: we are already throwing another exception
}
if (e instanceof RuntimeException)
throw (RuntimeException) e;
else if (e instanceof IOException)
throw (IOException) e;
else
throw newIOException("Got unexpected exception while " + "starting the connector server: " + e, e);
}
rmiServerImpl = rmiServer;
synchronized (openedServers) {
openedServers.add(this);
}
state = STARTED;
if (tracing) {
logger.trace("start", "Connector Server Address = " + address);
logger.trace("start", "started.");
}
}
use of javax.management.InstanceNotFoundException in project jdk8u_jdk by JetBrains.
the class RelationService method initializeMissingRoles.
// Initializes roles associated to given role infos to default value (empty
// ArrayList of ObjectNames) in given relation.
// It will succeed for every role except if the role info has a minimum
// cardinality greater than 0. In that case, an InvalidRoleValueException
// will be raised.
//
// -param relationBaseFlag flag true if the relation is a RelationSupport
// object, false if it is an MBean
// -param relationObj RelationSupport object (if relation is internal)
// -param relationObjName ObjectName of the MBean to be added as a relation
// (only for the relation MBean)
// -param relationId relation id
// -param relationTypeName name of the relation type (has to be created
// in the Relation Service)
// -param roleInfoList list of role infos for roles to be defaulted
//
// -exception IllegalArgumentException if null paramater
// -exception RelationServiceNotRegisteredException if the Relation
// Service is not registered in the MBean Server
// -exception InvalidRoleValueException if role must have a non-empty
// value
// Revisit [cebro] Handle CIM qualifiers as REQUIRED to detect roles which
// should have been initialized by the user
private void initializeMissingRoles(boolean relationBaseFlag, RelationSupport relationObj, ObjectName relationObjName, String relationId, String relationTypeName, List<RoleInfo> roleInfoList) throws IllegalArgumentException, RelationServiceNotRegisteredException, InvalidRoleValueException {
if ((relationBaseFlag && (relationObj == null || relationObjName != null)) || (!relationBaseFlag && (relationObjName == null || relationObj != null)) || relationId == null || relationTypeName == null || roleInfoList == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(), "initializeMissingRoles", new Object[] { relationBaseFlag, relationObj, relationObjName, relationId, relationTypeName, roleInfoList });
// Can throw RelationServiceNotRegisteredException
isActive();
// empty value, according to its minimum cardinality
for (RoleInfo currRoleInfo : roleInfoList) {
String roleName = currRoleInfo.getName();
// Creates an empty value
List<ObjectName> emptyValue = new ArrayList<ObjectName>();
// Creates a role
Role role = new Role(roleName, emptyValue);
if (relationBaseFlag) {
// RelationTypeNotFoundException
try {
relationObj.setRoleInt(role, true, this, false);
} catch (RoleNotFoundException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (RelationNotFoundException exc2) {
throw new RuntimeException(exc2.getMessage());
} catch (RelationTypeNotFoundException exc3) {
throw new RuntimeException(exc3.getMessage());
}
} else {
// Relation is an MBean
// Use standard setRole()
Object[] params = new Object[1];
params[0] = role;
String[] signature = new String[1];
signature[0] = "javax.management.relation.Role";
// the relation MBeans are registered in the same MBean Server.
try {
myMBeanServer.setAttribute(relationObjName, new Attribute("Role", role));
} catch (InstanceNotFoundException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (ReflectionException exc3) {
throw new RuntimeException(exc3.getMessage());
} catch (MBeanException exc2) {
Exception wrappedExc = exc2.getTargetException();
if (wrappedExc instanceof InvalidRoleValueException) {
throw ((InvalidRoleValueException) wrappedExc);
} else {
throw new RuntimeException(wrappedExc.getMessage());
}
} catch (AttributeNotFoundException exc4) {
throw new RuntimeException(exc4.getMessage());
} catch (InvalidAttributeValueException exc5) {
throw new RuntimeException(exc5.getMessage());
}
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(), "initializeMissingRoles");
return;
}
use of javax.management.InstanceNotFoundException in project jdk8u_jdk by JetBrains.
the class RelationService method setRole.
/**
* Sets the given role in given relation.
* <P>Will check the role according to its corresponding role definition
* provided in relation's relation type
* <P>The Relation Service will keep track of the change to keep the
* consistency of relations by handling referenced MBean deregistrations.
*
* @param relationId relation id
* @param role role to be set (name and new value)
*
* @exception RelationServiceNotRegisteredException if the Relation
* Service is not registered in the MBean Server
* @exception IllegalArgumentException if null parameter
* @exception RelationNotFoundException if no relation with given id
* @exception RoleNotFoundException if the role does not exist or is not
* writable
* @exception InvalidRoleValueException if value provided for role is not
* valid:
* <P>- the number of referenced MBeans in given value is less than
* expected minimum degree
* <P>or
* <P>- the number of referenced MBeans in provided value exceeds expected
* maximum degree
* <P>or
* <P>- one referenced MBean in the value is not an Object of the MBean
* class expected for that role
* <P>or
* <P>- an MBean provided for that role does not exist
*
* @see #getRole
*/
public void setRole(String relationId, Role role) throws RelationServiceNotRegisteredException, IllegalArgumentException, RelationNotFoundException, RoleNotFoundException, InvalidRoleValueException {
if (relationId == null || role == null) {
String excMsg = "Invalid parameter.";
throw new IllegalArgumentException(excMsg);
}
RELATION_LOGGER.entering(RelationService.class.getName(), "setRole", new Object[] { relationId, role });
// Can throw RelationServiceNotRegisteredException
isActive();
// Can throw a RelationNotFoundException
Object relObj = getRelation(relationId);
if (relObj instanceof RelationSupport) {
// (as relation exists in the RS, its relation type is known)
try {
((RelationSupport) relObj).setRoleInt(role, true, this, false);
} catch (RelationTypeNotFoundException exc) {
throw new RuntimeException(exc.getMessage());
}
} else {
// Relation MBean
Object[] params = new Object[1];
params[0] = role;
String[] signature = new String[1];
signature[0] = "javax.management.relation.Role";
// InstanceNotFoundException
try {
myMBeanServer.setAttribute(((ObjectName) relObj), new Attribute("Role", role));
} catch (InstanceNotFoundException exc1) {
throw new RuntimeException(exc1.getMessage());
} catch (ReflectionException exc3) {
throw new RuntimeException(exc3.getMessage());
} catch (MBeanException exc2) {
Exception wrappedExc = exc2.getTargetException();
if (wrappedExc instanceof RoleNotFoundException) {
throw ((RoleNotFoundException) wrappedExc);
} else if (wrappedExc instanceof InvalidRoleValueException) {
throw ((InvalidRoleValueException) wrappedExc);
} else {
throw new RuntimeException(wrappedExc.getMessage());
}
} catch (AttributeNotFoundException exc4) {
throw new RuntimeException(exc4.getMessage());
} catch (InvalidAttributeValueException exc5) {
throw new RuntimeException(exc5.getMessage());
}
}
RELATION_LOGGER.exiting(RelationService.class.getName(), "setRole");
return;
}
Aggregations