use of org.csstudio.archive.reader.ArchiveReader in project org.csstudio.display.builder by kasemir.
the class ExportJob method run.
/**
* Job's main routine
* {@inheritDoc}
*/
@Override
protected final IStatus run(final IProgressMonitor monitor) {
monitor.beginTask("Data Export", IProgressMonitor.UNKNOWN);
try {
final PrintStream out;
if (filename != null) {
out = new PrintStream(filename);
printExportInfo(out);
} else
out = null;
// Start thread that checks monitor to cancels readers when
// user tries to abort the export job
final CancellationPoll cancel_poll = new CancellationPoll(monitor);
final Future<?> done = Activator.getThreadPool().submit(cancel_poll);
performExport(monitor, out);
// ask thread to exit
cancel_poll.exit = true;
if (out != null)
out.close();
// Wait for poller to quit
done.get();
} catch (final Exception ex) {
error_handler.handleExportError(ex);
}
for (ArchiveReader reader : archive_readers) reader.close();
monitor.done();
return Status.OK_STATUS;
}
use of org.csstudio.archive.reader.ArchiveReader in project org.csstudio.display.builder by kasemir.
the class ExportJob method createValueIterator.
/**
* @param item ModelItem
* @return ValueIterator for samples in the item
* @throws Exception on error
*/
protected ValueIterator createValueIterator(final ModelItem item) throws Exception {
if (source == Source.PLOT || !(item instanceof PVItem))
return new ModelSampleIterator(item, start, end);
// Start ValueIterator for each sub-archive
final ArchiveDataSource[] archives = ((PVItem) item).getArchiveDataSources();
final List<ValueIterator> iters = new ArrayList<>();
Exception error = null;
for (ArchiveDataSource archive : archives) {
// Create reader, remember to close it when done
final ArchiveReader reader = ArchiveRepository.getInstance().getArchiveReader(archive.getUrl());
archive_readers.add(reader);
// Create ValueIterator
try {
ValueIterator iter;
if (source == Source.OPTIMIZED_ARCHIVE && optimize_parameter > 1)
iter = reader.getOptimizedValues(archive.getKey(), item.getName(), start, end, (int) optimize_parameter);
else {
iter = reader.getRawValues(archive.getKey(), item.getName(), start, end);
if (source == Source.LINEAR_INTERPOLATION && optimize_parameter >= 1)
iter = new LinearValueIterator(iter, TimeDuration.ofSeconds(optimize_parameter));
}
iters.add(iter);
} catch (Exception ex) {
Logger.getLogger(getClass().getName()).log(Level.FINE, "Export error for " + item.getName(), ex);
if (error == null)
error = ex;
}
}
// If none of the iterators work out, report the first error that we found
if (iters.isEmpty() && error != null)
throw error;
// Return a merging iterator
return new MergingValueIterator(iters.toArray(new ValueIterator[iters.size()]));
}
use of org.csstudio.archive.reader.ArchiveReader in project org.csstudio.display.builder by kasemir.
the class ConnectJob method run.
/**
* {@inheritDoc}
*/
@Override
protected IStatus run(final IProgressMonitor monitor) {
monitor.beginTask(url, IProgressMonitor.UNKNOWN);
monitor.subTask(url);
try (final ArchiveReader reader = ArchiveRepository.getInstance().getArchiveReader(url)) {
final StringBuilder buf = new StringBuilder();
buf.append("Archive Data Server: " + reader.getServerName() + "\n\n");
buf.append("URL:\n" + reader.getURL() + "\n\n");
buf.append("Version: " + reader.getVersion() + "\n\n");
buf.append("Description:\n" + reader.getDescription());
final ArchiveInfo[] infos = reader.getArchiveInfos();
archiveServerConnected(buf.toString(), infos);
} catch (final Exception ex) {
logger.log(Level.WARNING, "Cannot connect to archive " + url, ex);
archiveServerError(url, ex);
monitor.setCanceled(true);
return Status.CANCEL_STATUS;
}
monitor.done();
return Status.OK_STATUS;
}
use of org.csstudio.archive.reader.ArchiveReader in project org.csstudio.display.builder by kasemir.
the class SearchJob method run.
/**
* {@inheritDoc}
*/
@Override
protected IStatus run(final IProgressMonitor monitor) {
final ArrayList<ChannelInfo> channels = new ArrayList<>();
monitor.beginTask(Messages.Search, archives.length);
for (ArchiveDataSource archive : archives) {
try (final ArchiveReader reader = ArchiveRepository.getInstance().getArchiveReader(archive.getUrl())) {
monitor.subTask(archive.getName());
final String[] names;
if (pattern_is_glob)
names = reader.getNamesByPattern(archive.getKey(), pattern);
else
names = reader.getNamesByRegExp(archive.getKey(), pattern);
for (String name : names) channels.add(new ChannelInfo(name, archive));
monitor.worked(1);
} catch (final Exception ex) {
monitor.setCanceled(true);
monitor.done();
archiveServerError(archive.getUrl(), ex);
return Status.CANCEL_STATUS;
}
}
receivedChannelInfos((ChannelInfo[]) channels.toArray(new ChannelInfo[channels.size()]));
monitor.done();
return Status.OK_STATUS;
}
use of org.csstudio.archive.reader.ArchiveReader in project org.csstudio.display.builder by kasemir.
the class ImportArchiveReaderFactory method getArchiveReader.
/**
* {@inheritDoc}
*/
@Override
public ArchiveReader getArchiveReader(final String url) throws Exception {
// Avoid duplicate readers for same URL
synchronized (cache) {
ArchiveReader reader = cache.get(url);
if (reader != null)
return reader;
}
// Get path, importer from URL
final String[] type_path = parseURL(url);
final String type = type_path[0];
final String path = type_path[1];
final SampleImporterInfo importer = SampleImporters.getImporter(type);
if (importer == null)
throw new Exception("Unknown import data type " + type);
final ImportArchiveReader reader = new ImportArchiveReader(url, path, importer);
// Cache the reader by URL
synchronized (cache) {
cache.put(url, reader);
}
return reader;
}
Aggregations