KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > jdo > cache > CacheCfMod


1 /*
2  * Created on Jul 29, 2005
3  */

4 package com.nightlabs.ipanema.jdo.cache;
5
6 import org.apache.log4j.Logger;
7
8 import com.nightlabs.config.ConfigModule;
9 import com.nightlabs.config.InitException;
10
11 /**
12  * @author Marco Schulze - marco at nightlabs dot de
13  */

14 public class CacheCfMod extends ConfigModule
15 {
16     public static final Logger LOGGER = Logger.getLogger(CacheCfMod.class);
17
18     private String JavaDoc documentation;
19
20     private long threadErrorWaitMSec = 0;
21     private long localListenerReactionTimeMSec = 0;
22     private long waitForChangesTimeoutMSec = 0;
23     private long cacheManagerThreadIntervalMSec = 0;
24     private long resyncRemoteListenersIntervalMSec = 0;
25     private int carrierContainerCount = 0;
26     private long carrierContainerActivityMSec = 0;
27
28     public CacheCfMod()
29     {
30     }
31
32     /**
33      * @see com.nightlabs.config.ConfigModule#init()
34      */

35     public void init() throws InitException
36     {
37         documentation = "This is the documentation for the settings in this ConfigModule.\n" +
38                 "\n" +
39                 "* threadErrorWaitMSec: This specifies, how long the threads of the Cache\n" +
40                 " (CacheManagerThread and NotificationThread) shall wait before trying\n" +
41                 " again, after an error occured (e.g. because of lost connection to the\n" +
42                 " server). Default is 60000 (1 min).\n" +
43                 "\n" +
44                 "* localListenerReactionTimeMSec: This is the time in millisec, in which the\n" +
45                 " local class based change listeners can download a changed object and add\n" +
46                 " it to the cache again, before the remote listener will be unregistered.\n" +
47                 " Default is 300000 (5 min).\n" +
48                 "\n" +
49                 "* waitForChangesTimeoutMSec: How long shall JDOManager.waitForChanges(String, long)\n" +
50                 " wait before returning null if no changes occur. Note, that there's a\n" +
51                 " server-side min and max. If this is exceeded, the timeout will be silently\n" +
52                 " changed.\n" +
53                 " Note, that this must be shorter than any bean-rmi-timeout.\n" +
54                 "\n" +
55                 "* cacheManagerThreadIntervalMSec: How long will the CacheManagerThread sleep between\n" +
56                 " being active. Default is 3000 (3 sec). This means, in periods of 3 sec, new\n" +
57                 " remote-listeners will be added to the server or old ones removed and all 3 sec\n" +
58                 " it will be checked, whether the CarrierContainers need to be rolled (and\n" +
59                 " therefore old ones be dropped).\n" +
60                 "\n" +
61                 "* resyncRemoteListenersIntervalMSec: In which intervals shall the Cache sync all\n" +
62                 " the listeners (means drop all remote ones and resubscribe the ones in its local\n" +
63                 " CacheManagerThread.currentlySubscribedObjectIDs. Default is 3600000 (60 min).\n" +
64                 "\n" +
65                 "* carrierContainerCount: Carriers (means the cached objects in their wrappers)\n" +
66                 " expire after a certain time. To avoid iterating all Carriers and check their\n" +
67                 " age, they will be put into the active CarrierContainer when they are created.\n" +
68                 " This allows to simply throw away the complete oldest container once it expired.\n" +
69                 " The expiry age of a Carrier is therefore carrierContainerCount multiplied with\n" +
70                 " carrierContainerActivityMSec. Default is 24. Minimum is 2 and maximum 300.\n" +
71                 "\n" +
72                 "* carrierContainerActivityMSec: How long shall the active CarrierContainer be\n" +
73                 " active, before it will be replaced by a new one (and rolled through the\n" +
74                 " LinkedList. Default is 300000 (5 min). Minimum is 1 min and maximum 30 min.\n";
75
76         if (threadErrorWaitMSec <= 0)
77             setThreadErrorWaitMSec(60 * 1000);
78
79         if (localListenerReactionTimeMSec <= 0)
80             setLocalListenerReactionTimeMSec(5 * 60 * 1000);
81
82         if (waitForChangesTimeoutMSec <= 0)
83             setWaitForChangesTimeoutMSec(15 * 60 * 1000);
84
85         if (cacheManagerThreadIntervalMSec < 100)
86             setCacheManagerThreadIntervalMSec(3 * 1000);
87
88         if (resyncRemoteListenersIntervalMSec <= 0)
89             setResyncRemoteListenersIntervalMSec(60 * 60 * 1000);
90
91         if (carrierContainerCount < 2 || carrierContainerCount > 300)
92             setCarrierContainerCount(24);
93
94         if (carrierContainerActivityMSec < 60 * 1000 || 30 * 60 * 1000 < carrierContainerActivityMSec)
95             setCarrierContainerActivityMSec(5 * 60 * 1000);
96
97         if (LOGGER.isDebugEnabled()) {
98             LOGGER.debug("The Cache settings are:");
99             LOGGER.debug(" threadErrorWaitMSec=" + threadErrorWaitMSec);
100             LOGGER.debug(" localListenerReactionTimeMSec=" + localListenerReactionTimeMSec);
101             LOGGER.debug(" waitForChangesTimeoutMSec=" + waitForChangesTimeoutMSec);
102             LOGGER.debug(" cacheManagerThreadIntervalMSec=" + cacheManagerThreadIntervalMSec);
103             LOGGER.debug(" resyncRemoteListenersIntervalMSec=" + resyncRemoteListenersIntervalMSec);
104             LOGGER.debug(" carrierContainerCount=" + carrierContainerCount);
105             LOGGER.debug(" carrierContainerActivityMSec=" + carrierContainerActivityMSec);
106         }
107     }
108
109     /**
110      * @return Returns the cacheManagerThreadIntervalMSec.
111      */

112     public long getCacheManagerThreadIntervalMSec()
113     {
114         return cacheManagerThreadIntervalMSec;
115     }
116     /**
117      * @param cacheManagerThreadIntervalMSec The cacheManagerThreadIntervalMSec to set.
118      */

119     public void setCacheManagerThreadIntervalMSec(
120             long cacheManagerThreadIntervalMSec)
121     {
122         this.cacheManagerThreadIntervalMSec = cacheManagerThreadIntervalMSec;
123         setChanged();
124     }
125     /**
126      * @return Returns the carrierContainerActivityMSec.
127      */

128     public long getCarrierContainerActivityMSec()
129     {
130         return carrierContainerActivityMSec;
131     }
132     /**
133      * @param carrierContainerActivityMSec The carrierContainerActivityMSec to set.
134      */

135     public void setCarrierContainerActivityMSec(long carrierContainerActivityMSec)
136     {
137         this.carrierContainerActivityMSec = carrierContainerActivityMSec;
138         setChanged();
139     }
140     /**
141      * @return Returns the carrierContainerCount.
142      */

143     public int getCarrierContainerCount()
144     {
145         return carrierContainerCount;
146     }
147     /**
148      * @param carrierContainerCount The carrierContainerCount to set.
149      */

150     public void setCarrierContainerCount(int carrierContainerCount)
151     {
152         this.carrierContainerCount = carrierContainerCount;
153         setChanged();
154     }
155     /**
156      * @return Returns the documentation.
157      */

158     public String JavaDoc getDocumentation()
159     {
160         return documentation;
161     }
162     /**
163      * @param documentation The documentation to set.
164      */

165     public void setDocumentation(String JavaDoc documentation)
166     {
167         this.documentation = documentation;
168 // setChanged();
169
}
170     /**
171      * @return Returns the localListenerReactionTimeMSec.
172      */

173     public long getLocalListenerReactionTimeMSec()
174     {
175         return localListenerReactionTimeMSec;
176     }
177     /**
178      * @param localListenerReactionTimeMSec The localListenerReactionTimeMSec to set.
179      */

180     public void setLocalListenerReactionTimeMSec(
181             long localListenerReactionTimeMSec)
182     {
183         this.localListenerReactionTimeMSec = localListenerReactionTimeMSec;
184         setChanged();
185     }
186     /**
187      * @return Returns the resyncRemoteListenersIntervalMSec.
188      */

189     public long getResyncRemoteListenersIntervalMSec()
190     {
191         return resyncRemoteListenersIntervalMSec;
192     }
193     /**
194      * @param resyncRemoteListenersIntervalMSec The resyncRemoteListenersIntervalMSec to set.
195      */

196     public void setResyncRemoteListenersIntervalMSec(
197             long resyncRemoteListenersIntervalMSec)
198     {
199         this.resyncRemoteListenersIntervalMSec = resyncRemoteListenersIntervalMSec;
200         setChanged();
201     }
202     /**
203      * @return Returns the threadErrorWaitMSec.
204      */

205     public long getThreadErrorWaitMSec()
206     {
207         return threadErrorWaitMSec;
208     }
209     /**
210      * @param threadErrorWaitMSec The threadErrorWaitMSec to set.
211      */

212     public void setThreadErrorWaitMSec(long threadErrorWaitMSec)
213     {
214         this.threadErrorWaitMSec = threadErrorWaitMSec;
215         setChanged();
216     }
217     /**
218      * @return Returns the waitForChangesTimeoutMSec.
219      */

220     public long getWaitForChangesTimeoutMSec()
221     {
222         return waitForChangesTimeoutMSec;
223     }
224     /**
225      * @param waitForChangesTimeoutMSec The waitForChangesTimeoutMSec to set.
226      */

227     public void setWaitForChangesTimeoutMSec(long waitForChangesTimeoutMSec)
228     {
229         this.waitForChangesTimeoutMSec = waitForChangesTimeoutMSec;
230         setChanged();
231     }
232 }
233
Popular Tags