1 package org.apache.commons.jcs3.auxiliary;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Properties;
23
24 import org.apache.commons.jcs3.engine.behavior.IElementSerializer;
25 import org.apache.commons.jcs3.engine.logging.behavior.ICacheEventLogger;
26 import org.apache.commons.jcs3.log.Log;
27 import org.apache.commons.jcs3.log.LogManager;
28 import org.apache.commons.jcs3.utils.config.OptionConverter;
29 import org.apache.commons.jcs3.utils.config.PropertySetter;
30 import org.apache.commons.jcs3.utils.serialization.StandardSerializer;
31
32
33
34
35
36 public class AuxiliaryCacheConfigurator
37 {
38
39 private static final Log log = LogManager.getLog( AuxiliaryCacheConfigurator.class );
40
41
42 public static final String ATTRIBUTE_PREFIX = ".attributes";
43
44
45
46
47
48
49 public static final String CACHE_EVENT_LOGGER_PREFIX = ".cacheeventlogger";
50
51
52
53
54
55
56 public static final String SERIALIZER_PREFIX = ".serializer";
57
58
59
60
61
62
63
64
65 public static ICacheEventLogger parseCacheEventLogger( final Properties props, final String auxPrefix )
66 {
67
68
69 final String eventLoggerClassName = auxPrefix + CACHE_EVENT_LOGGER_PREFIX;
70 final ICacheEventLogger cacheEventLogger = OptionConverter.instantiateByKey( props, eventLoggerClassName, null );
71 if ( cacheEventLogger != null )
72 {
73 final String cacheEventLoggerAttributePrefix = auxPrefix + CACHE_EVENT_LOGGER_PREFIX + ATTRIBUTE_PREFIX;
74 PropertySetter.setProperties( cacheEventLogger, props, cacheEventLoggerAttributePrefix + "." );
75 log.info( "Using custom cache event logger [{0}] for auxiliary [{1}]",
76 cacheEventLogger, auxPrefix );
77 }
78 else
79 {
80 log.info( "No cache event logger defined for auxiliary [{0}]", auxPrefix );
81 }
82 return cacheEventLogger;
83 }
84
85
86
87
88
89
90
91
92 public static IElementSerializer parseElementSerializer( final Properties props, final String auxPrefix )
93 {
94
95
96 final String elementSerializerClassName = auxPrefix + SERIALIZER_PREFIX;
97 IElementSerializer elementSerializer = OptionConverter.instantiateByKey( props, elementSerializerClassName, null );
98 if ( elementSerializer != null )
99 {
100 final String attributePrefix = auxPrefix + SERIALIZER_PREFIX + ATTRIBUTE_PREFIX;
101 PropertySetter.setProperties( elementSerializer, props, attributePrefix + "." );
102 log.info( "Using custom element serializer [{0}] for auxiliary [{1}]",
103 elementSerializer, auxPrefix );
104 }
105 else
106 {
107
108 elementSerializer = new StandardSerializer();
109 log.info( "Using standard serializer [{0}] for auxiliary [{1}]",
110 elementSerializer, auxPrefix );
111 }
112 return elementSerializer;
113 }
114 }