001: package com.sun.portal.ubt.admin.mbeans;
002:
003: import com.sun.portal.admin.server.mbeans.PSResource;
004: import com.sun.portal.admin.server.PASModule;
005: import com.sun.portal.admin.server.AdminServerUtil;
006: import com.sun.portal.admin.common.context.PSConfigContext;
007: import com.sun.portal.admin.common.context.PortalDomainContext;
008: import com.sun.portal.admin.common.util.AdminUtil;
009: import com.sun.portal.log.common.PortalLogger;
010:
011: import javax.management.*;
012: import javax.management.remote.JMXConnector;
013: import java.util.Hashtable;
014: import java.util.List;
015: import java.util.LinkedList;
016: import java.util.logging.Logger;
017: import java.util.logging.Level;
018: import java.util.logging.LogRecord;
019:
020: /**
021: *
022: */
023: public class UBTSettingsHostBridge extends PSResource implements
024: UBTSettingsHostBridgeMBean {
025: private String psPortalID;
026: private static Logger logger = PortalLogger
027: .getLogger(UBTSettingsHostBridge.class);
028:
029: public void init(PSConfigContext cc, PortalDomainContext pdc,
030: List path) {
031: super .init(cc, pdc, path);
032: psPortalID = (String) path.get(1);
033: }
034:
035: public Hashtable getUBTSettings(String instance) throws Exception {
036: Object obj = null;
037: MBeanServerConnection serverConnection = null;
038: try {
039: //get appropriate MBeanServerConnector
040: serverConnection = getConnection(instance);
041: //invoke getCommonLogDetails on PortalLogconfigurator on that server
042: ObjectName ubtConfigObjName = getUbtConfigObjName();
043: obj = serverConnection.getAttribute(ubtConfigObjName,
044: "UBTSettings");
045: } finally {
046: closeRemoteConnection(serverConnection);
047: }
048: if (obj == null)
049: return null;
050: else
051: return (Hashtable) obj;
052: }
053:
054: public void setUBTSettings(Hashtable values, String instance)
055: throws Exception {
056: Object obj = null;
057: MBeanServerConnection serverConnection = null;
058: try {
059: //get appropriate MBeanServerConnector
060: serverConnection = getConnection(instance);
061: //invoke getCommonLogDetails on PortalLogconfigurator on that server
062: ObjectName ubtConfigObjName = getUbtConfigObjName();
063: Attribute attribute = new Attribute("UBTSettings", values);
064: serverConnection.setAttribute(ubtConfigObjName, attribute);
065: } finally {
066: closeRemoteConnection(serverConnection);
067: }
068: }
069:
070: private ObjectName getUbtConfigObjName()
071: throws MalformedObjectNameException {
072: LinkedList path = new LinkedList();
073: path.addFirst(m_sPsDomainID);
074: path.addFirst(psPortalID);
075: path.addFirst("UBTSettings");
076: return AdminUtil.getResourceMBeanObjectName(
077: UBTSettingsMBean.PORTAL_UBT_SETTINGS_OBJECT_NAME, path);
078: }
079:
080: private void closeRemoteConnection(
081: MBeanServerConnection serverConnection) {
082: try {
083: if (!serverConnection.equals(PASModule.getMBeanServer()))
084: ((JMXConnector) serverConnection).close();
085: } catch (Exception e) {
086: //drop through it is not open
087: }
088: }
089:
090: private MBeanServerConnection getConnection(String instance)
091: throws Exception {
092: MBeanServerConnection serverConnection;
093: String host = getHost(instance);
094: //find if it is local or remote
095: if (isRemote(instance)) {
096: try {
097: JMXConnector connector = AdminServerUtil
098: .getJMXConnector(host);
099: serverConnection = connector.getMBeanServerConnection();
100: } catch (Exception e) {
101: LogRecord rec = new LogRecord(Level.WARNING,
102: "PSUB_CSPUAM0009");
103: rec.setParameters(new Object[] { host });
104: rec.setThrown(e);
105: rec.setLoggerName(logger.getName());
106: logger.log(rec);
107: throw e;
108: }
109: } else {
110: serverConnection = PASModule.getMBeanServer();
111: }
112: return serverConnection;
113: }
114:
115: private String getHost(String instance) throws Exception {
116: String host = null;
117: ObjectName objName = getPortalInstanceObjectName(instance);
118: host = (String) (PASModule.getMBeanServer().getAttribute(
119: objName, "Host"));
120: return host;
121: }
122:
123: private boolean isRemote(String instance) throws Exception {
124: boolean isRemote = false;
125: MBeanServer server = PASModule.getMBeanServer();
126: Boolean isLocal = (Boolean) server.invoke(
127: getPortalInstanceObjectName(instance), "isLocal", null,
128: null);
129: isRemote = !isLocal.booleanValue();
130: return isRemote;
131: }
132:
133: private ObjectName getPortalInstanceObjectName(String instance)
134: throws Exception {
135: return AdminUtil.getInstanceMBeanObjectName(m_sPsDomainID,
136: psPortalID, instance);
137: }
138:
139: }
|