001: ///////////////////////////////////////////////////////////////////////////////
002: //
003: // Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
004: //
005: // All Rights Reserved
006: //
007: // This program is free software; you can redistribute it and/or modify
008: // it under the terms of the GNU General Public License and GNU Library
009: // General Public License as published by the Free Software Foundation;
010: // either version 2, or (at your option) any later version.
011: //
012: // This program is distributed in the hope that it will be useful,
013: // but WITHOUT ANY WARRANTY; without even the implied warranty of
014: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: // GNU General Public License and GNU Library General Public License
016: // for more details.
017: //
018: // You should have received a copy of the GNU General Public License
019: // and GNU Library General Public License along with this program; if
020: // not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
021: // MA 02139, USA.
022: //
023: ///////////////////////////////////////////////////////////////////////////////
024: package org.myoodb.performance;
025:
026: public class LogClient {
027: public static int PORT = 54321;
028: public static String USERNAME = "admin";
029: public static String PASSWORD = "admin";
030:
031: public static void main(String args[]) throws Exception {
032: StreamProtocolClient.register(); // use optimized object protocol definitions
033:
034: org.myoodb.MyOodbDatabase db = org.myoodb.MyOodbDatabase.open(
035: "tcp://localhost:" + PORT, USERNAME, PASSWORD);
036:
037: org.myoodb.collectable.LogObject logObject = null;
038: org.myoodb.collectable.LogStore root = (org.myoodb.collectable.LogStore) db
039: .getRoot("LogStore");
040: if (root == null) {
041: root = (org.myoodb.collectable.LogStore) db
042: .createRoot("LogStore",
043: "org.myoodb.collectable.LogStoreDbImpl");
044: //root = (org.myoodb.collectable.LogStore) db.createRoot("LogStore", org.myoodb.collectable.LogStoreDbImpl.class);
045:
046: System.out.println("\nTiming log create/add/find: 1250");
047: long start = System.currentTimeMillis();
048: for (int i = 0; i < 1250; i++) {
049: logObject = (org.myoodb.collectable.LogObject) db
050: .createObject("org.myoodb.collectable.LogObjectDbImpl");
051: //logObject = (org.myoodb.collectable.LogObject) db.createObject(org.myoodb.collectable.LogObjectDbImpl.class);
052:
053: // XXX: LogStore.addLogObject can/will set time
054: //logObject.setTime(time);
055:
056: // XXX: LogObject.setLogStore is not in side LogStore.addLogObject so that
057: // if the LogObject is locked, it does not lock the LogStore.
058: logObject.setLogStore(root);
059: root.addLogObject(logObject);
060:
061: System.out.print(".");
062: System.out.flush();
063:
064: if (logObject.equals(root.getLogObject(logObject
065: .getTime())) == false) {
066: System.out.println("\nLogObject not found: "
067: + logObject.getTime());
068: }
069: }
070: long stop = System.currentTimeMillis();
071: System.out.println("Total time(ms): " + (stop - start)
072: + ", " + root);
073: } else {
074: System.out
075: .println("\nTiming log access/find ( in one big get ): "
076: + root);
077:
078: long start = System.currentTimeMillis();
079:
080: java.util.ArrayList<org.myoodb.collectable.LogObject> logs = root
081: .getLogObjects();
082:
083: long stop = System.currentTimeMillis();
084:
085: System.out.println("Total time(ms): " + (stop - start));
086:
087: java.util.Iterator iter = logs.iterator();
088: for (int i = 0; iter.hasNext(); i++) {
089: logObject = (org.myoodb.collectable.LogObject) iter
090: .next();
091:
092: System.out.print(i + ":" + logObject.getTime() + ",");
093: System.out.flush();
094:
095: if (logObject.equals(root.getLogObject(logObject
096: .getTime())) == false) {
097: System.out.println("LogObject not found: "
098: + logObject.getTime());
099: }
100: }
101: }
102: }
103: }
|