/**
* Copyright (C) 2014 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.sesame.engine;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Set;
import org.joda.beans.Bean;
import org.joda.beans.BeanDefinition;
import org.joda.beans.ImmutableBean;
import org.joda.beans.JodaBeanUtils;
import org.joda.beans.MetaProperty;
import org.joda.beans.Property;
import org.joda.beans.PropertyDefinition;
import org.joda.beans.impl.direct.DirectFieldsBeanBuilder;
import org.joda.beans.impl.direct.DirectMetaBean;
import org.joda.beans.impl.direct.DirectMetaProperty;
import org.joda.beans.impl.direct.DirectMetaPropertyMap;
import org.threeten.bp.Duration;
import org.threeten.bp.Instant;
/**
* Holds timings for the execution of a view cycle.
*/
@BeanDefinition
public class ViewTimer implements ImmutableBean {
/**
* The time at which the view cycle was started.
*/
@PropertyDefinition(validate = "notNull")
private final Instant _start;
/**
* The total duration of the view cycle.
*/
@PropertyDefinition(validate = "notNull")
private final Duration _totalDuration;
/**
* THe duration of the initialization phase of the cycle. This
* records the time spent setting up data for the engine.
*/
@PropertyDefinition(validate = "notNull")
private final Duration _initializationDuration;
/**
* The duration of the execution of the view by the engine.
*/
@PropertyDefinition(validate = "notNull")
private final Duration _executionDuration;
/**
* The duration of the results building phase of the cycle. This
* records the time spent creating the results object from the
* data returned by the engine.
*/
@PropertyDefinition(validate = "notNull")
private final Duration _resultsBuildDuration;
public ViewTimer(Instant start, long startInitialization, long startExecution, long startResultsBuild, long end) {
_start = start;
_totalDuration = Duration.ofNanos(end - startInitialization);
_initializationDuration = Duration.ofNanos(startExecution - startInitialization);
_executionDuration = Duration.ofNanos(startResultsBuild - startExecution);
_resultsBuildDuration = Duration.ofNanos(end - startResultsBuild);
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code ViewTimer}.
* @return the meta-bean, not null
*/
public static ViewTimer.Meta meta() {
return ViewTimer.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(ViewTimer.Meta.INSTANCE);
}
/**
* Returns a builder used to create an instance of the bean.
* @return the builder, not null
*/
public static ViewTimer.Builder builder() {
return new ViewTimer.Builder();
}
/**
* Restricted constructor.
* @param builder the builder to copy from, not null
*/
protected ViewTimer(ViewTimer.Builder builder) {
JodaBeanUtils.notNull(builder._start, "start");
JodaBeanUtils.notNull(builder._totalDuration, "totalDuration");
JodaBeanUtils.notNull(builder._initializationDuration, "initializationDuration");
JodaBeanUtils.notNull(builder._executionDuration, "executionDuration");
JodaBeanUtils.notNull(builder._resultsBuildDuration, "resultsBuildDuration");
this._start = builder._start;
this._totalDuration = builder._totalDuration;
this._initializationDuration = builder._initializationDuration;
this._executionDuration = builder._executionDuration;
this._resultsBuildDuration = builder._resultsBuildDuration;
}
@Override
public ViewTimer.Meta metaBean() {
return ViewTimer.Meta.INSTANCE;
}
@Override
public <R> Property<R> property(String propertyName) {
return metaBean().<R>metaProperty(propertyName).createProperty(this);
}
@Override
public Set<String> propertyNames() {
return metaBean().metaPropertyMap().keySet();
}
//-----------------------------------------------------------------------
/**
* Gets the time at which the view cycle was started.
* @return the value of the property, not null
*/
public Instant getStart() {
return _start;
}
//-----------------------------------------------------------------------
/**
* Gets the total duration of the view cycle.
* @return the value of the property, not null
*/
public Duration getTotalDuration() {
return _totalDuration;
}
//-----------------------------------------------------------------------
/**
* Gets tHe duration of the initialization phase of the cycle. This
* records the time spent setting up data for the engine.
* @return the value of the property, not null
*/
public Duration getInitializationDuration() {
return _initializationDuration;
}
//-----------------------------------------------------------------------
/**
* Gets the duration of the execution of the view by the engine.
* @return the value of the property, not null
*/
public Duration getExecutionDuration() {
return _executionDuration;
}
//-----------------------------------------------------------------------
/**
* Gets the duration of the results building phase of the cycle. This
* records the time spent creating the results object from the
* data returned by the engine.
* @return the value of the property, not null
*/
public Duration getResultsBuildDuration() {
return _resultsBuildDuration;
}
//-----------------------------------------------------------------------
/**
* Returns a builder that allows this bean to be mutated.
* @return the mutable builder, not null
*/
public Builder toBuilder() {
return new Builder(this);
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
ViewTimer other = (ViewTimer) obj;
return JodaBeanUtils.equal(getStart(), other.getStart()) &&
JodaBeanUtils.equal(getTotalDuration(), other.getTotalDuration()) &&
JodaBeanUtils.equal(getInitializationDuration(), other.getInitializationDuration()) &&
JodaBeanUtils.equal(getExecutionDuration(), other.getExecutionDuration()) &&
JodaBeanUtils.equal(getResultsBuildDuration(), other.getResultsBuildDuration());
}
return false;
}
@Override
public int hashCode() {
int hash = getClass().hashCode();
hash = hash * 31 + JodaBeanUtils.hashCode(getStart());
hash = hash * 31 + JodaBeanUtils.hashCode(getTotalDuration());
hash = hash * 31 + JodaBeanUtils.hashCode(getInitializationDuration());
hash = hash * 31 + JodaBeanUtils.hashCode(getExecutionDuration());
hash = hash * 31 + JodaBeanUtils.hashCode(getResultsBuildDuration());
return hash;
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(192);
buf.append("ViewTimer{");
int len = buf.length();
toString(buf);
if (buf.length() > len) {
buf.setLength(buf.length() - 2);
}
buf.append('}');
return buf.toString();
}
protected void toString(StringBuilder buf) {
buf.append("start").append('=').append(JodaBeanUtils.toString(getStart())).append(',').append(' ');
buf.append("totalDuration").append('=').append(JodaBeanUtils.toString(getTotalDuration())).append(',').append(' ');
buf.append("initializationDuration").append('=').append(JodaBeanUtils.toString(getInitializationDuration())).append(',').append(' ');
buf.append("executionDuration").append('=').append(JodaBeanUtils.toString(getExecutionDuration())).append(',').append(' ');
buf.append("resultsBuildDuration").append('=').append(JodaBeanUtils.toString(getResultsBuildDuration())).append(',').append(' ');
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code ViewTimer}.
*/
public static class Meta extends DirectMetaBean {
/**
* The singleton instance of the meta-bean.
*/
static final Meta INSTANCE = new Meta();
/**
* The meta-property for the {@code start} property.
*/
private final MetaProperty<Instant> _start = DirectMetaProperty.ofImmutable(
this, "start", ViewTimer.class, Instant.class);
/**
* The meta-property for the {@code totalDuration} property.
*/
private final MetaProperty<Duration> _totalDuration = DirectMetaProperty.ofImmutable(
this, "totalDuration", ViewTimer.class, Duration.class);
/**
* The meta-property for the {@code initializationDuration} property.
*/
private final MetaProperty<Duration> _initializationDuration = DirectMetaProperty.ofImmutable(
this, "initializationDuration", ViewTimer.class, Duration.class);
/**
* The meta-property for the {@code executionDuration} property.
*/
private final MetaProperty<Duration> _executionDuration = DirectMetaProperty.ofImmutable(
this, "executionDuration", ViewTimer.class, Duration.class);
/**
* The meta-property for the {@code resultsBuildDuration} property.
*/
private final MetaProperty<Duration> _resultsBuildDuration = DirectMetaProperty.ofImmutable(
this, "resultsBuildDuration", ViewTimer.class, Duration.class);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
this, null,
"start",
"totalDuration",
"initializationDuration",
"executionDuration",
"resultsBuildDuration");
/**
* Restricted constructor.
*/
protected Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case 109757538: // start
return _start;
case -1965553416: // totalDuration
return _totalDuration;
case -1109030316: // initializationDuration
return _initializationDuration;
case 440870092: // executionDuration
return _executionDuration;
case 1739046348: // resultsBuildDuration
return _resultsBuildDuration;
}
return super.metaPropertyGet(propertyName);
}
@Override
public ViewTimer.Builder builder() {
return new ViewTimer.Builder();
}
@Override
public Class<? extends ViewTimer> beanType() {
return ViewTimer.class;
}
@Override
public Map<String, MetaProperty<?>> metaPropertyMap() {
return _metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code start} property.
* @return the meta-property, not null
*/
public final MetaProperty<Instant> start() {
return _start;
}
/**
* The meta-property for the {@code totalDuration} property.
* @return the meta-property, not null
*/
public final MetaProperty<Duration> totalDuration() {
return _totalDuration;
}
/**
* The meta-property for the {@code initializationDuration} property.
* @return the meta-property, not null
*/
public final MetaProperty<Duration> initializationDuration() {
return _initializationDuration;
}
/**
* The meta-property for the {@code executionDuration} property.
* @return the meta-property, not null
*/
public final MetaProperty<Duration> executionDuration() {
return _executionDuration;
}
/**
* The meta-property for the {@code resultsBuildDuration} property.
* @return the meta-property, not null
*/
public final MetaProperty<Duration> resultsBuildDuration() {
return _resultsBuildDuration;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case 109757538: // start
return ((ViewTimer) bean).getStart();
case -1965553416: // totalDuration
return ((ViewTimer) bean).getTotalDuration();
case -1109030316: // initializationDuration
return ((ViewTimer) bean).getInitializationDuration();
case 440870092: // executionDuration
return ((ViewTimer) bean).getExecutionDuration();
case 1739046348: // resultsBuildDuration
return ((ViewTimer) bean).getResultsBuildDuration();
}
return super.propertyGet(bean, propertyName, quiet);
}
@Override
protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) {
metaProperty(propertyName);
if (quiet) {
return;
}
throw new UnsupportedOperationException("Property cannot be written: " + propertyName);
}
}
//-----------------------------------------------------------------------
/**
* The bean-builder for {@code ViewTimer}.
*/
public static class Builder extends DirectFieldsBeanBuilder<ViewTimer> {
private Instant _start;
private Duration _totalDuration;
private Duration _initializationDuration;
private Duration _executionDuration;
private Duration _resultsBuildDuration;
/**
* Restricted constructor.
*/
protected Builder() {
}
/**
* Restricted copy constructor.
* @param beanToCopy the bean to copy from, not null
*/
protected Builder(ViewTimer beanToCopy) {
this._start = beanToCopy.getStart();
this._totalDuration = beanToCopy.getTotalDuration();
this._initializationDuration = beanToCopy.getInitializationDuration();
this._executionDuration = beanToCopy.getExecutionDuration();
this._resultsBuildDuration = beanToCopy.getResultsBuildDuration();
}
//-----------------------------------------------------------------------
@Override
public Object get(String propertyName) {
switch (propertyName.hashCode()) {
case 109757538: // start
return _start;
case -1965553416: // totalDuration
return _totalDuration;
case -1109030316: // initializationDuration
return _initializationDuration;
case 440870092: // executionDuration
return _executionDuration;
case 1739046348: // resultsBuildDuration
return _resultsBuildDuration;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
}
@Override
public Builder set(String propertyName, Object newValue) {
switch (propertyName.hashCode()) {
case 109757538: // start
this._start = (Instant) newValue;
break;
case -1965553416: // totalDuration
this._totalDuration = (Duration) newValue;
break;
case -1109030316: // initializationDuration
this._initializationDuration = (Duration) newValue;
break;
case 440870092: // executionDuration
this._executionDuration = (Duration) newValue;
break;
case 1739046348: // resultsBuildDuration
this._resultsBuildDuration = (Duration) newValue;
break;
default:
throw new NoSuchElementException("Unknown property: " + propertyName);
}
return this;
}
@Override
public Builder set(MetaProperty<?> property, Object value) {
super.set(property, value);
return this;
}
@Override
public Builder setString(String propertyName, String value) {
setString(meta().metaProperty(propertyName), value);
return this;
}
@Override
public Builder setString(MetaProperty<?> property, String value) {
super.setString(property, value);
return this;
}
@Override
public Builder setAll(Map<String, ? extends Object> propertyValueMap) {
super.setAll(propertyValueMap);
return this;
}
@Override
public ViewTimer build() {
return new ViewTimer(this);
}
//-----------------------------------------------------------------------
/**
* Sets the {@code start} property in the builder.
* @param start the new value, not null
* @return this, for chaining, not null
*/
public Builder start(Instant start) {
JodaBeanUtils.notNull(start, "start");
this._start = start;
return this;
}
/**
* Sets the {@code totalDuration} property in the builder.
* @param totalDuration the new value, not null
* @return this, for chaining, not null
*/
public Builder totalDuration(Duration totalDuration) {
JodaBeanUtils.notNull(totalDuration, "totalDuration");
this._totalDuration = totalDuration;
return this;
}
/**
* Sets the {@code initializationDuration} property in the builder.
* @param initializationDuration the new value, not null
* @return this, for chaining, not null
*/
public Builder initializationDuration(Duration initializationDuration) {
JodaBeanUtils.notNull(initializationDuration, "initializationDuration");
this._initializationDuration = initializationDuration;
return this;
}
/**
* Sets the {@code executionDuration} property in the builder.
* @param executionDuration the new value, not null
* @return this, for chaining, not null
*/
public Builder executionDuration(Duration executionDuration) {
JodaBeanUtils.notNull(executionDuration, "executionDuration");
this._executionDuration = executionDuration;
return this;
}
/**
* Sets the {@code resultsBuildDuration} property in the builder.
* @param resultsBuildDuration the new value, not null
* @return this, for chaining, not null
*/
public Builder resultsBuildDuration(Duration resultsBuildDuration) {
JodaBeanUtils.notNull(resultsBuildDuration, "resultsBuildDuration");
this._resultsBuildDuration = resultsBuildDuration;
return this;
}
//-----------------------------------------------------------------------
@Override
public String toString() {
StringBuilder buf = new StringBuilder(192);
buf.append("ViewTimer.Builder{");
int len = buf.length();
toString(buf);
if (buf.length() > len) {
buf.setLength(buf.length() - 2);
}
buf.append('}');
return buf.toString();
}
protected void toString(StringBuilder buf) {
buf.append("start").append('=').append(JodaBeanUtils.toString(_start)).append(',').append(' ');
buf.append("totalDuration").append('=').append(JodaBeanUtils.toString(_totalDuration)).append(',').append(' ');
buf.append("initializationDuration").append('=').append(JodaBeanUtils.toString(_initializationDuration)).append(',').append(' ');
buf.append("executionDuration").append('=').append(JodaBeanUtils.toString(_executionDuration)).append(',').append(' ');
buf.append("resultsBuildDuration").append('=').append(JodaBeanUtils.toString(_resultsBuildDuration)).append(',').append(' ');
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}