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

86 lines
2.2 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;
import java.util.List;
import java.util.Map;
2015-01-06 17:14:16 +01:00
import com.minres.scviewer.database.HierNode;
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
2012-06-17 19:53:05 +02:00
Long id;
2015-01-01 23:17:32 +01:00
TextDb database
2015-01-01 23:17:32 +01:00
2012-06-17 19:53:05 +02:00
String fullName;
2015-01-01 23:17:32 +01:00
2012-06-17 19:53:05 +02:00
String kind;
2015-01-01 23:17:32 +01:00
2012-06-17 19:53:05 +02:00
def generators = [];
2015-01-01 23:17:32 +01:00
2015-01-09 09:16:40 +01:00
private TreeSet<Tx> allTransactions;
2015-01-01 23:17:32 +01:00
2015-01-06 17:14:16 +01:00
TxStream(int id, TextDb db, String name, String kind){
super(name)
2012-06-17 19:53:05 +02:00
this.id=id
this.database=db
this.fullName=name
this.kind=kind
}
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() {
2012-06-17 19:53:05 +02:00
return database;
}
// FIXME: maybe need to be somewhere else
2012-06-17 19:53:05 +02:00
public int getMaxConcurrrentTx() {
def rowendtime = [0]
2015-01-06 17:14:16 +01:00
getTransactions().each{Tx tx ->
2012-06-17 19:53:05 +02:00
def rowIdx = 0
for(rowIdx=0; rowendtime.size()<rowIdx || rowendtime[rowIdx]>tx.beginTime.value; rowIdx++);
2015-01-01 23:17:32 +01:00
if(rowendtime.size<=rowIdx){
rowendtime<<tx.endTime?.value?:tx.beginTime.value+1
} else {
rowendtime[rowIdx]=tx.endTime?.value?:tx.beginTime.value+1
}
2012-06-17 19:53:05 +02:00
}
return rowendtime.size()
}
@Override
2015-01-09 09:16:40 +01:00
public NavigableSet<ITx> getTransactions() {
if(!allTransactions){
allTransactions=new TreeSet<Tx>()
allTransactions.addAll(generators.transactions.flatten())
}
2012-06-17 19:53:05 +02:00
return allTransactions
}
@Override
2015-01-06 17:14:16 +01:00
public ITx getTransactionById(long id) {
if(!allTransactions)
allTransactions=generators.transactions.flatten().sort{it.beginTime.value}
allTransactions.find{it.id==id}
}
2012-06-17 19:53:05 +02:00
}