Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/650#discussion_r30615918
  
    --- Diff: 
core/src/main/java/brooklyn/event/feed/windows/WindowsPerformanceCounterFeed.java
 ---
    @@ -251,10 +258,71 @@ public T call() throws Exception {
             }
         }
     
    +    private static class SendPerfCountersToSensors implements 
PollHandler<WinRmToolResponse> {
    +
    +        private final EntityLocal entity;
    +        private final List<WindowsPerformanceCounterPollConfig<?>> polls;
    +
    +        public SendPerfCountersToSensors(EntityLocal entity, 
List<WindowsPerformanceCounterPollConfig<?>> polls) {
    +            this.entity = entity;
    +            this.polls = polls;
    +        }
    +
    +        @Override
    +        public boolean checkSuccess(WinRmToolResponse val) {
    +            if (val.getStatusCode() != 0) return false;
    +            String stderr = val.getStdErr();
    +            if (stderr == null || stderr.length() != 0) return false;
    +            String out = val.getStdOut();
    +            if (out == null || out.length() == 0) return false;
    +            return true;
    +        }
    +
    +        @Override
    +        public void onSuccess(WinRmToolResponse val) {
    +            String[] values = val.getStdOut().split("\r\n");
    +            for (int i = 0; i < polls.size(); i++) {
    +                Class<?> clazz = polls.get(i).getSensor().getType();
    +                Maybe<? extends Object> maybeValue = 
TypeCoercions.tryCoerce(values[i], TypeToken.of(clazz));
    +                Object value = maybeValue.isAbsent() ? null : 
maybeValue.get();
    +                AttributeSensor<Object> attribute = 
(AttributeSensor<Object>) Sensors.newSensor(clazz, 
polls.get(i).getSensor().getName(), polls.get(i).getDescription());
    +                entity.setAttribute(attribute, value);
    +            }
    +        }
    +
    +        @Override
    +        public void onFailure(WinRmToolResponse val) {
    +            log.error("Windows Performance Counter query did not respond 
as expected. exitcode={} stdout={} stderr={}",
    +                    new Object[]{val.getStatusCode(), val.getStdOut(), 
val.getStdErr()});
    +            for (WindowsPerformanceCounterPollConfig<?> config : polls) {
    +                
entity.setAttribute(Sensors.newSensor(config.getSensor().getClass(), 
config.getPerformanceCounterName(), config.getDescription()), null);
    +            }
    +        }
    +
    +        @Override
    +        public void onException(Exception exception) {
    +            log.error("Detected exception while retrieving Windows 
Performance Counters from entity " +
    +                    entity.getDisplayName(), exception);
    +            for (WindowsPerformanceCounterPollConfig<?> config : polls) {
    +                
entity.setAttribute(Sensors.newSensor(config.getSensor().getClass(), 
config.getPerformanceCounterName(), config.getDescription()), null);
    +            }
    +        }
    +
    +        @Override
    +        public String getDescription() {
    +            return "" + polls;
    +        }
    +
    +        @Override
    +        public String toString() {
    +            return super.toString()+"["+getDescription()+"]";
    +        }
    +    }
    +
         /**
          * A poll handler that takes the result of the <tt>typeperf</tt> 
invocation and sets the appropriate sensors.
          */
    -    private static class SendPerfCountersToSensors implements 
PollHandler<SshPollValue> {
    +    private static class SendPerfCountersToSensors2 implements 
PollHandler<SshPollValue> {
    --- End diff --
    
    Do we need this class? It appears to never be used.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to