KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > MainTest


1 /*
2  * JEFFREE: Java(TM) Embedded Framework FREE
3  * Copyright (C) 1999-2003 - Opensugar
4  *
5  * The contents of this file are subject to the Jeffree Public License,
6  * as defined by the file JEFFREE_LICENSE.TXT
7  *
8  * You may not use this file except in compliance with the License.
9  * You may obtain a copy of the License on the Objectweb web site
10  * (www.objectweb.org).
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
14  * the specific terms governing rights and limitations under the License.
15  *
16  * The Original Code is JEFFREE, including the java package com.opensugar.cube,
17  * released January 1, 2003.
18  *
19  * The Initial Developer of the Original Code is Opensugar.
20  * The Original Code is Copyright Opensugar.
21  * All Rights Reserved.
22  *
23  * Initial developer(s): Pierre Scokaert (Opensugar)
24  * Contributor(s):
25  */

26
27 import com.opensugar.cube.Launcher;
28 import com.opensugar.cube.Util;
29
30 import java.io.File JavaDoc;
31 import java.io.FileNotFoundException JavaDoc;
32 import java.io.IOException JavaDoc;
33
34 public class MainTest extends Main {
35
36    public static void main( String JavaDoc[] args ) throws Exception JavaDoc {
37       new MainTest( args );
38    }
39
40    protected MainTest( String JavaDoc[] args ) {
41       if ( args.length != 1 ) {
42          usage();
43       }
44
45
46       IOException JavaDoc exceptionWhileLoadingProperties = null;
47       try {
48          loadProperties();
49       }
50       catch( IOException JavaDoc e ) {
51          exceptionWhileLoadingProperties = e;
52       }
53
54       FileNotFoundException JavaDoc exceptionWhileSettingSystemStreams = null;
55       try {
56          setSystemStreams();
57       }
58       catch ( FileNotFoundException JavaDoc e ) {
59          exceptionWhileSettingSystemStreams = e;
60       }
61
62       // Now we can start writing to stderr and stdout, NOT before the call to
63
// setSystemStreams has returned
64

65       if ( exceptionWhileLoadingProperties != null ) {
66          System.err.println( "Error while loading properties: " + exceptionWhileLoadingProperties.toString() );
67       }
68       if ( exceptionWhileSettingSystemStreams != null ) {
69          System.err.println( "Error while setting system streams: " + exceptionWhileSettingSystemStreams.toString() );
70       }
71
72
73
74       int charge = -1;
75       try {
76          charge = Integer.valueOf( args[ 0 ] ).intValue();
77       }
78       catch ( Exception JavaDoc e ) {
79          usage();
80       }
81
82       System.getProperties().put( "com.opensugar.cube.systemBundleJarFile", "lib/cube0.jar" );
83
84       System.setProperty( "com.opensugar.cube.test", "" + true );
85       if ( System.getProperty( "com.opensugar.cube.test.admin.port" ) == null ) {
86          System.setProperty( "com.opensugar.cube.test.admin.port", "" + 4000 );
87       }
88       if ( System.getProperty( "com.opensugar.cube.test.telnet.port" ) == null ) {
89          System.setProperty( "com.opensugar.cube.test.telnet.port", "" + 6000 );
90       }
91       if ( System.getProperty( "com.opensugar.cube.test.http.port" ) == null ) {
92          System.setProperty( "com.opensugar.cube.test.http.port", "" + 10000 );
93       }
94       File JavaDoc refDir = new File JavaDoc( "osc" );
95       String JavaDoc baseDirBase = "osc";
96       File JavaDoc dir;
97       for ( int i = 0; i < charge; i++ ) {
98          System.out.println( "####### " + i + " #######" );
99          dir = new File JavaDoc( baseDirBase + i );
100          if ( !dir.exists() ) {
101             Util.recursiveFileCopy( refDir, dir );
102          }
103          //( new LauncherThread( new File( dir, "bs" ) ) ).start();
104
new Launcher( new File JavaDoc( dir, "bs" ), null );
105       }
106
107       Object JavaDoc obj = new Object JavaDoc();
108       synchronized( obj ) {
109          try {
110             obj.wait();
111          }
112          catch ( InterruptedException JavaDoc ignore ) {}
113       }
114       
115    }
116
117    private class LauncherThread extends Thread JavaDoc {
118       private File JavaDoc baseDir;
119       public LauncherThread( File JavaDoc baseDir ) {
120          this.baseDir = baseDir;
121       }
122       public void run() {
123          new Launcher( baseDir, null );
124       }
125    }
126
127    private static void usage() {
128       System.out.println( "Usage:" );
129       System.out.println( "\tjava MainTest n" );
130       System.out.println( "\t\t n must be an integer (number of cubes to start)" );
131
132       System.exit( 1 );
133    }
134
135 }
136
Popular Tags