001: package sisc.modules.hashtable;
002:
003: import sisc.data.*;
004: import java.io.IOException;
005:
006: import sisc.io.ValueWriter;
007: import sisc.ser.Serializer;
008: import sisc.ser.Deserializer;
009: import sisc.util.ExpressionVisitor;
010: import sisc.modules.Threads.Mutex;
011:
012: public class SynchronizedHashtable extends HashtableBase {
013:
014: private HashtableBase delegate;
015:
016: public SynchronizedHashtable() {
017: }
018:
019: public SynchronizedHashtable(HashtableBase delegate) {
020: this .delegate = delegate;
021: }
022:
023: public HashtableBase getDelegate() {
024: return delegate;
025: }
026:
027: public Procedure getEqualsProc() {
028: return delegate.getEqualsProc();
029: }
030:
031: public Procedure getHashProc() {
032: return delegate.getHashProc();
033: }
034:
035: public Value get(Value k) {
036: Mutex m = Mutex.of(this );
037: m.acquire();
038: try {
039: return delegate.get(k);
040: } finally {
041: m.unlock();
042: }
043: }
044:
045: public Value put(Value k, Value v) {
046: Mutex m = Mutex.of(this );
047: m.acquire();
048: try {
049: return delegate.put(k, v);
050: } finally {
051: m.unlock();
052: }
053: }
054:
055: public Value remove(Value k) {
056: Mutex m = Mutex.of(this );
057: m.acquire();
058: try {
059: return delegate.remove(k);
060: } finally {
061: m.unlock();
062: }
063: }
064:
065: public int size() {
066: Mutex m = Mutex.of(this );
067: m.acquire();
068: try {
069: return delegate.size();
070: } finally {
071: m.unlock();
072: }
073: }
074:
075: public void clear() {
076: Mutex m = Mutex.of(this );
077: m.acquire();
078: try {
079: delegate.clear();
080: } finally {
081: m.unlock();
082: }
083: }
084:
085: public void addAList(Pair p) {
086: Mutex m = Mutex.of(this );
087: m.acquire();
088: try {
089: delegate.addAList(p);
090: } finally {
091: m.unlock();
092: }
093: }
094:
095: public Pair toAList() {
096: Mutex m = Mutex.of(this );
097: m.acquire();
098: try {
099: return delegate.toAList();
100: } finally {
101: m.unlock();
102: }
103: }
104:
105: public Pair keys() {
106: Mutex m = Mutex.of(this );
107: m.acquire();
108: try {
109: return delegate.keys();
110: } finally {
111: m.unlock();
112: }
113: }
114:
115: public boolean valueEqual(Value v) {
116: Mutex m = Mutex.of(this );
117: m.acquire();
118: try {
119: return delegate.valueEqual(v);
120: } finally {
121: m.unlock();
122: }
123: }
124:
125: public int valueHashCode() {
126: Mutex m = Mutex.of(this );
127: m.acquire();
128: try {
129: return delegate.valueHashCode();
130: } finally {
131: m.unlock();
132: }
133: }
134:
135: public void serialize(Serializer s) throws IOException {
136: Mutex m = Mutex.of(this );
137: m.acquire();
138: try {
139: s.writeExpression(delegate);
140: } finally {
141: m.unlock();
142: }
143: }
144:
145: public void deserialize(Deserializer s) throws IOException {
146: Mutex m = Mutex.of(this );
147: m.acquire();
148: try {
149: delegate = (HashtableBase) s.readExpression();
150: } finally {
151: m.unlock();
152: }
153: }
154:
155: public boolean visit(ExpressionVisitor v) {
156: Mutex m = Mutex.of(this );
157: m.acquire();
158: try {
159: return delegate.visit(v);
160: } finally {
161: m.unlock();
162: }
163: }
164:
165: public void display(ValueWriter w) throws IOException {
166: Mutex m = Mutex.of(this );
167: m.acquire();
168: try {
169: delegate.display(w);
170: } finally {
171: m.unlock();
172: }
173: }
174:
175: }
176:
177: /*
178: * The contents of this file are subject to the Mozilla Public
179: * License Version 1.1 (the "License"); you may not use this file
180: * except in compliance with the License. You may obtain a copy of
181: * the License at http://www.mozilla.org/MPL/
182: *
183: * Software distributed under the License is distributed on an "AS
184: * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
185: * implied. See the License for the specific language governing
186: * rights and limitations under the License.
187: *
188: * The Original Code is the Second Interpreter of Scheme Code (SISC).
189: *
190: * The Initial Developer of the Original Code is Scott G. Miller.
191: * Portions created by Scott G. Miller are Copyright (C) 2000-2007
192: * Scott G. Miller. All Rights Reserved.
193: *
194: * Contributor(s):
195: * Matthias Radestock
196: *
197: * Alternatively, the contents of this file may be used under the
198: * terms of the GNU General Public License Version 2 or later (the
199: * "GPL"), in which case the provisions of the GPL are applicable
200: * instead of those above. If you wish to allow use of your
201: * version of this file only under the terms of the GPL and not to
202: * allow others to use your version of this file under the MPL,
203: * indicate your decision by deleting the provisions above and
204: * replace them with the notice and other provisions required by
205: * the GPL. If you do not delete the provisions above, a recipient
206: * may use your version of this file under either the MPL or the
207: * GPL.
208: */
|