Source Code Cross Referenced for AbstractAppServer.java in  » Net » Terracotta » com » tc » test » server » appserver » 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 » Terracotta » com.tc.test.server.appserver 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003:         * notice. All rights reserved.
004:         */
005:        package com.tc.test.server.appserver;
006:
007:        import org.apache.commons.io.FileUtils;
008:        import org.codehaus.cargo.util.internal.log.AbstractLogger;
009:        import org.codehaus.cargo.util.log.LogLevel;
010:
011:        import com.tc.test.Handle;
012:        import com.tc.text.Banner;
013:
014:        import java.io.File;
015:        import java.io.FileOutputStream;
016:        import java.io.IOException;
017:        import java.text.DateFormat;
018:        import java.text.SimpleDateFormat;
019:        import java.util.Date;
020:        import java.util.Properties;
021:
022:        /**
023:         * Handles installation and dynamic port assignment for an appserver instance.
024:         */
025:        public abstract class AbstractAppServer implements  AppServer {
026:
027:            private final AppServerStartupEnvironment installation;
028:            private File instance;
029:
030:            public AbstractAppServer(AppServerInstallation installation) {
031:                this .installation = (AppServerStartupEnvironment) installation;
032:            }
033:
034:            protected final synchronized File createInstance(
035:                    AppServerParameters params) throws Exception {
036:                instance = new File(installation.sandboxDirectory()
037:                        + File.separator + params.instanceName());
038:                if (instance.exists()) {
039:                    try {
040:                        FileUtils.deleteDirectory(instance);
041:                    } catch (IOException e) {
042:                        Banner.warnBanner(instance + " exists.\n"
043:                                + Handle.getJavaProcessFileHandles(instance));
044:                        instance = new File(instance.getAbsolutePath()
045:                                + "_"
046:                                + new SimpleDateFormat("yyyyMMdd-HHmmss")
047:                                        .format(new Date()));
048:                    }
049:                }
050:                instance.mkdir();
051:                return instance;
052:            }
053:
054:            /**
055:             * The specific appserver implementation uses the server install directory to locate the immutable appserver
056:             * installation files used to start running instances in the working directory.
057:             */
058:            protected final File serverInstallDirectory() {
059:                if (!installation.isRepoInstall())
060:                    return installation.serverInstallDirectory();
061:                return new File(installation.serverInstallDirectory()
062:                        + File.separator + serverType() + "-" + majorVersion()
063:                        + "." + minorVersion());
064:
065:            }
066:
067:            /**
068:             * The server name is used to create a parent directory for the server install directory which the appserver
069:             * implementation refers to as it's home directory.
070:             */
071:            protected final String serverType() {
072:                return installation.serverType();
073:            }
074:
075:            protected final String majorVersion() {
076:                return installation.majorVersion();
077:            }
078:
079:            protected final String minorVersion() {
080:                return installation.minorVersion();
081:            }
082:
083:            protected final File sandboxDirectory() {
084:                return installation.sandboxDirectory();
085:            }
086:
087:            /**
088:             * Implementing classes call this method to assign a series of properties to be available as system properties to the
089:             * appserver's JVM. Properties are optionally set by calling {@link StandardAppServerParameters}, passing a
090:             * <tt>Properties</tt> object to it's overloaded constructor. These instance specific properties are written to disk
091:             * and read by the appserver JVM. Two properties are always set by default: {@link AppServerConstants.APP_INSTANCE}
092:             * and {@link AppServerConstants.APP_PORT}.
093:             */
094:            protected final void setProperties(AppServerParameters params,
095:                    int port, File instance) {
096:                Properties props = params.properties();
097:                if (props == null)
098:                    props = new Properties();
099:                props.setProperty(AppServerConstants.APP_INSTANCE, params
100:                        .instanceName());
101:                props.setProperty(AppServerConstants.APP_PORT, Integer
102:                        .toString(port));
103:                File propsFile = new File(instance + ".properties");
104:                FileOutputStream fos = null;
105:                try {
106:                    propsFile.createNewFile();
107:                    fos = new FileOutputStream(propsFile, false);
108:                    props.store(fos, "Available Application System Properties");
109:                } catch (IOException ioe) {
110:                    throw new RuntimeException(
111:                            "Unable to write properties file to: " + propsFile,
112:                            ioe);
113:                } finally {
114:                    if (fos != null) {
115:                        try {
116:                            fos.close();
117:                        } catch (IOException ioe) {
118:                            throw new RuntimeException(
119:                                    "Unable to write properties file to: "
120:                                            + propsFile, ioe);
121:                        }
122:                    }
123:                }
124:            }
125:
126:            public final static class ConsoleLogger extends AbstractLogger {
127:
128:                private static final DateFormat FORMAT = new SimpleDateFormat(
129:                        "MM-dd-yyyy HH:mm:ss.SSS");
130:
131:                private final String instance;
132:
133:                public ConsoleLogger(String instance) {
134:                    this .instance = instance;
135:                }
136:
137:                protected void doLog(LogLevel level, String message,
138:                        String category) {
139:                    String msg = "[" + FORMAT.format(new Date()) + "]" + "["
140:                            + level.getLevel() + "][" + instance + "] "
141:                            + message;
142:                    System.out.println(msg);
143:                }
144:            }
145:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.