KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > se > storage > raf > log > backup > LogObject


1 /*
2  * Jalisto - JAva LIght STOrage
3  * Copyright (C) 2000-2005 Xcalia http://www.xcalia.com
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Xcalia
20  * 71, rue Desnouettes
21  * 75014 Paris - France
22  * http://www.xcalia.com
23  */

24 package org.objectweb.jalisto.se.storage.raf.log.backup;
25
26 import org.objectweb.jalisto.se.storage.raf.log.synraf.action.LogRecord;
27
28 import java.io.*;
29
30 public abstract class LogObject implements Serializable {
31
32     public abstract void writeTo(DataOutput out) throws IOException;
33
34     public abstract Object JavaDoc internalReadFrom(DataInput in) throws IOException;
35
36     public abstract void undoOn(RandomAccessFile raf) throws IOException;
37
38     public abstract void corrupt(RandomAccessFile raf) throws IOException;
39
40     public static Object JavaDoc readFrom(DataInput in) throws IOException {
41         short classCode = in.readShort();
42         if (classCode == FILELENGTH_SERIAL_CODE) {
43             return logFileLengthModification.internalReadFrom(in);
44         } else if (classCode == RECORD_SERIAL_CODE) {
45             return logRecord.internalReadFrom(in);
46         } else if (classCode == BEGIN_SERIAL_CODE) {
47             return new LogBoundary(true);
48         } else if (classCode == END_SERIAL_CODE) {
49             return new LogBoundary(false);
50         }
51         return null;
52     }
53
54     public static void writeLogRecord(DataOutput out, long address, byte[] before, int newDatasLength)
55             throws IOException {
56         out.writeShort(RECORD_SERIAL_CODE);
57         out.writeLong(address);
58         out.writeInt(newDatasLength);
59         out.writeInt(before.length);
60         out.write(before);
61     }
62
63     public static void writeLogFileLengthModification(DataOutput out, byte[] deletedBytes)
64             throws IOException {
65         out.writeShort(FILELENGTH_SERIAL_CODE);
66         out.writeBoolean(true);
67         out.writeLong(deletedBytes.length);
68         out.write(deletedBytes);
69     }
70
71     public static void writeLogFileLengthModification(DataOutput out, long sizeModification)
72             throws IOException {
73         out.writeShort(FILELENGTH_SERIAL_CODE);
74         out.writeBoolean(false);
75         out.writeLong(sizeModification);
76     }
77
78     public static void writeLogBoundary(DataOutput out, boolean isBegin)
79             throws IOException {
80         if (isBegin) {
81             out.writeShort(BEGIN_SERIAL_CODE);
82         } else {
83             out.writeShort(END_SERIAL_CODE);
84         }
85     }
86
87     private static LogRecord logRecord = new LogRecord();
88     private static LogFileLengthModification logFileLengthModification = new LogFileLengthModification();
89
90
91     public static final short RECORD_SERIAL_CODE = 1;
92     public static final short FILELENGTH_SERIAL_CODE = 2;
93     public static final short BEGIN_SERIAL_CODE = 3;
94     public static final short END_SERIAL_CODE = 4;
95
96     static final long serialVersionUID = -7699636669241161460L;
97 }
98
Popular Tags