001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2005 Emic Networks.
004: * Contact: sequoia@continuent.org
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: * Initial developer(s): Emmanuel Cecchet.
019: * Contributor(s): ______________________.
020: */package org.continuent.sequoia.controller.recoverylog.events;
021:
022: import java.sql.PreparedStatement;
023: import java.sql.SQLException;
024:
025: import org.continuent.sequoia.common.i18n.Translate;
026: import org.continuent.sequoia.common.log.Trace;
027: import org.continuent.sequoia.controller.recoverylog.LoggerThread;
028:
029: /**
030: * This class defines a LogRequestEvent to log a request log entry.
031: *
032: * @author <a href="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet</a>
033: * @version 1.0
034: */
035: public class LogRequestCompletionEvent implements LogEvent {
036: private long logId;
037: private boolean success;
038: private long execTime;
039: private int updateCount;
040:
041: /**
042: * Creates a new <code>LogRequestEvent</code> object
043: *
044: * @param logId the recovery log id entry to update
045: * @param success true if the execution was successful
046: * @param updateCount the number of updated rows returned by executeUpdate()
047: * if applicable
048: * @param execTime request execution time in ms
049: */
050: public LogRequestCompletionEvent(long logId, boolean success,
051: int updateCount, long execTime) {
052: this .logId = logId;
053: this .success = success;
054: this .execTime = execTime;
055: this .updateCount = updateCount;
056: }
057:
058: /**
059: * @see org.continuent.sequoia.controller.recoverylog.events.LogEvent#belongToTransaction(long)
060: */
061: public boolean belongToTransaction(long tid) {
062: return false;
063: }
064:
065: /**
066: * @see org.continuent.sequoia.controller.recoverylog.events.LogEvent#execute(org.continuent.sequoia.controller.recoverylog.LoggerThread)
067: */
068: public void execute(LoggerThread loggerThread) {
069: Trace logger = loggerThread.getLogger();
070: try {
071: if (logger.isDebugEnabled())
072: logger.debug(Translate.get(
073: "recovery.jdbc.loggerthread.log.info", logId));
074:
075: PreparedStatement pstmt = loggerThread
076: .getUpdatePreparedStatement();
077: if (success)
078: pstmt.setString(1, LogEntry.SUCCESS);
079: else
080: pstmt.setString(1, LogEntry.FAILED);
081: pstmt.setInt(2, updateCount);
082: pstmt.setLong(3, execTime);
083: pstmt.setLong(4, logId);
084: if (logger.isDebugEnabled())
085: logger.debug(pstmt.toString());
086: int updatedRows = pstmt.executeUpdate();
087: if (updatedRows != 1)
088: logger
089: .error("Recovery log was unable to update request completion status: "
090: + pstmt.toString());
091: } catch (SQLException e) {
092: loggerThread.invalidateLogStatements();
093: logger.error(Translate.get(
094: "recovery.jdbc.loggerthread.log.update.failed",
095: new String[] { Long.toString(logId),
096: Boolean.toString(success) }), e);
097: // Push object back in the queue, it needs to be logged again
098: loggerThread.putBackAtHeadOfQueue(this , e);
099: }
100: }
101:
102: /**
103: * @see java.lang.Object#toString()
104: */
105: public String toString() {
106: return "LogRequestCompletionEvent id " + logId + ", success="
107: + success;
108: }
109:
110: }
|