KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > core > storage > AbstractCluster


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// This file is
5
// Copyright (C) 2003-@year@ Per Nyfelt. All rights reserved.
6
//
7
package org.ozoneDB.core.storage;
8
9 import org.ozoneDB.core.Env;
10 import org.ozoneDB.core.Permissions;
11 import org.ozoneDB.core.ObjectID;
12 import org.ozoneDB.DxLib.DxMap;
13
14 /**
15  * @author Per Nyfelt
16  */

17 public abstract class AbstractCluster implements Cluster {
18
19     /**
20      * The environment. Will be set by the clusterStore.
21      */

22     public transient Env env;
23
24     public transient AbstractClusterStore clusterStore;
25
26     protected Permissions permissions;
27
28     protected ClusterID clusterID;
29
30     /**
31      * Maps ObjectIDs into StorageObjectContainers.
32      */

33     protected DxMap containers;
34
35     public DxMap containers() {
36         return containers;
37     }
38
39     public Env env() {
40         return env;
41     }
42
43     public void setEnv(Env _env) {
44         this.env = _env;
45     }
46
47     public void setClusterStore(AbstractClusterStore _clusterStore) {
48         this.clusterStore = _clusterStore;
49     }
50
51     public Permissions permissions() {
52         return permissions;
53     }
54
55     public ClusterID clusterID() {
56         return clusterID;
57     }
58
59     public StorageObjectContainer containerForID(ObjectID id) {
60         return (StorageObjectContainer) containers.elementForKey(id);
61     }
62
63     public void removeContainer(StorageObjectContainer container) {
64         if (containers.removeForKey(container.id()) == null) {
65             throw new IllegalStateException JavaDoc("Unable to remove container from cluster.");
66         }
67     }
68
69     public void registerContainer(StorageObjectContainer container) {
70         synchronized (container) {
71             container.setCluster(this);
72             if (containers.addForKey(container, container.id()) == false) {
73                 throw new IllegalStateException JavaDoc("Unable to add id " + container.id() + " to cluster " + clusterID());
74             }
75         }
76     }
77 }
78
Popular Tags