1   /*** 
2    * 
3    * Copyright 2004 Hiram Chirino
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); 
6    * you may not use this file except in compliance with the License. 
7    * You may obtain a copy of the License at 
8    * 
9    * http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, 
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
14   * See the License for the specific language governing permissions and 
15   * limitations under the License. 
16   * 
17   **/
18  package org.codehaus.activemq.journal.howl;
19  
20  import java.io.File;
21  
22  import org.codehaus.activemq.journal.Journal;
23  import org.codehaus.activemq.journal.JournalPerfToolSupport;
24  import org.objectweb.howl.log.Configuration;
25  
26  /***
27   * A Performance statistics gathering tool for the HOWL based Journal.
28   * 
29   * @version $Revision: 1.3 $
30   */
31  public class JournalPerfTool extends JournalPerfToolSupport {
32  	
33      private int maxLogFiles=  2;
34  	private int bufferSize = 1024*4;
35  	private int maxBuffers = 20;
36  	private int maxBlocksPerFile = 100;
37  	
38  	public static void main(String[] args) throws Exception {
39  		
40  		try {
41  			JournalPerfTool tool = new JournalPerfTool();
42  			if( args.length > 0 ) {
43  				tool.journalDirectory = new File(args[0]);
44  			}
45  			if( args.length > 1 ) {
46  				tool.workerIncrement = Integer.parseInt(args[1]);
47  			}
48  			if( args.length > 2 ) {
49  				tool.incrementDelay = Long.parseLong(args[2]);
50  			}
51  			if( args.length > 3 ) {
52  				tool.verbose = Boolean.getBoolean(args[3]);
53  			}
54  			if( args.length > 4 ) {
55  				tool.recordSize = Integer.parseInt(args[4]);
56  			}
57  			if( args.length > 5 ) {
58  				tool.syncFrequency = Integer.parseInt(args[5]);
59  			}
60  			if( args.length > 6 ) {
61  				tool.workerThinkTime = Integer.parseInt(args[6]);
62  			}
63  			
64  			if( args.length > 7 ) {
65  				tool.maxLogFiles = Integer.parseInt(args[7]);
66  			}
67  			if( args.length > 8 ) {
68  				tool.bufferSize = Integer.parseInt(args[8]);
69  			}
70  			if( args.length > 9 ) {
71  				tool.maxBuffers = Integer.parseInt(args[9]);
72  			}
73  			if( args.length > 10 ) {
74  				tool.maxBlocksPerFile = Integer.parseInt(args[10]);
75  			}
76  			tool.exec();
77  		} catch (Throwable e) {
78  			e.printStackTrace();
79  		}
80  	}
81  
82  	public Journal createJournal() throws Exception {
83  		Configuration c = new Configuration();
84  		c.setLogFileDir(journalDirectory.getPath());
85  		c.setMaxLogFiles(maxLogFiles);
86  		c.setBufferSize(bufferSize);
87  		c.setMaxBuffers(maxBuffers);
88  		c.setMaxBlocksPerFile(maxBlocksPerFile);
89  		return new HowlJournal( c );
90  	}
91  	
92  }