All Downloads are FREE. Search and download functionalities are using the official Maven repository.

brooklyn.management.internal.NonDeploymentUsageManager Maven / Gradle / Ivy

There is a newer version: 0.7.0-M1
Show newest version
package brooklyn.management.internal;

import java.util.Set;

import brooklyn.entity.Application;
import brooklyn.entity.basic.Lifecycle;
import brooklyn.location.Location;
import brooklyn.management.usage.ApplicationUsage;
import brooklyn.management.usage.LocationUsage;

import com.google.common.base.Predicate;


public class NonDeploymentUsageManager implements UsageManager {

    private final ManagementContextInternal initialManagementContext;
    
    public NonDeploymentUsageManager(ManagementContextInternal initialManagementContext) {
        this.initialManagementContext = initialManagementContext;
    }
    
    private boolean isInitialManagementContextReal() {
        return (initialManagementContext != null && !(initialManagementContext instanceof NonDeploymentManagementContext));
    }

    @Override
    public void recordApplicationEvent(Application app, Lifecycle state) {
        if (isInitialManagementContextReal()) {
            initialManagementContext.getUsageManager().recordApplicationEvent(app, state);
        } else {
            throw new IllegalStateException("Non-deployment context "+this+" is not valid for this operation");
        }
    }

    @Override
    public void recordLocationEvent(Location loc, Lifecycle state) {
        if (isInitialManagementContextReal()) {
            initialManagementContext.getUsageManager().recordLocationEvent(loc, state);
        } else {
            throw new IllegalStateException("Non-deployment context "+this+" is not valid for this operation");
        }
    }

    @Override
    public LocationUsage getLocationUsage(String locationId) {
        if (isInitialManagementContextReal()) {
            return initialManagementContext.getUsageManager().getLocationUsage(locationId);
        } else {
            throw new IllegalStateException("Non-deployment context "+this+" is not valid for this operation");
        }
    }

    @Override
    public Set getLocationUsage(Predicate filter) {
        if (isInitialManagementContextReal()) {
            return initialManagementContext.getUsageManager().getLocationUsage(filter);
        } else {
            throw new IllegalStateException("Non-deployment context "+this+" is not valid for this operation");
        }
    }

    @Override
    public ApplicationUsage getApplicationUsage(String appId) {
        if (isInitialManagementContextReal()) {
            return initialManagementContext.getUsageManager().getApplicationUsage(appId);
        } else {
            throw new IllegalStateException("Non-deployment context "+this+" is not valid for this operation");
        }
    }

    @Override
    public Set getApplicationUsage(Predicate filter) {
        if (isInitialManagementContextReal()) {
            return initialManagementContext.getUsageManager().getApplicationUsage(filter);
        } else {
            throw new IllegalStateException("Non-deployment context "+this+" is not valid for this operation");
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy