Merge branch 'develop'
This commit is contained in:
22
plugins/com.minres.scviewer.database.text/.classpath
Normal file
22
plugins/com.minres.scviewer.database.text/.classpath
Normal file
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/mapdb-3.0.7.jar" sourcepath="lib/mapdb-3.0.7-sources.jar">
|
||||
<attributes>
|
||||
<attribute name="javadoc_location" value="jar:platform:/resource/com.minres.scviewer.database.text/lib/mapdb-3.0.7-javadoc.jar!/"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src/"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/eclipse-collections-9.2.0.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/eclipse-collections-api-9.2.0.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/eclipse-collections-forkjoin-9.2.0.jar"/>
|
||||
<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="output" path="target/classes"/>
|
||||
</classpath>
|
||||
2
plugins/com.minres.scviewer.database.text/.gitignore
vendored
Normal file
2
plugins/com.minres.scviewer.database.text/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/bin
|
||||
/target/
|
||||
40
plugins/com.minres.scviewer.database.text/.project
Normal file
40
plugins/com.minres.scviewer.database.text/.project
Normal file
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>com.minres.scviewer.database.text</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ds.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
<nature>org.eclipse.jdt.groovy.core.groovyNature</nature>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,9 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.release=disabled
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
@@ -0,0 +1,3 @@
|
||||
eclipse.preferences.version=1
|
||||
groovy.compiler.level=-1
|
||||
groovy.script.filters=**/*.dsld,y,**/*.gradle,n
|
||||
@@ -0,0 +1,4 @@
|
||||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
||||
@@ -0,0 +1,23 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Textual transaction database
|
||||
Bundle-SymbolicName: com.minres.scviewer.database.text
|
||||
Bundle-Version: 2.0.2.qualifier
|
||||
Bundle-Vendor: MINRES Technologies GmbH
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Import-Package: org.osgi.framework;version="1.3.0"
|
||||
Require-Bundle: com.minres.scviewer.database,
|
||||
org.codehaus.groovy;bundle-version="2.5.8",
|
||||
org.eclipse.osgi.services;bundle-version="3.4.0",
|
||||
com.google.guava;bundle-version="15.0.0"
|
||||
Service-Component: OSGI-INF/component.xml
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Automatic-Module-Name: com.minres.scviewer.database.text
|
||||
Bundle-ClassPath: lib/mapdb-3.0.7.jar,
|
||||
.,
|
||||
lib/eclipse-collections-9.2.0.jar,
|
||||
lib/eclipse-collections-api-9.2.0.jar,
|
||||
lib/eclipse-collections-forkjoin-9.2.0.jar,
|
||||
lib/kotlin-stdlib-1.2.42.jar,
|
||||
lib/lz4-1.3.0.jar,
|
||||
lib/elsa-3.0.0-M5.jar
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="TextDbLoader">
|
||||
<implementation class="com.minres.scviewer.database.text.TextDbLoader"/>
|
||||
<service>
|
||||
<provide interface="com.minres.scviewer.database.IWaveformDbLoader"/>
|
||||
</service>
|
||||
</scr:component>
|
||||
25
plugins/com.minres.scviewer.database.text/build.properties
Normal file
25
plugins/com.minres.scviewer.database.text/build.properties
Normal file
@@ -0,0 +1,25 @@
|
||||
###############################################################################
|
||||
# Copyright (c) 2014, 2015 MINRES Technologies GmbH and others.
|
||||
# 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:
|
||||
# MINRES Technologies GmbH - initial API and implementation
|
||||
###############################################################################
|
||||
bin.includes = META-INF/,\
|
||||
.,\
|
||||
OSGI-INF/,\
|
||||
lib/,\
|
||||
lib/mapdb-3.0.7.jar,\
|
||||
lib/eclipse-collections-9.2.0.jar,\
|
||||
lib/eclipse-collections-api-9.2.0.jar,\
|
||||
lib/eclipse-collections-forkjoin-9.2.0.jar,\
|
||||
lib/kotlin-stdlib-1.2.42.jar,\
|
||||
lib/lz4-1.3.0.jar,\
|
||||
lib/elsa-3.0.0-M5.jar
|
||||
bin.excludes = **/*.groovy,\
|
||||
lib/mapdb-3.0.7-sources.jar,\
|
||||
lib/mapdb-3.0.7-javadoc.jar
|
||||
source.. = src/
|
||||
BIN
plugins/com.minres.scviewer.database.text/lib/eclipse-collections-9.2.0.jar
Executable file
BIN
plugins/com.minres.scviewer.database.text/lib/eclipse-collections-9.2.0.jar
Executable file
Binary file not shown.
BIN
plugins/com.minres.scviewer.database.text/lib/eclipse-collections-api-9.2.0.jar
Executable file
BIN
plugins/com.minres.scviewer.database.text/lib/eclipse-collections-api-9.2.0.jar
Executable file
Binary file not shown.
Binary file not shown.
BIN
plugins/com.minres.scviewer.database.text/lib/elsa-3.0.0-M5.jar
Executable file
BIN
plugins/com.minres.scviewer.database.text/lib/elsa-3.0.0-M5.jar
Executable file
Binary file not shown.
BIN
plugins/com.minres.scviewer.database.text/lib/kotlin-stdlib-1.2.42.jar
Executable file
BIN
plugins/com.minres.scviewer.database.text/lib/kotlin-stdlib-1.2.42.jar
Executable file
Binary file not shown.
BIN
plugins/com.minres.scviewer.database.text/lib/lz4-1.3.0.jar
Executable file
BIN
plugins/com.minres.scviewer.database.text/lib/lz4-1.3.0.jar
Executable file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
plugins/com.minres.scviewer.database.text/lib/mapdb-3.0.7.jar
Normal file
BIN
plugins/com.minres.scviewer.database.text/lib/mapdb-3.0.7.jar
Normal file
Binary file not shown.
45
plugins/com.minres.scviewer.database.text/pom.xml
Normal file
45
plugins/com.minres.scviewer.database.text/pom.xml
Normal file
@@ -0,0 +1,45 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>com.minres.scviewer.database.text</artifactId>
|
||||
<version>2.0.2-SNAPSHOT</version>
|
||||
<parent>
|
||||
<groupId>com.minres.scviewer</groupId>
|
||||
<artifactId>com.minres.scviewer.parent</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<relativePath>../..</relativePath>
|
||||
</parent>
|
||||
<packaging>eclipse-plugin</packaging>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.tycho</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<compilerId>groovy-eclipse-compiler</compilerId>
|
||||
<compilerArguments>
|
||||
<indy/><!-- optional; supported by batch 2.4.12-04+ -->
|
||||
</compilerArguments>
|
||||
<!-- set verbose to be true if you want lots of uninteresting messages -->
|
||||
<!-- <verbose>true</verbose> -->
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-eclipse-compiler</artifactId>
|
||||
<version>${groovy-eclipse-compiler-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-eclipse-batch</artifactId>
|
||||
<version>${groovy-eclipse-batch-version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,242 @@
|
||||
/*******************************************************************************
|
||||
* 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.ITxGenerator
|
||||
import com.minres.scviewer.database.ITxStream
|
||||
import com.minres.scviewer.database.IWaveform
|
||||
import com.minres.scviewer.database.IWaveformDb
|
||||
import com.minres.scviewer.database.IWaveformDbLoader
|
||||
import com.minres.scviewer.database.RelationType
|
||||
|
||||
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 Exception {
|
||||
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, "tmp", 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.getMaxConcurrency() }
|
||||
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()
|
||||
}
|
||||
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])
|
||||
ITxStream stream=streamsById[Integer.parseInt(matcher[0][3])]
|
||||
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,67 @@
|
||||
/*******************************************************************************
|
||||
* 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.*
|
||||
|
||||
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,59 @@
|
||||
/*******************************************************************************
|
||||
* 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.ITxAttributeType;
|
||||
import com.minres.scviewer.database.ITxAttribute
|
||||
|
||||
class TxAttribute implements ITxAttribute{
|
||||
|
||||
TxAttributeType attributeType
|
||||
|
||||
def value
|
||||
|
||||
TxAttribute(String name, DataType dataType, AssociationType type, value){
|
||||
attributeType = TxAttributeTypeFactory.instance.getAttrType(name, dataType, type)
|
||||
switch(dataType){
|
||||
case DataType.STRING:
|
||||
case DataType.ENUMERATION:
|
||||
this.value=value[1..-2]
|
||||
break;
|
||||
default:
|
||||
this.value=value
|
||||
}
|
||||
}
|
||||
|
||||
TxAttribute(TxAttributeType other){
|
||||
attributeType=other
|
||||
}
|
||||
|
||||
TxAttribute(TxAttributeType other, value){
|
||||
this(other.name, other.dataType, other.type, value)
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return attributeType.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AssociationType getType() {
|
||||
attributeType.type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType getDataType() {
|
||||
attributeType.dataType;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*******************************************************************************
|
||||
* 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.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,38 @@
|
||||
/*******************************************************************************
|
||||
* 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.ITxAttributeType
|
||||
import com.minres.scviewer.database.ITxAttribute
|
||||
|
||||
class TxAttributeTypeFactory {
|
||||
private static final instance = new TxAttributeTypeFactory()
|
||||
|
||||
def attributes = [:]
|
||||
|
||||
private TxAttributeTypeFactory() {
|
||||
TxAttributeTypeFactory.metaClass.constructor = {-> instance }
|
||||
}
|
||||
|
||||
ITxAttributeType getAttrType(String name, DataType dataType, AssociationType type){
|
||||
def key = name+":"+dataType.toString()
|
||||
ITxAttributeType res
|
||||
if(attributes.containsKey(key)){
|
||||
res=attributes[key]
|
||||
} else {
|
||||
res=new TxAttributeType(name, dataType, type)
|
||||
attributes[key]=res
|
||||
}
|
||||
return res
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.minres.scviewer.database.text;
|
||||
|
||||
import com.minres.scviewer.database.ITx
|
||||
import com.minres.scviewer.database.ITxEvent
|
||||
import com.minres.scviewer.database.IWaveformEvent
|
||||
|
||||
class TxEvent implements ITxEvent {
|
||||
|
||||
final ITxEvent.Type type;
|
||||
|
||||
final Tx transaction;
|
||||
|
||||
final Long time
|
||||
|
||||
TxEvent(ITxEvent.Type type, ITx transaction) {
|
||||
super();
|
||||
this.type = type;
|
||||
this.transaction = transaction;
|
||||
this.time = type==ITxEvent.Type.BEGIN?transaction.beginTime:transaction.endTime
|
||||
}
|
||||
|
||||
@Override
|
||||
IWaveformEvent duplicate() throws CloneNotSupportedException {
|
||||
new TxEvent(type, transaction, time)
|
||||
}
|
||||
|
||||
@Override
|
||||
int compareTo(IWaveformEvent o) {
|
||||
time.compareTo(o.time)
|
||||
}
|
||||
|
||||
@Override
|
||||
String toString() {
|
||||
type.toString()+"@"+time+" of tx #"+transaction.id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/*******************************************************************************
|
||||
* 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.ITxAttributeType
|
||||
import com.minres.scviewer.database.ITxAttribute;
|
||||
import com.minres.scviewer.database.ITxEvent;
|
||||
import com.minres.scviewer.database.ITxGenerator;
|
||||
import com.minres.scviewer.database.ITxStream;
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.IWaveformEvent;
|
||||
|
||||
class TxGenerator implements ITxGenerator{
|
||||
Long id
|
||||
TxStream 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
|
||||
}
|
||||
|
||||
ITxStream<? extends ITxEvent> getStream(){
|
||||
return stream;
|
||||
}
|
||||
|
||||
List<ITx> getTransactions(){
|
||||
return transactions
|
||||
}
|
||||
|
||||
Boolean isActive() {return active};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.minres.scviewer.database.text
|
||||
|
||||
import com.minres.scviewer.database.ITxRelation
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
|
||||
class TxRelation implements ITxRelation {
|
||||
Tx source
|
||||
|
||||
Tx target
|
||||
|
||||
RelationType relationType
|
||||
|
||||
|
||||
public TxRelation(RelationType relationType, Tx source, Tx target) {
|
||||
this.source = source;
|
||||
this.target = target;
|
||||
this.relationType = relationType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RelationType getRelationType() {
|
||||
return relationType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITx getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITx getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
/*******************************************************************************
|
||||
* 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 org.mapdb.Serializer
|
||||
|
||||
import com.minres.scviewer.database.ITxEvent;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.IWaveformDb
|
||||
import com.minres.scviewer.database.IWaveformEvent
|
||||
import com.minres.scviewer.database.ITxGenerator
|
||||
import com.minres.scviewer.database.HierNode;
|
||||
import com.minres.scviewer.database.IHierNode
|
||||
import com.minres.scviewer.database.ITxStream
|
||||
import com.minres.scviewer.database.ITx
|
||||
|
||||
class TxStream extends HierNode implements ITxStream {
|
||||
|
||||
Long id
|
||||
|
||||
IWaveformDb database
|
||||
|
||||
String fullName
|
||||
|
||||
String kind
|
||||
|
||||
def generators = []
|
||||
|
||||
int maxConcurrency
|
||||
|
||||
private TreeMap<Long, List<ITxEvent>> events
|
||||
|
||||
TxStream(TextDbLoader loader, int id, String name, String kind){
|
||||
super(name)
|
||||
this.id=id
|
||||
this.database=loader.db
|
||||
this.fullName=name
|
||||
this.kind=kind
|
||||
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 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))
|
||||
}
|
||||
}
|
||||
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()
|
||||
}
|
||||
return maxConcurrency
|
||||
}
|
||||
|
||||
private putEvent(ITxEvent event){
|
||||
if(!events.containsKey(event.time))
|
||||
events.put(event.time, [event])
|
||||
else
|
||||
events[event.time]<<event
|
||||
}
|
||||
|
||||
@Override
|
||||
public NavigableMap getEvents() {
|
||||
return events;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection getWaveformEventsAtTime(Long time) {
|
||||
return events.get(time);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean equals(IWaveform other) {
|
||||
return(other instanceof TxStream && this.getId()==other.getId());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user