KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > continuent > sequoia > controller > recoverylog > events > LogRequestCompletionEvent


1 /**
2  * Sequoia: Database clustering technology.
3  * Copyright (C) 2005 Emic Networks.
4  * Contact: sequoia@continuent.org
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * Initial developer(s): Emmanuel Cecchet.
19  * Contributor(s): ______________________.
20  */

21
22 package org.continuent.sequoia.controller.recoverylog.events;
23
24 import java.sql.PreparedStatement JavaDoc;
25 import java.sql.SQLException JavaDoc;
26
27 import org.continuent.sequoia.common.i18n.Translate;
28 import org.continuent.sequoia.common.log.Trace;
29 import org.continuent.sequoia.controller.recoverylog.LoggerThread;
30
31 /**
32  * This class defines a LogRequestEvent to log a request log entry.
33  *
34  * @author <a HREF="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet</a>
35  * @version 1.0
36  */

37 public class LogRequestCompletionEvent implements LogEvent
38 {
39   private long logId;
40   private boolean success;
41   private long execTime;
42   private int updateCount;
43   private long completionLogId;
44
45   /**
46    * Creates a new <code>LogRequestEvent</code> object
47    *
48    * @param logId the recovery log id entry to update
49    * @param success true if the execution was successful
50    * @param updateCount the number of updated rows returned by executeUpdate()
51    * if applicable
52    * @param execTime request execution time in ms
53    * @param completionLogId the last logId assigned before this event
54    * was created
55    */

56   public LogRequestCompletionEvent(long logId, boolean success,
57       int updateCount, long execTime, long completionLogId)
58   {
59     this.logId = logId;
60     this.success = success;
61     this.execTime = execTime;
62     this.updateCount = updateCount;
63     this.completionLogId = completionLogId;
64   }
65
66   /**
67    * @see org.continuent.sequoia.controller.recoverylog.events.LogEvent#belongToTransaction(long)
68    */

69   public boolean belongToTransaction(long tid)
70   {
71     return false;
72   }
73
74   /**
75    * @see org.continuent.sequoia.controller.recoverylog.events.LogEvent#execute(org.continuent.sequoia.controller.recoverylog.LoggerThread)
76    */

77   public void execute(LoggerThread loggerThread)
78   {
79     Trace logger = loggerThread.getLogger();
80     try
81     {
82       if (logger.isDebugEnabled())
83         logger.debug(Translate
84             .get("recovery.jdbc.loggerthread.log.info", logId));
85
86       PreparedStatement JavaDoc pstmt = loggerThread.getUpdatePreparedStatement();
87       if (success)
88         pstmt.setString(1, LogEntry.SUCCESS);
89       else
90         pstmt.setString(1, LogEntry.FAILED);
91       pstmt.setInt(2, updateCount);
92       pstmt.setLong(3, execTime);
93       pstmt.setLong(4, completionLogId);
94       pstmt.setLong(5, logId);
95       if (logger.isDebugEnabled())
96         logger.debug(pstmt.toString());
97       int updatedRows = pstmt.executeUpdate();
98       if (updatedRows != 1)
99         logger
100             .error("Recovery log was unable to update request completion status: "
101                 + pstmt.toString());
102     }
103     catch (SQLException JavaDoc e)
104     {
105       loggerThread.invalidateLogStatements();
106       logger.error(Translate.get(
107           "recovery.jdbc.loggerthread.log.update.failed", new String JavaDoc[]{
108               Long.toString(logId), Boolean.toString(success)}), e);
109       // Push object back in the queue, it needs to be logged again
110
loggerThread.putBackAtHeadOfQueue(this, e);
111     }
112   }
113
114   /**
115    * @see java.lang.Object#toString()
116    */

117   public String JavaDoc toString()
118   {
119     return "LogRequestCompletionEvent id " + logId + ", success=" + success;
120   }
121
122 }
123
Popular Tags