Java Code Examples for org.apache.brooklyn.api.sensor.SensorEvent#getSensor()

The following examples show how to use org.apache.brooklyn.api.sensor.SensorEvent#getSensor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FollowTheSunPolicy.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Override
public void onEvent(SensorEvent<Object> event) {
    if (LOG.isTraceEnabled()) LOG.trace("{} received event {}", FollowTheSunPolicy.this, event);
    Entity source = event.getSource();
    Object value = event.getValue();
    Sensor<?> sensor = event.getSensor();
    
    if (sensor.equals(itemUsageMetric)) {
        onItemMetricUpdated((Movable)source, (Map<? extends Movable, Double>) value, true);
    } else if (sensor.equals(Attributes.LOCATION_CHANGED)) {
        onContainerLocationUpdated(source, true);
    } else if (sensor.equals(FollowTheSunPool.CONTAINER_ADDED)) {
        onContainerAdded((Entity) value, true);
    } else if (sensor.equals(FollowTheSunPool.CONTAINER_REMOVED)) {
        onContainerRemoved((Entity) value, true);
    } else if (sensor.equals(FollowTheSunPool.ITEM_ADDED)) {
        onItemAdded((Movable) value, true);
    } else if (sensor.equals(FollowTheSunPool.ITEM_REMOVED)) {
        onItemRemoved((Movable) value, true);
    } else if (sensor.equals(FollowTheSunPool.ITEM_MOVED)) {
        ContainerItemPair pair = (ContainerItemPair) value;
        onItemMoved((Movable)pair.item, pair.container, true);
    }
}
 
Example 2
Source File: ItemsInContainersGroupImpl.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Override
public void onEvent(SensorEvent<Object> event) {
    Entity source = event.getSource();
    Object value = event.getValue();
    Sensor sensor = event.getSensor();
    
    if (sensor.equals(AbstractGroup.MEMBER_ADDED)) {
        onContainerAdded((Entity) value);
    } else if (sensor.equals(AbstractGroup.MEMBER_REMOVED)) {
        onContainerRemoved((Entity) value);
    } else if (sensor.equals(Movable.CONTAINER)) {
        onItemMoved((Movable)source, (BalanceableContainer<?>) value);
    } else {
        throw new IllegalStateException("Unhandled event type "+sensor+": "+event);
    }
}
 
Example 3
Source File: Propagator.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void onEvent(SensorEvent<Object> event) {
    // propagate upwards
    Sensor<?> sourceSensor = event.getSensor();
    Sensor<?> destinationSensor = getDestinationSensor(sourceSensor);

    if (!sensorFilter.apply(sourceSensor)) {
        return; // ignoring excluded sensor
    }
    
    if (LOG.isTraceEnabled()) LOG.trace("enricher {} got {}, propagating via {}{}", 
            new Object[] {this, event, entity, (sourceSensor == destinationSensor ? "" : " (as "+destinationSensor+")")});
    
    emit((Sensor)destinationSensor, event.getValue());
}
 
Example 4
Source File: FollowTheSunPoolImpl.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public void onEvent(SensorEvent<Object> event) {
    if (LOG.isTraceEnabled()) LOG.trace("{} received event {}", FollowTheSunPoolImpl.this, event);
    Entity source = event.getSource();
    Object value = event.getValue();
    Sensor<?> sensor = event.getSensor();

    if (sensor.equals(AbstractGroup.MEMBER_ADDED)) {
        if (source.equals(containerGroup)) {
            onContainerAdded((Entity) value);
        } else if (source.equals(itemGroup)) {
            onItemAdded((Entity)value);
        } else {
            throw new IllegalStateException("unexpected event source="+source);
        }
    } else if (sensor.equals(AbstractGroup.MEMBER_REMOVED)) {
        if (source.equals(containerGroup)) {
            onContainerRemoved((Entity) value);
        } else if (source.equals(itemGroup)) {
            onItemRemoved((Entity) value);
        } else {
            throw new IllegalStateException("unexpected event source="+source);
        }
    } else if (sensor.equals(Startable.SERVICE_UP)) {
        // TODO What if start has failed? Is there a sensor to indicate that?
        if ((Boolean)value) {
            onContainerUp(source);
        } else {
            onContainerDown(source);
        }
    } else if (sensor.equals(Movable.CONTAINER)) {
        onItemMoved(source, (Entity) value);
    } else {
        throw new IllegalStateException("Unhandled event type "+sensor+": "+event);
    }
}
 
Example 5
Source File: BalanceableWorkerPoolImpl.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public void onEvent(SensorEvent<Object> event) {
    if (LOG.isTraceEnabled()) LOG.trace("{} received event {}", BalanceableWorkerPoolImpl.this, event);
    Entity source = event.getSource();
    Object value = event.getValue();
    Sensor<?> sensor = event.getSensor();
    
    if (sensor.equals(AbstractGroup.MEMBER_ADDED)) {
        if (source.equals(containerGroup)) {
            onContainerAdded((BalanceableContainer<?>) value);
        } else if (source.equals(itemGroup)) {
            onItemAdded((Entity)value);
        } else {
            throw new IllegalStateException("unexpected event source="+source);
        }
    } else if (sensor.equals(AbstractGroup.MEMBER_REMOVED)) {
        if (source.equals(containerGroup)) {
            onContainerRemoved((BalanceableContainer<?>) value);
        } else if (source.equals(itemGroup)) {
            onItemRemoved((Entity) value);
        } else {
            throw new IllegalStateException("unexpected event source="+source);
        }
    } else if (sensor.equals(Startable.SERVICE_UP)) {
        // TODO What if start has failed? Is there a sensor to indicate that?
        if ((Boolean)value) {
            onContainerUp((BalanceableContainer<?>) source);
        } else {
            onContainerDown((BalanceableContainer<?>) source);
        }
    } else if (sensor.equals(Movable.CONTAINER)) {
        onItemMoved(source, (BalanceableContainer<?>) value);
    } else {
        throw new IllegalStateException("Unhandled event type "+sensor+": "+event);
    }
}