use of org.neo4j.helpers.Triplet in project graphdb by neo4j-attic.
the class MasterUtil method packResponse.
public static <T> Response<T> packResponse(GraphDatabaseService graphDb, SlaveContext context, T response, Predicate<Long> filter) {
List<Triplet<String, Long, TxExtractor>> stream = new ArrayList<Triplet<String, Long, TxExtractor>>();
Set<String> resourceNames = new HashSet<String>();
XaDataSourceManager dsManager = ((AbstractGraphDatabase) graphDb).getConfig().getTxModule().getXaDataSourceManager();
for (Pair<String, Long> txEntry : context.lastAppliedTransactions()) {
String resourceName = txEntry.first();
final XaDataSource dataSource = dsManager.getXaDataSource(resourceName);
if (dataSource == null) {
throw new RuntimeException("No data source '" + resourceName + "' found");
}
resourceNames.add(resourceName);
long masterLastTx = dataSource.getLastCommittedTxId();
for (long txId = txEntry.other() + 1; txId <= masterLastTx; txId++) {
if (filter.accept(txId)) {
final long tx = txId;
TxExtractor extractor = new TxExtractor() {
@Override
public ReadableByteChannel extract() {
try {
return dataSource.getCommittedTransaction(tx);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void extract(LogBuffer buffer) {
try {
dataSource.getCommittedTransaction(tx, buffer);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
};
stream.add(Triplet.of(resourceName, txId, extractor));
}
}
}
StoreId storeId = ((NeoStoreXaDataSource) dsManager.getXaDataSource(Config.DEFAULT_DATA_SOURCE_NAME)).getStoreId();
return new Response<T>(response, storeId, TransactionStream.create(resourceNames, stream));
}
use of org.neo4j.helpers.Triplet in project graphdb by neo4j-attic.
the class LuceneDataSource method listStoreFiles.
@Override
public ClosableIterable<File> listStoreFiles() throws IOException {
final Collection<File> files = new ArrayList<File>();
final Collection<SnapshotDeletionPolicy> snapshots = new ArrayList<SnapshotDeletionPolicy>();
for (Map.Entry<IndexIdentifier, Triplet<IndexWriter, AtomicBoolean, SnapshotDeletionPolicy>> writer : indexWriters.entrySet()) {
SnapshotDeletionPolicy deletionPolicy = writer.getValue().third();
File indexDirectory = getFileDirectory(baseStorePath, writer.getKey());
for (String fileName : deletionPolicy.snapshot().getFileNames()) {
files.add(new File(indexDirectory, fileName));
}
snapshots.add(deletionPolicy);
}
files.add(providerStore.getFile());
return new ClosableIterable<File>() {
public Iterator<File> iterator() {
return files.iterator();
}
public void close() {
for (SnapshotDeletionPolicy deletionPolicy : snapshots) {
deletionPolicy.release();
}
}
};
}
Aggregations