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

brooklyn.management.usage.ApplicationUsage Maven / Gradle / Ivy

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

import static com.google.common.base.Preconditions.checkNotNull;

import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;

import brooklyn.entity.basic.Lifecycle;

import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

/**
 */
public class ApplicationUsage {
    
    public static class ApplicationEvent {
        private final Date date;
        private final Lifecycle state;

        public ApplicationEvent(Lifecycle state) {
            this.date = new Date();
            this.state = checkNotNull(state, "state");
        }

        public Date getDate() {
            return date;
        }

        public Lifecycle getState() {
            return state;
        }
        
        @Override
        public String toString() {
            return Objects.toStringHelper(this).add("date", date).add("state", state).toString();
        }
    }
    
    private final String applicationId;
    private final String applicationName;
    private final String entityType;
    private final Map metadata;
    private final List events = Collections.synchronizedList(Lists.newArrayList());

    public ApplicationUsage(String applicationId, String applicationName, String entityType, Map metadata) {
        this.applicationId = checkNotNull(applicationId, "applicationId");
        this.applicationName = checkNotNull(applicationName, "applicationName");
        this.entityType = checkNotNull(entityType, "entityType");
        this.metadata = checkNotNull(metadata, "metadata");
    }

    public String getApplicationId() {
        return applicationId;
    }

    public String getApplicationName() {
        return applicationName;
    }

    public String getEntityType() {
        return entityType;
    }

    public Map getMetadata() {
        return metadata;
    }
    
    public List getEvents() {
        synchronized (events) {
            return ImmutableList.copyOf(events);
        }
    }

    public void addEvent(ApplicationEvent event) {
        events.add(checkNotNull(event, "event"));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy