01: /**
02: * Sequoia: Database clustering technology.
03: * Copyright (C) 2005 Emic Networks.
04: * Contact: sequoia@continuent.org
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
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: */package org.continuent.sequoia.controller.recoverylog.events;
21:
22: import java.sql.SQLException;
23:
24: import org.continuent.sequoia.controller.recoverylog.LoggerThread;
25:
26: /**
27: * This class defines a GetNumberOfLogEntriesEvent that finds a number of log
28: * entries available between 2 log id boundaries.
29: *
30: * @author <a href="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet</a>
31: * @version 1.0
32: */
33: public class GetNumberOfLogEntriesEvent implements LogEvent {
34: private long lowerId;
35: private long upperId;
36: private long nbOfLogEntries;
37:
38: /**
39: * Creates a new <code>GetNumberOfLogEntriesEvent</code> object
40: *
41: * @param lowerLogId the lower log id
42: * @param upperLogId the upper log id
43: */
44: public GetNumberOfLogEntriesEvent(long lowerLogId, long upperLogId) {
45: this .lowerId = lowerLogId;
46: this .upperId = upperLogId;
47: }
48:
49: /**
50: * @see org.continuent.sequoia.controller.recoverylog.events.LogEvent#belongToTransaction(long)
51: */
52: public boolean belongToTransaction(long tid) {
53: return false;
54: }
55:
56: /**
57: * @see org.continuent.sequoia.controller.recoverylog.events.LogEvent#execute(org.continuent.sequoia.controller.recoverylog.LoggerThread)
58: */
59: public void execute(LoggerThread loggerThread) {
60: try {
61: nbOfLogEntries = loggerThread.getNumberOfLogEntries(
62: lowerId, upperId);
63: } catch (SQLException e) {
64: loggerThread.invalidateLogStatements();
65: loggerThread.getLogger().error(
66: "Failed to retrieve number of log entries", e);
67: // Push object back in the queue, it needs to be logged again
68: loggerThread.putBackAtHeadOfQueue(this , e);
69: } finally {
70: synchronized (this ) {
71: notify();
72: }
73: }
74: }
75:
76: /**
77: * Returns the nbOfLogEntries value. This value can only be retrieved after
78: * complete execution of the event.
79: *
80: * @return Returns the nbOfLogEntries.
81: */
82: public long getNbOfLogEntries() {
83: return nbOfLogEntries;
84: }
85:
86: /**
87: * @see java.lang.Object#toString()
88: */
89: public String toString() {
90: return "Get number of log entries between " + lowerId + " and "
91: + upperId;
92: }
93:
94: }
|