001: // kelondroProfile.java
002: // (C) 2006 by Michael Peter Christen; mc@anomic.de, Frankfurt a. M., Germany
003: // first published 23.06.2006 on http://www.anomic.de
004: //
005: // This is a part of the kelondro database,
006: // which is a part of YaCy, a peer-to-peer based web search engine
007: //
008: // $LastChangedDate: 2006-04-02 22:40:07 +0200 (So, 02 Apr 2006) $
009: // $LastChangedRevision: 1986 $
010: // $LastChangedBy: orbiter $
011: //
012: // LICENSE
013: //
014: // This program is free software; you can redistribute it and/or modify
015: // it under the terms of the GNU General Public License as published by
016: // the Free Software Foundation; either version 2 of the License, or
017: // (at your option) any later version.
018: //
019: // This program is distributed in the hope that it will be useful,
020: // but WITHOUT ANY WARRANTY; without even the implied warranty of
021: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
022: // GNU General Public License for more details.
023: //
024: // You should have received a copy of the GNU General Public License
025: // along with this program; if not, write to the Free Software
026: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
027:
028: package de.anomic.kelondro;
029:
030: public class kelondroProfile implements Cloneable {
031:
032: private long accRead;
033: private long accWrite;
034: private long accDelete;
035:
036: public kelondroProfile() {
037: accRead = 0;
038: accWrite = 0;
039: accDelete = 0;
040: }
041:
042: public long timeRead() {
043: return accRead;
044: }
045:
046: public long timeWrite() {
047: return accWrite;
048: }
049:
050: public long timeDelete() {
051: return accDelete;
052: }
053:
054: public void timeReset() {
055: accRead = 0;
056: accWrite = 0;
057: accDelete = 0;
058: }
059:
060: protected long startRead() {
061: return System.currentTimeMillis();
062: }
063:
064: protected void stopRead(long handle) {
065: accRead += System.currentTimeMillis() - handle;
066: }
067:
068: protected long startWrite() {
069: return System.currentTimeMillis();
070: }
071:
072: protected void stopWrite(long handle) {
073: accWrite += System.currentTimeMillis() - handle;
074: }
075:
076: protected long startDelete() {
077: return System.currentTimeMillis();
078: }
079:
080: protected void stopDelete(long handle) {
081: accDelete += System.currentTimeMillis() - handle;
082: }
083:
084: public Object clone() {
085: kelondroProfile clone = new kelondroProfile();
086: clone.accRead = this .accRead;
087: clone.accWrite = this .accWrite;
088: clone.accDelete = this .accDelete;
089: return clone;
090: }
091:
092: public String toString() {
093: return "read=" + accRead + ", write=" + accWrite + ", delete="
094: + accDelete;
095: }
096:
097: public static kelondroProfile consolidate(kelondroProfile[] profiles) {
098: for (int i = 1; i < profiles.length; i++)
099: consolidate(profiles[0], profiles[i]);
100: return profiles[0];
101: }
102:
103: public static kelondroProfile consolidate(kelondroProfile profile1,
104: kelondroProfile profile2) {
105: profile1.accRead += profile2.accRead;
106: profile1.accWrite += profile2.accWrite;
107: profile1.accDelete += profile2.accDelete;
108: return profile1;
109: }
110:
111: public static kelondroProfile delta(kelondroProfile newer,
112: kelondroProfile older) {
113: kelondroProfile result = new kelondroProfile();
114: result.accRead = newer.accRead - older.accRead;
115: result.accWrite = newer.accWrite - older.accWrite;
116: result.accDelete = newer.accDelete - older.accDelete;
117: return result;
118: }
119: }
|