1 22 package org.jboss.management.j2ee; 23 24 import org.jboss.logging.Logger; 25 26 import javax.management.JMException ; 27 import javax.management.MBeanServer ; 28 import javax.management.MalformedObjectNameException ; 29 import javax.management.ObjectName ; 30 31 38 public class URLResource extends J2EEResource 39 implements URLResourceMBean 40 { 41 43 private static Logger log = Logger.getLogger(URLResource.class); 45 46 private StateManagement mState; 47 private ObjectName mService; 48 49 51 public static ObjectName create(MBeanServer pServer, String pName, ObjectName pService) 52 { 53 ObjectName lServer = null; 54 try 55 { 56 lServer = (ObjectName ) pServer.queryNames(new ObjectName (J2EEDomain.getDomainName() + ":" + 57 J2EEManagedObject.TYPE + "=" + J2EETypeConstants.J2EEServer + "," + 58 "*"), 59 null).iterator().next(); 60 } 61 catch (Exception e) 62 { 63 log.error("Could not create JSR-77 URLResource: " + pName, e); 64 return null; 65 } 66 try 67 { 68 return pServer.createMBean("org.jboss.management.j2ee.URLResource", 70 null, 71 new Object []{ 72 pName, 73 lServer, 74 pService 75 }, 76 new String []{ 77 String .class.getName(), 78 ObjectName .class.getName(), 79 ObjectName .class.getName() 80 }).getObjectName(); 81 } 82 catch (Exception e) 83 { 84 log.error("Could not create JSR-77 URLResource: " + pName, e); 85 return null; 86 } 87 } 88 89 public static void destroy(MBeanServer pServer, String pName) 90 { 91 try 92 { 93 J2EEManagedObject.removeObject(pServer, 94 J2EEDomain.getDomainName() + ":" + 95 J2EEManagedObject.TYPE + "=" + J2EETypeConstants.URLResource + "," + 96 "name=" + pName + "," + 97 "*"); 98 } 99 catch (Exception e) 100 { 101 log.error("Could not destroy JSR-77 URLResource: " + pName, e); 102 } 103 } 104 105 107 111 public URLResource(String pName, ObjectName pServer, ObjectName pService) 112 throws 113 MalformedObjectNameException , 114 InvalidParentException 115 { 116 super(J2EETypeConstants.URLResource, pName, pServer); 117 if (log.isDebugEnabled()) 118 log.debug("Service name: " + pService); 119 mService = pService; 120 mState = new StateManagement(this); 121 } 122 123 125 public String [] getEventTypes() 126 { 127 return StateManagement.stateTypes; 128 } 129 130 public String getEventType(int pIndex) 131 { 132 if (pIndex >= 0 && pIndex < StateManagement.stateTypes.length) 133 { 134 return StateManagement.stateTypes[pIndex]; 135 } 136 else 137 { 138 return null; 139 } 140 } 141 142 144 public long getStartTime() 145 { 146 return mState.getStartTime(); 147 } 148 149 public int getState() 150 { 151 return mState.getState(); 152 } 153 public String getStateString() 154 { 155 return mState.getStateString(); 156 } 157 158 public void mejbStart() 159 { 160 try 161 { 162 server.invoke(mService, 163 "start", 164 new Object []{}, 165 new String []{}); 166 } 167 catch (Exception e) 168 { 169 log.error("Start of URL Resource failed", e); 170 } 171 } 172 173 public void mejbStartRecursive() 174 { 175 mejbStart(); 177 } 178 179 public void mejbStop() 180 { 181 try 182 { 183 server.invoke(mService, 184 "stop", 185 new Object []{}, 186 new String []{}); 187 } 188 catch (Exception e) 189 { 190 log.error("Stop of URL Resource failed", e); 191 } 192 } 193 194 public void postCreation() 195 { 196 try 197 { 198 server.addNotificationListener(mService, mState, null, null); 199 } 200 catch (JMException e) 201 { 202 log.debug("Failed to add notification listener", e); 203 } 204 sendNotification(NotificationConstants.OBJECT_CREATED, "URL Resource created"); 205 } 206 207 public void preDestruction() 208 { 209 sendNotification(NotificationConstants.OBJECT_DELETED, "URL Resource deleted"); 210 try 212 { 213 server.removeNotificationListener(mService, mState); 214 } 215 catch (JMException jme) 216 { 217 } 219 } 220 221 223 public String toString() 224 { 225 return "URLResource { " + super.toString() + " } [ " + 226 " ]"; 227 } 228 229 231 233 235 } 237 | Popular Tags |