Exemplo n.º 1
0
  /** {@inheritDoc} */
  @Override
  protected void doDispose() {
    printDebugInfo("DISPOSE");

    DynamicValueProperty property = _dalProperty;

    setDalProperty(null);

    if (property != null && !property.isDestroyed()) {
      // remove link listener
      property.removeLinkListener(this);

      // remove value listeners
      property.removeDynamicValueListener(this);

      // remove response listeners
      property.removeResponseListener(this);

      // try to dispose the DAL property
      PropertyFactory factory =
          DALPropertyFactoriesProvider.getInstance()
              .getPropertyFactory(getProcessVariableAddress().getControlSystem());

      // if the property is not used anymore by other connectors,
      // destroy it
      if (property.getDynamicValueListeners().length <= 1
          && property.getResponseListeners().length <= 0) {

        printDebugInfo("DESTROY");

        factory.getPropertyFamily().destroy(property);

        // <**** Workarround (FIXME: Remove, when DAL is fixed) ***
        // DAL caches a reference to a former ResponseListener
        // via its latestResponse and latestRequest fields on
        // DynamicValuePropertyImpl.class
        // ********************************************************
        /*
         * try { Object e = property.getLatestResponse();
         *
         * property.getAsynchronous(null);
         *
         * while (e == property.getLatestResponse()) { Thread.sleep(1);
         * } } catch (DataExchangeException e) { e.printStackTrace(); }
         * catch (InterruptedException e) { e.printStackTrace(); }
         */
        // **** Workarround (Remove, when DAL is fixed)************>
        assert !factory.getPropertyFamily().contains(property)
            : "!getPropertyFactory().getPropertyFamily().contains(property)";
      }
    }
  }
Exemplo n.º 2
0
  /**
   * {@inheritDoc}
   *
   * @throws Exception
   */
  @Test
  public void testCacheBug() throws Exception {
    String pv = "Chiller:Pressure:1";

    // get the pv as DoubleProperty
    DoubleProperty doubleProperty = _propertyFactory.getProperty(pv, DoubleProperty.class, null);
    assertNotNull(doubleProperty);
    assertTrue(doubleProperty instanceof DoubleProperty);

    doubleProperty.addDynamicValueListener(
        new DynamicValueListener() {

          public void conditionChange(DynamicValueEvent arg0) {}

          public void errorResponse(DynamicValueEvent arg0) {}

          public void timelagStarts(DynamicValueEvent arg0) {}

          public void timelagStops(DynamicValueEvent arg0) {}

          public void timeoutStarts(DynamicValueEvent arg0) {}

          public void timeoutStops(DynamicValueEvent arg0) {}

          public void valueChanged(DynamicValueEvent event) {
            AnyData anyData = event.getData();
            MetaData metaData = anyData.getMetaData();
            System.out.println("Metadata available = " + (metaData != null ? "yes" : "no"));
          }

          public void valueUpdated(DynamicValueEvent arg0) {}
        });

    Thread.sleep(5000);
  }
Exemplo n.º 3
0
  /** {@inheritDoc} */
  protected void doInit() {
    // get or create a real DAL property
    DynamicValueProperty property = null;

    try {
      RemoteInfo ri = getProcessVariableAddress().toDalRemoteInfo();

      PropertyFactory factory =
          DALPropertyFactoriesProvider.getInstance()
              .getPropertyFactory(getProcessVariableAddress().getControlSystem());

      switch (getValueType()) {
        case OBJECT:
          property = factory.getProperty(ri);
          break;
        case STRING:
          /*
           * swende: 2010-03-06: this is a dirty quickfix which is related
           * to problems with SDS displays that specifiy
           * "pv[severity], String" as pv address / please remove if it
           * does not work as expected or when all current SDS files at
           * DESY have been propertly changed
           */
          String characteristic = getProcessVariableAddress().getCharacteristic();
          // If connection is made as pv[severity] or just pv, than ignore everything
          // and go to default. In all other cases (e.g. pv[graphMin}, string), create
          // a default property.
          if (characteristic != null
              && !CharacteristicInfo.C_SEVERITY.getName().equals(characteristic)) {
            property = factory.getProperty(ri);
            break;
          }
        default:
          property = factory.getProperty(ri, getValueType().getDalType(), null);
          break;
      }

      if (property != null) {
        setDalProperty(property);
      }
    } catch (Throwable e) {
      forwardError(e.getLocalizedMessage());
    }
  }