KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > common > domains > registry > PersistentStore


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.admin.common.domains.registry;
25
26 import java.io.IOException JavaDoc;
27
28
29 import java.lang.ClassNotFoundException JavaDoc;
30
31
32 import java.io.File JavaDoc;
33
34
35 class PersistentStore implements LockingStore
36 {
37
38   PersistentStore(){
39     state = new Unlocked(this);
40   }
41   
42   public long lastModified(){
43     return getStore().lastModified();
44   }
45
46   public Object JavaDoc readObject() throws IOException JavaDoc, TimeoutException, ClassNotFoundException JavaDoc{
47     return state.readObject();
48   }
49
50   public void writeObject(Object JavaDoc o) throws IOException JavaDoc, TimeoutException, IllegalStateException JavaDoc{
51     state.writeObject(o);
52   }
53
54   public void lock() throws IOException JavaDoc, TimeoutException{
55     state.lock();
56   }
57
58   public void unlock(){
59     state.unlock();
60   }
61
62   void setState(LockingStore s){
63     state = s;
64   }
65
66   LockingStore getState(){
67     return state;
68   }
69
70   protected void finalize(){
71     state.unlock();
72   }
73   
74   File JavaDoc getLock() {
75     return LOCK;
76   }
77   
78   File JavaDoc getStore(){
79     return STORE;
80   }
81       // Location of the underlying storage
82
private static File JavaDoc STORE;
83   private static File JavaDoc LOCK;
84
85   {
86     STORE = new File JavaDoc(System.getProperty(CONFIG_ROOT), STORE_NAME);
87     LOCK = new File JavaDoc(System.getProperty(CONFIG_ROOT), LOCK_NAME);
88   }
89   
90   private LockingStore state;
91
92   public static final String JavaDoc CONFIG_ROOT = "com.sun.aas.configRoot";
93   public static final String JavaDoc STORE_NAME = "domains.bin";
94   public static final String JavaDoc LOCK_NAME = "domains.lck";
95   
96 }
97
98     
99
Popular Tags