use of javax.management.JMException in project OpenAM by OpenRock.
the class Agent method configAgentsOnly.
/**
* process realm's Agents (only)
*
* the HashMap of attributes/values:
* CLIConstants.ATTR_NAME_AGENT_TYPE
* type is extracted from the set; can be:
* J2EEAgent, 2.2_Agent
* WebAgent
* don't do "SharedAgent" (authenticators)
*
* J2EEAgent should have:
* "com.sun.identity.agents.config.login.url"
* "com.sun.identity.client.notification.url"
* "groupmembership"
* WebAgent should have:
* "com.sun.identity.agents.config.agenturi.prefix"
* "com.sun.identity.agents.config.login.url"
* "groupmembership"
* 2.2_Agent should have:
* "groupmembership"
*/
public static void configAgentsOnly(String realm, Map<String, Map<String, String>> agtAttrs) {
String classMethod = "Agent.configAgentsOnly:";
if ((agtAttrs == null) || agtAttrs.isEmpty()) {
if (debug.messageEnabled()) {
debug.message(classMethod + "got null attr map for realm " + realm);
}
return;
}
SsoServerPolicyAgents sss = sunMib.getPolicyAgentsGroup();
TableSsoServerPolicy22AgentTable t22tab = null;
TableSsoServerPolicyJ2EEAgentTable j2eetab = null;
TableSsoServerPolicyWebAgentTable watab = null;
SsoServerWSSAgents ssa = sunMib.getWssAgentsGroup();
TableSsoServerWSSAgentsSTSAgentTable ststab = null;
TableSsoServerWSSAgentsWSPAgentTable wsptab = null;
TableSsoServerWSSAgentsWSCAgentTable wsctab = null;
TableSsoServerWSSAgentsDSCAgentTable dsctab = null;
/*
* get the tables
*/
if (sss != null) {
try {
t22tab = sss.accessSsoServerPolicy22AgentTable();
j2eetab = sss.accessSsoServerPolicyJ2EEAgentTable();
watab = sss.accessSsoServerPolicyWebAgentTable();
ststab = ssa.accessSsoServerWSSAgentsSTSAgentTable();
wsptab = ssa.accessSsoServerWSSAgentsWSPAgentTable();
wsctab = ssa.accessSsoServerWSSAgentsWSCAgentTable();
dsctab = ssa.accessSsoServerWSSAgentsDSCAgentTable();
} catch (SnmpStatusException ex) {
debug.error(classMethod + "getting Agents tables: ", ex);
// can't do anything without the tables
return;
}
}
if (ssa != null) {
try {
ststab = ssa.accessSsoServerWSSAgentsSTSAgentTable();
wsptab = ssa.accessSsoServerWSSAgentsWSPAgentTable();
wsctab = ssa.accessSsoServerWSSAgentsWSCAgentTable();
dsctab = ssa.accessSsoServerWSSAgentsDSCAgentTable();
} catch (SnmpStatusException ex) {
debug.error(classMethod + "getting WSS Agents tables: ", ex);
// can't do anything without the tables
return;
}
}
StringBuilder sb = new StringBuilder(classMethod);
if (debug.messageEnabled()) {
sb.append("agents for realm ").append(realm).append(", # = ").append(agtAttrs.size()).append("\n");
}
// index for web agents
int wai = 1;
// index for j2ee agents
int j2eei = 1;
// index for 2.2_agents
int t22i = 1;
// index for STS agents
int stsi = 1;
// index for WSP agents
int wspi = 1;
// index for WSC agents
int wsci = 1;
// index for DSC agents
int dsci = 1;
Integer ri = getRealmIndexFromName(realm);
/*
* if the realm isn't in the table, there's not much point
* in doing the rest
*/
if (ri == null) {
debug.error(classMethod + "didn't find index for realm " + realm);
return;
}
for (Map.Entry<String, Map<String, String>> entry : agtAttrs.entrySet()) {
String agtname = entry.getKey();
Map<String, String> hm = entry.getValue();
;
String atype = hm.get(Constants.ATTR_NAME_AGENT_TYPE);
String grpmem = hm.get("groupmembership");
// group and agent name can't have ":" in it, or jdmk gags
if (grpmem == null) {
grpmem = None;
} else {
grpmem = getEscapedString(grpmem);
}
agtname = getEscapedString(agtname);
if (debug.messageEnabled()) {
sb.append(" agent name = ").append(agtname).append(", type = ").append(atype).append(", membership = ").append(grpmem).append("\n");
}
if (atype.equals("WebAgent")) {
String aurl = hm.get("com.sun.identity.agents.config.agenturi.prefix");
String lurl = hm.get("com.sun.identity.agents.config.login.url");
SsoServerPolicyWebAgentEntryImpl aei = new SsoServerPolicyWebAgentEntryImpl(sunMib);
aei.SsoServerRealmIndex = ri;
aei.PolicyWebAgentIndex = new Integer(wai++);
aei.PolicyWebAgentName = agtname;
aei.PolicyWebAgentGroup = grpmem;
aei.PolicyWebAgentAgentURL = aurl;
aei.PolicyWebAgentServerURL = lurl;
ObjectName aname = aei.createSsoServerPolicyWebAgentEntryObjectName(server);
if (aname == null) {
debug.error(classMethod + "Error creating object for Policy WebAgent '" + agtname + "'");
continue;
}
try {
watab.addEntry(aei, aname);
if ((server != null) && (aei != null)) {
server.registerMBean(aei, aname);
}
} catch (JMException ex) {
debug.error(classMethod + agtname + ": " + ex.getMessage());
} catch (SnmpStatusException ex) {
debug.error(classMethod + agtname + ": " + ex.getMessage());
}
} else if (atype.equals("2.2_Agent")) {
SsoServerPolicy22AgentEntryImpl aei = new SsoServerPolicy22AgentEntryImpl(sunMib);
aei.SsoServerRealmIndex = ri;
aei.Policy22AgentIndex = new Integer(t22i++);
aei.Policy22AgentName = agtname;
ObjectName aname = aei.createSsoServerPolicy22AgentEntryObjectName(server);
if (aname == null) {
debug.error(classMethod + "Error creating object for Policy 2.2 Agent '" + agtname + "'");
continue;
}
try {
t22tab.addEntry(aei, aname);
if ((server != null) && (aei != null)) {
server.registerMBean(aei, aname);
}
} catch (JMException ex) {
debug.error(classMethod + agtname + ": " + ex.getMessage());
} catch (SnmpStatusException ex) {
debug.error(classMethod + agtname + ": " + ex.getMessage());
}
} else if (atype.equals("J2EEAgent")) {
SsoServerPolicyJ2EEAgentEntryImpl aei = new SsoServerPolicyJ2EEAgentEntryImpl(sunMib);
String aurl = hm.get("com.sun.identity.client.notification.url");
if (aurl == null) {
aurl = None;
}
String lurl = hm.get("com.sun.identity.agents.config.login.url");
aei.PolicyJ2EEAgentGroup = grpmem;
aei.PolicyJ2EEAgentAgentURL = aurl;
aei.PolicyJ2EEAgentServerURL = lurl;
aei.PolicyJ2EEAgentName = agtname;
aei.PolicyJ2EEAgentIndex = new Integer(j2eei++);
aei.SsoServerRealmIndex = ri;
ObjectName aname = aei.createSsoServerPolicyJ2EEAgentEntryObjectName(server);
if (aname == null) {
debug.error(classMethod + "Error creating object for Policy J2EE Agent '" + agtname + "'");
continue;
}
try {
j2eetab.addEntry(aei, aname);
if ((server != null) && (aei != null)) {
server.registerMBean(aei, aname);
}
} catch (JMException ex) {
debug.error(classMethod + agtname + ": " + ex.getMessage());
} catch (SnmpStatusException ex) {
debug.error(classMethod + agtname + ": " + ex.getMessage());
}
} else if (atype.equals("SharedAgent")) {
// SharedAgent type are agent authenticators
} else {
debug.error(classMethod + "agent type = " + atype + ", agent name = " + agtname + " not supported.");
}
}
if (debug.messageEnabled()) {
debug.message(sb.toString());
}
}
use of javax.management.JMException in project camel by apache.
the class DefaultManagementLifecycleStrategy method onRoutesAdd.
public void onRoutesAdd(Collection<Route> routes) {
for (Route route : routes) {
// enabled, then enlist the route as a known route
if (getCamelContext().getStatus().isStarting() || getManagementStrategy().getManagementAgent().getRegisterAlways() || getManagementStrategy().getManagementAgent().getRegisterNewRoutes()) {
// register as known route id
knowRouteIds.add(route.getId());
}
if (!shouldRegister(route, route)) {
// avoid registering if not needed, skip to next route
continue;
}
Object mr = getManagementObjectStrategy().getManagedObjectForRoute(camelContext, route);
// skip already managed routes, for example if the route has been restarted
if (getManagementStrategy().isManaged(mr, null)) {
LOG.trace("The route is already managed: {}", route);
continue;
}
// and set me as the counter
if (route instanceof EventDrivenConsumerRoute) {
EventDrivenConsumerRoute edcr = (EventDrivenConsumerRoute) route;
Processor processor = edcr.getProcessor();
if (processor instanceof CamelInternalProcessor && mr instanceof ManagedRoute) {
CamelInternalProcessor internal = (CamelInternalProcessor) processor;
ManagedRoute routeMBean = (ManagedRoute) mr;
CamelInternalProcessor.InstrumentationAdvice task = internal.getAdvice(CamelInternalProcessor.InstrumentationAdvice.class);
if (task != null) {
// we need to wrap the counter with the camel context so we get stats updated on the context as well
if (camelContextMBean != null) {
CompositePerformanceCounter wrapper = new CompositePerformanceCounter(routeMBean, camelContextMBean);
task.setCounter(wrapper);
} else {
task.setCounter(routeMBean);
}
}
}
}
try {
manageObject(mr);
} catch (JMException e) {
LOG.warn("Could not register Route MBean", e);
} catch (Exception e) {
LOG.warn("Could not create Route MBean", e);
}
}
}
use of javax.management.JMException in project ignite by apache.
the class IgniteCacheDatabaseSharedManager method stop0.
/** {@inheritDoc} */
@Override
protected void stop0(boolean cancel) {
if (memPlcMap != null) {
for (MemoryPolicy memPlc : memPlcMap.values()) {
memPlc.pageMemory().stop();
memPlc.evictionTracker().stop();
IgniteConfiguration cfg = cctx.gridConfig();
try {
cfg.getMBeanServer().unregisterMBean(U.makeMBeanName(cfg.getIgniteInstanceName(), "MemoryMetrics", memPlc.memoryMetrics().getName()));
} catch (JMException e) {
U.error(log, "Failed to unregister MBean for memory metrics: " + memPlc.memoryMetrics().getName(), e);
}
}
}
}
use of javax.management.JMException in project voltdb by VoltDB.
the class MBeanRegistry method register.
/**
* Registers a new MBean with the platform MBean server.
* @param bean the bean being registered
* @param parent if not null, the new bean will be registered as a child
* node of this parent.
*/
public void register(ZKMBeanInfo bean, ZKMBeanInfo parent) throws JMException {
assert bean != null;
String path = null;
if (parent != null) {
path = mapBean2Path.get(parent);
assert path != null;
}
path = makeFullPath(path, parent);
mapBean2Path.put(bean, path);
mapName2Bean.put(bean.getName(), bean);
if (bean.isHidden())
return;
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName oname = makeObjectName(path, bean);
try {
mbs.registerMBean(bean, oname);
} catch (JMException e) {
LOG.warn("Failed to register MBean " + bean.getName());
throw e;
}
}
use of javax.management.JMException in project geode by apache.
the class MBeanUtil method registerServerNotificationListener.
static void registerServerNotificationListener() {
if (mbeanServer == null) {
return;
}
try {
// the MBeanServerDelegate name is spec'ed as the following...
ObjectName delegate = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate");
mbeanServer.addNotificationListener(delegate, new NotificationListener() {
public void handleNotification(Notification notification, Object handback) {
MBeanServerNotification serverNotification = (MBeanServerNotification) notification;
if (MBeanServerNotification.UNREGISTRATION_NOTIFICATION.equals(serverNotification.getType())) {
ObjectName objectName = serverNotification.getMBeanName();
synchronized (MBeanUtil.managedResources) {
Object entry = MBeanUtil.managedResources.get(objectName);
if (entry == null)
return;
if (!(entry instanceof ManagedResource)) {
throw new ClassCastException(LocalizedStrings.MBeanUtil_0_IS_NOT_A_MANAGEDRESOURCE.toLocalizedString(new Object[] { entry.getClass().getName() }));
}
ManagedResource resource = (ManagedResource) entry;
{
// call cleanup on managedResource
cleanupResource(resource);
}
}
}
}
}, null, null);
} catch (JMException e) {
logStackTrace(Level.WARN, e, LocalizedStrings.MBeanUtil_FAILED_TO_REGISTER_SERVERNOTIFICATIONLISTENER.toLocalizedString());
} catch (JMRuntimeException e) {
logStackTrace(Level.WARN, e, LocalizedStrings.MBeanUtil_FAILED_TO_REGISTER_SERVERNOTIFICATIONLISTENER.toLocalizedString());
}
}
Aggregations