1 29 30 package com.caucho.server.deploy; 31 32 import com.caucho.lifecycle.Lifecycle; 33 import com.caucho.lifecycle.LifecycleListener; 34 import com.caucho.lifecycle.LifecycleNotification; 35 import com.caucho.management.server.AbstractManagedObject; 36 import com.caucho.management.server.DeployControllerMXBean; 37 import com.caucho.util.Alarm; 38 39 import javax.management.ListenerNotFoundException ; 40 import javax.management.MBeanNotificationInfo ; 41 import javax.management.NotificationBroadcasterSupport ; 42 import javax.management.NotificationEmitter ; 43 import javax.management.NotificationFilter ; 44 import javax.management.NotificationListener ; 45 import java.util.Date ; 46 import java.util.logging.Level ; 47 import java.util.logging.Logger ; 48 49 52 abstract public class DeployControllerAdmin<C extends EnvironmentDeployController> 53 extends AbstractManagedObject 54 implements DeployControllerMXBean, 55 NotificationEmitter , 56 LifecycleListener, 57 java.io.Serializable 58 { 59 private transient final C _controller; 60 61 private transient final NotificationBroadcasterSupport _broadcaster; 63 64 private long _sequence = 0; 65 66 public DeployControllerAdmin(C controller) 67 { 68 _controller = controller; 69 _broadcaster = new NotificationBroadcasterSupport (); 70 controller.addLifecycleListener(this); 71 } 72 73 76 protected C getController() 77 { 78 return _controller; 79 } 80 81 protected void register() 82 { 83 registerSelf(); 84 } 85 86 protected void unregister() 87 { 88 unregisterSelf(); 89 } 90 91 public String getName() 92 { 93 return _controller.getMBeanId(); 94 } 95 96 public String getStartupMode() 97 { 98 return _controller.getStartupMode(); 99 } 100 101 public String getRedeployMode() 102 { 103 return _controller.getRedeployMode(); 104 } 105 106 public long getRedeployCheckInterval() 107 { 108 return _controller.getRedeployCheckInterval(); 109 } 110 111 public String getState() 112 { 113 return getController().getState(); 114 } 115 116 public Date getStartTime() 117 { 118 return new Date (getController().getStartTime()); 119 } 120 121 124 public void start() 125 throws Exception 126 { 127 getController().start(); 128 } 129 130 public void stop() 131 throws Exception 132 { 133 getController().stop(); 134 } 135 136 public void restart() 137 throws Exception 138 { 139 getController().stop(); 140 getController().start(); 141 } 142 143 public void update() 144 throws Exception 145 { 146 getController().update(); 147 } 148 149 152 public String getRootDirectory() 153 { 154 return _controller.getRootDirectory().getNativePath(); 155 } 156 157 public void addNotificationListener(NotificationListener listener, 158 NotificationFilter filter, 159 Object handback) 160 throws IllegalArgumentException 161 { 162 _broadcaster.addNotificationListener(listener, filter, handback); 163 } 164 165 public void removeNotificationListener(NotificationListener listener) 166 throws ListenerNotFoundException 167 { 168 _broadcaster.removeNotificationListener(listener); 169 } 170 171 public void removeNotificationListener(NotificationListener listener, 172 NotificationFilter filter, 173 Object handback) 174 throws ListenerNotFoundException 175 { 176 _broadcaster.removeNotificationListener(listener, filter, handback); 177 } 178 179 public MBeanNotificationInfo [] getNotificationInfo() 180 { 181 MBeanNotificationInfo status = new MBeanNotificationInfo (new String [] { "jmx.attribute.change" }, "status", "status attribute changes"); 183 184 return new MBeanNotificationInfo [] { status }; 185 } 186 187 synchronized public void lifecycleEvent(int oldState, int newState) 188 { 189 Logger log = _controller.getLog(); 190 191 long timestamp = Alarm.getCurrentTime(); 192 193 String oldValue = Lifecycle.getStateName(oldState); 194 String newValue = Lifecycle.getStateName(newState); 195 String message = newValue; 196 197 if (log.isLoggable(Level.FINEST)) 198 log.log(Level.FINEST, toString() + " lifecycleEvent `" + newValue + "'"); 199 200 if (newState == Lifecycle.IS_ACTIVE) { 201 LifecycleNotification notif; 202 notif = new LifecycleNotification(LifecycleNotification.AFTER_START, 203 this, _sequence++, timestamp, 204 toString () + " started"); 205 206 _broadcaster.sendNotification(notif); 207 } 208 209 if (oldState == Lifecycle.IS_ACTIVE) { 210 LifecycleNotification notif; 211 notif = new LifecycleNotification(LifecycleNotification.BEFORE_STOP, 212 this, _sequence++, timestamp, 213 toString() + " stopping"); 214 215 _broadcaster.sendNotification(notif); 216 } 217 218 225 } 226 227 public String toString() 228 { 229 String name = getClass().getName(); 230 231 int i = name.lastIndexOf('.') + 1; 232 233 if (i > 0 && i < name.length()) 234 name = name.substring(i); 235 236 return name + "[" + getObjectName() + "]"; 237 } 238 } 239 | Popular Tags |