brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahgittin <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: Sensors chained for service up
Date Fri, 29 Aug 2014 22:18:05 GMT
Github user ahgittin commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/131#discussion_r16923651
  
    --- Diff: core/src/main/java/brooklyn/enricher/basic/AbstractMultipleSensorAggregator.java
---
    @@ -0,0 +1,144 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package brooklyn.enricher.basic;
    +
    +import java.util.Collection;
    +import java.util.Collections;
    +import java.util.LinkedHashMap;
    +import java.util.Map;
    +
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +import brooklyn.entity.Entity;
    +import brooklyn.event.AttributeSensor;
    +import brooklyn.event.Sensor;
    +import brooklyn.event.SensorEvent;
    +import brooklyn.event.SensorEventListener;
    +import brooklyn.util.collections.MutableMap;
    +
    +import com.google.common.base.Preconditions;
    +import com.google.common.collect.ImmutableMap;
    +
    +/** Building on {@link AbstractAggregator} for a single source sensor (on multiple children
and/or members) */
    +public abstract class AbstractMultipleSensorAggregator<U> extends AbstractAggregator<Object,U>
implements SensorEventListener<Object> {
    +
    +    private static final Logger LOG = LoggerFactory.getLogger(AbstractMultipleSensorAggregator.class);
    +
    +    
    +    /** access via {@link #getValues(Sensor)} */
    +    private final Map<String, Map<Entity,Object>> values = Collections.synchronizedMap(new
LinkedHashMap<String, Map<Entity,Object>>());
    +
    +    public AbstractMultipleSensorAggregator() {}
    +
    +    protected abstract Collection<Sensor<?>> getSourceSensors();
    +    
    +    @Override
    +    protected void setEntityLoadingConfig() {
    +        super.setEntityLoadingConfig();
    +        Preconditions.checkNotNull(getSourceSensors(), "sourceSensors must be set");
    +    }
    +    
    +    protected void setEntityBeforeSubscribingProducerChildrenEvents() {
    +        if (LOG.isDebugEnabled()) LOG.debug("{} subscribing to children of {}", new Object[]
{this, producer });
    +        for (Sensor<?> sourceSensor: getSourceSensors()) {
    +            subscribeToChildren(producer, sourceSensor, this);
    +        }
    +    }
    +
    +    protected void addProducerHardcoded(Entity producer) {
    +        for (Sensor<?> sourceSensor: getSourceSensors()) {
    +            subscribe(producer, sourceSensor, this);
    +        }
    +        onProducerAdded(producer);
    +    }
    +
    +    protected void addProducerChild(Entity producer) {
    --- End diff --
    
    +1


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message