001: package org.tigris.scarab.services;
002:
003: /* ================================================================
004: * Copyright (c) 2000-2002 CollabNet. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are
008: * met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: *
017: * 3. The end-user documentation included with the redistribution, if
018: * any, must include the following acknowlegement: "This product includes
019: * software developed by Collab.Net <http://www.Collab.Net/>."
020: * Alternately, this acknowlegement may appear in the software itself, if
021: * and wherever such third-party acknowlegements normally appear.
022: *
023: * 4. The hosted project names must not be used to endorse or promote
024: * products derived from this software without prior written
025: * permission. For written permission, please contact info@collab.net.
026: *
027: * 5. Products derived from this software may not use the "Tigris" or
028: * "Scarab" names nor may "Tigris" or "Scarab" appear in their names without
029: * prior written permission of Collab.Net.
030: *
031: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
032: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
033: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
034: * IN NO EVENT SHALL COLLAB.NET OR ITS CONTRIBUTORS BE LIABLE FOR ANY
035: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
036: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
037: * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
038: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
039: * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
040: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
041: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
042: *
043: * ====================================================================
044: *
045: * This software consists of voluntary contributions made by many
046: * individuals on behalf of Collab.Net.
047: */
048:
049: import org.apache.turbine.Turbine;
050: import org.apache.fulcrum.BaseService;
051: import org.apache.fulcrum.InitializationException;
052: import org.apache.torque.Torque;
053: import org.apache.torque.TorqueException;
054: import org.tigris.scarab.om.*;
055: import org.tigris.scarab.util.Log;
056:
057: /**
058: * Turbine does not yet have a way to initialize components directly, and
059: * use of fulcrum's DatabaseService causes fulcrum to try to treat all the
060: * Managers as services. So this service is used to initialize Torque.
061: * It also creates an instance of each scarab om object to avoid deadlock.
062: *
063: * @author <a href="mailto:jmcnally@collab.net">John McNally</a>
064: * @version $Id: TorqueService.java 9891 2005-10-23 13:57:24Z jorgeuriarte $
065: */
066: public class TorqueService extends BaseService {
067: /**
068: * Initializes the service by setting up Torque.
069: */
070: public void init() throws InitializationException {
071: try {
072: Torque.init(Turbine.getConfiguration());
073: Log.get("org.apache.fulcrum").info(
074: " Loading om instances via managers...");
075: loadOM();
076: Log.get("org.apache.fulcrum").info(
077: " Done loading om instances.");
078: } catch (Exception e) {
079: throw new InitializationException(
080: "Can't initialize Torque!", e); //EXCEPTION
081: }
082:
083: // indicate that the service initialized correctly
084: setInit(true);
085: }
086:
087: /**
088: * This method loads all the classes in the org.tigris.scarab.om
089: * package. The torque classes of Foo and FooPeer contain a circular
090: * relationship so loading the class of Foo requires a FooPeer instance
091: * and creating a FooPeer instance requires the Foo class to be loaded.
092: * It is possible to deadlock if multiple threads attempt to load Foo
093: * simultaneously. A full analysis of possible deadlock scenarios has not
094: * been done, so to be as safe as possible we create one instance of each
095: * om object via the Manager.getInstance() method; this makes sure the
096: * Managers are initialized as well. It may be possible to
097: * reduce this to only calling Class.forName on each class.
098: */
099: protected void loadOM() throws Exception {
100: ActivityManager.getInstance();
101: ActivitySetManager.getInstance();
102: ActivitySetTypeManager.getInstance();
103: AttachmentManager.getInstance();
104: AttachmentTypeManager.getInstance();
105: AttributeClassManager.getInstance();
106: AttributeGroupManager.getInstance();
107: AttributeManager.getInstance();
108: AttributeOptionManager.getInstance();
109: AttributeTypeManager.getInstance();
110: // AttributeValue class is abstract
111: AttributeValueManager.getManager();
112: Class.forName("org.tigris.scarab.om.AttributeValue");
113: DependManager.getInstance();
114: DependTypeManager.getInstance();
115: FrequencyManager.getInstance();
116: GlobalParameterManager.getInstance();
117: // Issue class does not have public no-arg ctor
118: IssueManager.getManager();
119: Class.forName("org.tigris.scarab.om.Issue");
120: IssueTemplateInfoManager.getInstance();
121: IssueTypeManager.getInstance();
122: IssueVoteManager.getInstance();
123: MITListItemManager.getInstance();
124: MITListManager.getInstance();
125: ModificationManager.getInstance();
126: ModuleManager.getInstance();
127: OptionRelationshipManager.getInstance();
128: PendingGroupUserRoleManager.getInstance();
129: QueryManager.getInstance();
130: RAttributeAttributeGroupManager.getInstance();
131: ReportManager.getInstance();
132: RIssueTypeAttributeManager.getInstance();
133: RIssueTypeOptionManager.getInstance();
134: RModuleAttributeManager.getInstance();
135: RModuleIssueTypeManager.getInstance();
136: RModuleOptionManager.getInstance();
137: RModuleUserAttributeManager.getInstance();
138: // ROptionOption class does not have public no-arg ctor
139: ROptionOptionManager.getManager();
140: Class.forName("org.tigris.scarab.om.ROptionOption");
141: RQueryUserManager.getInstance();
142: ScarabUserManager.getInstance();
143: ScopeManager.getInstance();
144: UserPreferenceManager.getInstance();
145: UserVoteManager.getInstance();
146: }
147:
148: /**
149: * Shuts down the service.
150: *
151: * This method halts the IDBroker's daemon thread in all of
152: * the DatabaseMap's.
153: */
154: public void shutdown() {
155: try {
156: Torque.shutdown();
157: } catch (TorqueException te) {
158: Log.get("org.apache.fulcrum").error(
159: "TorqueService.shutdown(): " + te);
160: }
161: }
162: }
|