Ejemplo n.º 1
0
  private boolean checkUpdateAndConnection() throws HibernateException {

    long now = new Date().getTime();

    try {
      Date lastUpdate = database.getLastMeasurementUpdateTime();
      if (lastUpdate != null) {
        long time = lastUpdate.getTime();
        updated = (time > now - delay) ? Ternary.True : Ternary.False;
        updatedCause = "Last Update: " + new Date(time);
      } else {
        updated = Ternary.False;
        updatedCause = "Never Updated";
      }
      connected = Ternary.True;
      connectedCause = "";
    } catch (HibernateException e) {
      connected = Ternary.False;
      connectedCause = e.getMessage();
      throw e;
    } finally {
      if (eventBus != null) {
        if (!updated.equals(wasUpdated)) {
          ConnectionStatusChangedRemoteEvent.fire(
              eventBus, ConnectionType.databaseUpdate, updated, updatedCause);
        }

        if (!connected.equals(wasConnected)) {
          ConnectionStatusChangedRemoteEvent.fire(
              eventBus, ConnectionType.databaseConnect, connected, connectedCause);
        }
      }
    }

    return !updated.isFalse();
  }
Ejemplo n.º 2
0
 public boolean isConnected() {
   return connected.isTrue();
 }