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


001:        /*
002:         * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003:         * notice. All rights reserved.
004:         */
005:        package com.tc.test.activepassive;
006:
007:        import org.apache.commons.io.FileUtils;
008:
009:        import com.tc.config.schema.setup.TestTVSConfigurationSetupManagerFactory;
010:        import com.tc.config.schema.test.ApplicationConfigBuilder;
011:        import com.tc.config.schema.test.HaConfigBuilder;
012:        import com.tc.config.schema.test.L2ConfigBuilder;
013:        import com.tc.config.schema.test.L2SConfigBuilder;
014:        import com.tc.config.schema.test.SystemConfigBuilder;
015:        import com.tc.config.schema.test.TerracottaConfigBuilder;
016:        import com.tc.logging.TCLogger;
017:        import com.tc.logging.TCLogging;
018:
019:        import java.io.File;
020:        import java.io.FileOutputStream;
021:        import java.io.IOException;
022:        import java.io.PrintWriter;
023:
024:        public class ActivePassiveServerConfigCreator {
025:            public static final String DEV_MODE = "development";
026:            public static final String PROD_MODE = "production";
027:
028:            private static TCLogger logger = TCLogging
029:                    .getTestingLogger(ActivePassiveServerConfigCreator.class);
030:            private final int serverCount;
031:            private final int[] dsoPorts;
032:            private final int[] jmxPorts;
033:            private final int[] l2GroupPorts;
034:            private final String[] serverNames;
035:            private final String serverPersistence;
036:            private final boolean serverDiskless;
037:            private final String configModel;
038:            private final File configFile;
039:            private final File tempDir;
040:            private final TestTVSConfigurationSetupManagerFactory configFactory;
041:            private final String[] dataLocations;
042:
043:            public ActivePassiveServerConfigCreator(int serverCount,
044:                    int[] dsoPorts, int[] jmxPorts, int[] l2GroupPorts,
045:                    String[] serverNames, String serverPersistence,
046:                    boolean serverDiskless, String configModel,
047:                    File configFile, File tempDir,
048:                    TestTVSConfigurationSetupManagerFactory configFactory) {
049:                this .serverCount = serverCount;
050:                this .dsoPorts = dsoPorts;
051:                this .jmxPorts = jmxPorts;
052:                this .l2GroupPorts = l2GroupPorts;
053:                this .serverNames = serverNames;
054:                this .serverPersistence = serverPersistence;
055:                this .serverDiskless = serverDiskless;
056:                this .configModel = configModel;
057:                this .configFile = configFile;
058:                this .tempDir = tempDir;
059:                this .configFactory = configFactory;
060:                dataLocations = new String[serverCount];
061:
062:                checkPersistenceAndDiskLessMode();
063:            }
064:
065:            public String getDataLocation(int i) {
066:                if (i < 1 && i > dataLocations.length) {
067:                    throw new AssertionError("Invalid index=[" + i
068:                            + "]... there are [" + dataLocations.length
069:                            + "] servers involved in this test.");
070:                }
071:                if (serverDiskless) {
072:                    return dataLocations[i];
073:                } else {
074:                    return dataLocations[0];
075:                }
076:            }
077:
078:            private void checkPersistenceAndDiskLessMode() {
079:                if (!serverDiskless
080:                        && serverPersistence
081:                                .equals(ActivePassivePersistenceMode.TEMPORARY_SWAP_ONLY)) {
082:                    throw new AssertionError(
083:                            "The servers are not running in diskless mode so persistence mode should be set to permanent-store");
084:                }
085:            }
086:
087:            private void checkConfigurationModel() {
088:                if (!configModel.equals(DEV_MODE)
089:                        && !configModel.equals(PROD_MODE)) {
090:                    throw new AssertionError("Unknown operating mode.");
091:                }
092:            }
093:
094:            private void cleanDataDirectory(String dataLocation)
095:                    throws IOException {
096:                File dbDir = new File(dataLocation);
097:                logger.info("DBHome: " + dbDir.getAbsolutePath());
098:                if (dbDir.exists()) {
099:                    FileUtils.cleanDirectory(dbDir);
100:                }
101:            }
102:
103:            public void writeL2Config() throws Exception {
104:                checkConfigurationModel();
105:                SystemConfigBuilder system = SystemConfigBuilder
106:                        .newMinimalInstance();
107:                system.setConfigurationModel(configModel);
108:
109:                String dataLocationHome = tempDir.getAbsolutePath()
110:                        + File.separator + "server-data";
111:                cleanDataDirectory(dataLocationHome);
112:                String logLocationHome = tempDir.getAbsolutePath()
113:                        + File.separator + "server-logs" + File.separator;
114:
115:                boolean gcEnabled = configFactory.getGCEnabled();
116:                boolean gcVerbose = configFactory.getGCVerbose();
117:                int gcIntervalInSec = configFactory.getGCIntervalInSec();
118:
119:                L2ConfigBuilder[] l2s = new L2ConfigBuilder[serverCount];
120:                for (int i = 0; i < serverCount; i++) {
121:                    L2ConfigBuilder l2 = new L2ConfigBuilder();
122:                    if (serverDiskless) {
123:                        dataLocations[i] = dataLocationHome + File.separator
124:                                + "server-" + i;
125:                        l2.setData(dataLocations[i]);
126:                    } else {
127:                        l2.setData(dataLocationHome);
128:                        if (dataLocations[0] == null) {
129:                            dataLocations[0] = dataLocationHome;
130:                        }
131:                    }
132:                    l2.setLogs(logLocationHome + "server-" + i);
133:                    l2.setName(serverNames[i]);
134:                    l2.setDSOPort(dsoPorts[i]);
135:                    l2.setJMXPort(jmxPorts[i]);
136:                    l2.setL2GroupPort(l2GroupPorts[i]);
137:                    l2.setPersistenceMode(serverPersistence);
138:                    l2.setGCEnabled(gcEnabled);
139:                    l2.setGCVerbose(gcVerbose);
140:                    l2.setGCInterval(gcIntervalInSec);
141:                    l2s[i] = l2;
142:                }
143:                HaConfigBuilder ha = new HaConfigBuilder();
144:                if (this .serverDiskless) {
145:                    ha
146:                            .setMode(HaConfigBuilder.HA_MODE_NETWORKED_ACTIVE_PASSIVE);
147:                } else {
148:                    ha
149:                            .setMode(HaConfigBuilder.HA_MODE_DISK_BASED_ACTIVE_PASSIVE);
150:                }
151:
152:                L2SConfigBuilder l2sConfigbuilder = new L2SConfigBuilder();
153:                l2sConfigbuilder.setL2s(l2s);
154:                l2sConfigbuilder.setHa(ha);
155:
156:                ApplicationConfigBuilder app = ApplicationConfigBuilder
157:                        .newMinimalInstance();
158:
159:                TerracottaConfigBuilder configBuilder = new TerracottaConfigBuilder();
160:                configBuilder.setSystem(system);
161:                configBuilder.setServers(l2sConfigbuilder);
162:                configBuilder.setApplication(app);
163:
164:                String configAsString = configBuilder.toString();
165:                System.err.println("Writing config to file:"
166:                        + configFile.getAbsolutePath() + configAsString);
167:
168:                FileOutputStream fileOutputStream = new FileOutputStream(
169:                        configFile);
170:                PrintWriter out = new PrintWriter((fileOutputStream));
171:                out.println(configAsString);
172:                out.flush();
173:                out.close();
174:            }
175:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.