1 21 package org.objectweb.fractal.jmx.comm; 22 23 import org.objectweb.fractal.api.control.BindingController; 24 import org.objectweb.fractal.api.control.LifeCycleController; 25 26 import org.objectweb.fractal.jmx.agent.AdminAttributes; 27 28 import javax.management.ObjectName ; 30 import javax.management.JMException ; 31 import javax.management.InstanceNotFoundException ; 32 import javax.management.JMRuntimeException ; 33 import com.sun.jdmk.comm.HtmlAdaptorServer; 35 36 77 public class RI_HtmlAdaptor implements BindingController, LifeCycleController, CommunicatorAttributes { 78 private static final String ADAPTOR = "RI_HtmlAdaptor"; 79 private AdminAttributes _adminAtt; 80 private HtmlAdaptorServer _htmlAdaptor = new HtmlAdaptorServer(); 81 private int _port = _htmlAdaptor.getPort(); 82 83 public String [] listFc() { 87 return new String [] { "adminAtt" }; 88 } 89 90 public Object lookupFc(final String itfName) { 91 if (itfName.equals("adminAtt")) 92 return _adminAtt; 93 else 94 return null; 95 } 96 97 public void bindFc(final String itfName, final Object itfValue) { 98 if (itfName.equals("adminAtt")) { 99 _adminAtt = (AdminAttributes) itfValue; 100 } 101 } 102 103 public void unbindFc(final String itfName) { 104 if (itfName.equals("adminAtt")) { 105 _adminAtt = null; 106 } 107 } 108 109 public String getFcState() { 113 return null; 114 } 115 116 public synchronized void startFc() { 117 ObjectName oName; 118 String id = '@' + Integer.toHexString(this.hashCode()); 119 try { 120 if (_htmlAdaptor != null 122 && _htmlAdaptor.getState() == HtmlAdaptorServer.ONLINE 123 && _htmlAdaptor.getPort() == _port) { 124 return; 126 } 127 if (_htmlAdaptor != null) { 129 _htmlAdaptor.stop(); 130 oName = new ObjectName (ADAPTOR + id + ":type=html,port=" + _htmlAdaptor.getPort()); 131 try { 132 _adminAtt.getRawMBeanServer().unregisterMBean(oName); 133 } catch (InstanceNotFoundException ignore) {} 134 } 135 _htmlAdaptor = new HtmlAdaptorServer(_port); 137 oName = new ObjectName (ADAPTOR + id + ":type=html,port=" + _port); 138 _adminAtt.getRawMBeanServer().registerMBean(_htmlAdaptor, oName); 139 _htmlAdaptor.start(); 140 if (!_htmlAdaptor.waitState(HtmlAdaptorServer.ONLINE, 5000)) 142 throw new JMRuntimeException ( 143 "HtmlAdaptorServer failed to start with port=" 144 + _htmlAdaptor.getPort() 145 + ", current state=" 146 + _htmlAdaptor.getState()); 147 } catch (JMException e) { 149 throw new JMRuntimeException (e.toString()); 150 } 151 } 152 153 public void stopFc() {} 154 155 public int getPort() { 159 return _port; 160 } 161 162 public void setPort(final int port) { 163 this._port = port; 164 } 165 } 166 | Popular Tags |