KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > mbeans > TransactionsRecoveryMBean


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.admin.mbeans;
25
26 import com.sun.enterprise.admin.event.AdminEventResult;
27 import com.sun.enterprise.admin.event.AdminEvent;
28 import com.sun.enterprise.admin.event.AdminEventMulticaster;
29 import com.sun.enterprise.admin.event.tx.TransactionsRecoveryEvent;
30
31 import com.sun.enterprise.server.ApplicationServer;
32
33 import com.sun.enterprise.admin.config.BaseConfigMBean;
34 import com.sun.enterprise.admin.config.MBeanConfigException;
35
36 import com.sun.enterprise.util.i18n.StringManager;
37 import java.util.Collection JavaDoc;
38 import java.util.Iterator JavaDoc;
39 import java.util.HashMap JavaDoc;
40 import java.util.logging.Level JavaDoc;
41
42 /**
43  * object name for this mbean: <domainName>:type=transactions-recovery,category=config
44  * TransactionsRecoveryMBean sends request to transactions recovery
45  *
46  * @author alexkrav
47  *
48  */

49 public class TransactionsRecoveryMBean extends BaseConfigMBean
50 {
51    
52     public TransactionsRecoveryMBean()
53     {
54         super();
55     }
56     
57     ///////////////////////////////////////////////////////////////////////////
58
/**
59      * Recovers transaction for given server instance
60      *
61      * @throws MBeanConfigException if not SUCCESS result of event handling
62      *
63      */

64     public void recoverTransactions() throws MBeanConfigException
65     {
66         
67         fine("TransactionsRecoverytMBean.recoveryTransactions for server");
68      
69         sendTransactionsRecoveryEvent(getServerName(), getServerName(), null);
70         
71     }
72     
73     ///////////////////////////////////////////////////////////////////////////
74

75  
76    private void sendTransactionsRecoveryEvent(String JavaDoc destinationServer, String JavaDoc serverToRecover,
77                     String JavaDoc transactionLogDir) throws MBeanConfigException
78    {
79         AdminEvent event = new TransactionsRecoveryEvent(getServerName(),
80                     serverToRecover,
81                     transactionLogDir);
82         event.setTargetDestination(destinationServer);
83         AdminEventResult res = forwardEvent(event);
84         if(!AdminEventResult.SUCCESS.equals(res.getResultCode()))
85         {
86             Throwable JavaDoc exc = null;
87             exc = res.getFirstThrowable();
88             if (exc != null) {
89                 throw new MBeanConfigException(_strMgr.getString("tx.exceptionInTargetServer",
90                     exc.getMessage()));
91             }
92             throw new MBeanConfigException(_strMgr.getString("tx.notSuccessInSendReturn",
93                     res.getResultCode()));
94         }
95     }
96       
97
98      private AdminEventResult forwardEvent(AdminEvent e) {
99         AdminEventResult result = null;
100         result = AdminEventMulticaster.multicastEvent(e);
101         return result;
102     }
103     
104      private void fine(String JavaDoc s) {
105          _sLogger.log(Level.FINE, s);
106      }
107
108     private String JavaDoc getServerName()
109     {
110         return ApplicationServer.getServerContext().getInstanceName();
111     }
112      
113     ///////////////////////////////////////////////////////////////////////////
114

115     private static final StringManager _strMgr =
116                 StringManager.getManager(EJBTimerManagementMBean.class);
117     ///////////////////////////////////////////////////////////////////////////
118

119 }
120
Popular Tags