KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jalisto > se > impl > server > page > info > InMemoryPageInfo


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.impl.server.page.info;
25
26 import org.objectweb.jalisto.se.impl.InFileAddress;
27
28 import java.util.ArrayList JavaDoc;
29
30 public class InMemoryPageInfo {
31
32     protected InMemoryPageInfo(PageInfo pageInfo) {
33         ifa = pageInfo.getPageIfa();
34         freeSpaceSize = pageInfo.getEmptySpace();
35         transactionalImage = -1;
36         pid = pageInfo.getPid();
37     }
38
39     public void getAFreeSpace(Object JavaDoc sessionId) {
40         freeSpaceSize--;
41     }
42
43     public void freeASpace(Object JavaDoc sessionId) {
44         freeSpaceSize++;
45     }
46
47     public int getFreeSpaceSize() {
48         return freeSpaceSize;
49     }
50
51     public InFileAddress getInstancePageIfa() {
52         return ifa;
53     }
54
55     public Object JavaDoc getPid() {
56         return pid;
57     }
58
59     public String JavaDoc toString() {
60         return "IMPO:" + freeSpaceSize + "@" + ifa.getAddress();
61     }
62
63     public void begin(Object JavaDoc sessionId) {
64         transactionalImage = freeSpaceSize;
65     }
66
67     public boolean rollback(Object JavaDoc sessionId) {
68         if (transactionalImage < 0) {
69             return false;
70         }
71         freeSpaceSize = transactionalImage;
72         return true;
73     }
74
75     private InFileAddress ifa;
76     protected int freeSpaceSize;
77     private int transactionalImage;
78     private Object JavaDoc pid;
79
80
81     public static InMemoryPageInfo createNewInstance(ArrayList JavaDoc sessionIds, boolean isMonoImplementation,
82                                                      PageInfo pageInfo) {
83         if (isMonoImplementation) {
84             return new InMemoryPageInfo(pageInfo);
85         } else {
86             return new InMemoryPageInfoMulti(sessionIds, pageInfo);
87         }
88     }
89 }
90
Popular Tags