7b6e662f9ee40b90888a04d9b3958d305d9cdea3
[IRC.git] / Robust / Transactions / TransactionalIO / src / TransactionalIO / core / GlobalINodeState.java
1 /*
2  * Adapter.java
3  *
4  * Copyright 2006 Sun Microsystems, Inc., 4150 Network Circle, Santa
5  * Clara, California 95054, U.S.A.  All rights reserved.  
6  * 
7  * Sun Microsystems, Inc. has intellectual property rights relating to
8  * technology embodied in the product that is described in this
9  * document.  In particular, and without limitation, these
10  * intellectual property rights may include one or more of the
11  * U.S. patents listed at http://www.sun.com/patents and one or more
12  * additional patents or pending patent applications in the U.S. and
13  * in other countries.
14  * 
15  * U.S. Government Rights - Commercial software.
16  * Government users are subject to the Sun Microsystems, Inc. standard
17  * license agreement and applicable provisions of the FAR and its
18  * supplements.  Use is subject to license terms.  Sun, Sun
19  * Microsystems, the Sun logo and Java are trademarks or registered
20  * trademarks of Sun Microsystems, Inc. in the U.S. and other
21  * countries.  
22  * 
23  * This product is covered and controlled by U.S. Export Control laws
24  * and may be subject to the export or import laws in other countries.
25  * Nuclear, missile, chemical biological weapons or nuclear maritime
26  * end uses or end users, whether direct or indirect, are strictly
27  * prohibited.  Export or reexport to countries subject to
28  * U.S. embargo or to entities identified on U.S. export exclusion
29  * lists, including, but not limited to, the denied persons and
30  * specially designated nationals lists is strictly prohibited.
31  */
32 package TransactionalIO.core;
33
34 import java.util.Collections;
35 import java.util.HashMap;
36 import java.util.Map;
37 import java.util.concurrent.ConcurrentHashMap;
38 import java.util.concurrent.atomic.AtomicLong;
39
40 /**
41  * Obstruction-free atomic object implementation. Visible reads.
42  * Support snapshots and early release.
43  * @author Navid Farri
44  */
45 public class GlobalINodeState {
46
47    // public HashMap<Integer,BlockLock> lockmap;  
48     public HashMap lockmap;
49     private ConcurrentHashMap conlockmap = new ConcurrentHashMap();
50     
51     public GlobalLength commitedfilesize;
52     public int seqNum = 0;
53     private INode inode;
54
55     public GlobalINodeState() {
56     }
57     
58     
59     
60     
61     protected GlobalINodeState(INode inode, long length) {
62         lockmap = new HashMap();
63        
64         commitedfilesize = new GlobalLength(length);
65      //   System.out.println(length);
66         this.inode = inode;
67     }
68     
69     
70
71
72     public GlobalLength getCommitedfilesize() {
73         return commitedfilesize;
74     }
75
76     public void setCommitedfilesize(GlobalLength commitedfilesize) {
77         this.commitedfilesize = commitedfilesize;
78     }
79     
80
81      public BlockDataStructure getBlockDataStructure(Integer blocknumber) {
82      /*       synchronized (lockmap) {
83                 if (lockmap.containsKey(blocknumber)) {
84                     return ((BlockDataStructure) (lockmap.get(blocknumber)));
85                 } else {
86                     BlockDataStructure tmp = new BlockDataStructure(inode, blocknumber);
87                     lockmap.put(blocknumber, tmp);
88                     return tmp;
89                }    
90            }
91      }*/   
92     BlockDataStructure rec = (BlockDataStructure)conlockmap.get(blocknumber);
93     if (rec == null) {
94         // record does not yet exist
95         BlockDataStructure newRec = new BlockDataStructure(inode, blocknumber);
96         rec = (BlockDataStructure)conlockmap.putIfAbsent(blocknumber, newRec);
97         if (rec == null) {
98             // put succeeded, use new value
99             rec = newRec;
100         }
101     }
102     return rec;
103 }
104          
105             
106      
107
108
109 }
110