1 23 24 package org.apache.slide.common; 25 26 import java.io.FileInputStream ; 27 28 import javax.management.AttributeChangeNotification ; 29 import javax.management.MBeanRegistration ; 30 import javax.management.MBeanServer ; 31 import javax.management.Notification ; 32 import javax.management.NotificationBroadcasterSupport ; 33 import javax.management.ObjectName ; 34 import javax.xml.parsers.SAXParser ; 35 import javax.xml.parsers.SAXParserFactory ; 36 37 import org.apache.slide.authenticate.SecurityToken; 38 import org.apache.slide.util.conf.Configuration; 39 import org.apache.slide.util.conf.ConfigurationElement; 40 import org.apache.slide.util.conf.Populate; 41 import org.xml.sax.InputSource ; 42 43 48 public final class Slide 49 extends NotificationBroadcasterSupport 50 implements SlideMBean, MBeanRegistration { 51 52 53 55 56 59 private int state = STOPPED; 60 61 62 65 private String configFile = null; 66 67 68 71 private long sequenceNumber = 0; 72 73 74 76 77 public ObjectName preRegister(MBeanServer server, ObjectName name) 78 throws Exception { 79 return new ObjectName (OBJECT_NAME); 80 } 81 82 83 public void postRegister(Boolean registrationDone) { 84 if (!registrationDone.booleanValue()) 85 destroy(); 86 } 87 88 89 public void preDeregister() 90 throws Exception { 91 } 92 93 94 public void postDeregister() { 95 destroy(); 96 } 97 98 99 101 102 105 public String getName() { 106 return NAME; 107 } 108 109 110 113 public int getState() { 114 return state; 115 } 116 117 118 121 public String getStateString() { 122 return states[state]; 123 } 124 125 126 129 public void init() 130 throws Exception { 131 132 } 133 134 135 138 public void init(String configFile) 139 throws Exception { 140 141 this.configFile = configFile; 142 143 } 144 145 146 149 public void start() 150 throws Exception { 151 152 Notification notification = null; 153 154 if (state != STOPPED) 155 return; 156 157 state = STARTING; 158 159 161 notification = new AttributeChangeNotification 162 (this, sequenceNumber++, System.currentTimeMillis(), 163 "Starting " + NAME, "State", "java.lang.Integer", 164 new Integer (STOPPED), new Integer (STARTING)); 165 sendNotification(notification); 166 167 try { 168 169 if (configFile == null) { 170 171 Domain.selfInit(); 172 173 } else { 174 175 SAXParserFactory factory = SAXParserFactory.newInstance(); 176 factory.setNamespaceAware(false); 177 factory.setValidating(false); 178 SAXParser parser = factory.newSAXParser(); 179 180 FileInputStream is = new FileInputStream (configFile); 181 Populate pop = new Populate(); 183 Configuration slideConfiguration = 184 new ConfigurationElement(pop.load(new InputSource (is), 185 parser.getXMLReader())); 186 187 Domain.init(slideConfiguration); 188 189 Domain.start(); 190 191 } 192 193 } catch (Throwable t) { 194 state = STOPPED; 195 notification = new AttributeChangeNotification 196 (this, sequenceNumber++, System.currentTimeMillis(), 197 "Stopped " + NAME, "State", "java.lang.Integer", 198 new Integer (STARTING), new Integer (STOPPED)); 199 sendNotification(notification); 200 } 201 202 state = STARTED; 203 notification = new AttributeChangeNotification 204 (this, sequenceNumber++, System.currentTimeMillis(), 205 "Started " + NAME, "State", "java.lang.Integer", 206 new Integer (STARTING), new Integer (STARTED)); 207 sendNotification(notification); 208 209 } 210 211 212 215 public void stop() { 216 217 Notification notification = null; 218 219 if (state != STARTED) 220 return; 221 222 state = STOPPING; 223 224 notification = new AttributeChangeNotification 225 (this, sequenceNumber++, System.currentTimeMillis(), 226 "Stopping " + NAME, "State", "java.lang.Integer", 227 new Integer (STARTED), new Integer (STOPPING)); 228 sendNotification(notification); 229 230 try { 231 232 Domain.stop(); 233 234 } catch (Throwable t) { 235 236 t.printStackTrace(); 238 239 } 240 241 state = STOPPED; 242 243 notification = new AttributeChangeNotification 244 (this, sequenceNumber++, System.currentTimeMillis(), 245 "Stopped " + NAME, "State", "java.lang.Integer", 246 new Integer (STOPPING), new Integer (STOPPED)); 247 sendNotification(notification); 248 249 } 250 251 252 255 public void destroy() { 256 257 if (getState() != STOPPED) 258 stop(); 259 260 } 261 262 263 270 public NamespaceAccessToken accessNamespace(SecurityToken token, 271 String namespaceName) { 272 return Domain.accessNamespace(token, namespaceName); 273 } 274 275 276 281 public void closeNamespace(NamespaceAccessToken token) { 282 Domain.closeNamespace(token); 283 } 284 285 286 292 public void closeNamespace(SecurityToken token, String namespaceName) { 293 Domain.closeNamespace(token, namespaceName); 294 } 295 296 297 303 public DomainAccessToken accessDomain(SecurityToken token) { 304 return Domain.accessDomain(token); 305 } 306 307 308 } 309 | Popular Tags |