Detecting LiveView Server UP status from a LiveView Java client

Detecting LiveView Server UP status from a LiveView Java client

book

Article ID: KB0080030

calendar_today

Updated On:

Products Versions
TIBCO Live Datamart 2.x, 10.x

Description

How, from a Java client, do I know my TIBCO® LiveView server is running and ready?

Resolution

A LiveView server starts the StreamBase (SB) data-layer, compiles each Table as needed, and then starts SB publishers and other embedded SB applications. The web-service to which LiveView (LV) clients connect (lv:// protocol) may accept connections before all tables are loaded, which is when a connection will succeed, but a query for a specific table will fail. Most of the time, LV client connections are not allowed until all tables are loaded.

The following is based on the SimpleQuery.java example from the "sample_lv-java_clientapi" project.

To determine if the LiveView Server is running replace:
conn = LiveViewConnectionFactory.getConnection("lv://localhost");
With:
  Boolean connected = false;
  while (!connected) {
    try {
      if (conn = LiveViewConnectionFactory.getConnection("lv://localhost")) {
          connected = true;
      }
    } catch (Exception e) {
      connected = false;
    }
    Thread.sleep(1000); // milliseconds
  }
This will wait, testing once each second, until the LiveView Server accepts connections.

If the Table for a query is unavailable, then following the registration of a query listener, the sample's listener will report:
Query exception received: com.streambase.liveview.client.LiveViewException: Unknown table 'ItemsSales'
Query was closed
These are reported from the Listener callbacks:
  @Override
  public void queryClosed(QueryClosedEvent event) {
    //the listener is notified when the query is closed either by the client or server
    System.out.println("Query was closed");
  }
			
  @Override
  public void exceptionRaised(QueryExceptionEvent event) {
    //if an error occurs during your query, the listener is notified 
    System.out.println("Query exception received: " + event.getException());
  }

To respond to this result you should have these methods throw an exception which can be caught to trigger waiting and trying again following the previous while-loop pattern, or exit the client.

Issue/Introduction

Java Client API usage