Пример #1
0
 private void recomputeValue() {
   long v = 0;
   for (Job job : ((VirtualMachine) getParent()).getJobs()) {
     Probe<?> p = job.getProbe(JobStorageTrProbe.KEY);
     v += ((Number) p.getValue()).longValue();
   }
   setValue(Long.valueOf(v));
 }
Пример #2
0
  @Override
  public void setup(Probed parent) {
    if (!(parent instanceof VirtualMachine)) throw new IllegalArgumentException("Illegal Parent");
    super.setup(parent);

    // register listeners
    {
      NotificationListener l =
          new NotificationListener() {
            @Override
            protected void notificationPerformed(
                Notifier notifier, int notification_code, Object data) {
              if (notification_code == NotificationCodes.ENTITY_ADDED && data instanceof Job) {
                ((Probed) data)
                    .getProbe(JobStorageTrProbe.KEY)
                    .addListener(NotificationCodes.PROBE_VALUE_CHANGED, this);
              } else if (notification_code == NotificationCodes.ENTITY_REMOVED
                  && data instanceof Job) {
                ((Probed) data)
                    .getProbe(JobStorageTrProbe.KEY)
                    .removeListener(NotificationCodes.PROBE_VALUE_CHANGED, this);
              }
              VmStorageTrProbe.this.recomputeValue();
            }
          };

      registeredListener(l);

      ((Notifier) getParent()).addListener(NotificationCodes.ENTITY_ADDED, l);
      ((Notifier) getParent()).addListener(NotificationCodes.ENTITY_REMOVED, l);
      for (Job job : ((VirtualMachine) getParent()).getJobs()) {
        Probe<?> p = job.getProbe(JobStorageTrProbe.KEY);
        p.addListener(NotificationCodes.PROBE_VALUE_CHANGED, l);
      }
      recomputeValue();
    }
  }