refactor groovy classes to Java, 1st step
This commit is contained in:
parent
4d8e7a3cd1
commit
a51f922ea4
|
@ -18,5 +18,6 @@
|
|||
<classpathentry exported="true" kind="lib" path="lib/kotlin-stdlib-1.2.42.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/lz4-1.3.0.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/elsa-3.0.0-M5.jar"/>
|
||||
<classpathentry kind="con" path="GROOVY_DSL_SUPPORT"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
|
|
|
@ -1,245 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
import java.nio.charset.CharsetDecoder;
|
||||
import java.util.Collection;
|
||||
import java.util.zip.GZIPInputStream
|
||||
|
||||
import org.codehaus.groovy.ast.stmt.CatchStatement
|
||||
import org.mapdb.DB
|
||||
import org.mapdb.DBMaker
|
||||
|
||||
import groovy.io.FileType
|
||||
|
||||
import com.minres.scviewer.database.AssociationType
|
||||
import com.minres.scviewer.database.DataType
|
||||
import com.minres.scviewer.database.IWaveform
|
||||
import com.minres.scviewer.database.IWaveformDb
|
||||
import com.minres.scviewer.database.IWaveformDbLoader
|
||||
import com.minres.scviewer.database.InputFormatException
|
||||
import com.minres.scviewer.database.RelationType
|
||||
import com.minres.scviewer.database.tx.ITxGenerator
|
||||
|
||||
public class TextDbLoader implements IWaveformDbLoader{
|
||||
|
||||
private Long maxTime;
|
||||
|
||||
IWaveformDb db;
|
||||
|
||||
def streams = []
|
||||
|
||||
def relationTypes=[:]
|
||||
|
||||
DB mapDb
|
||||
|
||||
public TextDbLoader() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getMaxTime() {
|
||||
return maxTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IWaveform> getAllWaves() {
|
||||
return streams;
|
||||
}
|
||||
|
||||
public Map<Long, ITxGenerator> getGeneratorsById() {
|
||||
TreeMap<Long, ITxGenerator> res = new TreeMap<Long, ITxGenerator>();
|
||||
streams.each{TxStream stream -> stream.generators.each{res.put(it.id, id)} }
|
||||
return res;
|
||||
}
|
||||
|
||||
static final byte[] x = "scv_tr_stream".bytes
|
||||
|
||||
@Override
|
||||
boolean load(IWaveformDb db, File file) throws InputFormatException {
|
||||
if(file.isDirectory() || !file.exists()) return false;
|
||||
this.db=db
|
||||
this.streams=[]
|
||||
try {
|
||||
def gzipped = isGzipped(file)
|
||||
if(isTxfile(gzipped?new GZIPInputStream(new FileInputStream(file)):new FileInputStream(file))){
|
||||
def mapDbFile = File.createTempFile("."+file.name, null /*"tmp"*/, null /*file.parentFile*/)
|
||||
mapDbFile.delete()
|
||||
mapDbFile.deleteOnExit()
|
||||
this.mapDb = DBMaker
|
||||
.fileDB(mapDbFile)
|
||||
.fileMmapEnableIfSupported()
|
||||
.fileMmapPreclearDisable()
|
||||
.cleanerHackEnable()
|
||||
.allocateStartSize(64*1024*1024)
|
||||
.allocateIncrement(64*1024*1024)
|
||||
.make()
|
||||
// NPE here --->
|
||||
parseInput(gzipped?new GZIPInputStream(new FileInputStream(file)):new FileInputStream(file))
|
||||
streams.each{ TxStream stream -> stream.getWidth() }
|
||||
return true
|
||||
}
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
return false
|
||||
} catch (IllegalArgumentException e) {
|
||||
return false
|
||||
} catch (NumberFormatException e) {
|
||||
return false
|
||||
} catch(EOFException e) {
|
||||
return true;
|
||||
} catch(Exception e) {
|
||||
System.out.println("---->>> Exception "+e.toString()+" caught while loading database");
|
||||
//System.out.println("---->>> Exception "+e.toString()+" caught while loading database. StackTrace following... ");
|
||||
//e.printStackTrace()
|
||||
} catch(Error e) {
|
||||
System.out.println("---->>> Exception "+e.toString()+" caught while loading database. StackTrace following... ");
|
||||
e.printStackTrace()
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isTxfile(InputStream istream) {
|
||||
byte[] buffer = new byte[x.size()]
|
||||
def readCnt = istream.read(buffer, 0, x.size())
|
||||
istream.close()
|
||||
if(readCnt==x.size()){
|
||||
for(int i=0; i<x.size(); i++)
|
||||
if(buffer[i]!=x[i]) return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private static boolean isGzipped(File f) {
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = new FileInputStream(f);
|
||||
byte [] signature = new byte[2];
|
||||
int nread = is.read( signature ); //read the gzip signature
|
||||
return nread == 2 && signature[ 0 ] == (byte) 0x1f && signature[ 1 ] == (byte) 0x8b;
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
} finally {
|
||||
if(is!=null) is.close()
|
||||
}
|
||||
}
|
||||
|
||||
private stringToScale(String scale){
|
||||
switch(scale.trim()){
|
||||
case "fs":return 1L
|
||||
case "ps":return 1000L
|
||||
case "ns":return 1000000L
|
||||
case "us":return 1000000000L
|
||||
case "ms":return 1000000000000L
|
||||
case "s": return 1000000000000000L
|
||||
}
|
||||
return 1L
|
||||
}
|
||||
|
||||
private def parseInput(InputStream inputStream){
|
||||
def streamsById = [:]
|
||||
def generatorsById = [:]
|
||||
def transactionsById = [:]
|
||||
TxGenerator generator
|
||||
Tx transaction
|
||||
boolean endTransaction=false
|
||||
def matcher
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
|
||||
long lineCnt=0;
|
||||
reader.eachLine { line ->
|
||||
def tokens = line.split(/\s+/) as ArrayList
|
||||
switch(tokens[0]){
|
||||
case "scv_tr_stream":
|
||||
if ((matcher = line =~ /^scv_tr_stream\s+\(ID (\d+),\s+name\s+"([^"]+)",\s+kind\s+"([^"]+)"\)$/)) {
|
||||
def id = Integer.parseInt(matcher[0][1])
|
||||
def stream = new TxStream(this, id, matcher[0][2], matcher[0][3])
|
||||
streams<<stream
|
||||
streamsById[id]=stream
|
||||
}
|
||||
break;
|
||||
case "scv_tr_generator":
|
||||
if ((matcher = line =~ /^scv_tr_generator\s+\(ID\s+(\d+),\s+name\s+"([^"]+)",\s+scv_tr_stream\s+(\d+),$/)) {
|
||||
def id = Integer.parseInt(matcher[0][1])
|
||||
TxStream stream=streamsById[Integer.parseInt(matcher[0][3])] as TxStream
|
||||
generator=new TxGenerator(id, stream, matcher[0][2])
|
||||
stream.generators<<generator
|
||||
generatorsById[id]=generator
|
||||
}
|
||||
break;
|
||||
case "begin_attribute":
|
||||
if ((matcher = line =~ /^begin_attribute \(ID (\d+), name "([^"]+)", type "([^"]+)"\)$/)) {
|
||||
generator.begin_attrs << TxAttributeType.getAttrType(matcher[0][2], DataType.valueOf(matcher[0][3]), AssociationType.BEGIN)
|
||||
}
|
||||
break;
|
||||
case "end_attribute":
|
||||
if ((matcher = line =~ /^end_attribute \(ID (\d+), name "([^"]+)", type "([^"]+)"\)$/)) {
|
||||
generator.end_attrs << TxAttributeType.getAttrType(matcher[0][2], DataType.valueOf(matcher[0][3]), AssociationType.END)
|
||||
}
|
||||
break;
|
||||
case ")":
|
||||
generator=null
|
||||
break
|
||||
case "tx_begin"://matcher = line =~ /^tx_begin\s+(\d+)\s+(\d+)\s+(\d+)\s+([munpf]?s)/
|
||||
def id = Integer.parseInt(tokens[1])
|
||||
TxGenerator gen=generatorsById[Integer.parseInt(tokens[2])]
|
||||
transaction = new Tx(id, gen.stream, gen, Long.parseLong(tokens[3])*stringToScale(tokens[4]))
|
||||
gen.transactions << transaction
|
||||
transactionsById[id]= transaction
|
||||
gen.begin_attrs_idx=0;
|
||||
maxTime = maxTime>transaction.beginTime?maxTime:transaction.beginTime
|
||||
endTransaction=false
|
||||
break
|
||||
case "tx_end"://matcher = line =~ /^tx_end\s+(\d+)\s+(\d+)\s+(\d+)\s+([munpf]?s)/
|
||||
def id = Integer.parseInt(tokens[1])
|
||||
transaction = transactionsById[id]
|
||||
assert Integer.parseInt(tokens[2])==transaction.generator.id
|
||||
transaction.endTime = Long.parseLong(tokens[3])*stringToScale(tokens[4])
|
||||
transaction.generator.end_attrs_idx=0;
|
||||
maxTime = maxTime>transaction.endTime?maxTime:transaction.endTime
|
||||
endTransaction=true
|
||||
break
|
||||
case "tx_record_attribute"://matcher = line =~ /^tx_record_attribute\s+(\d+)\s+"([^"]+)"\s+(\S+)\s*=\s*(.+)$/
|
||||
def id = Integer.parseInt(tokens[1])
|
||||
def name = tokens[2][1..-2]
|
||||
def type = tokens[3] as DataType
|
||||
def remaining = tokens.size()>5?tokens[5..-1].join(' '):""
|
||||
transactionsById[id].attributes<<new TxAttribute(name, type, AssociationType.RECORD, remaining)
|
||||
break
|
||||
case "a"://matcher = line =~ /^a\s+(.+)$/
|
||||
if(endTransaction){
|
||||
transaction.attributes << new TxAttribute(transaction.generator.end_attrs[transaction.generator.end_attrs_idx], tokens[1])
|
||||
transaction.generator.end_attrs_idx++
|
||||
} else {
|
||||
transaction.attributes << new TxAttribute(transaction.generator.begin_attrs[transaction.generator.begin_attrs_idx], tokens[1])
|
||||
transaction.generator.begin_attrs_idx++
|
||||
}
|
||||
break
|
||||
case "tx_relation"://matcher = line =~ /^tx_relation\s+\"(\S+)\"\s+(\d+)\s+(\d+)$/
|
||||
Tx tr2= transactionsById[Integer.parseInt(tokens[2])]
|
||||
Tx tr1= transactionsById[Integer.parseInt(tokens[3])]
|
||||
def relType=tokens[1][1..-2]
|
||||
if(!relationTypes.containsKey(relType)) relationTypes[relType]=RelationType.create(relType)
|
||||
def rel = new TxRelation(relationTypes[relType], tr1, tr2)
|
||||
tr1.outgoingRelations<<rel
|
||||
tr2.incomingRelations<<rel
|
||||
break
|
||||
default:
|
||||
println "Don't know what to do with: '$line'"
|
||||
|
||||
}
|
||||
lineCnt++
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<RelationType> getAllRelationTypes(){
|
||||
return relationTypes.values();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,268 @@
|
|||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.EOFException;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import org.mapdb.DB;
|
||||
import org.mapdb.DBMaker;
|
||||
|
||||
import com.minres.scviewer.database.AssociationType;
|
||||
import com.minres.scviewer.database.DataType;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.IWaveformDbLoader;
|
||||
import com.minres.scviewer.database.InputFormatException;
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
import com.minres.scviewer.database.tx.ITxGenerator;
|
||||
|
||||
public class TextDbLoader implements IWaveformDbLoader{
|
||||
|
||||
private Long maxTime=0L;
|
||||
|
||||
IWaveformDb db;
|
||||
|
||||
List<IWaveform> streams;
|
||||
|
||||
Map<String, RelationType> relationTypes=new HashMap<String, RelationType>();
|
||||
|
||||
DB mapDb;
|
||||
|
||||
public TextDbLoader() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getMaxTime() {
|
||||
return maxTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IWaveform> getAllWaves() {
|
||||
return streams;
|
||||
}
|
||||
|
||||
public Map<Long, ITxGenerator> getGeneratorsById() {
|
||||
TreeMap<Long, ITxGenerator> res = new TreeMap<Long, ITxGenerator>();
|
||||
for(IWaveform stream: streams){ for(ITxGenerator it: ((TxStream)stream).getGenerators()){res.put(it.getId(), it);} }
|
||||
return res;
|
||||
}
|
||||
|
||||
static final byte[] x = "scv_tr_stream".getBytes();
|
||||
|
||||
@Override
|
||||
public boolean load(IWaveformDb db, File file) throws InputFormatException {
|
||||
if(file.isDirectory() || !file.exists()) return false;
|
||||
this.db=db;
|
||||
this.streams = new ArrayList<>();
|
||||
try {
|
||||
boolean gzipped = isGzipped(file);
|
||||
if(isTxfile(gzipped?new GZIPInputStream(new FileInputStream(file)):new FileInputStream(file))){
|
||||
File mapDbFile = File.createTempFile("."+file.getName(), null /*"tmp"*/, null /*file.parentFile*/);
|
||||
mapDbFile.delete();
|
||||
mapDbFile.deleteOnExit();
|
||||
this.mapDb = DBMaker
|
||||
.fileDB(mapDbFile)
|
||||
.fileMmapEnableIfSupported()
|
||||
.fileMmapPreclearDisable()
|
||||
.cleanerHackEnable()
|
||||
.allocateStartSize(64*1024*1024)
|
||||
.allocateIncrement(64*1024*1024)
|
||||
.make();
|
||||
// NPE here --->
|
||||
parseInput(gzipped?new GZIPInputStream(new FileInputStream(file)):new FileInputStream(file));
|
||||
for(IWaveform stream: streams){ stream.getWidth(); }
|
||||
return true;
|
||||
}
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
return false;
|
||||
} catch (IllegalArgumentException e) {
|
||||
return false;
|
||||
} catch(EOFException e) {
|
||||
return true;
|
||||
} catch(Exception e) {
|
||||
System.out.println("---->>> Exception "+e.toString()+" caught while loading database");
|
||||
e.printStackTrace();
|
||||
} catch(Error e) {
|
||||
System.out.println("---->>> Exception "+e.toString()+" caught while loading database. StackTrace following... ");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isTxfile(InputStream istream) {
|
||||
byte[] buffer = new byte[x.length];
|
||||
try {
|
||||
int readCnt = istream.read(buffer, 0, x.length);
|
||||
istream.close();
|
||||
if(readCnt==x.length){
|
||||
for(int i=0; i<x.length; i++)
|
||||
if(buffer[i]!=x[i]) return false;
|
||||
}
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isGzipped(File f) {
|
||||
try(InputStream is = new FileInputStream(f)) {
|
||||
byte [] signature = new byte[2];
|
||||
int nread = is.read( signature ); //read the gzip signature
|
||||
return nread == 2 && signature[ 0 ] == (byte) 0x1f && signature[ 1 ] == (byte) 0x8b;
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private long stringToScale(String scale){
|
||||
String cmp = scale.trim();
|
||||
if("fs".equals(cmp)) return 1L;
|
||||
if("ps".equals(cmp)) return 1000L;
|
||||
if("ns".equals(cmp)) return 1000000L;
|
||||
if("us".equals(cmp)) return 1000000000L;
|
||||
if("ms".equals(cmp)) return 1000000000000L;
|
||||
if("s".equals(cmp) ) return 1000000000000000L;
|
||||
return 1L;
|
||||
}
|
||||
|
||||
static final Pattern scv_tr_stream = Pattern.compile("^scv_tr_stream\\s+\\(ID (\\d+),\\s+name\\s+\"([^\"]+)\",\\s+kind\\s+\"([^\"]+)\"\\)$");
|
||||
static final Pattern scv_tr_generator = Pattern.compile("^scv_tr_generator\\s+\\(ID\\s+(\\d+),\\s+name\\s+\"([^\"]+)\",\\s+scv_tr_stream\\s+(\\d+),$");
|
||||
static final Pattern begin_attribute = Pattern.compile("^begin_attribute \\(ID (\\d+), name \"([^\"]+)\", type \"([^\"]+)\"\\)$");
|
||||
static final Pattern end_attribute = Pattern.compile("^end_attribute \\(ID (\\d+), name \"([^\"]+)\", type \"([^\"]+)\"\\)$");
|
||||
|
||||
HashMap<Long, TxStream> streamsById = new HashMap<Long, TxStream>();
|
||||
HashMap<Long, TxGenerator> generatorsById = new HashMap<Long, TxGenerator>();
|
||||
HashMap<Long, Tx> transactionsById = new HashMap<Long, Tx>();
|
||||
TxGenerator generator = null;
|
||||
Tx transaction = null;
|
||||
boolean endTransaction=false;
|
||||
BufferedReader reader =null;
|
||||
|
||||
private void parseInput(InputStream inputStream) throws IOException{
|
||||
reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
|
||||
String curLine = reader.readLine();
|
||||
String nextLine = null;
|
||||
while((nextLine=reader.readLine())!=null && curLine!=null) {
|
||||
curLine=parseLine(curLine, nextLine);
|
||||
}
|
||||
if(curLine!=null)
|
||||
parseLine(curLine, nextLine);
|
||||
}
|
||||
|
||||
private String parseLine(String curLine, String nextLine) throws IOException{
|
||||
String[] tokens = curLine.split("\\s+");
|
||||
if("tx_record_attribute".equals(tokens[0])){//matcher = line =~ /^tx_record_attribute\s+(\d+)\s+"([^"]+)"\s+(\S+)\s*=\s*(.+)$/
|
||||
Long id = Long.parseLong(tokens[1]);
|
||||
String name = tokens[2].substring(1, tokens[2].length());
|
||||
DataType type = DataType.valueOf(tokens[3]);
|
||||
String remaining = tokens.length>5?String.join(" ", Arrays.copyOfRange(tokens, 5, tokens.length-1)):"";
|
||||
transactionsById.get(id).getAttributes().add(new TxAttribute(name, type, AssociationType.RECORD, remaining));
|
||||
} else if("tx_begin".equals(tokens[0])){//matcher = line =~ /^tx_begin\s+(\d+)\s+(\d+)\s+(\d+)\s+([munpf]?s)/
|
||||
Long id = Long.parseLong(tokens[1]);
|
||||
TxGenerator gen=generatorsById.get(Long.parseLong(tokens[2]));
|
||||
transaction = new Tx(id, gen.getStream(), gen, Long.parseLong(tokens[3])*stringToScale(tokens[4]));
|
||||
gen.getTransactions().add(transaction);
|
||||
transactionsById.put(id, transaction);
|
||||
maxTime = maxTime>transaction.getBeginTime()?maxTime:transaction.getBeginTime();
|
||||
if(nextLine!=null && nextLine.charAt(0)=='a') {
|
||||
int idx=0;
|
||||
while(nextLine!=null && nextLine.charAt(0)=='a') {
|
||||
String[] attrTokens=nextLine.split("\\s+");
|
||||
TxAttribute attr = new TxAttribute(gen.getBeginAttrs().get(idx), attrTokens[1]);
|
||||
transaction.getAttributes().add(attr);
|
||||
idx++;
|
||||
nextLine=reader.readLine();
|
||||
}
|
||||
}
|
||||
} else if("tx_end".equals(tokens[0])){//matcher = line =~ /^tx_end\s+(\d+)\s+(\d+)\s+(\d+)\s+([munpf]?s)/
|
||||
Long id = Long.parseLong(tokens[1]);
|
||||
transaction = transactionsById.get(id);
|
||||
assert Integer.parseInt(tokens[2])==transaction.getGenerator().getId();
|
||||
transaction.setEndTime(Long.parseLong(tokens[3])*stringToScale(tokens[4]));
|
||||
maxTime = maxTime>transaction.getEndTime()?maxTime:transaction.getEndTime();
|
||||
if(nextLine!=null && nextLine.charAt(0)=='a') {
|
||||
TxGenerator gen = (TxGenerator) transaction.getGenerator();
|
||||
int idx=0;
|
||||
while(nextLine!=null && nextLine.charAt(0)=='a') {
|
||||
String[] attrTokens=nextLine.split("\\s+");
|
||||
TxAttribute attr = new TxAttribute(gen.getEndAttrs().get(idx), attrTokens[1]);
|
||||
transaction.getAttributes().add(attr);
|
||||
idx++;
|
||||
nextLine=reader.readLine();
|
||||
}
|
||||
}
|
||||
} else if("tx_relation".equals(tokens[0])){//matcher = line =~ /^tx_relation\s+\"(\S+)\"\s+(\d+)\s+(\d+)$/
|
||||
Tx tr2= transactionsById.get(Long.parseLong(tokens[2]));
|
||||
Tx tr1= transactionsById.get(Long.parseLong(tokens[3]));
|
||||
String relType=tokens[1].substring(1, tokens[1].length()-2);
|
||||
if(!relationTypes.containsKey(relType))
|
||||
relationTypes.put(relType, RelationType.create(relType));
|
||||
TxRelation rel = new TxRelation(relationTypes.get(relType), tr1, tr2);
|
||||
tr1.getOutgoingRelations().add(rel);
|
||||
tr2.getIncomingRelations().add(rel);
|
||||
} else if("scv_tr_stream".equals(tokens[0])){
|
||||
Matcher matcher = scv_tr_stream.matcher(curLine);
|
||||
if (matcher.matches()) {
|
||||
Long id = Long.parseLong(matcher.group(1));
|
||||
TxStream stream = new TxStream(this, id, matcher.group(2), matcher.group(3));
|
||||
streams.add(stream);
|
||||
streamsById.put(id, stream);
|
||||
}
|
||||
} else if("scv_tr_generator".equals(tokens[0])){
|
||||
Matcher matcher = scv_tr_generator.matcher(curLine);
|
||||
if ((matcher.matches())) {
|
||||
Long id = Long.parseLong(matcher.group(1));
|
||||
TxStream stream=streamsById.get(Long.parseLong(matcher.group(3)));
|
||||
generator=new TxGenerator(id, stream, matcher.group(2));
|
||||
stream.getGenerators().add(generator);
|
||||
generatorsById.put(id, generator);
|
||||
}
|
||||
} else if("begin_attribute".equals(tokens[0])){
|
||||
Matcher matcher = begin_attribute.matcher(curLine);
|
||||
if ((matcher.matches())) {
|
||||
generator.getBeginAttrs().add(TxAttributeType.getAttrType(matcher.group(2), DataType.valueOf(matcher.group(3)), AssociationType.BEGIN));
|
||||
}
|
||||
} else if("end_attribute".equals(tokens[0])){
|
||||
Matcher matcher = end_attribute.matcher(curLine);
|
||||
if ((matcher.matches())) {
|
||||
generator.getEndAttrs().add(TxAttributeType.getAttrType(matcher.group(2), DataType.valueOf(matcher.group(3)), AssociationType.END));
|
||||
}
|
||||
} else if(")".equals(tokens[0])){
|
||||
generator=null;
|
||||
} else if("a".equals(tokens[0])){//matcher = line =~ /^a\s+(.+)$/
|
||||
System.out.println("Don't know what to do with: '"+curLine+"'");
|
||||
} else
|
||||
System.out.println("Don't know what to do with: '"+curLine+"'");
|
||||
return nextLine;
|
||||
}
|
||||
|
||||
public Collection<RelationType> getAllRelationTypes(){
|
||||
return relationTypes.values();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* 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
|
||||
|
||||
import com.minres.scviewer.database.*
|
||||
import com.minres.scviewer.database.tx.ITx
|
||||
import com.minres.scviewer.database.tx.ITxAttribute
|
||||
import com.minres.scviewer.database.tx.ITxRelation
|
||||
|
||||
class Tx implements ITx {
|
||||
|
||||
Long id
|
||||
|
||||
TxGenerator generator
|
||||
|
||||
TxStream stream
|
||||
|
||||
int concurrencyIndex
|
||||
|
||||
Long beginTime
|
||||
|
||||
Long endTime
|
||||
|
||||
ArrayList<ITxAttribute> attributes = new ArrayList<ITxAttribute>()
|
||||
|
||||
def incomingRelations =[]
|
||||
|
||||
def outgoingRelations =[]
|
||||
|
||||
Tx(int id, TxStream stream, TxGenerator generator, Long begin){
|
||||
this.id=id
|
||||
this.stream=stream
|
||||
this.generator=generator
|
||||
this.beginTime=begin
|
||||
this.endTime=begin
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ITxRelation> getIncomingRelations() {
|
||||
return incomingRelations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ITxRelation> getOutgoingRelations() {
|
||||
return outgoingRelations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ITx o) {
|
||||
def res =beginTime.compareTo(o.beginTime)
|
||||
if(res!=0)
|
||||
return res
|
||||
else
|
||||
return id.compareTo(o.id)
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "tx#"+getId()+"["+getBeginTime()/1000000+"ns - "+getEndTime()/1000000+"ns]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import com.minres.scviewer.database.*;
|
||||
import com.minres.scviewer.database.tx.ITx;
|
||||
import com.minres.scviewer.database.tx.ITxAttribute;
|
||||
import com.minres.scviewer.database.tx.ITxGenerator;
|
||||
import com.minres.scviewer.database.tx.ITxRelation;
|
||||
|
||||
class Tx implements ITx, Serializable{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -855200240003328221L;
|
||||
|
||||
private final Long id;
|
||||
|
||||
private final TxGenerator generator;
|
||||
|
||||
private final IWaveform stream;
|
||||
|
||||
private int concurrencyIndex;
|
||||
|
||||
private final Long beginTime;
|
||||
|
||||
private Long endTime;
|
||||
|
||||
private final List<ITxAttribute> attributes = new ArrayList<>();
|
||||
|
||||
private final List<ITxRelation> incomingRelations = new ArrayList<>();
|
||||
|
||||
private final List<ITxRelation> outgoingRelations = new ArrayList<>();
|
||||
|
||||
Tx(Long id, IWaveform stream, TxGenerator generator, Long begin){
|
||||
this.id=id;
|
||||
this.stream=stream;
|
||||
this.generator=generator;
|
||||
this.beginTime=begin;
|
||||
this.endTime=begin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ITxRelation> getIncomingRelations() {
|
||||
return incomingRelations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ITxRelation> getOutgoingRelations() {
|
||||
return outgoingRelations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ITx o) {
|
||||
int res =beginTime.compareTo(o.getBeginTime());
|
||||
if(res!=0)
|
||||
return res;
|
||||
else
|
||||
return id.compareTo(o.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "tx#"+getId()+"["+getBeginTime()/1000000+"ns - "+getEndTime()/1000000+"ns]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWaveform getStream() {
|
||||
return stream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITxGenerator getGenerator() {
|
||||
return generator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getBeginTime() {
|
||||
return beginTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public void setEndTime(long l) {
|
||||
endTime=l;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getConcurrencyIndex() {
|
||||
return concurrencyIndex;
|
||||
}
|
||||
|
||||
public void setConcurrencyIndex(int idx) {
|
||||
concurrencyIndex=idx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ITxAttribute> getAttributes() {
|
||||
return attributes;
|
||||
}
|
||||
|
||||
}
|
|
@ -8,37 +8,44 @@
|
|||
* Contributors:
|
||||
* IT Just working - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.text
|
||||
package com.minres.scviewer.database.text;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.minres.scviewer.database.AssociationType;
|
||||
import com.minres.scviewer.database.DataType;
|
||||
import com.minres.scviewer.database.tx.ITxAttribute
|
||||
import com.minres.scviewer.database.tx.ITxAttributeType
|
||||
import com.minres.scviewer.database.tx.ITxAttribute;
|
||||
import com.minres.scviewer.database.tx.ITxAttributeType;
|
||||
|
||||
class TxAttribute implements ITxAttribute{
|
||||
public class TxAttribute implements ITxAttribute, Serializable {
|
||||
|
||||
TxAttributeType attributeType
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 4767726016651807152L;
|
||||
|
||||
def value
|
||||
ITxAttributeType attributeType;
|
||||
|
||||
TxAttribute(String name, DataType dataType, AssociationType type, value){
|
||||
attributeType = TxAttributeTypeFactory.instance.getAttrType(name, dataType, type)
|
||||
String value;
|
||||
|
||||
TxAttribute(String name, DataType dataType, AssociationType type, String value){
|
||||
attributeType = TxAttributeTypeFactory.INSTANCE.getAttrType(name, dataType, type);
|
||||
switch(dataType){
|
||||
case DataType.STRING:
|
||||
case DataType.ENUMERATION:
|
||||
this.value=value[1..-2]
|
||||
case STRING:
|
||||
case ENUMERATION:
|
||||
this.value=value.substring(1, value.length()-2);
|
||||
break;
|
||||
default:
|
||||
this.value=value
|
||||
this.value=value;
|
||||
}
|
||||
}
|
||||
|
||||
TxAttribute(TxAttributeType other){
|
||||
attributeType=other
|
||||
TxAttribute(ITxAttributeType type){
|
||||
attributeType=type;
|
||||
}
|
||||
|
||||
TxAttribute(TxAttributeType other, value){
|
||||
this(other.name, other.dataType, other.type, value)
|
||||
TxAttribute(ITxAttributeType type, String value){
|
||||
this(type.getName(), type.getDataType(), type.getType(), value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -48,12 +55,17 @@ class TxAttribute implements ITxAttribute{
|
|||
|
||||
@Override
|
||||
public AssociationType getType() {
|
||||
attributeType.type;
|
||||
return attributeType.getType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType getDataType() {
|
||||
attributeType.dataType;
|
||||
return attributeType.getDataType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,31 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* 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
|
||||
|
||||
import com.minres.scviewer.database.AssociationType;
|
||||
import com.minres.scviewer.database.DataType;
|
||||
import com.minres.scviewer.database.tx.ITxAttributeType
|
||||
|
||||
class TxAttributeType implements ITxAttributeType {
|
||||
String name
|
||||
DataType dataType
|
||||
AssociationType type
|
||||
|
||||
static TxAttributeType getAttrType(String name, DataType dataType, AssociationType type){
|
||||
TxAttributeTypeFactory.instance.getAttrType(name, dataType, type)
|
||||
}
|
||||
|
||||
TxAttributeType(String name, DataType dataType, AssociationType type){
|
||||
this.name=name
|
||||
this.dataType=dataType
|
||||
this.type=type
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.minres.scviewer.database.AssociationType;
|
||||
import com.minres.scviewer.database.DataType;
|
||||
import com.minres.scviewer.database.tx.ITxAttributeType;
|
||||
|
||||
class TxAttributeType implements ITxAttributeType, Serializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 7159721937208946828L;
|
||||
|
||||
private String name;
|
||||
|
||||
private DataType dataType;
|
||||
|
||||
private AssociationType type;
|
||||
|
||||
static ITxAttributeType getAttrType(String name, DataType dataType, AssociationType type){
|
||||
return TxAttributeTypeFactory.INSTANCE.getAttrType(name, dataType, type);
|
||||
}
|
||||
|
||||
TxAttributeType(String name, DataType dataType, AssociationType type){
|
||||
this.name=name;
|
||||
this.dataType=dataType;
|
||||
this.type=type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType getDataType() {
|
||||
return dataType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssociationType getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
|
@ -8,31 +8,30 @@
|
|||
* Contributors:
|
||||
* IT Just working - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.text
|
||||
package com.minres.scviewer.database.text;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.minres.scviewer.database.AssociationType;
|
||||
import com.minres.scviewer.database.DataType
|
||||
import com.minres.scviewer.database.tx.ITxAttribute
|
||||
import com.minres.scviewer.database.tx.ITxAttributeType
|
||||
import com.minres.scviewer.database.DataType;
|
||||
import com.minres.scviewer.database.tx.ITxAttributeType;
|
||||
|
||||
class TxAttributeTypeFactory {
|
||||
static final TxAttributeTypeFactory instance = new TxAttributeTypeFactory()
|
||||
public class TxAttributeTypeFactory {
|
||||
public static final TxAttributeTypeFactory INSTANCE = new TxAttributeTypeFactory();
|
||||
|
||||
def attributes = [:]
|
||||
HashMap<String, ITxAttributeType> attributes = new HashMap<>();
|
||||
|
||||
private TxAttributeTypeFactory() {
|
||||
TxAttributeTypeFactory.metaClass.constructor = {-> instance }
|
||||
}
|
||||
private TxAttributeTypeFactory() {}
|
||||
|
||||
ITxAttributeType getAttrType(String name, DataType dataType, AssociationType type){
|
||||
def key = name+":"+dataType.toString()
|
||||
ITxAttributeType res
|
||||
String key = name+":"+dataType.toString();
|
||||
ITxAttributeType res;
|
||||
if(attributes.containsKey(key)){
|
||||
res=attributes[key]
|
||||
res=attributes.get(key);
|
||||
} else {
|
||||
res=new TxAttributeType(name, dataType, type)
|
||||
attributes[key]=res
|
||||
res=new TxAttributeType(name, dataType, type);
|
||||
attributes.put(key, res);
|
||||
}
|
||||
return res
|
||||
return res;
|
||||
}
|
||||
}
|
|
@ -1,11 +1,18 @@
|
|||
package com.minres.scviewer.database.text;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.minres.scviewer.database.EventKind;
|
||||
import com.minres.scviewer.database.WaveformType;
|
||||
import com.minres.scviewer.database.tx.ITx;
|
||||
import com.minres.scviewer.database.tx.ITxEvent;
|
||||
|
||||
class TxEvent implements ITxEvent {
|
||||
class TxEvent implements ITxEvent, Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 4481575593229248159L;
|
||||
|
||||
final EventKind kind;
|
||||
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* 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
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.minres.scviewer.database.IWaveform
|
||||
import com.minres.scviewer.database.tx.ITx
|
||||
import com.minres.scviewer.database.tx.ITxAttribute
|
||||
import com.minres.scviewer.database.tx.ITxAttributeType
|
||||
import com.minres.scviewer.database.tx.ITxGenerator
|
||||
|
||||
class TxGenerator implements ITxGenerator{
|
||||
Long id
|
||||
IWaveform stream
|
||||
String name
|
||||
Boolean active = false
|
||||
ArrayList<ITx> transactions=[]
|
||||
|
||||
ArrayList<ITxAttributeType> begin_attrs = []
|
||||
int begin_attrs_idx = 0
|
||||
ArrayList<ITxAttributeType> end_attrs= []
|
||||
int end_attrs_idx = 0
|
||||
|
||||
TxGenerator(int id, TxStream stream, name){
|
||||
this.id=id
|
||||
this.stream=stream
|
||||
this.name=name
|
||||
}
|
||||
|
||||
IWaveform getStream(){
|
||||
return stream;
|
||||
}
|
||||
|
||||
List<ITx> getTransactions(){
|
||||
return transactions
|
||||
}
|
||||
|
||||
Boolean isActive() {return active};
|
||||
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.tx.ITx;
|
||||
import com.minres.scviewer.database.tx.ITxAttributeType;
|
||||
import com.minres.scviewer.database.tx.ITxGenerator;
|
||||
|
||||
class TxGenerator implements ITxGenerator, Serializable{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -1477511353554904763L;
|
||||
|
||||
Long id;
|
||||
|
||||
IWaveform stream;
|
||||
|
||||
String name;
|
||||
|
||||
Boolean active = false;
|
||||
|
||||
ArrayList<ITx> transactions=new ArrayList<ITx>();
|
||||
|
||||
ArrayList<ITxAttributeType> beginAttrs = new ArrayList<ITxAttributeType>();
|
||||
|
||||
ArrayList<ITxAttributeType> endAttrs= new ArrayList<ITxAttributeType>();
|
||||
|
||||
TxGenerator(Long id, TxStream stream, String name){
|
||||
this.id=id;
|
||||
this.stream=stream;
|
||||
this.name=name;
|
||||
}
|
||||
|
||||
public IWaveform getStream(){
|
||||
return stream;
|
||||
}
|
||||
|
||||
public List<ITx> getTransactions(){
|
||||
return transactions;
|
||||
}
|
||||
|
||||
Boolean isActive() {return active;}
|
||||
|
||||
@Override
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public ArrayList<ITxAttributeType> getBeginAttrs() {
|
||||
return beginAttrs;
|
||||
}
|
||||
|
||||
public ArrayList<ITxAttributeType> getEndAttrs() {
|
||||
return endAttrs;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +1,17 @@
|
|||
package com.minres.scviewer.database.text;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
import com.minres.scviewer.database.tx.ITx;
|
||||
import com.minres.scviewer.database.tx.ITxRelation;
|
||||
|
||||
class TxRelation implements ITxRelation {
|
||||
class TxRelation implements ITxRelation, Serializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -347668857680574140L;
|
||||
|
||||
final Tx source;
|
||||
|
||||
final Tx target;
|
||||
|
|
|
@ -1,135 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* 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
|
||||
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.Map.Entry
|
||||
|
||||
import org.mapdb.Serializer
|
||||
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.IWaveformDb
|
||||
import com.minres.scviewer.database.WaveformType
|
||||
import com.minres.scviewer.database.tx.ITx
|
||||
import com.minres.scviewer.database.tx.ITxEvent
|
||||
import com.minres.scviewer.database.tx.ITxGenerator
|
||||
import com.minres.scviewer.database.EventKind
|
||||
import com.minres.scviewer.database.HierNode;
|
||||
import com.minres.scviewer.database.IEvent
|
||||
import com.minres.scviewer.database.IHierNode
|
||||
|
||||
class TxStream extends HierNode implements IWaveform {
|
||||
|
||||
Long id
|
||||
|
||||
IWaveformDb database
|
||||
|
||||
String fullName
|
||||
|
||||
def generators = []
|
||||
|
||||
int maxConcurrency
|
||||
|
||||
private TreeMap<Long, IEvent[]> events
|
||||
|
||||
TxStream(TextDbLoader loader, int id, String name, String kind){
|
||||
super(name)
|
||||
this.id=id
|
||||
this.database=loader.db
|
||||
this.fullName=name
|
||||
this.maxConcurrency=0
|
||||
//events = new TreeMap<Long, List<ITxEvent>>()
|
||||
events = loader.mapDb.treeMap(name).keySerializer(Serializer.LONG).createOrOpen();
|
||||
}
|
||||
|
||||
List<ITxGenerator> getGenerators(){
|
||||
return generators as List<ITxGenerator>
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWaveformDb getDb() {
|
||||
return database
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
if(!maxConcurrency){
|
||||
generators.each {TxGenerator generator ->
|
||||
generator.transactions.each{ Tx tx ->
|
||||
putEvent(new TxEvent(EventKind.BEGIN, tx))
|
||||
putEvent(new TxEvent(EventKind.END, tx))
|
||||
}
|
||||
}
|
||||
def rowendtime = [0]
|
||||
events.keySet().each{long time ->
|
||||
def value=events.get(time)
|
||||
def starts=value.findAll{IEvent event ->event.kind==EventKind.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()
|
||||
}
|
||||
return maxConcurrency
|
||||
}
|
||||
|
||||
private putEvent(ITxEvent event){
|
||||
if(!events.containsKey(event.time))
|
||||
events.put(event.time, [event] as IEvent[])
|
||||
else {
|
||||
def entries = events[event.time] as List
|
||||
entries<<event
|
||||
events.put(event.time, entries as IEvent[])
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NavigableMap<Long, IEvent[]> getEvents() {
|
||||
return events;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEvent[] getEventsAtTime(Long time) {
|
||||
return events.get(time);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSame(IWaveform other) {
|
||||
return(other instanceof TxStream && this.getId()==other.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEvent[] getEventsBeforeTime(Long time) {
|
||||
Entry<Long, IEvent[]> e = events.floorEntry(time);
|
||||
if(e==null)
|
||||
return null;
|
||||
else
|
||||
return events.floorEntry(time).getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WaveformType getType() {
|
||||
return WaveformType.TRANSACTION;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,144 @@
|
|||
/*******************************************************************************
|
||||
* 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;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.NavigableMap;
|
||||
|
||||
import org.mapdb.BTreeMap;
|
||||
import org.mapdb.Serializer;
|
||||
|
||||
import com.minres.scviewer.database.EventKind;
|
||||
import com.minres.scviewer.database.HierNode;
|
||||
import com.minres.scviewer.database.IEvent;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.WaveformType;
|
||||
import com.minres.scviewer.database.tx.ITx;
|
||||
import com.minres.scviewer.database.tx.ITxEvent;
|
||||
import com.minres.scviewer.database.tx.ITxGenerator;
|
||||
|
||||
class TxStream extends HierNode implements IWaveform, Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 6721893017334753858L;
|
||||
|
||||
private Long id;
|
||||
|
||||
private IWaveformDb database;
|
||||
|
||||
private ArrayList<ITxGenerator> generators = new ArrayList<ITxGenerator>();
|
||||
|
||||
private int maxConcurrency;
|
||||
|
||||
private BTreeMap<Long, IEvent[]> events;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
TxStream(TextDbLoader loader, Long id, String name, String kind){
|
||||
super(name);
|
||||
this.id=id;
|
||||
this.database=loader.db;
|
||||
this.maxConcurrency=0;
|
||||
//events = new TreeMap<Long, List<ITxEvent>>()
|
||||
events = (BTreeMap<Long, IEvent[]>) loader.mapDb.treeMap(name).keySerializer(Serializer.LONG).createOrOpen();
|
||||
}
|
||||
|
||||
List<ITxGenerator> getGenerators(){
|
||||
return generators;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWaveformDb getDb() {
|
||||
return database;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
if(maxConcurrency==0){
|
||||
for(ITxGenerator generator:getGenerators()) {
|
||||
for(ITx tx:generator.getTransactions()){
|
||||
putEvent(new TxEvent(EventKind.BEGIN, tx));
|
||||
putEvent(new TxEvent(EventKind.END, tx));
|
||||
}
|
||||
}
|
||||
ArrayList<Long> rowendtime = new ArrayList<Long>();
|
||||
rowendtime.add(0l);
|
||||
for(Long time: events.keySet()){
|
||||
IEvent[] value=events.get(time);
|
||||
Arrays.asList(value).stream().filter(event -> event.getKind()==EventKind.BEGIN).forEach(event -> {
|
||||
ITx tx = ((ITxEvent)event).getTransaction();
|
||||
int rowIdx = 0;
|
||||
for(rowIdx=0; rowIdx<rowendtime.size() && rowendtime.get(rowIdx)>tx.getBeginTime(); rowIdx++);
|
||||
if(rowendtime.size()<=rowIdx)
|
||||
rowendtime.add(tx.getEndTime());
|
||||
else
|
||||
rowendtime.set(rowIdx, tx.getEndTime());
|
||||
((Tx)tx).setConcurrencyIndex(rowIdx);
|
||||
|
||||
});
|
||||
}
|
||||
maxConcurrency=rowendtime.size();
|
||||
}
|
||||
return maxConcurrency;
|
||||
}
|
||||
|
||||
private void putEvent(ITxEvent event){
|
||||
if(!events.containsKey(event.getTime()))
|
||||
events.put(event.getTime(), new ITxEvent[]{event} );
|
||||
else {
|
||||
IEvent[] entries = events.get(event.getTime());
|
||||
IEvent[] newEntries = Arrays.copyOf(entries, entries.length+1);
|
||||
newEntries[entries.length]=event;
|
||||
events.put(event.getTime(), newEntries);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NavigableMap<Long, IEvent[]> getEvents() {
|
||||
return (NavigableMap<Long, IEvent[]>)events;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEvent[] getEventsAtTime(Long time) {
|
||||
return events.get(time);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSame(IWaveform other) {
|
||||
return(other instanceof TxStream && this.getId()==other.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEvent[] getEventsBeforeTime(Long time) {
|
||||
Entry<Long, IEvent[]> e = events.floorEntry(time);
|
||||
if(e==null)
|
||||
return null;
|
||||
else
|
||||
return events.floorEntry(time).getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WaveformType getType() {
|
||||
return WaveformType.TRANSACTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
|
@ -10,9 +10,15 @@
|
|||
*******************************************************************************/
|
||||
package com.minres.scviewer.database;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class RelationType {
|
||||
public class RelationType implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 6394859077558971735L;
|
||||
|
||||
private static HashMap<String, RelationType> registry = new HashMap<>();
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
package com.minres.scviewer.database.internal;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
@ -25,7 +26,12 @@ import com.minres.scviewer.database.IWaveformDb;
|
|||
import com.minres.scviewer.database.IWaveformDbLoader;
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
|
||||
public class WaveformDb extends HierNode implements IWaveformDb {
|
||||
public class WaveformDb extends HierNode implements IWaveformDb, Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 3274692080405194894L;
|
||||
|
||||
private static List<IWaveformDbLoader> loaders=new LinkedList<>();
|
||||
|
||||
|
|
|
@ -3,5 +3,6 @@
|
|||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src/"/>
|
||||
<classpathentry kind="con" path="GROOVY_DSL_SUPPORT"/>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
||||
|
|
Loading…
Reference in New Issue