SCViewer/com.minres.scviewer.databas.../src/com/minres/scviewer/database/text/TxStream.groovy

111 lines
2.8 KiB
Groovy
Raw Normal View History

2012-06-17 20:34:50 +02:00
/*******************************************************************************
* Copyright (c) 2012 IT Just working.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IT Just working - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.database.text
2012-06-17 19:53:05 +02:00
import java.beans.PropertyChangeListener;
2015-01-20 18:50:15 +01:00
import java.util.Collection;
import java.util.Comparator;
2012-06-17 19:53:05 +02:00
import java.util.List;
import java.util.Map;
2015-01-20 18:50:15 +01:00
import java.util.NavigableMap;
2012-06-17 19:53:05 +02:00
2015-01-20 18:50:15 +01:00
import com.google.common.collect.TreeMultimap;
2015-01-06 17:14:16 +01:00
import com.minres.scviewer.database.HierNode;
2015-01-20 18:50:15 +01:00
import com.minres.scviewer.database.ITxEvent;
import com.minres.scviewer.database.IWaveform;
2015-01-06 17:14:16 +01:00
import com.minres.scviewer.database.IWaveformDb
import com.minres.scviewer.database.ITxGenerator
import com.minres.scviewer.database.IHierNode
import com.minres.scviewer.database.ITxStream
import com.minres.scviewer.database.ITx
2012-06-17 19:53:05 +02:00
2015-01-06 17:14:16 +01:00
class TxStream extends HierNode implements ITxStream {
2015-01-01 23:17:32 +01:00
2015-01-20 18:50:15 +01:00
Long id
2015-01-01 23:17:32 +01:00
IWaveformDb database
2015-01-01 23:17:32 +01:00
2015-01-20 18:50:15 +01:00
String fullName
2015-01-01 23:17:32 +01:00
2015-01-20 18:50:15 +01:00
String kind
2015-01-01 23:17:32 +01:00
2015-01-20 18:50:15 +01:00
def generators = []
int maxConcurrency
private TreeMap<Long, List<ITxEvent>> events
2015-01-01 23:17:32 +01:00
TxStream(IWaveformDb db, int id, String name, String kind){
2015-01-06 17:14:16 +01:00
super(name)
2012-06-17 19:53:05 +02:00
this.id=id
this.database=db
this.fullName=name
this.kind=kind
2015-01-20 18:50:15 +01:00
this.maxConcurrency=0
events = new TreeMap<Long, List<ITxEvent>>()
2012-06-17 19:53:05 +02:00
}
2015-01-06 17:14:16 +01:00
List<ITxGenerator> getGenerators(){
return generators as List<ITxGenerator>
2012-06-17 19:53:05 +02:00
}
@Override
2015-01-06 17:14:16 +01:00
public IWaveformDb getDb() {
2015-01-20 18:50:15 +01:00
return database
2012-06-17 19:53:05 +02:00
}
2015-01-20 18:50:15 +01:00
@Override
public int getMaxConcurrency() {
if(!maxConcurrency){
generators.each {TxGenerator generator ->
generator.transactions.each{ Tx tx ->
putEvent(new TxEvent(ITxEvent.Type.BEGIN, tx))
putEvent(new TxEvent(ITxEvent.Type.END, tx))
2015-01-01 23:17:32 +01:00
}
2015-01-20 18:50:15 +01:00
}
def rowendtime = [0]
events.keySet().each{long time ->
def value=events.get(time)
def starts=value.findAll{ITxEvent event ->event.type==ITxEvent.Type.BEGIN}
starts.each {ITxEvent event ->
Tx tx = event.transaction
def rowIdx = 0
for(rowIdx=0; rowIdx<rowendtime.size() && rowendtime[rowIdx]>tx.beginTime; rowIdx++);
if(rowendtime.size<=rowIdx)
rowendtime<<tx.endTime
else
rowendtime[rowIdx]=tx.endTime
tx.concurrencyIndex=rowIdx
}
}
maxConcurrency=rowendtime.size()
2012-06-17 19:53:05 +02:00
}
2015-01-20 18:50:15 +01:00
return maxConcurrency
2012-06-17 19:53:05 +02:00
}
2015-01-20 18:50:15 +01:00
private putEvent(ITxEvent event){
if(!events.containsKey(event.time))
events.put(event.time, [event])
else
events[event.time]<<event
2015-01-20 18:50:15 +01:00
}
2012-06-17 19:53:05 +02:00
@Override
2015-01-20 18:50:15 +01:00
public NavigableMap getEvents() {
return events;
2012-06-17 19:53:05 +02:00
}
@Override
2015-01-20 18:50:15 +01:00
public Collection getWaveformEventsAtTime(Long time) {
return events.get(time);
}
2012-06-17 19:53:05 +02:00
}