fixes deferred loading of Tx when being referenced
This commit is contained in:
parent
f9d38b5091
commit
6f2f5a388c
@ -129,7 +129,7 @@ public class FtrDbLoader implements IWaveformDbLoader {
|
||||
* Gets the transaction.
|
||||
*
|
||||
* @param txId the tx id
|
||||
* @return the transaction
|
||||
* @return the transaction or null if the transaction is not available
|
||||
*/
|
||||
public synchronized ITx getTransaction(long txId) {
|
||||
if (txCache.containsKey(txId))
|
||||
@ -139,7 +139,7 @@ public class FtrDbLoader implements IWaveformDbLoader {
|
||||
txCache.put(txId, tx);
|
||||
return tx;
|
||||
} else {
|
||||
throw new IllegalArgumentException();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -528,12 +528,14 @@ public class FtrDbLoader implements IWaveformDbLoader {
|
||||
CborType next = cborDecoder.peekType();
|
||||
while(next != null && !break_type.isEqualType(next)) {
|
||||
long sz = cborDecoder.readArrayLength();
|
||||
assert(sz==3);
|
||||
assert(sz==5);
|
||||
long type_id = cborDecoder.readInt();
|
||||
long from_id = cborDecoder.readInt();
|
||||
long to_id = cborDecoder.readInt();
|
||||
long from_fiber = sz>3?cborDecoder.readInt():-1;
|
||||
long to_fiber = sz>3?cborDecoder.readInt():-1;
|
||||
String rel_name = strDict.get((int)type_id);
|
||||
FtrRelation ftrRel = new FtrRelation(relationTypes.getOrDefault(rel_name, RelationTypeFactory.create(rel_name)), from_id, to_id);
|
||||
FtrRelation ftrRel = new FtrRelation(relationTypes.getOrDefault(rel_name, RelationTypeFactory.create(rel_name)), from_id, to_id, from_fiber, to_fiber);
|
||||
relationsOut.put(from_id, ftrRel);
|
||||
relationsIn.put(to_id, ftrRel);
|
||||
next = cborDecoder.peekType();
|
||||
|
@ -10,8 +10,14 @@
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.ftr;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
import com.minres.scviewer.database.tx.ITx;
|
||||
import com.minres.scviewer.database.tx.ITxAttribute;
|
||||
import com.minres.scviewer.database.tx.ITxRelation;
|
||||
|
||||
/**
|
||||
@ -53,7 +59,9 @@ class TxRelation implements ITxRelation {
|
||||
*/
|
||||
@Override
|
||||
public ITx getSource() {
|
||||
return loader.getTransaction(scvRelation.source);
|
||||
ITx tx = loader.getTransaction(scvRelation.source);
|
||||
if(tx!=null) return tx;
|
||||
return new TxFacade(scvRelation.source_fiber, scvRelation.source);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,7 +71,82 @@ class TxRelation implements ITxRelation {
|
||||
*/
|
||||
@Override
|
||||
public ITx getTarget() {
|
||||
return loader.getTransaction(scvRelation.target);
|
||||
ITx tx = loader.getTransaction(scvRelation.target);
|
||||
if(tx!=null) return tx;
|
||||
return new TxFacade(scvRelation.target_fiber, scvRelation.target);
|
||||
}
|
||||
|
||||
private class TxFacade implements ITx {
|
||||
|
||||
final long fiberId;
|
||||
|
||||
final long txId;
|
||||
|
||||
ITx tx = null;
|
||||
|
||||
public TxFacade(long fiberId, long txId) {
|
||||
this.fiberId = fiberId;
|
||||
this.txId=txId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ITx o) {
|
||||
return tx==null?-1:tx.compareTo(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return txId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWaveform getStream() {
|
||||
if(tx==null) {
|
||||
TxStream fiber = loader.txStreams.get(fiberId);
|
||||
fiber.loadStream();
|
||||
tx = loader.getTransaction(txId);
|
||||
return loader.txStreams.get(fiberId);
|
||||
} else
|
||||
return tx.getStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IWaveform getGenerator() {
|
||||
if(tx==null) {
|
||||
loader.txStreams.get(fiberId).loadStream();
|
||||
tx = loader.getTransaction(txId);
|
||||
}
|
||||
return tx.getGenerator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBeginTime() {
|
||||
return tx==null?-1:tx.getBeginTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getEndTime() {
|
||||
return tx==null?-1:tx.getBeginTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ITxAttribute> getAttributes() {
|
||||
return tx==null?new ArrayList<>():tx.getAttributes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ITxRelation> getIncomingRelations() {
|
||||
return tx==null?new ArrayList<>():tx.getIncomingRelations();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ITxRelation> getOutgoingRelations() {
|
||||
return tx==null?new ArrayList<>():tx.getOutgoingRelations();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return tx==null?("tx#" + getId() + "[not available]"):tx.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -71,6 +71,18 @@ class TxStream extends AbstractTxStream {
|
||||
return chunks;
|
||||
}
|
||||
|
||||
public void loadStream() {
|
||||
try {
|
||||
List<byte[]> chunks = getChunks();
|
||||
int blockid = 0;
|
||||
for (byte[] bs : chunks) {
|
||||
loader.parseTx(this, blockid, bs);
|
||||
blockid++;
|
||||
}
|
||||
} catch (InputFormatException e) {
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Gets the events.
|
||||
*
|
||||
@ -79,17 +91,9 @@ class TxStream extends AbstractTxStream {
|
||||
@Override
|
||||
public IEventList getEvents() {
|
||||
if(events.size()==0) {
|
||||
try {
|
||||
List<byte[]> chunks = getChunks();
|
||||
int blockid = 0;
|
||||
for (byte[] bs : chunks) {
|
||||
loader.parseTx(this, blockid, bs);
|
||||
blockid++;
|
||||
}
|
||||
} catch (InputFormatException e) {
|
||||
} catch (IOException e) {
|
||||
}
|
||||
loadStream();
|
||||
}
|
||||
return events;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user