Make lazy waveform and attribute loading explicit and thread safe
This commit is contained in:
1 parent
182b5bc01e
commit
82c4dcf552
12 files changed
+162
-71
No files matched your search
@@ -16,3 +16,4 @@ Service-Component: OSGI-INF/component.xml
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Automatic-Module-Name: com.minres.scviewer.database.ftr
|
||||
Bundle-ClassPath: .
|
||||
Export-Package: com.minres.scviewer.database.ftr;x-friends:="com.minres.scviewer.database.test"
|
||||
+3
-3
@@ -82,7 +82,7 @@ abstract class AbstractTxStream extends HierNode implements IWaveform {
|
||||
*/
|
||||
@Override
|
||||
public IEvent[] getEventsAtTime(long time) {
|
||||
return events.get(time);
|
||||
return getEvents().get(time);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,11 +93,11 @@ abstract class AbstractTxStream extends HierNode implements IWaveform {
|
||||
*/
|
||||
@Override
|
||||
public IEvent[] getEventsBeforeTime(long time) {
|
||||
EventEntry e = events.floorEntry(time);
|
||||
EventEntry e = getEvents().floorEntry(time);
|
||||
if (e == null)
|
||||
return new IEvent[] {};
|
||||
else
|
||||
return events.floorEntry(time).events;
|
||||
return e.events;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -344,7 +344,7 @@ public class FtrDbLoader implements IWaveformDbLoader {
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOG.error("Error parsing file "+file.getName(), e);
|
||||
throw new IllegalStateException("Cannot parse attributes in " + file.getName(), e);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
+12
-13
@@ -11,10 +11,10 @@
|
||||
package com.minres.scviewer.database.ftr;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.minres.scviewer.database.InputFormatException;
|
||||
import com.minres.scviewer.database.LazyValue;
|
||||
import com.minres.scviewer.database.tx.ITxAttribute;
|
||||
|
||||
/**
|
||||
@@ -41,7 +41,7 @@ class FtrTx implements Serializable {
|
||||
long endTime;
|
||||
|
||||
/** The attributes. */
|
||||
final List<ITxAttribute> attributes = new ArrayList<>();
|
||||
private final LazyValue<List<ITxAttribute>> attributes = new LazyValue<>();
|
||||
|
||||
final long blockId;
|
||||
|
||||
@@ -75,15 +75,14 @@ class FtrTx implements Serializable {
|
||||
}
|
||||
|
||||
public List<ITxAttribute> getAttributes(FtrDbLoader loader) {
|
||||
if(attributes.size()==0)
|
||||
try {
|
||||
final TxStream stream = loader.txStreams.get(streamId);
|
||||
final byte[] chunk = stream.getChunks().get((int)blockId);
|
||||
attributes.addAll(loader.parseAtrributes(chunk, blockOffset));
|
||||
} catch (InputFormatException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return attributes;
|
||||
}
|
||||
return attributes.get(() -> {
|
||||
try {
|
||||
TxStream stream = loader.txStreams.get(streamId);
|
||||
byte[] chunk = stream.getChunks().get((int) blockId);
|
||||
return List.copyOf(loader.parseAtrributes(chunk, blockOffset));
|
||||
} catch (InputFormatException e) {
|
||||
throw new IllegalStateException("Cannot read attributes for transaction " + id, e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+1
-17
@@ -10,14 +10,12 @@
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.ftr;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.minres.scviewer.database.DirectionType;
|
||||
import com.minres.scviewer.database.IEventList;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.InputFormatException;
|
||||
|
||||
/**
|
||||
* The Class TxGenerator.
|
||||
@@ -65,21 +63,7 @@ class TxGenerator extends AbstractTxStream {
|
||||
*/
|
||||
@Override
|
||||
public IEventList getEvents() {
|
||||
if(stream.events.size()==0) {
|
||||
try {
|
||||
List<byte[]> chunks = stream.getChunks();
|
||||
int blockid = 0;
|
||||
for (byte[] bs : chunks) {
|
||||
loader.parseTx(stream, blockid++, bs);
|
||||
}
|
||||
} catch (InputFormatException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
stream.loadStream();
|
||||
return events;
|
||||
}
|
||||
/**
|
||||
|
||||
+28
-31
@@ -17,6 +17,7 @@ import java.util.List;
|
||||
import com.minres.scviewer.database.DirectionType;
|
||||
import com.minres.scviewer.database.IEventList;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.LazyValue;
|
||||
import com.minres.scviewer.database.InputFormatException;
|
||||
|
||||
/**
|
||||
@@ -29,7 +30,8 @@ class TxStream extends AbstractTxStream {
|
||||
|
||||
final ArrayList<Long> fileOffsets = new ArrayList<>();
|
||||
|
||||
final ArrayList<byte[]> chunks = new ArrayList<>();
|
||||
private final LazyValue<List<byte[]>> chunks = new LazyValue<>();
|
||||
private final LazyValue<Boolean> parsed = new LazyValue<>();
|
||||
|
||||
/**
|
||||
* Instantiates a new tx stream.
|
||||
@@ -66,37 +68,32 @@ class TxStream extends AbstractTxStream {
|
||||
}
|
||||
|
||||
public List<byte[]> getChunks() throws InputFormatException {
|
||||
if(chunks.size()==0) {
|
||||
chunks.addAll(loader.getChunksAtOffsets(fileOffsets));
|
||||
}
|
||||
return chunks;
|
||||
}
|
||||
return chunks.get(() -> {
|
||||
try {
|
||||
return List.copyOf(loader.getChunksAtOffsets(fileOffsets));
|
||||
} catch (InputFormatException e) {
|
||||
throw new IllegalStateException("Cannot read stream " + getFullName(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void loadStream() {
|
||||
if(chunks.size()>0) return;
|
||||
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.
|
||||
*
|
||||
* @return the events
|
||||
*/
|
||||
@Override
|
||||
public IEventList getEvents() {
|
||||
if(events.size()==0) {
|
||||
loadStream();
|
||||
}
|
||||
return events;
|
||||
}
|
||||
public void loadStream() {
|
||||
parsed.get(() -> {
|
||||
try {
|
||||
int blockId = 0;
|
||||
for (byte[] chunk : getChunks()) loader.parseTx(this, blockId++, chunk);
|
||||
return Boolean.TRUE;
|
||||
} catch (InputFormatException | IOException e) {
|
||||
throw new IllegalStateException("Cannot parse stream " + getFullName(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEventList getEvents() {
|
||||
loadStream();
|
||||
return events;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DirectionType getDirection() {
|
||||
|
||||
Reference in new issue
Block a user