KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > config > ConfigLockLevel


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.object.config;
5
6 import com.tc.object.lockmanager.api.LockLevel;
7
8 import java.util.Collections JavaDoc;
9 import java.util.HashMap JavaDoc;
10 import java.util.Map JavaDoc;
11
12 public class ConfigLockLevel {
13   static final String JavaDoc WRITE_NAME = "write";
14   static final String JavaDoc READ_NAME = "read";
15   static final String JavaDoc CONCURRENT_NAME = "concurrent";
16   static final String JavaDoc SYNCHRONOUS_WRITE_NAME = "synchronous-write";
17
18   public static final ConfigLockLevel WRITE = new ConfigLockLevel(WRITE_NAME, LockLevel.WRITE);
19   public static final ConfigLockLevel READ = new ConfigLockLevel(READ_NAME, LockLevel.READ);
20   public static final ConfigLockLevel CONCURRENT = new ConfigLockLevel(CONCURRENT_NAME, LockLevel.CONCURRENT);
21   public static final ConfigLockLevel SYNCHRONOUS_WRITE = new ConfigLockLevel(SYNCHRONOUS_WRITE_NAME,
22                                                                                    LockLevel.SYNCHRONOUS_WRITE);
23
24   private static final Map JavaDoc locksByLevel;
25
26   static {
27     HashMap JavaDoc tmp = new HashMap JavaDoc();
28
29     tmp.put(WRITE_NAME, WRITE);
30     tmp.put(READ_NAME, READ);
31     tmp.put(CONCURRENT_NAME, CONCURRENT);
32     tmp.put(SYNCHRONOUS_WRITE_NAME, SYNCHRONOUS_WRITE);
33
34     locksByLevel = Collections.unmodifiableMap(tmp);
35   }
36
37   private final String JavaDoc lockLevelName;
38   private final int level;
39
40   private ConfigLockLevel(String JavaDoc lockTypeName, int type) {
41     this.lockLevelName = lockTypeName;
42     this.level = type;
43   }
44
45   public int getLevel() {
46     return level;
47   }
48
49   public String JavaDoc toString() {
50     return lockLevelName;
51   }
52
53   public static ConfigLockLevel lockLevelByName(String JavaDoc typeName) {
54     ConfigLockLevel rv = null;
55     if (typeName != null) rv = (ConfigLockLevel) locksByLevel.get(typeName);
56     return rv;
57   }
58 }
59
Popular Tags