fix copyright header, javadoc, and warnings
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 IT Just working.
|
||||
* Copyright (c) 2012 IT Just working
|
||||
* Copyright (c) 2020 MINRES Technologies GmbH
|
||||
* 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
|
||||
@ -12,7 +13,6 @@ package com.minres.scviewer.database.text;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.TreeMap;
|
||||
@ -23,105 +23,137 @@ import com.minres.scviewer.database.IEvent;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.WaveformType;
|
||||
import com.minres.scviewer.database.tx.ITxEvent;
|
||||
import com.minres.scviewer.database.tx.ITxGenerator;
|
||||
|
||||
/**
|
||||
* The Class AbstractTxStream.
|
||||
*/
|
||||
abstract class AbstractTxStream extends HierNode implements IWaveform {
|
||||
|
||||
/** The id. */
|
||||
private Long id;
|
||||
|
||||
|
||||
/** The loader. */
|
||||
protected TextDbLoader loader;
|
||||
|
||||
|
||||
/** The events. */
|
||||
TreeMap<Long, IEvent[]> events = new TreeMap<>();
|
||||
|
||||
private int maxConcurrency = 0;
|
||||
|
||||
private int concurrency = 0;
|
||||
|
||||
/** The concurrency calculated. */
|
||||
boolean concurrencyCalculated = false;
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new abstract tx stream.
|
||||
*
|
||||
* @param loader the loader
|
||||
* @param id the id
|
||||
* @param name the name
|
||||
*/
|
||||
public AbstractTxStream(TextDbLoader loader, Long id, String name) {
|
||||
super(name);
|
||||
this.loader=loader;
|
||||
this.id=id;
|
||||
}
|
||||
|
||||
void setConcurrency(int concurrency) {
|
||||
this.concurrency = concurrency;
|
||||
if(concurrency>maxConcurrency)
|
||||
maxConcurrency = concurrency;
|
||||
}
|
||||
|
||||
int getConcurrency() {
|
||||
return this.concurrency;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return maxConcurrency;
|
||||
this.loader = loader;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the event.
|
||||
*
|
||||
* @param evt the evt
|
||||
*/
|
||||
public void addEvent(ITxEvent evt) {
|
||||
if(!events.containsKey(evt.getTime()))
|
||||
events.put(evt.getTime(), new IEvent[] {evt});
|
||||
if (!events.containsKey(evt.getTime()))
|
||||
events.put(evt.getTime(), new IEvent[] { evt });
|
||||
else {
|
||||
IEvent[] evts = events.get(evt.getTime());
|
||||
IEvent[] newEvts = Arrays.copyOf(evts, evts.length+1);
|
||||
newEvts[evts.length]=evt;
|
||||
IEvent[] newEvts = Arrays.copyOf(evts, evts.length + 1);
|
||||
newEvts[evts.length] = evt;
|
||||
events.put(evt.getTime(), newEvts);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the events.
|
||||
*
|
||||
* @return the events
|
||||
*/
|
||||
@Override
|
||||
public NavigableMap<Long, IEvent[]> getEvents() {
|
||||
if(!concurrencyCalculated) calculateConcurrency();
|
||||
if (!concurrencyCalculated)
|
||||
calculateConcurrency();
|
||||
return events;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the events at time.
|
||||
*
|
||||
* @param time the time
|
||||
* @return the events at time
|
||||
*/
|
||||
@Override
|
||||
public IEvent[] getEventsAtTime(Long time) {
|
||||
if(!concurrencyCalculated) calculateConcurrency();
|
||||
if (!concurrencyCalculated)
|
||||
calculateConcurrency();
|
||||
return events.get(time);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the events before time.
|
||||
*
|
||||
* @param time the time
|
||||
* @return the events before time
|
||||
*/
|
||||
@Override
|
||||
public IEvent[] getEventsBeforeTime(Long time) {
|
||||
if(!concurrencyCalculated)
|
||||
if (!concurrencyCalculated)
|
||||
calculateConcurrency();
|
||||
Entry<Long, IEvent[]> e = events.floorEntry(time);
|
||||
if(e==null)
|
||||
return new IEvent[] {};
|
||||
else
|
||||
return events.floorEntry(time).getValue();
|
||||
Entry<Long, IEvent[]> e = events.floorEntry(time);
|
||||
if (e == null)
|
||||
return new IEvent[] {};
|
||||
else
|
||||
return events.floorEntry(time).getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type.
|
||||
*
|
||||
* @return the type
|
||||
*/
|
||||
@Override
|
||||
public WaveformType getType() {
|
||||
return WaveformType.TRANSACTION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
@Override
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate concurrency.
|
||||
*/
|
||||
synchronized void calculateConcurrency() {
|
||||
if(concurrencyCalculated) return;
|
||||
if (concurrencyCalculated)
|
||||
return;
|
||||
ArrayList<Long> rowendtime = new ArrayList<>();
|
||||
events.entrySet().stream().forEach( entry -> {
|
||||
events.entrySet().stream().forEach(entry -> {
|
||||
IEvent[] values = entry.getValue();
|
||||
Arrays.asList(values).stream().filter(e->e.getKind()==EventKind.BEGIN).forEach(evt -> {
|
||||
Tx tx = (Tx) ((TxEvent)evt).getTransaction();
|
||||
Arrays.asList(values).stream().filter(e -> e.getKind() == EventKind.BEGIN).forEach(evt -> {
|
||||
Tx tx = (Tx) ((TxEvent) evt).getTransaction();
|
||||
int rowIdx = 0;
|
||||
for(; rowIdx<rowendtime.size() && rowendtime.get(rowIdx)>tx.getBeginTime(); rowIdx++);
|
||||
if(rowendtime.size()<=rowIdx)
|
||||
for (; rowIdx < rowendtime.size() && rowendtime.get(rowIdx) > tx.getBeginTime(); rowIdx++)
|
||||
;
|
||||
if (rowendtime.size() <= rowIdx)
|
||||
rowendtime.add(tx.getEndTime());
|
||||
else
|
||||
rowendtime.set(rowIdx, tx.getEndTime());
|
||||
tx.setConcurrencyIndex(rowIdx);
|
||||
});
|
||||
});
|
||||
concurrencyCalculated=true;
|
||||
concurrencyCalculated = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,21 +1,43 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 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
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.text;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
|
||||
/**
|
||||
* The Class ScvRelation.
|
||||
*/
|
||||
class ScvRelation implements Serializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
/** The Constant serialVersionUID. */
|
||||
private static final long serialVersionUID = -347668857680574140L;
|
||||
|
||||
/** The source. */
|
||||
final long source;
|
||||
|
||||
|
||||
/** The target. */
|
||||
final long target;
|
||||
|
||||
|
||||
/** The relation type. */
|
||||
final RelationType relationType;
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new scv relation.
|
||||
*
|
||||
* @param relationType the relation type
|
||||
* @param source the source
|
||||
* @param target the target
|
||||
*/
|
||||
public ScvRelation(RelationType relationType, long source, long target) {
|
||||
this.source = source;
|
||||
this.target = target;
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 IT Just working.
|
||||
* Copyright (c) 2020 MINRES Technologies GmbH
|
||||
* 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
|
||||
@ -16,32 +17,54 @@ import java.util.List;
|
||||
|
||||
import com.minres.scviewer.database.tx.ITxAttribute;
|
||||
|
||||
class ScvTx implements Serializable{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* The Class ScvTx.
|
||||
*/
|
||||
class ScvTx implements Serializable {
|
||||
|
||||
/** The Constant serialVersionUID. */
|
||||
private static final long serialVersionUID = -855200240003328221L;
|
||||
|
||||
/** The id. */
|
||||
final long id;
|
||||
|
||||
|
||||
/** The generator id. */
|
||||
final long generatorId;
|
||||
|
||||
/** The stream id. */
|
||||
final long streamId;
|
||||
|
||||
|
||||
/** The begin time. */
|
||||
long beginTime;
|
||||
|
||||
|
||||
/** The end time. */
|
||||
long endTime;
|
||||
|
||||
|
||||
/** The attributes. */
|
||||
final List<ITxAttribute> attributes = new ArrayList<>();
|
||||
|
||||
ScvTx(long id, long streamId, long generatorId, long begin){
|
||||
this.id=id;
|
||||
this.streamId=streamId;
|
||||
this.generatorId=generatorId;
|
||||
this.beginTime=begin;
|
||||
this.endTime=begin;
|
||||
|
||||
/**
|
||||
* Instantiates a new scv tx.
|
||||
*
|
||||
* @param id the id
|
||||
* @param streamId the stream id
|
||||
* @param generatorId the generator id
|
||||
* @param begin the begin
|
||||
*/
|
||||
ScvTx(long id, long streamId, long generatorId, long begin) {
|
||||
this.id = id;
|
||||
this.streamId = streamId;
|
||||
this.generatorId = generatorId;
|
||||
this.beginTime = begin;
|
||||
this.endTime = begin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
Long getId() {return id;}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 IT Just working.
|
||||
* Copyright (c) 2020 MINRES Technologies GmbH
|
||||
* 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
|
||||
@ -47,101 +48,128 @@ import com.minres.scviewer.database.RelationType;
|
||||
import com.minres.scviewer.database.RelationTypeFactory;
|
||||
import com.minres.scviewer.database.tx.ITx;
|
||||
|
||||
public class TextDbLoader implements IWaveformDbLoader{
|
||||
/**
|
||||
* The Class TextDbLoader.
|
||||
*/
|
||||
public class TextDbLoader implements IWaveformDbLoader {
|
||||
|
||||
private Long maxTime=0L;
|
||||
/** The max time. */
|
||||
private Long maxTime = 0L;
|
||||
|
||||
DB mapDb=null;
|
||||
|
||||
final List<String> attrValues = new ArrayList<>();
|
||||
/** The map db. */
|
||||
DB mapDb = null;
|
||||
|
||||
/** The attr values. */
|
||||
final List<String> attrValues = new ArrayList<>();
|
||||
|
||||
/** The relation types. */
|
||||
final Map<String, RelationType> relationTypes = UnifiedMap.newMap();
|
||||
|
||||
final Map<Long, TxStream> txStreams = UnifiedMap.newMap();
|
||||
|
||||
final Map<Long, TxGenerator> txGenerators = UnifiedMap.newMap();
|
||||
|
||||
Map<Long, ScvTx> transactions = null;
|
||||
|
||||
final Map<String, TxAttributeType> attributeTypes = UnifiedMap.newMap();
|
||||
/** The tx streams. */
|
||||
final Map<Long, TxStream> txStreams = UnifiedMap.newMap();
|
||||
|
||||
/** The tx generators. */
|
||||
final Map<Long, TxGenerator> txGenerators = UnifiedMap.newMap();
|
||||
|
||||
/** The transactions. */
|
||||
Map<Long, ScvTx> transactions = null;
|
||||
|
||||
/** The attribute types. */
|
||||
final Map<String, TxAttributeType> attributeTypes = UnifiedMap.newMap();
|
||||
|
||||
/** The relations in. */
|
||||
final HashMultimap<Long, ScvRelation> relationsIn = HashMultimap.create();
|
||||
|
||||
/** The relations out. */
|
||||
final HashMultimap<Long, ScvRelation> relationsOut = HashMultimap.create();
|
||||
|
||||
HashMap<Long, Tx> txCache = new HashMap<>();
|
||||
/** The tx cache. */
|
||||
HashMap<Long, Tx> txCache = new HashMap<>();
|
||||
|
||||
List<Thread> threads = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
/** The threads. */
|
||||
List<Thread> threads = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Gets the max time.
|
||||
*
|
||||
* @return the max time
|
||||
*/
|
||||
@Override
|
||||
public Long getMaxTime() {
|
||||
return maxTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the all waves.
|
||||
*
|
||||
* @return the all waves
|
||||
*/
|
||||
@Override
|
||||
public Collection<IWaveform> getAllWaves() {
|
||||
return new ArrayList<>(txStreams.values());
|
||||
}
|
||||
|
||||
/** The Constant x. */
|
||||
static final byte[] x = "scv_tr_stream".getBytes();
|
||||
|
||||
/**
|
||||
* Load.
|
||||
*
|
||||
* @param db the db
|
||||
* @param file the file
|
||||
* @return true, if successful
|
||||
* @throws InputFormatException the input format exception
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public boolean load(IWaveformDb db, File file) throws InputFormatException {
|
||||
public boolean load(IWaveformDb db, File file) throws InputFormatException {
|
||||
dispose();
|
||||
if(file.isDirectory() || !file.exists()) return false;
|
||||
if (file.isDirectory() || !file.exists())
|
||||
return false;
|
||||
TextDbParser parser = new TextDbParser(this);
|
||||
boolean gzipped = isGzipped(file);
|
||||
try {
|
||||
if(!isTxfile(gzipped?new GZIPInputStream(new FileInputStream(file)):new FileInputStream(file)))
|
||||
return false;
|
||||
} catch(Exception e) {
|
||||
if (!isTxfile(gzipped ? new GZIPInputStream(new FileInputStream(file)) : new FileInputStream(file)))
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
throw new InputFormatException();
|
||||
}
|
||||
|
||||
if(file.length() < 75000000*(gzipped?1:10) || "memory".equals(System.getProperty("ScvBackingDB", "file")))
|
||||
mapDb = DBMaker
|
||||
.memoryDirectDB()
|
||||
.allocateStartSize(512l*1024l*1024l)
|
||||
.allocateIncrement(128l*1024l*1024l)
|
||||
.cleanerHackEnable()
|
||||
.make();
|
||||
|
||||
if (file.length() < 75000000 * (gzipped ? 1 : 10)
|
||||
|| "memory".equals(System.getProperty("ScvBackingDB", "file")))
|
||||
mapDb = DBMaker.memoryDirectDB().allocateStartSize(512l * 1024l * 1024l)
|
||||
.allocateIncrement(128l * 1024l * 1024l).cleanerHackEnable().make();
|
||||
else {
|
||||
File mapDbFile;
|
||||
try {
|
||||
mapDbFile = File.createTempFile("."+file.getName(), ".mapdb", null /*file.parentFile*/);
|
||||
mapDbFile = File.createTempFile("." + file.getName(), ".mapdb", null /* file.parentFile */);
|
||||
Files.delete(Paths.get(mapDbFile.getPath()));
|
||||
} catch (IOException e1) {
|
||||
return false;
|
||||
}
|
||||
mapDb = DBMaker
|
||||
.fileDB(mapDbFile)
|
||||
.fileMmapEnable() // Always enable mmap
|
||||
.fileMmapEnableIfSupported()
|
||||
.fileMmapPreclearDisable()
|
||||
.allocateStartSize(512l*1024l*1024l)
|
||||
.allocateIncrement(128l*1024l*1024l)
|
||||
.cleanerHackEnable()
|
||||
.make();
|
||||
mapDb = DBMaker.fileDB(mapDbFile).fileMmapEnable() // Always enable mmap
|
||||
.fileMmapEnableIfSupported().fileMmapPreclearDisable().allocateStartSize(512l * 1024l * 1024l)
|
||||
.allocateIncrement(128l * 1024l * 1024l).cleanerHackEnable().make();
|
||||
mapDbFile.deleteOnExit();
|
||||
}
|
||||
try {
|
||||
parser.txSink = mapDb.treeMap("transactions", Serializer.LONG,Serializer.JAVA).createFromSink();
|
||||
parser.parseInput(gzipped?new GZIPInputStream(new FileInputStream(file)):new FileInputStream(file));
|
||||
parser.txSink = mapDb.treeMap("transactions", Serializer.LONG, Serializer.JAVA).createFromSink();
|
||||
parser.parseInput(gzipped ? new GZIPInputStream(new FileInputStream(file)) : new FileInputStream(file));
|
||||
transactions = parser.txSink.create();
|
||||
} catch(IllegalArgumentException|ArrayIndexOutOfBoundsException e) {
|
||||
} catch(Exception e) {
|
||||
System.out.println("---->>> Exception "+e.toString()+" caught while loading database");
|
||||
} catch (IllegalArgumentException | ArrayIndexOutOfBoundsException e) {
|
||||
} catch (Exception e) {
|
||||
System.out.println("---->>> Exception " + e.toString() + " caught while loading database");
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
for(TxStream stream:txStreams.values()) {
|
||||
for (TxStream stream : txStreams.values()) {
|
||||
Thread t = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
stream.calculateConcurrency();
|
||||
} catch (Exception e) {/* don't let exceptions bubble up */ }
|
||||
stream.calculateConcurrency();
|
||||
} catch (Exception e) {
|
||||
/* don't let exceptions bubble up */ }
|
||||
}
|
||||
};
|
||||
threads.add(t);
|
||||
@ -149,31 +177,41 @@ public class TextDbLoader implements IWaveformDbLoader{
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Dispose.
|
||||
*/
|
||||
@Override
|
||||
public void dispose() {
|
||||
attrValues.clear();
|
||||
relationTypes.clear();
|
||||
txStreams.clear();
|
||||
txGenerators.clear();
|
||||
transactions = null;
|
||||
attributeTypes.clear();
|
||||
txStreams.clear();
|
||||
txGenerators.clear();
|
||||
transactions = null;
|
||||
attributeTypes.clear();
|
||||
relationsIn.clear();
|
||||
relationsOut.clear();
|
||||
if(mapDb!=null) {
|
||||
if (mapDb != null) {
|
||||
mapDb.close();
|
||||
mapDb=null;
|
||||
mapDb = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if is txfile.
|
||||
*
|
||||
* @param istream the istream
|
||||
* @return true, if is txfile
|
||||
*/
|
||||
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;
|
||||
if (readCnt == x.length) {
|
||||
for (int i = 0; i < x.length; i++)
|
||||
if (buffer[i] != x[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
@ -181,178 +219,254 @@ public class TextDbLoader implements IWaveformDbLoader{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is gzipped.
|
||||
*
|
||||
* @param f the f
|
||||
* @return true, if is gzipped
|
||||
*/
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<RelationType> getAllRelationTypes(){
|
||||
/**
|
||||
* Gets the all relation types.
|
||||
*
|
||||
* @return the all relation types
|
||||
*/
|
||||
public Collection<RelationType> getAllRelationTypes() {
|
||||
return relationTypes.values();
|
||||
}
|
||||
|
||||
/**
|
||||
* The Class TextDbParser.
|
||||
*/
|
||||
static class TextDbParser {
|
||||
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 \"([^\"]+)\"\\)$");
|
||||
|
||||
|
||||
/** The Constant scv_tr_stream. */
|
||||
static final Pattern scv_tr_stream = Pattern
|
||||
.compile("^scv_tr_stream\\s+\\(ID (\\d+),\\s+name\\s+\"([^\"]+)\",\\s+kind\\s+\"([^\"]+)\"\\)$");
|
||||
|
||||
/** The Constant scv_tr_generator. */
|
||||
static final Pattern scv_tr_generator = Pattern
|
||||
.compile("^scv_tr_generator\\s+\\(ID\\s+(\\d+),\\s+name\\s+\"([^\"]+)\",\\s+scv_tr_stream\\s+(\\d+),$");
|
||||
|
||||
/** The Constant begin_attribute. */
|
||||
static final Pattern begin_attribute = Pattern
|
||||
.compile("^begin_attribute \\(ID (\\d+), name \"([^\"]+)\", type \"([^\"]+)\"\\)$");
|
||||
|
||||
/** The Constant end_attribute. */
|
||||
static final Pattern end_attribute = Pattern
|
||||
.compile("^end_attribute \\(ID (\\d+), name \"([^\"]+)\", type \"([^\"]+)\"\\)$");
|
||||
|
||||
/** The loader. */
|
||||
final TextDbLoader loader;
|
||||
|
||||
|
||||
/** The transaction by id. */
|
||||
HashMap<Long, ScvTx> transactionById = new HashMap<>();
|
||||
|
||||
|
||||
/** The tx sink. */
|
||||
TreeMapSink<Long, ScvTx> txSink;
|
||||
|
||||
|
||||
/** The reader. */
|
||||
BufferedReader reader = null;
|
||||
|
||||
TxGenerator generator=null;
|
||||
|
||||
|
||||
/** The generator. */
|
||||
TxGenerator generator = null;
|
||||
|
||||
/** The attr value lut. */
|
||||
Map<String, Integer> attrValueLut = new HashMap<>();
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new text db parser.
|
||||
*
|
||||
* @param loader the loader
|
||||
*/
|
||||
public TextDbParser(TextDbLoader loader) {
|
||||
super();
|
||||
this.loader = loader;
|
||||
}
|
||||
|
||||
void parseInput(InputStream inputStream) throws IOException{
|
||||
/**
|
||||
* Parses the input.
|
||||
*
|
||||
* @param inputStream the input stream
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
void parseInput(InputStream inputStream) throws IOException {
|
||||
reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
|
||||
String curLine = reader.readLine();
|
||||
String nextLine = null;
|
||||
while((nextLine=reader.readLine())!=null && curLine!=null) {
|
||||
curLine=parseLine(curLine, nextLine);
|
||||
while ((nextLine = reader.readLine()) != null && curLine != null) {
|
||||
curLine = parseLine(curLine, nextLine);
|
||||
}
|
||||
if(curLine!=null)
|
||||
if (curLine != null)
|
||||
parseLine(curLine, nextLine);
|
||||
}
|
||||
|
||||
private TxAttributeType getAttrType(String name, DataType dataType, AssociationType type){
|
||||
String key =name+"-"+dataType.toString();
|
||||
/**
|
||||
* Gets the attr type.
|
||||
*
|
||||
* @param name the name
|
||||
* @param dataType the data type
|
||||
* @param type the type
|
||||
* @return the attr type
|
||||
*/
|
||||
private TxAttributeType getAttrType(String name, DataType dataType, AssociationType type) {
|
||||
String key = name + "-" + dataType.toString();
|
||||
TxAttributeType res;
|
||||
if(loader.attributeTypes.containsKey(key)){
|
||||
res=loader.attributeTypes.get(key);
|
||||
if (loader.attributeTypes.containsKey(key)) {
|
||||
res = loader.attributeTypes.get(key);
|
||||
} else {
|
||||
res=new TxAttributeType(name, dataType, type);
|
||||
res = new TxAttributeType(name, dataType, type);
|
||||
loader.attributeTypes.put(key, res);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private String parseLine(String curLine, String nextLine) throws IOException{
|
||||
/**
|
||||
* Parses the line.
|
||||
*
|
||||
* @param curLine the cur line
|
||||
* @param nextLine the next line
|
||||
* @return the string
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
private String parseLine(String curLine, String nextLine) throws IOException {
|
||||
String[] tokens = curLine.split("\\s+");
|
||||
if("tx_record_attribute".equals(tokens[0])){
|
||||
if ("tx_record_attribute".equals(tokens[0])) {
|
||||
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)):"";
|
||||
String remaining = tokens.length > 5 ? String.join(" ", Arrays.copyOfRange(tokens, 5, tokens.length))
|
||||
: "";
|
||||
TxAttributeType attrType = getAttrType(name, type, AssociationType.RECORD);
|
||||
transactionById.get(id).attributes.add(new TxAttribute(attrType, getAttrString(attrType, remaining)));
|
||||
} else if("tx_begin".equals(tokens[0])){
|
||||
} else if ("tx_begin".equals(tokens[0])) {
|
||||
Long id = Long.parseLong(tokens[1]);
|
||||
Long genId = Long.parseLong(tokens[2]);
|
||||
TxGenerator gen=loader.txGenerators.get(genId);
|
||||
ScvTx scvTx = new ScvTx(id, gen.stream.getId(), genId, Long.parseLong(tokens[3])*stringToScale(tokens[4]));
|
||||
loader.maxTime = loader.maxTime>scvTx.beginTime?loader.maxTime:scvTx.beginTime;
|
||||
TxGenerator gen = loader.txGenerators.get(genId);
|
||||
ScvTx scvTx = new ScvTx(id, gen.stream.getId(), genId,
|
||||
Long.parseLong(tokens[3]) * stringToScale(tokens[4]));
|
||||
loader.maxTime = loader.maxTime > scvTx.beginTime ? loader.maxTime : scvTx.beginTime;
|
||||
TxStream stream = loader.txStreams.get(gen.stream.getId());
|
||||
stream.setConcurrency(stream.getConcurrency()+1);
|
||||
if(nextLine!=null && nextLine.charAt(0)=='a') {
|
||||
int idx=0;
|
||||
while(nextLine!=null && nextLine.charAt(0)=='a') {
|
||||
String[] attrTokens=nextLine.split("\\s+");
|
||||
stream.setConcurrency(stream.getConcurrency() + 1);
|
||||
if (nextLine != null && nextLine.charAt(0) == 'a') {
|
||||
int idx = 0;
|
||||
while (nextLine != null && nextLine.charAt(0) == 'a') {
|
||||
String[] attrTokens = nextLine.split("\\s+");
|
||||
TxAttributeType attrType = gen.beginAttrs.get(idx);
|
||||
TxAttribute attr = new TxAttribute(attrType, getAttrString(attrType, attrTokens[1]));
|
||||
scvTx.attributes.add(attr);
|
||||
idx++;
|
||||
nextLine=reader.readLine();
|
||||
nextLine = reader.readLine();
|
||||
}
|
||||
}
|
||||
txSink.put(id, scvTx);
|
||||
transactionById.put(id, scvTx);
|
||||
} else if("tx_end".equals(tokens[0])){
|
||||
} else if ("tx_end".equals(tokens[0])) {
|
||||
Long id = Long.parseLong(tokens[1]);
|
||||
ScvTx scvTx = transactionById.get(id);
|
||||
assert Long.parseLong(tokens[2])==scvTx.generatorId;
|
||||
scvTx.endTime=Long.parseLong(tokens[3])*stringToScale(tokens[4]);
|
||||
loader.maxTime = loader.maxTime>scvTx.endTime?loader.maxTime:scvTx.endTime;
|
||||
assert Long.parseLong(tokens[2]) == scvTx.generatorId;
|
||||
scvTx.endTime = Long.parseLong(tokens[3]) * stringToScale(tokens[4]);
|
||||
loader.maxTime = loader.maxTime > scvTx.endTime ? loader.maxTime : scvTx.endTime;
|
||||
TxGenerator gen = loader.txGenerators.get(scvTx.generatorId);
|
||||
TxStream stream = loader.txStreams.get(gen.stream.getId());
|
||||
if(scvTx.beginTime==scvTx.endTime)
|
||||
stream.addEvent(new TxEvent(loader, EventKind.SINGLE, id, scvTx.beginTime));
|
||||
else {
|
||||
stream.addEvent(new TxEvent(loader, EventKind.BEGIN, id, scvTx.beginTime));
|
||||
stream.addEvent(new TxEvent(loader, EventKind.END, id, scvTx.endTime));
|
||||
if (scvTx.beginTime == scvTx.endTime) {
|
||||
TxEvent evt = new TxEvent(loader, EventKind.SINGLE, id, scvTx.beginTime);
|
||||
stream.addEvent(evt);
|
||||
gen.addEvent(evt);
|
||||
} else {
|
||||
TxEvent begEvt = new TxEvent(loader, EventKind.BEGIN, id, scvTx.beginTime);
|
||||
stream.addEvent(begEvt);
|
||||
gen.addEvent(begEvt);
|
||||
TxEvent endEvt = new TxEvent(loader, EventKind.END, id, scvTx.endTime);
|
||||
stream.addEvent(endEvt);
|
||||
gen.addEvent(endEvt);
|
||||
}
|
||||
stream.setConcurrency(stream.getConcurrency()-1);
|
||||
if(nextLine!=null && nextLine.charAt(0)=='a') {
|
||||
int idx=0;
|
||||
while(nextLine!=null && nextLine.charAt(0)=='a') {
|
||||
String[] attrTokens=nextLine.split("\\s+");
|
||||
stream.setConcurrency(stream.getConcurrency() - 1);
|
||||
if (nextLine != null && nextLine.charAt(0) == 'a') {
|
||||
int idx = 0;
|
||||
while (nextLine != null && nextLine.charAt(0) == 'a') {
|
||||
String[] attrTokens = nextLine.split("\\s+");
|
||||
TxAttributeType attrType = gen.endAttrs.get(idx);
|
||||
TxAttribute attr = new TxAttribute(attrType, getAttrString(attrType, attrTokens[1]));
|
||||
scvTx.attributes.add(attr);
|
||||
idx++;
|
||||
nextLine=reader.readLine();
|
||||
nextLine = reader.readLine();
|
||||
}
|
||||
}
|
||||
} else if("tx_relation".equals(tokens[0])){
|
||||
Long tr2= Long.parseLong(tokens[2]);
|
||||
Long tr1= Long.parseLong(tokens[3]);
|
||||
String relType=tokens[1].substring(1, tokens[1].length()-1);
|
||||
if(!loader.relationTypes.containsKey(relType))
|
||||
} else if ("tx_relation".equals(tokens[0])) {
|
||||
Long tr2 = Long.parseLong(tokens[2]);
|
||||
Long tr1 = Long.parseLong(tokens[3]);
|
||||
String relType = tokens[1].substring(1, tokens[1].length() - 1);
|
||||
if (!loader.relationTypes.containsKey(relType))
|
||||
loader.relationTypes.put(relType, RelationTypeFactory.create(relType));
|
||||
ScvRelation rel = new ScvRelation(loader.relationTypes.get(relType), tr1, tr2);
|
||||
loader.relationsOut.put(tr1, rel);
|
||||
loader.relationsIn.put(tr2, rel);
|
||||
} else if("scv_tr_stream".equals(tokens[0])){
|
||||
} 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(loader, id, matcher.group(2), matcher.group(3));
|
||||
loader.txStreams.put(id, stream);
|
||||
}
|
||||
} else if("scv_tr_generator".equals(tokens[0])){
|
||||
} 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=loader.txStreams.get(Long.parseLong(matcher.group(3)));
|
||||
generator=new TxGenerator(loader, id, matcher.group(2), stream);
|
||||
loader.txGenerators.put(id, generator);
|
||||
TxStream stream = loader.txStreams.get(Long.parseLong(matcher.group(3)));
|
||||
generator = new TxGenerator(loader, id, matcher.group(2), stream);
|
||||
loader.txGenerators.put(id, generator);
|
||||
}
|
||||
} else if("begin_attribute".equals(tokens[0])){
|
||||
} else if ("begin_attribute".equals(tokens[0])) {
|
||||
Matcher matcher = begin_attribute.matcher(curLine);
|
||||
if ((matcher.matches())) {
|
||||
TxAttributeType attrType = getAttrType(matcher.group(2), DataType.valueOf(matcher.group(3)), AssociationType.BEGIN);
|
||||
TxAttributeType attrType = getAttrType(matcher.group(2), DataType.valueOf(matcher.group(3)),
|
||||
AssociationType.BEGIN);
|
||||
generator.beginAttrs.add(attrType);
|
||||
}
|
||||
} else if("end_attribute".equals(tokens[0])){
|
||||
} else if ("end_attribute".equals(tokens[0])) {
|
||||
Matcher matcher = end_attribute.matcher(curLine);
|
||||
if ((matcher.matches())) {
|
||||
TxAttributeType attrType = getAttrType(matcher.group(2), DataType.valueOf(matcher.group(3)), AssociationType.END);
|
||||
TxAttributeType attrType = getAttrType(matcher.group(2), DataType.valueOf(matcher.group(3)),
|
||||
AssociationType.END);
|
||||
generator.endAttrs.add(attrType);
|
||||
}
|
||||
} 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 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+"'");
|
||||
System.out.println("Don't know what to do with: '" + curLine + "'");
|
||||
return nextLine;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the attr string.
|
||||
*
|
||||
* @param attrType the attr type
|
||||
* @param string the string
|
||||
* @return the attr string
|
||||
*/
|
||||
private String getAttrString(TxAttributeType attrType, String string) {
|
||||
String value;
|
||||
switch(attrType.getDataType()){
|
||||
switch (attrType.getDataType()) {
|
||||
case STRING:
|
||||
case ENUMERATION:
|
||||
value=string.substring(1, string.length()-1);
|
||||
value = string.substring(1, string.length() - 1);
|
||||
break;
|
||||
default:
|
||||
value=string;
|
||||
value = string;
|
||||
}
|
||||
if(attrValueLut.containsKey(value)){
|
||||
if (attrValueLut.containsKey(value)) {
|
||||
return loader.attrValues.get(attrValueLut.get(value));
|
||||
} else {
|
||||
attrValueLut.put(value, loader.attrValues.size());
|
||||
@ -361,20 +475,38 @@ public class TextDbLoader implements IWaveformDbLoader{
|
||||
}
|
||||
}
|
||||
|
||||
private long stringToScale(String scale){
|
||||
/**
|
||||
* String to scale.
|
||||
*
|
||||
* @param scale the scale
|
||||
* @return the long
|
||||
*/
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the transaction.
|
||||
*
|
||||
* @param txId the tx id
|
||||
* @return the transaction
|
||||
*/
|
||||
public ITx getTransaction(long txId) {
|
||||
if(txCache.containsKey(txId))
|
||||
if (txCache.containsKey(txId))
|
||||
return txCache.get(txId);
|
||||
Tx tx = new Tx(this, txId);
|
||||
txCache.put(txId, tx);
|
||||
@ -382,4 +514,3 @@ public class TextDbLoader implements IWaveformDbLoader{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 IT Just working.
|
||||
* Copyright (c) 2020 MINRES Technologies GmbH
|
||||
* 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
|
||||
@ -21,111 +22,217 @@ import com.minres.scviewer.database.tx.ITxAttribute;
|
||||
import com.minres.scviewer.database.tx.ITxGenerator;
|
||||
import com.minres.scviewer.database.tx.ITxRelation;
|
||||
|
||||
/**
|
||||
* The Class Tx.
|
||||
*/
|
||||
class Tx implements ITx {
|
||||
|
||||
|
||||
/** The loader. */
|
||||
private final TextDbLoader loader;
|
||||
|
||||
|
||||
/** The id. */
|
||||
private long id;
|
||||
|
||||
long beginTime=-1;
|
||||
|
||||
long endTime=-1;
|
||||
|
||||
|
||||
/** The begin time. */
|
||||
long beginTime = -1;
|
||||
|
||||
/** The end time. */
|
||||
long endTime = -1;
|
||||
|
||||
/** The concurrency index. */
|
||||
private int concurrencyIndex;
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new tx.
|
||||
*
|
||||
* @param loader the loader
|
||||
* @param scvTx the scv tx
|
||||
*/
|
||||
public Tx(TextDbLoader loader, ScvTx scvTx) {
|
||||
this.loader=loader;
|
||||
id=scvTx.id;
|
||||
this.loader = loader;
|
||||
id = scvTx.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new tx.
|
||||
*
|
||||
* @param loader the loader
|
||||
* @param txId the tx id
|
||||
*/
|
||||
public Tx(TextDbLoader loader, long txId) {
|
||||
this.loader=loader;
|
||||
id=txId;
|
||||
this.loader = loader;
|
||||
id = txId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the incoming relations.
|
||||
*
|
||||
* @return the incoming relations
|
||||
*/
|
||||
@Override
|
||||
public Collection<ITxRelation> getIncomingRelations() {
|
||||
Set<ScvRelation> rels = loader.relationsIn.get(id);
|
||||
return rels.stream().map(rel -> new TxRelation(loader, rel)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the outgoing relations.
|
||||
*
|
||||
* @return the outgoing relations
|
||||
*/
|
||||
@Override
|
||||
public Collection<ITxRelation> getOutgoingRelations() {
|
||||
Set<ScvRelation> rels = loader.relationsOut.get(id);
|
||||
return rels.stream().map(rel -> new TxRelation(loader, rel)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare to.
|
||||
*
|
||||
* @param o the o
|
||||
* @return the int
|
||||
*/
|
||||
@Override
|
||||
public int compareTo(ITx o) {
|
||||
int res =getBeginTime().compareTo(o.getBeginTime());
|
||||
if(res!=0)
|
||||
int res = getBeginTime().compareTo(o.getBeginTime());
|
||||
if (res != 0)
|
||||
return res;
|
||||
else
|
||||
return getId().compareTo(o.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (obj == null || getClass() != obj.getClass()) return false;
|
||||
return this.getScvTx().equals(((Tx) obj).getScvTx());
|
||||
}
|
||||
|
||||
/**
|
||||
* Equals.
|
||||
*
|
||||
* @param obj the obj
|
||||
* @return true, if successful
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null || getClass() != obj.getClass())
|
||||
return false;
|
||||
return this.getScvTx().equals(((Tx) obj).getScvTx());
|
||||
}
|
||||
|
||||
/**
|
||||
* Hash code.
|
||||
*
|
||||
* @return the int
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getScvTx().hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* To string.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "tx#"+getId()+"["+getBeginTime()/1000000+"ns - "+getEndTime()/1000000+"ns]";
|
||||
return "tx#" + getId() + "[" + getBeginTime() / 1000000 + "ns - " + getEndTime() / 1000000 + "ns]";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
@Override
|
||||
public Long getId() {
|
||||
return getScvTx().id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the stream.
|
||||
*
|
||||
* @return the stream
|
||||
*/
|
||||
@Override
|
||||
public IWaveform getStream() {
|
||||
return loader.txStreams.get(getScvTx().streamId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the generator.
|
||||
*
|
||||
* @return the generator
|
||||
*/
|
||||
@Override
|
||||
public ITxGenerator getGenerator() {
|
||||
return loader.txGenerators.get(getScvTx().generatorId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the begin time.
|
||||
*
|
||||
* @return the begin time
|
||||
*/
|
||||
@Override
|
||||
public Long getBeginTime() {
|
||||
if(beginTime<0) beginTime=getScvTx().beginTime;
|
||||
if (beginTime < 0)
|
||||
beginTime = getScvTx().beginTime;
|
||||
return beginTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the end time.
|
||||
*
|
||||
* @return the end time
|
||||
*/
|
||||
@Override
|
||||
public Long getEndTime() {
|
||||
if(endTime<0) endTime=getScvTx().endTime;
|
||||
if (endTime < 0)
|
||||
endTime = getScvTx().endTime;
|
||||
return endTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the end time.
|
||||
*
|
||||
* @param time the new end time
|
||||
*/
|
||||
void setEndTime(Long time) {
|
||||
getScvTx().endTime=time;
|
||||
getScvTx().endTime = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the concurrency index.
|
||||
*
|
||||
* @return the concurrency index
|
||||
*/
|
||||
@Override
|
||||
public int getConcurrencyIndex() {
|
||||
return concurrencyIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the concurrency index.
|
||||
*
|
||||
* @param idx the new concurrency index
|
||||
*/
|
||||
void setConcurrencyIndex(int idx) {
|
||||
concurrencyIndex=idx;
|
||||
concurrencyIndex = idx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the attributes.
|
||||
*
|
||||
* @return the attributes
|
||||
*/
|
||||
@Override
|
||||
public List<ITxAttribute> getAttributes() {
|
||||
return getScvTx().attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the scv tx.
|
||||
*
|
||||
* @return the scv tx
|
||||
*/
|
||||
private ScvTx getScvTx() {
|
||||
return loader.transactions.get(id);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 IT Just working.
|
||||
* Copyright (c) 2020 MINRES Technologies GmbH
|
||||
* 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
|
||||
@ -16,37 +17,66 @@ import com.minres.scviewer.database.AssociationType;
|
||||
import com.minres.scviewer.database.DataType;
|
||||
import com.minres.scviewer.database.tx.ITxAttribute;
|
||||
|
||||
public class TxAttribute implements ITxAttribute, Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* The Class TxAttribute.
|
||||
*/
|
||||
public class TxAttribute implements ITxAttribute, Serializable {
|
||||
|
||||
/** The Constant serialVersionUID. */
|
||||
private static final long serialVersionUID = 4767726016651807152L;
|
||||
|
||||
/** The attribute type. */
|
||||
private final TxAttributeType attributeType;
|
||||
|
||||
/** The value. */
|
||||
private final String value;
|
||||
|
||||
TxAttribute(TxAttributeType type, String value){
|
||||
this.attributeType=type;
|
||||
this.value=value;
|
||||
|
||||
/**
|
||||
* Instantiates a new tx attribute.
|
||||
*
|
||||
* @param type the type
|
||||
* @param value the value
|
||||
*/
|
||||
TxAttribute(TxAttributeType type, String value) {
|
||||
this.attributeType = type;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name.
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return attributeType.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type.
|
||||
*
|
||||
* @return the type
|
||||
*/
|
||||
@Override
|
||||
public AssociationType getType() {
|
||||
return attributeType.getType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the data type.
|
||||
*
|
||||
* @return the data type
|
||||
*/
|
||||
@Override
|
||||
public DataType getDataType() {
|
||||
return attributeType.getDataType();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value.
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
@Override
|
||||
public Object getValue() {
|
||||
return value;
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 IT Just working.
|
||||
* Copyright (c) 2020 MINRES Technologies GmbH
|
||||
* 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
|
||||
@ -16,34 +17,61 @@ import com.minres.scviewer.database.AssociationType;
|
||||
import com.minres.scviewer.database.DataType;
|
||||
import com.minres.scviewer.database.tx.ITxAttributeType;
|
||||
|
||||
/**
|
||||
* The Class TxAttributeType.
|
||||
*/
|
||||
class TxAttributeType implements ITxAttributeType, Serializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
/** The Constant serialVersionUID. */
|
||||
private static final long serialVersionUID = 7159721937208946828L;
|
||||
|
||||
|
||||
/** The name. */
|
||||
private String name;
|
||||
|
||||
|
||||
/** The data type. */
|
||||
private DataType dataType;
|
||||
|
||||
|
||||
/** The type. */
|
||||
private AssociationType type;
|
||||
|
||||
TxAttributeType(String name, DataType dataType, AssociationType type){
|
||||
this.name=name;
|
||||
this.dataType=dataType;
|
||||
this.type=type;
|
||||
|
||||
/**
|
||||
* Instantiates a new tx attribute type.
|
||||
*
|
||||
* @param name the name
|
||||
* @param dataType the data type
|
||||
* @param type the type
|
||||
*/
|
||||
TxAttributeType(String name, DataType dataType, AssociationType type) {
|
||||
this.name = name;
|
||||
this.dataType = dataType;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name.
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the data type.
|
||||
*
|
||||
* @return the data type
|
||||
*/
|
||||
@Override
|
||||
public DataType getDataType() {
|
||||
return dataType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type.
|
||||
*
|
||||
* @return the type
|
||||
*/
|
||||
@Override
|
||||
public AssociationType getType() {
|
||||
return type;
|
||||
|
@ -1,3 +1,13 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 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
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.text;
|
||||
|
||||
import com.minres.scviewer.database.EventKind;
|
||||
@ -5,50 +15,94 @@ import com.minres.scviewer.database.WaveformType;
|
||||
import com.minres.scviewer.database.tx.ITx;
|
||||
import com.minres.scviewer.database.tx.ITxEvent;
|
||||
|
||||
/**
|
||||
* The Class TxEvent.
|
||||
*/
|
||||
class TxEvent implements ITxEvent {
|
||||
|
||||
/** The loader. */
|
||||
final TextDbLoader loader;
|
||||
|
||||
|
||||
/** The kind. */
|
||||
final EventKind kind;
|
||||
|
||||
|
||||
/** The transaction. */
|
||||
final long transaction;
|
||||
|
||||
|
||||
/** The time. */
|
||||
final long time;
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new tx event.
|
||||
*
|
||||
* @param loader the loader
|
||||
* @param kind the kind
|
||||
* @param transaction the transaction
|
||||
* @param time the time
|
||||
*/
|
||||
TxEvent(TextDbLoader loader, EventKind kind, Long transaction, Long time) {
|
||||
this.loader=loader;
|
||||
this.loader = loader;
|
||||
this.kind = kind;
|
||||
this.transaction = transaction;
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate.
|
||||
*
|
||||
* @return the i tx event
|
||||
* @throws CloneNotSupportedException the clone not supported exception
|
||||
*/
|
||||
@Override
|
||||
public
|
||||
ITxEvent duplicate() throws CloneNotSupportedException {
|
||||
public ITxEvent duplicate() throws CloneNotSupportedException {
|
||||
return new TxEvent(loader, kind, transaction, time);
|
||||
}
|
||||
|
||||
/**
|
||||
* To string.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
@Override
|
||||
public
|
||||
String toString() {
|
||||
return kind.toString()+"@"+time+" of tx #"+transaction;
|
||||
public String toString() {
|
||||
return kind.toString() + "@" + time + " of tx #" + transaction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type.
|
||||
*
|
||||
* @return the type
|
||||
*/
|
||||
@Override
|
||||
public WaveformType getType() {
|
||||
return WaveformType.TRANSACTION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the kind.
|
||||
*
|
||||
* @return the kind
|
||||
*/
|
||||
@Override
|
||||
public EventKind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the time.
|
||||
*
|
||||
* @return the time
|
||||
*/
|
||||
@Override
|
||||
public Long getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the transaction.
|
||||
*
|
||||
* @return the transaction
|
||||
*/
|
||||
@Override
|
||||
public ITx getTransaction() {
|
||||
return loader.getTransaction(transaction);
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 IT Just working.
|
||||
* Copyright (c) 2020 MINRES Technologies GmbH
|
||||
* 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
|
||||
@ -16,39 +17,90 @@ import java.util.List;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.tx.ITxGenerator;
|
||||
|
||||
/**
|
||||
* The Class TxGenerator.
|
||||
*/
|
||||
class TxGenerator extends AbstractTxStream implements ITxGenerator {
|
||||
|
||||
/** The stream. */
|
||||
TxStream stream;
|
||||
|
||||
List<TxAttributeType> beginAttrs = new ArrayList<>();
|
||||
|
||||
List<TxAttributeType> endAttrs= new ArrayList<>();
|
||||
|
||||
TxGenerator(TextDbLoader loader, Long id, String name, TxStream stream){
|
||||
/** The begin attrs. */
|
||||
List<TxAttributeType> beginAttrs = new ArrayList<>();
|
||||
|
||||
/** The end attrs. */
|
||||
List<TxAttributeType> endAttrs = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Instantiates a new tx generator.
|
||||
*
|
||||
* @param loader the loader
|
||||
* @param id the id
|
||||
* @param name the name
|
||||
* @param stream the stream
|
||||
*/
|
||||
TxGenerator(TextDbLoader loader, Long id, String name, TxStream stream) {
|
||||
super(loader, id, name);
|
||||
this.stream=stream;
|
||||
this.stream = stream;
|
||||
stream.addChild(this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the stream.
|
||||
*
|
||||
* @return the stream
|
||||
*/
|
||||
@Override
|
||||
public IWaveform getStream(){
|
||||
public IWaveform getStream() {
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if is same.
|
||||
*
|
||||
* @param other the other
|
||||
* @return true, if is same
|
||||
*/
|
||||
@Override
|
||||
public boolean isSame(IWaveform other) {
|
||||
return(other instanceof TxGenerator && this.getId().equals(other.getId()));
|
||||
return (other instanceof TxGenerator && this.getId().equals(other.getId()));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the begin attrs.
|
||||
*
|
||||
* @return the begin attrs
|
||||
*/
|
||||
public List<TxAttributeType> getBeginAttrs() {
|
||||
return beginAttrs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the end attrs.
|
||||
*
|
||||
* @return the end attrs
|
||||
*/
|
||||
public List<TxAttributeType> getEndAttrs() {
|
||||
return endAttrs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the kind.
|
||||
*
|
||||
* @return the kind
|
||||
*/
|
||||
@Override
|
||||
public String getKind() {
|
||||
return stream.getKind();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the width.
|
||||
*
|
||||
* @return the width
|
||||
*/
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return stream.getWidth();
|
||||
}
|
||||
}
|
||||
|
@ -1,30 +1,66 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2020 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
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.text;
|
||||
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
import com.minres.scviewer.database.tx.ITx;
|
||||
import com.minres.scviewer.database.tx.ITxRelation;
|
||||
|
||||
/**
|
||||
* The Class TxRelation.
|
||||
*/
|
||||
class TxRelation implements ITxRelation {
|
||||
|
||||
/** The loader. */
|
||||
final TextDbLoader loader;
|
||||
|
||||
|
||||
/** The scv relation. */
|
||||
final ScvRelation scvRelation;
|
||||
|
||||
|
||||
/**
|
||||
* Instantiates a new tx relation.
|
||||
*
|
||||
* @param loader the loader
|
||||
* @param scvRelation the scv relation
|
||||
*/
|
||||
public TxRelation(TextDbLoader loader, ScvRelation scvRelation) {
|
||||
this.loader = loader;
|
||||
this.scvRelation = scvRelation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the relation type.
|
||||
*
|
||||
* @return the relation type
|
||||
*/
|
||||
@Override
|
||||
public RelationType getRelationType() {
|
||||
return scvRelation.relationType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the source.
|
||||
*
|
||||
* @return the source
|
||||
*/
|
||||
@Override
|
||||
public ITx getSource() {
|
||||
return loader.getTransaction(scvRelation.source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the target.
|
||||
*
|
||||
* @return the target
|
||||
*/
|
||||
@Override
|
||||
public ITx getTarget() {
|
||||
return loader.getTransaction(scvRelation.target);
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 IT Just working.
|
||||
* Copyright (c) 2020 MINRES Technologies GmbH
|
||||
* 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
|
||||
@ -12,23 +13,82 @@ package com.minres.scviewer.database.text;
|
||||
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
|
||||
/**
|
||||
* The Class TxStream.
|
||||
*/
|
||||
class TxStream extends AbstractTxStream {
|
||||
|
||||
|
||||
/** The kind. */
|
||||
final String kind;
|
||||
|
||||
TxStream(TextDbLoader loader, Long id, String name, String kind){
|
||||
|
||||
/**
|
||||
* Instantiates a new tx stream.
|
||||
*
|
||||
* @param loader the loader
|
||||
* @param id the id
|
||||
* @param name the name
|
||||
* @param kind the kind
|
||||
*/
|
||||
TxStream(TextDbLoader loader, Long id, String name, String kind) {
|
||||
super(loader, id, name);
|
||||
this.kind=kind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSame(IWaveform other) {
|
||||
return(other instanceof TxStream && this.getId().equals(other.getId()));
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is same.
|
||||
*
|
||||
* @param other the other
|
||||
* @return true, if is same
|
||||
*/
|
||||
@Override
|
||||
public boolean isSame(IWaveform other) {
|
||||
return (other instanceof TxStream && this.getId().equals(other.getId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the kind.
|
||||
*
|
||||
* @return the kind
|
||||
*/
|
||||
@Override
|
||||
public String getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
/** The max concurrency. */
|
||||
private int maxConcurrency = 0;
|
||||
|
||||
/** The concurrency. */
|
||||
private int concurrency = 0;
|
||||
|
||||
/**
|
||||
* Sets the concurrency.
|
||||
*
|
||||
* @param concurrency the new concurrency
|
||||
*/
|
||||
void setConcurrency(int concurrency) {
|
||||
this.concurrency = concurrency;
|
||||
if (concurrency > maxConcurrency)
|
||||
maxConcurrency = concurrency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the concurrency.
|
||||
*
|
||||
* @return the concurrency
|
||||
*/
|
||||
int getConcurrency() {
|
||||
return this.concurrency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the width.
|
||||
*
|
||||
* @return the width
|
||||
*/
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return maxConcurrency;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user