Source Code Cross Referenced for Runner.java in  » Net » Coadunation_1.0.1 » com » rift » coad » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » Coadunation_1.0.1 » com.rift.coad 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * CoadunationLib: The coaduntion implementation library.
003:         * Copyright (C) 2006  Rift IT Contracting
004:         * 
005:         * This library is free software; you can redistribute it and/or
006:         * modify it under the terms of the GNU Lesser General Public
007:         * License as published by the Free Software Foundation; either
008:         * version 2.1 of the License, or (at your option) any later version.
009:         * 
010:         * This library is distributed in the hope that it will be useful,
011:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013:         * Lesser General Public License for more details.
014:         * 
015:         * You should have received a copy of the GNU Lesser General Public
016:         * License along with this library; if not, write to the Free Software
017:         * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
018:         *
019:         * Runner.java
020:         *
021:         * This class is responsible for instanciating the coadunation environment properly.
022:         */
023:
024:        package com.rift.coad;
025:
026:        // log 4 j imports
027:        import org.apache.log4j.Logger;
028:        import org.apache.log4j.PropertyConfigurator;
029:        import org.apache.log4j.xml.DOMConfigurator;
030:        import org.apache.log4j.BasicConfigurator;
031:
032:        // coadunation imports
033:        import com.rift.coad.lib.cache.CacheRegistry;
034:        import com.rift.coad.lib.configuration.Configuration;
035:        import com.rift.coad.lib.configuration.ConfigurationFactory;
036:        import com.rift.coad.lib.db.DBSourceManager;
037:        import com.rift.coad.lib.deployment.DeploymentLoader;
038:        import com.rift.coad.lib.deployment.DeploymentManager;
039:        import com.rift.coad.lib.deployment.test.TestMonitor;
040:        import com.rift.coad.lib.deployment.bean.BeanManager;
041:        import com.rift.coad.lib.deployment.bean.BeanConnector;
042:        import com.rift.coad.lib.deployment.jmxbean.JMXBeanManager;
043:        import com.rift.coad.lib.deployment.jmxbean.JMXBeanConnector;
044:        import com.rift.coad.lib.deployment.webservice.WebServiceManager;
045:        import com.rift.coad.lib.deployment.webservice.WebServiceConnector;
046:        import com.rift.coad.lib.httpd.HttpDaemon;
047:        import com.rift.coad.lib.interceptor.InterceptorFactory;
048:        import com.rift.coad.lib.loader.MasterClassLoader;
049:        import com.rift.coad.lib.naming.NamingDirector;
050:        import com.rift.coad.lib.security.ThreadsPermissionContainer;
051:        import com.rift.coad.lib.security.ThreadPermissionSession;
052:        import com.rift.coad.lib.security.ThreadsPermissionContainerAccessor;
053:        import com.rift.coad.lib.security.user.UserSessionManager;
054:        import com.rift.coad.lib.security.user.UserSessionManagerAccessor;
055:        import com.rift.coad.lib.security.user.UserStoreManager;
056:        import com.rift.coad.lib.security.user.UserStoreManagerAccessor;
057:        import com.rift.coad.lib.security.login.handlers.PasswordInfoHandler;
058:        import com.rift.coad.lib.security.SessionManager;
059:        import com.rift.coad.lib.security.RoleManager;
060:        import com.rift.coad.lib.security.Validator;
061:        import com.rift.coad.lib.security.login.LoginManager;
062:        import com.rift.coad.lib.thread.CoadunationThreadGroup;
063:        import com.rift.coad.lib.thread.BasicThread;
064:        import com.rift.coad.lib.thirdparty.axis.AxisManager;
065:        import com.rift.coad.lib.transaction.TransactionDirector;
066:
067:        /**
068:         *
069:         * @author Brett Chaldecott
070:         */
071:        public class Runner {
072:
073:            /**
074:             * The implementation of the shut down hook. This object will get run when
075:             * this program is terminated.
076:             */
077:            public static class ShutdownHook extends Thread {
078:                /**
079:                 * The default constructor of the shutdown hook.
080:                 */
081:                public ShutdownHook() {
082:                }
083:
084:                /**
085:                 * This method will get called to shut down the coadunation base.
086:                 */
087:                public void run() {
088:                    // alert the waiting thread
089:                    alert();
090:                    synchronized (this ) {
091:                        try {
092:                            wait();
093:                        } catch (Exception ex) {
094:
095:                        }
096:                    }
097:                }
098:
099:                /**
100:                 * This method will alert the hook to the fact that this object is being
101:                 * shut down.
102:                 */
103:                private synchronized void alert() {
104:                    notify();
105:                }
106:
107:                /**
108:                 * This method will monitor
109:                 */
110:                public synchronized void monitor() {
111:                    try {
112:                        wait();
113:                    } catch (Exception ex) {
114:                        // do nothing
115:                    }
116:                }
117:
118:                /**
119:                 * Notify the caller thread to inform them of complete shut down.
120:                 */
121:                public synchronized void notifyOfCompletion() {
122:                    notifyAll();
123:                }
124:            }
125:
126:            // class constants
127:            public static final String RUNNER_USER = "runner_user";
128:
129:            // private member variables
130:            protected static Logger log = Logger.getLogger(Runner.class
131:                    .getName());
132:            private ThreadsPermissionContainer permissionContainer = null;
133:            private UserStoreManager userStoreManager = null;
134:            private UserSessionManager sessionManager = null;
135:            private CoadunationThreadGroup threadGroup = null;
136:            private BeanManager beanManager = null;
137:            private JMXBeanManager jmxBeanManager = null;
138:            private WebServiceManager webServiceManager = null;
139:            private DeploymentManager deploymentManager = null;
140:            private HttpDaemon httpDaemon = null;
141:
142:            /**
143:             * Creates a new instance of Main
144:             */
145:            public Runner() throws CoadException {
146:                // Validate the class loader
147:                System.out.println("Check the class loader");
148:                if (!(this .getClass().getClassLoader() instanceof  com.rift.coad.BaseClassLoader)) {
149:                    log.error("Invalid class loader");
150:                    System.exit(-1);
151:                }
152:                System.out.println("Try and init");
153:                try {
154:                    Configuration config = ConfigurationFactory.getInstance()
155:                            .getConfig(Runner.class);
156:
157:                    // instanciate the user permissions
158:                    log.info("Init the master class loader");
159:                    MasterClassLoader.init();
160:
161:                    // instanciate the user permissions
162:                    log.info("Init thread permissions");
163:                    permissionContainer = new ThreadsPermissionContainer();
164:                    ThreadsPermissionContainerAccessor
165:                            .init(permissionContainer);
166:                    log.info("Init session manager");
167:                    SessionManager.init(permissionContainer);
168:                    log.info("Init user store");
169:                    userStoreManager = new UserStoreManager();
170:                    UserStoreManagerAccessor.init(userStoreManager);
171:                    log.info("Init user session manager");
172:                    sessionManager = new UserSessionManager(
173:                            permissionContainer, userStoreManager);
174:                    sessionManager.startCleanup();
175:                    UserSessionManagerAccessor.init(sessionManager);
176:                    log.info("Init login module");
177:                    LoginManager.init(sessionManager, userStoreManager);
178:
179:                    // add a user to the session for the current thread
180:                    log.info("Init roles");
181:                    RoleManager.getInstance().startBackgroundThread();
182:
183:                    // setup a default user for the current thread
184:                    log.info("Init the default user for the runner");
185:                    Long threadId = new Long(Thread.currentThread().getId());
186:                    permissionContainer.putSession(threadId,
187:                            new ThreadPermissionSession(threadId,
188:                                    userStoreManager.getUserInfo(config
189:                                            .getString(RUNNER_USER))));
190:
191:                    // instanciate the thread manager
192:                    log.info("Init thread group");
193:                    threadGroup = new CoadunationThreadGroup(sessionManager,
194:                            userStoreManager);
195:
196:                    // init the interceptor factory
197:                    log.info("Init the interceptor factory");
198:                    InterceptorFactory.init(permissionContainer,
199:                            sessionManager, userStoreManager);
200:
201:                    // setup the current thread class loader
202:                    log.info("Init the naming director");
203:                    NamingDirector.init(threadGroup);
204:
205:                    log.info("Init the transaction director");
206:                    TransactionDirector.init();
207:
208:                    // instanciate the cache registry
209:                    log.info("Init the cache registry");
210:                    CacheRegistry.init(threadGroup);
211:
212:                    // instanciate the database sources
213:                    log.info("Init data stources");
214:                    DBSourceManager.init();
215:
216:                    // instanciate the bean manager
217:                    log.info("Init coadunation beans");
218:                    beanManager = new BeanManager(permissionContainer,
219:                            threadGroup);
220:                    BeanConnector.init(beanManager);
221:
222:                    // instanciate the jmx bean manager
223:                    log.info("Init JMX Beans");
224:                    jmxBeanManager = new JMXBeanManager(permissionContainer,
225:                            threadGroup);
226:                    JMXBeanConnector.init(jmxBeanManager);
227:
228:                    // instanciate the axis engine
229:                    log.info("Init AXIS");
230:                    AxisManager.init();
231:
232:                    // instanciate the web service manager
233:                    log.info("Init Web Service management");
234:                    webServiceManager = new WebServiceManager();
235:                    WebServiceConnector.init(webServiceManager);
236:
237:                    // instanciate the thread manager
238:                    log.info("Init Deployment Loader");
239:                    deploymentManager = new DeploymentManager(threadGroup,
240:                            beanManager, jmxBeanManager, webServiceManager);
241:
242:                    // instanciate the http daemon
243:                    log.info("Init Web Service HTTPD");
244:                    httpDaemon = new HttpDaemon(threadGroup);
245:
246:                } catch (Exception ex) {
247:                    System.out.println("Failed to start coadunation : "
248:                            + ex.getMessage());
249:                    ex.printStackTrace(System.out);
250:                    log.error("Failed to start coadunation : "
251:                            + ex.getMessage(), ex);
252:                    throw new CoadException(
253:                            "Failed start the Coadunation base because : "
254:                                    + ex.getMessage(), ex);
255:                }
256:            }
257:
258:            /**
259:             * This method will shut down the coadunation base.
260:             */
261:            public void shutdown() {
262:                try {
263:                    log.info("Shutting down HTTPD");
264:                    httpDaemon.shutdown();
265:                    log.info("Shutting down deployment manager");
266:                    deploymentManager.shutdown();
267:                    log.info("Shutting down the cache registry");
268:                    CacheRegistry.getInstance().shutdown();
269:                    log.info("Stopping the transaction director");
270:                    TransactionDirector.getInstance().stop();
271:                    log.info("Shut down the naming director");
272:                    NamingDirector.getInstance().shutdown();
273:                    log.info("Terminating the local thread group");
274:                    threadGroup.terminate();
275:                    log.info("Terminate the back ground thread");
276:                    RoleManager.getInstance().terminateBackgroundThread();
277:                    log.info("Terminating the session manager");
278:                    sessionManager.shutdown();
279:
280:                } catch (Exception ex) {
281:                    log.error("Shutdown failed : " + ex.getMessage(), ex);
282:                }
283:            }
284:
285:            /**
286:             * The main method responsible for starting the coadunation base.
287:             *
288:             * @param args the command line arguments
289:             */
290:            public static void main() {
291:                try {
292:                    String logFile = System.getProperty("Log.File");
293:                    if (logFile.endsWith("properties")) {
294:                        System.out
295:                                .println("Initing the log file from properties.");
296:                        PropertyConfigurator.configure(logFile);
297:                    } else if (logFile.endsWith("xml")) {
298:                        System.out.println("Initing the log file from xml.");
299:                        DOMConfigurator.configure(logFile);
300:                    } else {
301:                        System.out.println("Using the basic configuration.");
302:                        BasicConfigurator.configure();
303:                    }
304:                    System.out.println("Start");
305:                    Runner runner = new Runner();
306:                    ShutdownHook shutdownHook = new ShutdownHook();
307:                    Runtime.getRuntime().addShutdownHook(shutdownHook);
308:                    System.out.println("Initialization complete");
309:                    shutdownHook.monitor();
310:                    runner.shutdown();
311:                    shutdownHook.notifyOfCompletion();
312:                    log.info("Shut down complete");
313:                } catch (Exception ex) {
314:                    System.out.println("Failed to run the Coadunation base ["
315:                            + ex.getMessage() + "]");
316:                    ex.printStackTrace(System.out);
317:                    System.exit(-1);
318:                }
319:            }
320:
321:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.