KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > presumo > jms > persistence > LogFileEntry


1 /**
2  * This file is part of Presumo.
3  *
4  * Presumo is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * Presumo is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Presumo; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Copyright (c) 2001 Rob Cauble
19  */

20 package com.presumo.jms.persistence;
21
22 import com.presumo.jms.resources.Resources;
23 import com.presumo.util.log.Logger;
24 import com.presumo.util.log.LoggerFactory;
25
26 import java.io.DataInput JavaDoc;
27 import java.io.DataOutput JavaDoc;
28 import java.io.EOFException JavaDoc;
29 import java.io.IOException JavaDoc;
30
31 import java.util.HashSet JavaDoc;
32 import java.util.LinkedList JavaDoc;
33
34 /**
35  * Abstract base class for all possible entries that might go into a
36  * log file.
37  */

38 abstract class LogFileEntry
39 {
40   abstract boolean writeAndProcess(LinkedList JavaDoc mainQueue,
41                                     LinkedList JavaDoc pendingDelete,
42                                     HashSet JavaDoc persistentDelete,
43                                     DataOutput JavaDoc out) throws IOException JavaDoc;
44
45   abstract void read(DataInput JavaDoc in) throws IOException JavaDoc, EOFException JavaDoc;
46
47
48   abstract void restore(LinkedList JavaDoc mainQueue,
49                         LinkedList JavaDoc pendingDelete,
50                         HashSet JavaDoc persistentDelete);
51
52     
53   static final int INSERT = 0;
54   static final int DELETE = 1;
55   static final int GET_NEXT = 2;
56
57   /**
58    * Method to decode a LogFileEntry stored to disk
59    */

60   static LogFileEntry deserialize(DataInput JavaDoc in)
61           throws IOException JavaDoc, EOFException JavaDoc
62   {
63     try {
64       logger.entry("deserialize");
65             
66       int type = in.readInt();
67       LogFileEntry result = null;
68       switch (type) {
69       case INSERT:
70         result = new LogFileEntryInsert();
71         break;
72       case DELETE:
73         result = new LogFileEntryDelete();
74         break;
75       case GET_NEXT:
76         result = new LogFileEntryGetNext();
77         break;
78       default:
79         IllegalArgumentException JavaDoc temp = new IllegalArgumentException JavaDoc("Unknown log entry type: "+type);
80         logger.exception(temp);
81         throw temp;
82       }
83       result.read(in);
84       return result;
85     }
86     finally {
87       logger.exit("deserialize");
88     }
89   }
90   
91   ////////////////////////////// Misc stuff ////////////////////////////////
92
private static Logger logger =
93     LoggerFactory.getLogger(LogFileEntry.class, Resources.getBundle());
94   ///////////////////////////////////////////////////////////////////////////
95
}
96
97
Popular Tags