1 23 24 package com.sun.enterprise.management.model; 25 26 import java.util.*; 27 import javax.management.*; 28 29 import com.sun.enterprise.management.util.J2EEModuleCallBack; 30 31 public abstract class J2EEDeployedObjectMdl extends J2EEEventProviderMOMdl { 32 33 public static int STARTING_STATE = 0; 34 public static int RUNNING_STATE = 1; 35 public static int STOPPING_STATE = 2; 36 public static int STOPPED_STATE = 3; 37 public static int FAILED_STATE = 4; 38 39 private J2EEModuleCallBack module; 40 private int state = this.RUNNING_STATE; 41 private long startTime = System.currentTimeMillis(); 42 43 private long sequenceNo = 0; 44 45 47 private String [] eventTypes = new String [] {"j2ee.state.starting","j2ee.state.running","j2ee.state.stopping","j2ee.state.stopped","j2ee.state.failed"}; 48 49 J2EEDeployedObjectMdl(J2EEModuleCallBack m) { 50 super(m.getName(), m.getServerName(), false, false); 51 module = m; 52 } 53 54 57 public String getdeploymentDescriptor() { 58 return module.getDeploymentDescriptor(); 59 } 60 61 62 public String getserver() { 63 String qs = "name=" + getJ2EEServer() + ",j2eeType=J2EEServer"; 64 Set s = findNames(qs); 65 ObjectName[] sa = (ObjectName[]) s.toArray( 66 new ObjectName[s.size()]); 67 if (sa.length > 0) { 68 return sa[0].toString(); 69 } 70 return "Failed to find the server ObjectName"; 71 } 72 73 public String [] geteventTypes(){ 74 return eventTypes; 75 } 76 77 public int getstate(){ 78 return this.state; 79 } 80 81 public void setstate(int st){ 82 this.state = st; 83 this.stateChanged(eventTypes[st]); 84 } 85 86 public long getstartTime(){ 87 return this.startTime; 88 } 89 public void start() { 90 91 if ((this.state == this.STARTING_STATE) || 92 (this.state == this.RUNNING_STATE) || 93 (this.state == this.STOPPING_STATE)) { 94 throw new RuntimeException ( 95 new Exception ("cannot start because the current state is " + this.state)); 96 } 97 98 try{ 99 this.state = this.STARTING_STATE; 100 this.stateChanged("j2ee.state.starting"); 101 module.start(this); 102 this.state = this.RUNNING_STATE; 103 this.startTime = System.currentTimeMillis(); 104 this.stateChanged("j2ee.state.running"); 105 }catch(Exception ex){ 106 this.state = this.FAILED_STATE; 107 this.stateChanged("j2ee.state.failed"); 108 if(ex instanceof RuntimeException ) 109 throw (RuntimeException )ex; 110 throw new RuntimeException (ex); 111 } 112 } 113 114 public void stop() throws MBeanException { 115 116 if ((this.state == this.STOPPED_STATE) || 117 (this.state == this.STOPPING_STATE)) { 118 throw new RuntimeException ( 119 new Exception ("cannot stop because the current state is " + this.state)); 120 } 121 122 try{ 123 this.state = this.STOPPING_STATE; 124 this.stateChanged("j2ee.state.stopping"); 125 module.stop(this); 126 this.state = this.STOPPED_STATE; 127 this.stateChanged("j2ee.state.stopped"); 128 }catch(Exception ex){ 129 this.state = this.FAILED_STATE; 130 this.stateChanged("j2ee.state.failed"); 131 if(ex instanceof RuntimeException ) 132 throw (RuntimeException )ex; 133 throw new RuntimeException (ex); 134 } 135 } 136 137 public void startRecursive() throws MBeanException { 138 start(); 139 } 140 141 private void stateChanged(String state){ 142 if(this.getobjectName() == null){ 144 System.out.println("WARNING !!!!!!!! Could not send state notification event from the managed object because managed object does not exist bug # 4756051"); 145 return; 146 } 147 javax.management.Notification notification = new javax.management.Notification (state,this.getobjectName(),sequenceNo++); 148 this.sendNotification(notification); 149 } 150 151 154 158 161 } 165 | Popular Tags |