Search in sources :

Example 1 with ArchiveInfo

use of org.csstudio.archive.reader.ArchiveInfo in project org.csstudio.display.builder by kasemir.

the class ArchiveListGUI method connectToArchiveServer.

/**
 * Connect to archive data server.
 *  <p>
 *  On success, set <code>server</code>, update <code>archive_table</code>
 *  @param url Server URL
 */
private void connectToArchiveServer(final String url) {
    new ConnectJob(url) {

        @Override
        protected void archiveServerConnected(final String server_info, final ArchiveInfo[] infos) {
            ArchiveListGUI.this.server_info = server_info;
            if (urls.isDisposed())
                return;
            urls.getDisplay().asyncExec(new Runnable() {

                @Override
                public void run() {
                    if (info.isDisposed())
                        return;
                    ArchiveListGUI.this.url = url;
                    final List<ArchiveDataSource> archives = new ArrayList<>();
                    for (ArchiveInfo info : infos) archives.add(new ArchiveDataSource(url, info.getKey(), info.getName(), info.getDescription()));
                    archive_table.setInput(archives);
                    // Select all default archive data sources for this URL
                    final List<ArchiveDataSource> selected = new ArrayList<>();
                    for (ArchiveDataSource dataSource : default_archives) if (dataSource.getUrl().equals(url) && archives.contains(dataSource))
                        selected.add(dataSource);
                    archive_table.setSelection(new StructuredSelection(selected));
                    // Enable operations on server resp. archives
                    info.setEnabled(true);
                    handleArchiveUpdate();
                }
            });
        }

        @Override
        protected void archiveServerError(final String url, final Exception ex) {
            // Called from non-UI thread
            if (info.isDisposed())
                return;
            info.getDisplay().asyncExec(new Runnable() {

                @Override
                public void run() {
                    if (info.isDisposed())
                        return;
                    info.setEnabled(false);
                    handleServerError(url, ex);
                }
            });
        }
    }.schedule();
}
Also used : ArchiveInfo(org.csstudio.archive.reader.ArchiveInfo) ConnectJob(org.csstudio.trends.databrowser3.archive.ConnectJob) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ArchiveDataSource(org.csstudio.trends.databrowser3.model.ArchiveDataSource)

Example 2 with ArchiveInfo

use of org.csstudio.archive.reader.ArchiveInfo 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;
}
Also used : ArchiveInfo(org.csstudio.archive.reader.ArchiveInfo) ArchiveReader(org.csstudio.archive.reader.ArchiveReader)

Example 3 with ArchiveInfo

use of org.csstudio.archive.reader.ArchiveInfo in project org.csstudio.display.builder by kasemir.

the class ConnectJobTest method testConnectJob.

@Test(timeout = 20000)
public void testConnectJob() throws Exception {
    final TestProperties settings = new TestProperties();
    String url = settings.getString("archive_rdb_url");
    if (url == null) {
        System.out.println("Skipped");
        return;
    }
    System.out.println("Connecting to " + url);
    new ConnectJob(url) {

        @Override
        protected void archiveServerConnected(final String server_info, final ArchiveInfo[] infos) {
            System.out.println("Connected to " + server_info);
            System.out.println(infos.length + " archives:");
            for (final ArchiveInfo info : infos) {
                System.out.println(info.getKey() + ": " + info.getName() + " (" + info.getDescription() + ")");
            }
            info = "Connected";
            done.countDown();
        }

        @Override
        protected void archiveServerError(final String url, final Exception ex) {
            info = NLS.bind(Messages.ArchiveServerErrorFmt, url, ex.getMessage());
            done.countDown();
        }
    }.schedule();
    // Wait for success or error
    done.await();
    assertThat(info, equalTo("Connected"));
}
Also used : TestProperties(org.csstudio.apputil.test.TestProperties) ArchiveInfo(org.csstudio.archive.reader.ArchiveInfo) Test(org.junit.Test)

Aggregations

ArchiveInfo (org.csstudio.archive.reader.ArchiveInfo)3 ArrayList (java.util.ArrayList)1 TestProperties (org.csstudio.apputil.test.TestProperties)1 ArchiveReader (org.csstudio.archive.reader.ArchiveReader)1 ConnectJob (org.csstudio.trends.databrowser3.archive.ConnectJob)1 ArchiveDataSource (org.csstudio.trends.databrowser3.model.ArchiveDataSource)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 Test (org.junit.Test)1