1 22 package org.jboss.tm.recovery; 23 24 import java.util.ArrayList ; 25 26 import javax.management.Notification ; 27 import javax.management.NotificationFilter ; 28 import javax.management.NotificationListener ; 29 import javax.management.ObjectName ; 30 31 import org.jboss.system.ServiceMBeanSupport; 32 import org.jboss.system.server.Server; 33 import org.jboss.system.server.ServerImplMBean; 34 import org.jboss.tm.TxManager; 35 import org.jboss.tm.XidFactoryMBean; 36 37 43 public class RecoveryManagerService 44 extends ServiceMBeanSupport 45 implements NotificationListener , 46 RecoveryManagerServiceMBean 47 { 48 private ObjectName xidFactory; 49 private ObjectName txManager; 50 private RecoveryLogger recoveryLogger; 51 private XidFactoryMBean xidFactoryObj; 52 private TxManager txManagerObj; 53 private ArrayList xaResourceManagers = new ArrayList (); 54 55 private RecoveryManager recoveryManager; 57 58 60 63 protected void startService() throws Exception 64 { 65 super.startService(); 66 xidFactoryObj = 67 (XidFactoryMBean) getServer().getAttribute(xidFactory, "Instance"); 68 txManagerObj = 69 (TxManager) getServer().getAttribute(txManager, "TransactionManager"); 70 txManagerObj.setRecoveryLogger(recoveryLogger); 71 72 NotificationFilter filter = new NotificationFilter () 73 { 74 private static final long serialVersionUID = 1L; 75 76 public boolean isNotificationEnabled(Notification n) 77 { 78 return n.getType().equals(Server.START_NOTIFICATION_TYPE); 79 } 80 }; 81 82 this.getServer().addNotificationListener(ServerImplMBean.OBJECT_NAME, 83 this, 84 filter, 85 null); 86 } 87 88 91 protected void stopService() throws Exception 92 { 93 super.stopService(); 94 } 95 96 98 102 public void handleNotification(Notification notification, Object handback) 103 { 104 log.info("RECEIVED STARTUP NOTIFICATION"); 105 if ( recoveryLogger != null) 106 { 107 recover(); 108 } 109 txManagerObj.clearRecoveryPending(); 110 } 111 112 114 117 public ObjectName getXidFactory() 118 { 119 return xidFactory; 120 } 121 122 126 public void setXidFactory(ObjectName xidFactory) 127 { 128 this.xidFactory = xidFactory; 129 } 130 131 134 public ObjectName getTransactionManager() 135 { 136 return txManager; 137 } 138 139 143 public void setTransactionManager(ObjectName txManager) 144 { 145 this.txManager = txManager; 146 } 147 148 152 public void setRecoveryLogger(RecoveryLoggerInstance recoveryLogger) 153 { 154 this.recoveryLogger = recoveryLogger.getInstance(); 155 } 156 157 160 public void recover() 161 { 162 try 163 { 164 recoveryManager = 165 new RecoveryManager(xidFactoryObj, txManagerObj, recoveryLogger); 166 recoveryManager.recover(xaResourceManagers); 167 } 168 catch (Exception e) 169 { 170 log.error("Unable to recover", e); 171 } 172 } 173 174 178 public void registerRecoverable(Recoverable recoverable) 179 { 180 xaResourceManagers.add(recoverable); 181 } 182 183 } 184 | Popular Tags |