KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > tools > Statistics


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id: Statistics.java,v 1.3 2002/12/29 11:15:58 per_nyfelt Exp $
8

9 package org.ozoneDB.tools;
10
11 import org.ozoneDB.DxLib.DxObject;
12 import org.ozoneDB.io.stream.ResolvingObjectInputStream;
13
14 import java.io.*;
15
16
17 public class Statistics extends Object JavaDoc {
18     static String JavaDoc dir = File.separator + "stats";
19     public static String JavaDoc clusp = new String JavaDoc( "clusp" );
20
21
22     public static void main( String JavaDoc[] args ) {
23         try {
24             String JavaDoc odbdir = args[0].toString();
25             System.out.println( "ODB3X statistics" );
26             System.out.println( "----------------" );
27             printLastOID( odbdir );
28             printStats( odbdir );
29         } catch (Exception JavaDoc e) {
30             System.out.println( "\nusage: java Statistics <dir>" );
31             System.exit( 1 );
32         }
33     }
34
35
36     public static void printLastOID( String JavaDoc odbdir ) {
37     // FIXME:
38
// try {
39
// File f = new File (odbdir, Env.OID_FILE);
40
// RandomAccessFile rf = new RandomAccessFile (f, "rw");
41
// long id = rf.readLong ();
42
// System.out.println ("DatabaseID : " + (id>>40));
43
// System.out.println ("ObjectID count : " + (id & 0xFFFFF));
44
// System.out.println ("ClusterID count : " + (rf.readLong() & 0xFFFFF));
45
// System.out.println ("TransactionID count : " + (rf.readLong() & 0xFFFFF));
46
// rf.close ();
47
// } catch (IOException e) {
48
// System.err.println (e);
49
// }
50
}
51
52
53     public static void printStats( String JavaDoc odbdir ) {
54         System.out.print( "\nClusterSpace stats:" );
55         System.out.println( readClusterStats( odbdir ) );
56     }
57
58
59     public static void writeStats( DxObject cs, String JavaDoc path, String JavaDoc file ) {
60         try {
61             File f = new File( path + dir );
62             if (!f.exists()) {
63                 f.mkdir();
64             }
65             f = new File( path + dir, file );
66             FileOutputStream fo = new FileOutputStream( f );
67             ObjectOutputStream os = new ObjectOutputStream( fo );
68             os.writeObject( cs );
69             os.close();
70         } catch (Exception JavaDoc e) {
71             System.out.println( e );
72         }
73     }
74
75
76     public static DxObject readStats( String JavaDoc path, String JavaDoc file ) {
77         try {
78             File f = new File( path + dir, file );
79             FileInputStream fi = new FileInputStream( f );
80             ObjectInputStream is = new ResolvingObjectInputStream( fi );
81             DxObject obj = (DxObject)is.readObject();
82             fi.close();
83             return obj;
84         } catch (FileNotFoundException e) {
85         // nichts tun, wenn file nicht da, wird spaeter angelegt
86
} catch (Exception JavaDoc e) {
87             System.out.println( e );
88         }
89         return null;
90     }
91
92
93     public static void writeClusterStats( ClusterStats cs, String JavaDoc path ) {
94         writeStats( cs, path, clusp );
95     }
96
97
98     public static ClusterStats readClusterStats( String JavaDoc path ) {
99         ClusterStats cs = (ClusterStats)Statistics.readStats( path, clusp );
100         if (cs == null) {
101             cs = new ClusterStats();
102             writeClusterStats( cs, path );
103         }
104         return cs;
105     }
106 }
107
Popular Tags