KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tm > recovery > RecoveryManagerService


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.tm.recovery;
23
24 import java.util.ArrayList JavaDoc;
25
26 import javax.management.Notification JavaDoc;
27 import javax.management.NotificationFilter JavaDoc;
28 import javax.management.NotificationListener JavaDoc;
29 import javax.management.ObjectName JavaDoc;
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 /**
38  * Service MBean that manages crash recovery.
39  *
40  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
41  * @version $Revision: 37459 $
42  */

43 public class RecoveryManagerService
44       extends ServiceMBeanSupport
45       implements NotificationListener JavaDoc,
46                  RecoveryManagerServiceMBean
47 {
48    private ObjectName JavaDoc xidFactory;
49    private ObjectName JavaDoc txManager;
50    private RecoveryLogger recoveryLogger;
51    private XidFactoryMBean xidFactoryObj;
52    private TxManager txManagerObj;
53    private ArrayList JavaDoc xaResourceManagers = new ArrayList JavaDoc();
54
55    // TODO make pluggable
56
private RecoveryManager recoveryManager;
57
58    // ServiceMBeanSupport overrides ---------------------------------
59

60    /**
61     * @see org.jboss.system.ServiceMBeanSupport#startService()
62     */

63    protected void startService() throws Exception JavaDoc
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 JavaDoc filter = new NotificationFilter JavaDoc()
73       {
74          private static final long serialVersionUID = 1L;
75
76          public boolean isNotificationEnabled(Notification JavaDoc 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    /**
89     * @see org.jboss.system.ServiceMBeanSupport#stopService()
90     */

91    protected void stopService() throws Exception JavaDoc
92    {
93       super.stopService();
94    }
95
96    // NotificationListener implementation ---------------------------
97

98    /**
99     * @see javax.management.NotificationListener#handleNotification(
100     * javax.management.Notification, java.lang.Object)
101     */

102    public void handleNotification(Notification JavaDoc notification, Object JavaDoc handback)
103    {
104       log.info("RECEIVED STARTUP NOTIFICATION");
105       if (/* resources.size() > 0 && */ recoveryLogger != null)
106       {
107          recover();
108       }
109       txManagerObj.clearRecoveryPending();
110    }
111
112    // RecoveryManagerServiceMBean implementation --------------------
113

114    /**
115     * @see org.jboss.tm.recovery.RecoveryManagerServiceMBean#getXidFactory()
116     */

117    public ObjectName JavaDoc getXidFactory()
118    {
119       return xidFactory;
120    }
121
122    /**
123     * @see org.jboss.tm.recovery.RecoveryManagerServiceMBean#setXidFactory(
124     * javax.management.ObjectName)
125     */

126    public void setXidFactory(ObjectName JavaDoc xidFactory)
127    {
128       this.xidFactory = xidFactory;
129    }
130    
131    /**
132     * @see org.jboss.tm.recovery.RecoveryManagerServiceMBean#getTransactionManager()
133     */

134    public ObjectName JavaDoc getTransactionManager()
135    {
136       return txManager;
137    }
138
139    /**
140     * @see org.jboss.tm.recovery.RecoveryManagerServiceMBean#setTransactionManager(
141     * javax.management.ObjectName)
142     */

143    public void setTransactionManager(ObjectName JavaDoc txManager)
144    {
145       this.txManager = txManager;
146    }
147
148    /**
149     * @see org.jboss.tm.recovery.RecoveryManagerServiceMBean#setRecoveryLogger(
150     * org.jboss.tm.recovery.RecoveryLoggerInstance)
151     */

152    public void setRecoveryLogger(RecoveryLoggerInstance recoveryLogger)
153    {
154       this.recoveryLogger = recoveryLogger.getInstance();
155    }
156
157    /**
158     * @see org.jboss.tm.recovery.RecoveryManagerServiceMBean#recover()
159     */

160    public void recover()
161    {
162       try
163       {
164          recoveryManager =
165             new RecoveryManager(xidFactoryObj, txManagerObj, recoveryLogger);
166          recoveryManager.recover(xaResourceManagers);
167       }
168       catch (Exception JavaDoc e)
169       {
170          log.error("Unable to recover", e);
171       }
172    }
173
174    /**
175     * @see org.jboss.tm.recovery.RecoveryManagerServiceMBean#registerRecoverable(
176     * org.jboss.tm.recovery.Recoverable)
177     */

178    public void registerRecoverable(Recoverable recoverable)
179    {
180       xaResourceManagers.add(recoverable);
181    }
182
183 }
184
Popular Tags