1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| package org.jboss.cache; |
8 |
| |
9 |
| import org.jboss.cache.config.Configuration; |
10 |
| import org.jboss.cache.config.ConfigurationException; |
11 |
| import org.jboss.cache.factories.XmlConfigurationParser; |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| public class DefaultCacheFactory<K, V> implements CacheFactory<K, V> |
20 |
| { |
21 |
| private static CacheFactory singleton = new DefaultCacheFactory(); |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
2840
| public static <K, V> CacheFactory<K, V> getInstance()
|
27 |
| { |
28 |
2840
| return singleton;
|
29 |
| } |
30 |
| |
31 |
10
| public Cache<K, V> createCache() throws ConfigurationException
|
32 |
| { |
33 |
10
| return createCache(true);
|
34 |
| } |
35 |
| |
36 |
1718
| public Cache<K, V> createCache(boolean start) throws ConfigurationException
|
37 |
| { |
38 |
1718
| return createCache(new Configuration(), start);
|
39 |
| } |
40 |
| |
41 |
11
| public Cache<K, V> createCache(String configFileName) throws ConfigurationException
|
42 |
| { |
43 |
11
| return createCache(configFileName, true);
|
44 |
| } |
45 |
| |
46 |
109
| public Cache<K, V> createCache(String configFileName, boolean start) throws ConfigurationException
|
47 |
| { |
48 |
109
| XmlConfigurationParser parser = new XmlConfigurationParser();
|
49 |
109
| Configuration c = parser.parseFile(configFileName);
|
50 |
109
| return createCache(c, start);
|
51 |
| } |
52 |
| |
53 |
| |
54 |
| |
55 |
| |
56 |
| |
57 |
| |
58 |
| |
59 |
| |
60 |
124
| public Cache<K, V> createCache(Configuration configuration) throws ConfigurationException
|
61 |
| { |
62 |
124
| return createCache(configuration, true);
|
63 |
| } |
64 |
| |
65 |
| |
66 |
| |
67 |
| |
68 |
| |
69 |
| |
70 |
| |
71 |
| |
72 |
| |
73 |
2860
| public Cache<K, V> createCache(Configuration configuration, boolean start) throws ConfigurationException
|
74 |
| { |
75 |
2860
| try
|
76 |
| { |
77 |
2860
| CacheImpl<K, V> cache = new CacheImpl<K, V>();
|
78 |
2860
| cache.setConfiguration(configuration);
|
79 |
171
| if (start) cache.start();
|
80 |
2860
| return cache;
|
81 |
| } |
82 |
| catch (ConfigurationException ce) |
83 |
| { |
84 |
0
| throw ce;
|
85 |
| } |
86 |
| catch (RuntimeException re) |
87 |
| { |
88 |
0
| throw re;
|
89 |
| } |
90 |
| catch (Exception e) |
91 |
| { |
92 |
0
| throw new RuntimeException(e);
|
93 |
| } |
94 |
| } |
95 |
| } |