KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > myoodb > performance > Client


1 ///////////////////////////////////////////////////////////////////////////////
2
//
3
// Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
4
//
5
// All Rights Reserved
6
//
7
// This program is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License and GNU Library
9
// General Public License as published by the Free Software Foundation;
10
// either version 2, or (at your option) any later version.
11
//
12
// This program is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License and GNU Library General Public License
16
// for more details.
17
//
18
// You should have received a copy of the GNU General Public License
19
// and GNU Library General Public License along with this program; if
20
// not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
21
// MA 02139, USA.
22
//
23
///////////////////////////////////////////////////////////////////////////////
24
package org.myoodb.performance;
25
26 public class Client
27 {
28     public static int PORT = 54321;
29     public static String JavaDoc USERNAME = "admin";
30     public static String JavaDoc PASSWORD = "admin";
31
32     public static void main(String JavaDoc args[]) throws Exception JavaDoc
33     {
34         StreamProtocolClient.register(); // use optimized object protocol definitions
35

36         org.myoodb.MyOodbDatabase db = org.myoodb.MyOodbDatabase.open("myoodb://localhost:" + PORT, USERNAME, PASSWORD);
37
38         org.myoodb.collectable.LogStore root = (org.myoodb.collectable.LogStore) db.getRoot("LogStore");
39         org.myoodb.collectable.LogObject logObject = null;
40
41         if (root == null)
42         {
43             root = (org.myoodb.collectable.LogStore) db.createRoot("org.myoodb.collectable.LogStoreDbImpl", "LogStore");
44             //root = (org.myoodb.collectable.LogStore) db.createRoot(org.myoodb.collectable.LogStoreDbImpl.class, "LogStore");
45

46             logObject = (org.myoodb.collectable.LogObject) db.createObject("org.myoodb.collectable.LogObjectDbImpl");
47             //logObject = (org.myoodb.collectable.LogObject) db.createObject(org.myoodb.collectable.LogObjectDbImpl.class);
48

49             System.out.println("Timing object access: 250");
50             long start = System.currentTimeMillis();
51             for (int i = 0; i < 250; i++)
52             {
53                 logObject.getTime();
54             }
55             long stop = System.currentTimeMillis();
56             System.out.println("Total time(ms): " + (stop-start));
57
58             System.out.println("\nTiming object update: 250");
59             start = System.currentTimeMillis();
60             for (int i = 0; i < 250; i++)
61             {
62                 logObject.setTime(123);
63             }
64             stop = System.currentTimeMillis();
65             System.out.println("Total time(ms): " + (stop-start));
66
67             // XXX: LogObject.setLogStore is not in side LogStore.addLogObject so that if the LogObject is locked, it
68
// XXX: does not lock LogStore.LogStore to LogObject association determines when the LogObject is time
69
// XXX: stamped
70
logObject.setLogStore(root);
71             root.addLogObject(logObject);
72
73             System.out.println("\nTiming log create/add: 250");
74             start = System.currentTimeMillis();
75             for (int i = 0; i < 250; i++)
76             {
77                 logObject = (org.myoodb.collectable.LogObject) db.createObject("org.myoodb.collectable.LogObjectDbImpl");
78                 //logObject = (org.myoodb.collectable.LogObject) db.createObject(org.myoodb.collectable.LogObjectDbImpl.class);
79

80                 // XXX: LogObject.setLogStore is not in side LogStore.addLogObject so that if the LogObject is locked, it
81
// XXX: does not lock LogStore. LogStore to LogObject association determines when the LogObject is time
82
// XXX: stamped.
83
logObject.setLogStore(root);
84                 root.addLogObject(logObject);
85             }
86             stop = System.currentTimeMillis();
87             System.out.println("Total time(ms): " + (stop-start));
88         }
89         else
90         {
91             System.out.println("\nTiming log access ( in one big get ): 251");
92
93             long start = System.currentTimeMillis();
94
95             java.util.ArrayList JavaDoc<org.myoodb.collectable.LogObject> logs = root.getLogObjects();
96
97             long stop = System.currentTimeMillis();
98
99             System.out.println("Total time(ms): " + (stop-start));
100
101             java.util.Iterator JavaDoc iter = logs.iterator();
102             while (iter.hasNext())
103             {
104                 logObject = (org.myoodb.collectable.LogObject) iter.next();
105
106                 System.out.println(" Log Entry: " + logObject);
107             }
108         }
109     }
110 }
111
Popular Tags