File Source: WebloggerImpl.java
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */
18
19 package org.apache.roller.weblogger.business;
20
21 import org.apache.roller.weblogger.business.plugins.PluginManagerImpl;
22 import org.apache.roller.weblogger.business.plugins.PluginManager;
23 import java.io.IOException;
24 import java.util.Properties;
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.roller.weblogger.WebloggerException;
28 import org.apache.roller.weblogger.business.pings.AutoPingManager;
29 import org.apache.roller.weblogger.business.pings.PingQueueManager;
30 import org.apache.roller.weblogger.business.pings.PingTargetManager;
31 import org.apache.roller.weblogger.business.referrers.RefererManager;
32 import org.apache.roller.weblogger.business.referrers.ReferrerQueueManager;
33 import org.apache.roller.weblogger.business.referrers.ReferrerQueueManagerImpl;
34 import org.apache.roller.weblogger.business.search.IndexManager;
35 import org.apache.roller.weblogger.business.runnable.ThreadManager;
36 import org.apache.roller.weblogger.business.themes.ThemeManager;
37 import org.apache.roller.weblogger.config.PingConfig;
38
39
40 /**
41 * The abstract version of the Weblogger implementation.
42 *
43 * Here we put code that pertains to *all* implementations of the Weblogger
44 * interface, regardless of their persistence strategy.
45 */
46 @com.google.inject.Singleton
47 public abstract class WebloggerImpl implements Weblogger {
48
/*
P/P * Method: org.apache.roller.weblogger.business.WebloggerImpl__static_init
*
* Postconditions:
* init'ed(log)
*/
49 private static Log log = LogFactory.getLog(WebloggerImpl.class);
50
51 // managers
52 private final AutoPingManager autoPingManager;
53 private final BookmarkManager bookmarkManager;
54 private final FileManager fileManager;
55 private final IndexManager indexManager;
56 private final PingQueueManager pingQueueManager;
57 private final PingTargetManager pingTargetManager;
58 private final PluginManager pluginManager;
59 private final PropertiesManager propertiesManager;
60 private final RefererManager refererManager;
61 private final ReferrerQueueManager refererQueueManager;
62 private final ThemeManager themeManager;
63 private final ThreadManager threadManager;
64 private final UserManager userManager;
65 private final WeblogManager weblogManager;
66
67 // url strategy
68 private final URLStrategy urlStrategy;
69
70 // some simple attributes
71 private final String version;
72 private final String revision;
73 private final String buildTime;
74 private final String buildUser;
75
76
77 protected WebloggerImpl(
78 AutoPingManager autoPingManager,
79 BookmarkManager bookmarkManager,
80 FileManager fileManager,
81 IndexManager indexManager,
82 PingQueueManager pingQueueManager,
83 PingTargetManager pingTargetManager,
84 PluginManager pluginManager,
85 PropertiesManager propertiesManager,
86 RefererManager refererManager,
87 ReferrerQueueManager refererQueueManager,
88 ThemeManager themeManager,
89 ThreadManager threadManager,
90 UserManager userManager,
91 WeblogManager weblogManager,
/*
P/P * Method: void org.apache.roller.weblogger.business.WebloggerImpl(AutoPingManager, BookmarkManager, FileManager, IndexManager, PingQueueManager, PingTargetManager, PluginManager, PropertiesManager, RefererManager, ReferrerQueueManager, ThemeManager, ThreadManager, UserManager, WeblogManager, URLStrategy)
*
* Preconditions:
* (soft) log != null
*
* Presumptions:
* java.lang.Object:getClass(...)@112 != null
*
* Postconditions:
* this.autoPingManager == autoPingManager
* init'ed(this.autoPingManager)
* this.bookmarkManager == bookmarkManager
* init'ed(this.bookmarkManager)
* init'ed(this.buildTime)
* init'ed(this.buildUser)
* this.fileManager == fileManager
* init'ed(this.fileManager)
* this.indexManager == indexManager
* init'ed(this.indexManager)
* ...
*/
92 URLStrategy urlStrategy) throws WebloggerException {
93
94 this.autoPingManager = autoPingManager;
95 this.bookmarkManager = bookmarkManager;
96 this.fileManager = fileManager;
97 this.indexManager = indexManager;
98 this.pingQueueManager = pingQueueManager;
99 this.pingTargetManager = pingTargetManager;
100 this.pluginManager = pluginManager;
101 this.propertiesManager = propertiesManager;
102 this.refererManager = refererManager;
103 this.refererQueueManager = refererQueueManager;
104 this.themeManager = themeManager;
105 this.threadManager = threadManager;
106 this.userManager = userManager;
107 this.weblogManager = weblogManager;
108 this.urlStrategy = urlStrategy;
109
110 Properties props = new Properties();
111 try {
112 props.load(getClass().getResourceAsStream("/roller-version.properties"));
113 } catch (IOException e) {
114 log.error("roller-version.properties not found", e);
115 }
116
117 version = props.getProperty("ro.version", "UNKNOWN");
118 revision = props.getProperty("ro.revision", "UNKNOWN");
119 buildTime = props.getProperty("ro.buildTime", "UNKNOWN");
120 buildUser = props.getProperty("ro.buildUser", "UNKNOWN");
121 }
122
123
124 /**
125 *
126 *
127 * @see org.apache.roller.weblogger.modelWebloggerr#getFileManager()
128 */
129 public FileManager getFileManager() {
/*
P/P * Method: FileManager getFileManager()
*
* Postconditions:
* return_value == this.fileManager
* init'ed(return_value)
*/
130 return fileManager;
131 }
132
133
134 /**
135 *
136 *
137 * @see org.apache.roller.weblogger.modelWebloggerr#getThreadManager()
138 */
139 public ThreadManager getThreadManager() {
/*
P/P * Method: ThreadManager getThreadManager()
*
* Postconditions:
* return_value == this.threadManager
* init'ed(return_value)
*/
140 return threadManager;
141 }
142
143
144 /**
145 *
146 *
147 * @see org.apache.roller.weblogger.modelWebloggerr#getIndexManager()
148 */
149 public IndexManager getIndexManager() {
/*
P/P * Method: IndexManager getIndexManager()
*
* Postconditions:
* return_value == this.indexManager
* init'ed(return_value)
*/
150 return indexManager;
151 }
152
153
154 /**
155 *
156 *
157 * @see org.apache.roller.weblogger.modelWebloggerr#getThemeManager()
158 */
159 public ThemeManager getThemeManager() {
/*
P/P * Method: ThemeManager getThemeManager()
*
* Postconditions:
* return_value == this.themeManager
* init'ed(return_value)
*/
160 return themeManager;
161 }
162
163
164 /**
165 * @see org.apache.roller.weblogger.business.referrers.ReferrerQueueManager
166 */
167 public ReferrerQueueManager getReferrerQueueManager() {
/*
P/P * Method: ReferrerQueueManager getReferrerQueueManager()
*
* Postconditions:
* return_value == this.refererQueueManager
* init'ed(return_value)
*/
168 return refererQueueManager;
169 }
170
171
172
173 /**
174 *
175 *
176 * @see org.apache.roller.weblogger.modelWebloggerr#getUserManager()
177 */
178 public UserManager getUserManager() {
/*
P/P * Method: UserManager getUserManager()
*
* Postconditions:
* return_value == this.userManager
* init'ed(return_value)
*/
179 return userManager;
180 }
181
182
183 /**
184 *
185 *
186 * @see org.apache.roller.weblogger.modelWebloggerr#getBookmarkManager()
187 */
188 public BookmarkManager getBookmarkManager() {
/*
P/P * Method: BookmarkManager getBookmarkManager()
*
* Postconditions:
* return_value == this.bookmarkManager
* init'ed(return_value)
*/
189 return bookmarkManager;
190 }
191
192
193 /**
194 *
195 *
196 * @see org.apache.roller.weblogger.modelWebloggerr#getWeblogManager()
197 */
198 public WeblogManager getWeblogManager() {
/*
P/P * Method: WeblogManager getWeblogManager()
*
* Postconditions:
* return_value == this.weblogManager
* init'ed(return_value)
*/
199 return weblogManager;
200 }
201
202
203 /**
204 *
205 *
206 * @see org.apache.roller.weblogger.modelWebloggerr#getRefererManager()
207 */
208 public RefererManager getRefererManager() {
/*
P/P * Method: RefererManager getRefererManager()
*
* Postconditions:
* return_value == this.refererManager
* init'ed(return_value)
*/
209 return refererManager;
210 }
211
212
213 /**
214 *
215 *
216 * @see org.apache.roller.weblogger.modelWebloggerr#getPropertiesManager()
217 */
218 public PropertiesManager getPropertiesManager() {
/*
P/P * Method: PropertiesManager getPropertiesManager()
*
* Postconditions:
* return_value == this.propertiesManager
* init'ed(return_value)
*/
219 return propertiesManager;
220 }
221
222
223 /**
224 *
225 *
226 * @see org.apache.roller.weblogger.modelWebloggerr#getPingTargetManager()
227 */
228 public PingQueueManager getPingQueueManager() {
/*
P/P * Method: PingQueueManager getPingQueueManager()
*
* Postconditions:
* return_value == this.pingQueueManager
* init'ed(return_value)
*/
229 return pingQueueManager;
230 }
231
232
233 /**
234 *
235 *
236 * @see org.apache.roller.weblogger.modelWebloggerr#getPingTargetManager()
237 */
238 public AutoPingManager getAutopingManager() {
/*
P/P * Method: AutoPingManager getAutopingManager()
*
* Postconditions:
* return_value == this.autoPingManager
* init'ed(return_value)
*/
239 return autoPingManager;
240 }
241
242
243 /**
244 *
245 *
246 * @see org.apache.roller.weblogger.modelWebloggerr#getPingTargetManager()
247 */
248 public PingTargetManager getPingTargetManager() {
/*
P/P * Method: PingTargetManager getPingTargetManager()
*
* Postconditions:
* return_value == this.pingTargetManager
* init'ed(return_value)
*/
249 return pingTargetManager;
250 }
251
252
253 /**
254 *
255 *
256 * @see org.apache.roller.weblogger.modelWebloggerr#getPluginManager()
257 */
258 public PluginManager getPluginManager() {
/*
P/P * Method: PluginManager getPluginManager()
*
* Postconditions:
* return_value == this.pluginManager
* init'ed(return_value)
*/
259 return pluginManager;
260 }
261
262
263 /**
264 * @inheritDoc
265 */
266 public URLStrategy getUrlStrategy() {
/*
P/P * Method: URLStrategy getUrlStrategy()
*
* Postconditions:
* return_value == this.urlStrategy
* init'ed(return_value)
*/
267 return urlStrategy;
268 }
269
270
271 /**
272 * @inheritDoc
273 */
274 public void release() {
275 try {
/*
P/P * Method: void release()
*
* Preconditions:
* (soft) log != null
* (soft) this.autoPingManager != null
* (soft) this.bookmarkManager != null
* (soft) this.fileManager != null
* (soft) this.pingQueueManager != null
* (soft) this.pingTargetManager != null
* (soft) this.pluginManager != null
* (soft) this.refererManager != null
* (soft) this.threadManager != null
* (soft) this.userManager != null
* ...
*/
276 autoPingManager.release();
277 bookmarkManager.release();
278 fileManager.release();
279 pingTargetManager.release();
280 pingQueueManager.release();
281 pluginManager.release();
282 refererManager.release();
283 threadManager.release();
284 userManager.release();
285 weblogManager.release();
286 } catch(Throwable e) {
287 log.error("Error calling Roller.release()", e);
288 }
289 }
290
291
292 /**
293 * @inheritDoc
294 */
295 public void initialize() throws InitializationException {
296
/*
P/P * Method: void initialize()
*
* Preconditions:
* log != null
* init'ed(org/apache/roller/weblogger/config/WebloggerRuntimeConfig.configDefs)
* init'ed(this.threadManager.schedulerThread)
* org/apache/roller/weblogger/business/themes/ThemeManagerImpl.log != null
* org/apache/roller/weblogger/config/WebloggerConfig.config != null
* org/apache/roller/weblogger/config/WebloggerConfig.log != null
* this.indexManager != null
* init'ed(this.indexManager.searchEnabled)
* this.propertiesManager != null
* this.propertiesManager.strategy != null
* ...
*
* Presumptions:
* getAutopingManager(...).strategy != null
* getAutopingManager(...).strategy.emf != null
* getAutopingManager(...).strategy.threadLocalEntityManager != null
* getPingTargetManager(...).strategy != null
* getPingTargetManager(...).strategy.emf != null
* ...
*
* Postconditions:
* org/apache/roller/weblogger/business/pings/PingQueueProcessor.theInstance == old org/apache/roller/weblogger/business/pings/PingQueueProcessor.theInstance
* org/apache/roller/weblogger/config/WebloggerRuntimeConfig.configDefs == One-of{old org/apache/roller/weblogger/config/WebloggerRuntimeConfig.configDefs, &new RuntimeConfigDefs(unmarshall#1)}
* init'ed(org/apache/roller/weblogger/config/WebloggerRuntimeConfig.configDefs)
* this.indexManager.fRAMindex == One-of{old this.indexManager.fRAMindex, &new RAMDirectory(initialize#2*), &new RAMDirectory(initialize#3*)}
* init'ed(this.indexManager.inconsistentAtStartup)
* this.themeManager.themes == One-of{old this.themeManager.themes, &new HashMap(loadAllThemesFromDisk#1)}
* this.threadManager.schedulerThread == One-of{old this.threadManager.schedulerThread, &new Thread(initialize#8*)}
* this.threadManager.schedulerThread != null
* new ArrayList(RuntimeConfigDefs#1) num objects <= 1
* new RuntimeConfigDefs(unmarshall#1) num objects == new ArrayList(RuntimeConfigDefs#1) num objects
* ...
*/
297 log.info("Initializing Roller Weblogger business tier");
298
299 // TODO: this should probably be done in a more uniform fashion, possibly
300 // using annotations? biggest issue is controlling ordering
301 getPropertiesManager().initialize();
302 getThemeManager().initialize();
303 getThreadManager().initialize();
304 getIndexManager().initialize();
305
306 try {
307 // Initialize ping systems
308 // TODO: this should probably be moving inside ping manager initialize() methods?
309
310 // Initialize common targets from the configuration
311 PingConfig.initializeCommonTargets();
312
313 // Initialize ping variants
314 PingConfig.initializePingVariants();
315
316 // Remove custom ping targets if they have been disallowed
317 if (PingConfig.getDisallowCustomTargets()) {
318 log.info("Custom ping targets have been disallowed. Removing any existing custom targets.");
319 WebloggerFactory.getWeblogger().getPingTargetManager().removeAllCustomPingTargets();
320 }
321
322 // Remove all autoping configurations if ping usage has been disabled.
323 if (PingConfig.getDisablePingUsage()) {
324 log.info("Ping usage has been disabled. Removing any existing auto ping configurations.");
325 WebloggerFactory.getWeblogger().getAutopingManager().removeAllAutoPings();
326 }
327 } catch (Throwable t) {
328 throw new InitializationException("Error initializing ping systems", t);
329 }
330
331 // we always need to do a flush after initialization because it's
332 // possible that some changes need to be persisted
333 try {
334 flush();
335 } catch(WebloggerException ex) {
336 throw new InitializationException("Error flushing after initialization", ex);
337 }
338
339 log.info("Roller Weblogger business tier successfully initialized");
340 }
341
342
343 /**
344 * @inheritDoc
345 */
346 public void shutdown() {
347 try {
/*
P/P * Method: void shutdown()
*
* Preconditions:
* (soft) log != null
* (soft) org/apache/roller/weblogger/business/HitCountQueue.instance != null
* (soft) init'ed(org/apache/roller/weblogger/business/HitCountQueue.instance.worker)
* (soft) org/apache/roller/weblogger/business/HitCountQueue.log != null
* (soft) org/apache/roller/weblogger/business/referrers/ReferrerQueueManagerImpl.mLogger != null
* (soft) org/apache/roller/weblogger/business/search/IndexManagerImpl.mLogger != null
* (soft) this.indexManager.indexConsistencyMarker != null
* (soft) init'ed(this.indexManager.reader)
* (soft) this.indexManager.roller != null
* (soft) this.indexManager.roller.threadManager != null
* ...
*
* Test Vectors:
* this.indexManager: Addr_Set{null}, Inverse{null}
* this.refererQueueManager: Addr_Set{null}, Inverse{null}
* this.threadManager: Addr_Set{null}, Inverse{null}
*/
348 HitCountQueue.getInstance().shutdown();
349 if (getReferrerQueueManager() != null) getReferrerQueueManager().shutdown();
350 if (indexManager != null) indexManager.shutdown();
351 if (threadManager != null) threadManager.shutdown();
352 } catch(Throwable e) {
353 log.error("Error calling Roller.shutdown()", e);
354 }
355 }
356
357
358 /**
359 * Weblogger version
360 */
361 public String getVersion() {
/*
P/P * Method: String getVersion()
*
* Postconditions:
* return_value == this.version
* init'ed(return_value)
*/
362 return version;
363 }
364
365 /**
366 * Get source code repository revision # used to create build
367 */
368 public String getRevision() {
/*
P/P * Method: String getRevision()
*
* Postconditions:
* return_value == this.revision
* init'ed(return_value)
*/
369 return revision;
370 }
371
372 /**
373 * Weblogger build time
374 */
375 public String getBuildTime() {
/*
P/P * Method: String getBuildTime()
*
* Postconditions:
* return_value == this.buildTime
* init'ed(return_value)
*/
376 return buildTime;
377 }
378
379
380 /**
381 * Get username that built Weblogger
382 */
383 public String getBuildUser() {
/*
P/P * Method: String getBuildUser()
*
* Postconditions:
* return_value == this.buildUser
* init'ed(return_value)
*/
384 return buildUser;
385 }
386
387 }
SofCheck Inspector Build Version : 2.18479
| WebloggerImpl.java |
2009-Jan-02 14:24:50 |
| WebloggerImpl.class |
2009-Sep-04 03:12:30 |