Search in sources :

Example 1 with ArchiveFetchJob

use of org.csstudio.trends.databrowser3.archive.ArchiveFetchJob in project org.csstudio.display.builder by kasemir.

the class ArchiveFetchJobTest method fetchCompleted.

@Override
public void fetchCompleted(final ArchiveFetchJob job) {
    System.out.println("Completed " + job);
    final PlotSamples samples = item.getSamples();
    System.out.println(samples);
    got_anything = samples.size() > 0;
}
Also used : PlotSamples(org.csstudio.trends.databrowser3.model.PlotSamples)

Example 2 with ArchiveFetchJob

use of org.csstudio.trends.databrowser3.archive.ArchiveFetchJob in project org.csstudio.display.builder by kasemir.

the class ControllerBase method stop.

/**
 * Stop scrolling and model items
 *  @throws IllegalStateException when not running
 */
public void stop() {
    if (!isRunning())
        throw new IllegalStateException("Not started");
    // Stop ongoing archive access
    synchronized (archive_fetch_jobs) {
        for (ArchiveFetchJob job : archive_fetch_jobs) job.cancel();
        archive_fetch_jobs.clear();
    }
    // Stop update task
    model.stop();
    model.removeListener(model_listener);
    update_task.cancel(true);
    update_task = null;
}
Also used : ArchiveFetchJob(org.csstudio.trends.databrowser3.archive.ArchiveFetchJob)

Example 3 with ArchiveFetchJob

use of org.csstudio.trends.databrowser3.archive.ArchiveFetchJob in project org.csstudio.display.builder by kasemir.

the class ControllerBase method getArchivedData.

/**
 * Initiate archive data retrieval for a specific model item
 *  @param item Model item. NOP for non-PVItem
 *  @param start Start time
 *  @param end End time
 */
private void getArchivedData(final ModelItem item, final Instant start, final Instant end) {
    // Only useful for PVItems with archive data source
    if (!(item instanceof PVItem))
        return;
    final PVItem pv_item = (PVItem) item;
    if (pv_item.getArchiveDataSources().length <= 0)
        return;
    // Determine ongoing jobs for this item
    final List<ArchiveFetchJob> ongoing = new ArrayList<>();
    final ArchiveFetchJob new_job = makeArchiveFetchJob(pv_item, start, end);
    synchronized (archive_fetch_jobs) {
        for (Iterator<ArchiveFetchJob> iter = archive_fetch_jobs.iterator(); iter.hasNext(); ) /**/
        {
            final ArchiveFetchJob job = iter.next();
            if (job.getPVItem() == pv_item) {
                ongoing.add(job);
                iter.remove();
            }
        }
        // Track new job
        archive_fetch_jobs.add(new_job);
    }
    // job.schedule();
    Activator.getThreadPool().execute(() -> {
        // In background, stop ongoing jobs
        for (ArchiveFetchJob running : ongoing) {
            try {
                running.cancel();
                running.join(10000, null);
            } catch (Exception ex) {
                logger.log(Level.WARNING, "Cannot cancel " + running, ex);
            }
        }
        // .. then start new one
        new_job.schedule();
    });
}
Also used : ArchiveFetchJob(org.csstudio.trends.databrowser3.archive.ArchiveFetchJob) ArrayList(java.util.ArrayList) PVItem(org.csstudio.trends.databrowser3.model.PVItem)

Example 4 with ArchiveFetchJob

use of org.csstudio.trends.databrowser3.archive.ArchiveFetchJob in project org.csstudio.display.builder by kasemir.

the class ArchiveFetchJobTest method testMultipleArchives.

/**
 * Start ArchiveFetchJob for multiple data sources, one that fails, wait for its completion
 */
@Test(timeout = 60000)
public void testMultipleArchives() throws Exception {
    final TestProperties settings = new TestProperties();
    String url = settings.getString("archive_rdb_url");
    if (url == null) {
        System.out.println("Skipped");
        return;
    }
    item = new PVItem("DTL_LLRF:IOC1:Load", 1.0);
    // First URL is expected to fail
    item.addArchiveDataSource(new ArchiveDataSource("Broken_URL", 1, "failed_test"));
    // Second URL should return data
    item.addArchiveDataSource(new ArchiveDataSource(url, 1, "test"));
    runFetchJob();
}
Also used : TestProperties(org.csstudio.apputil.test.TestProperties) ArchiveDataSource(org.csstudio.trends.databrowser3.model.ArchiveDataSource) PVItem(org.csstudio.trends.databrowser3.model.PVItem) Test(org.junit.Test)

Example 5 with ArchiveFetchJob

use of org.csstudio.trends.databrowser3.archive.ArchiveFetchJob in project org.csstudio.display.builder by kasemir.

the class ArchiveFetchJobTest method testArchiveFetchJob.

/**
 * Start ArchiveFetchJob, wait for its completion
 */
@Test(timeout = 60000)
public void testArchiveFetchJob() throws Exception {
    final TestProperties settings = new TestProperties();
    String url = settings.getString("archive_rdb_url");
    if (url == null) {
        System.out.println("Skipped");
        return;
    }
    item = new PVItem("DTL_LLRF:IOC1:Load", 1.0);
    item.addArchiveDataSource(new ArchiveDataSource(url, 1, "test"));
    runFetchJob();
}
Also used : TestProperties(org.csstudio.apputil.test.TestProperties) ArchiveDataSource(org.csstudio.trends.databrowser3.model.ArchiveDataSource) PVItem(org.csstudio.trends.databrowser3.model.PVItem) Test(org.junit.Test)

Aggregations

PVItem (org.csstudio.trends.databrowser3.model.PVItem)3 TestProperties (org.csstudio.apputil.test.TestProperties)2 ArchiveFetchJob (org.csstudio.trends.databrowser3.archive.ArchiveFetchJob)2 ArchiveDataSource (org.csstudio.trends.databrowser3.model.ArchiveDataSource)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 PlotSamples (org.csstudio.trends.databrowser3.model.PlotSamples)1