Package com.opengamma.component.factory.infrastructure

Source Code of com.opengamma.component.factory.infrastructure.ScheduledExecutorServiceComponentFactory$Meta

/**
* Copyright (C) 2013 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.component.factory.infrastructure;

import com.opengamma.component.ComponentInfo;
import com.opengamma.component.ComponentRepository;
import com.opengamma.component.factory.AbstractComponentFactory;
import org.joda.beans.BeanBuilder;
import org.joda.beans.BeanDefinition;
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.DirectBeanBuilder;
import org.joda.beans.impl.direct.DirectMetaProperty;
import org.joda.beans.impl.direct.DirectMetaPropertyMap;
import org.springframework.scheduling.concurrent.ScheduledExecutorFactoryBean;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;

/**
* Component Factory for a shared ScheduledExecutorService.
*
* A reasonable default thread name prefix will be used if it is not provided.
*
*/
@BeanDefinition
public class ScheduledExecutorServiceComponentFactory extends AbstractComponentFactory {

  static final String DEFAULT_THREAD_PREFIX = "StandardInfra-";

  @PropertyDefinition(validate = "notNull")
  private String _classifier;

  @PropertyDefinition(validate = "notNull")
  private String _threadNamePrefix = DEFAULT_THREAD_PREFIX;

  @Override
  public void init(ComponentRepository repo, LinkedHashMap<String, String> configuration) throws Exception {

    final ComponentInfo info = new ComponentInfo(ScheduledExecutorService.class, getClassifier());
    final ScheduledExecutorService component = initScheduledExecutorService();
    repo.registerComponent(info, component);

  }

  protected final ScheduledExecutorService initScheduledExecutorService() {

    ScheduledExecutorFactoryBean factoryBean = new ScheduledExecutorFactoryBean();
    factoryBean.setThreadNamePrefix(getThreadNamePrefix());
    factoryBean.afterPropertiesSet();

    return factoryBean.getObject();

  }

  //------------------------- AUTOGENERATED START -------------------------
  ///CLOVER:OFF
  /**
   * The meta-bean for {@code ScheduledExecutorServiceComponentFactory}.
   * @return the meta-bean, not null
   */
  public static ScheduledExecutorServiceComponentFactory.Meta meta() {
    return ScheduledExecutorServiceComponentFactory.Meta.INSTANCE;
  }

  static {
    JodaBeanUtils.registerMetaBean(ScheduledExecutorServiceComponentFactory.Meta.INSTANCE);
  }

  @Override
  public ScheduledExecutorServiceComponentFactory.Meta metaBean() {
    return ScheduledExecutorServiceComponentFactory.Meta.INSTANCE;
  }

  @Override
  protected Object propertyGet(String propertyName, boolean quiet) {
    switch (propertyName.hashCode()) {
      case -281470431// classifier
        return getClassifier();
      case -1101780313// threadNamePrefix
        return getThreadNamePrefix();
    }
    return super.propertyGet(propertyName, quiet);
  }

  @Override
  protected void propertySet(String propertyName, Object newValue, boolean quiet) {
    switch (propertyName.hashCode()) {
      case -281470431// classifier
        setClassifier((String) newValue);
        return;
      case -1101780313// threadNamePrefix
        setThreadNamePrefix((String) newValue);
        return;
    }
    super.propertySet(propertyName, newValue, quiet);
  }

  @Override
  protected void validate() {
    JodaBeanUtils.notNull(_classifier, "classifier");
    JodaBeanUtils.notNull(_threadNamePrefix, "threadNamePrefix");
    super.validate();
  }

  @Override
  public boolean equals(Object obj) {
    if (obj == this) {
      return true;
    }
    if (obj != null && obj.getClass() == this.getClass()) {
      ScheduledExecutorServiceComponentFactory other = (ScheduledExecutorServiceComponentFactory) obj;
      return JodaBeanUtils.equal(getClassifier(), other.getClassifier()) &&
          JodaBeanUtils.equal(getThreadNamePrefix(), other.getThreadNamePrefix()) &&
          super.equals(obj);
    }
    return false;
  }

  @Override
  public int hashCode() {
    int hash = 7;
    hash += hash * 31 + JodaBeanUtils.hashCode(getClassifier());
    hash += hash * 31 + JodaBeanUtils.hashCode(getThreadNamePrefix());
    return hash ^ super.hashCode();
  }

  //-----------------------------------------------------------------------
  /**
   * Gets the classifier.
   * @return the value of the property, not null
   */
  public String getClassifier() {
    return _classifier;
  }

  /**
   * Sets the classifier.
   * @param classifier  the new value of the property, not null
   */
  public void setClassifier(String classifier) {
    JodaBeanUtils.notNull(classifier, "classifier");
    this._classifier = classifier;
  }

  /**
   * Gets the the {@code classifier} property.
   * @return the property, not null
   */
  public final Property<String> classifier() {
    return metaBean().classifier().createProperty(this);
  }

  //-----------------------------------------------------------------------
  /**
   * Gets the threadNamePrefix.
   * @return the value of the property, not null
   */
  public String getThreadNamePrefix() {
    return _threadNamePrefix;
  }

  /**
   * Sets the threadNamePrefix.
   * @param threadNamePrefix  the new value of the property, not null
   */
  public void setThreadNamePrefix(String threadNamePrefix) {
    JodaBeanUtils.notNull(threadNamePrefix, "threadNamePrefix");
    this._threadNamePrefix = threadNamePrefix;
  }

  /**
   * Gets the the {@code threadNamePrefix} property.
   * @return the property, not null
   */
  public final Property<String> threadNamePrefix() {
    return metaBean().threadNamePrefix().createProperty(this);
  }

  //-----------------------------------------------------------------------
  /**
   * The meta-bean for {@code ScheduledExecutorServiceComponentFactory}.
   */
  public static class Meta extends AbstractComponentFactory.Meta {
    /**
     * The singleton instance of the meta-bean.
     */
    static final Meta INSTANCE = new Meta();

    /**
     * The meta-property for the {@code classifier} property.
     */
    private final MetaProperty<String> _classifier = DirectMetaProperty.ofReadWrite(
        this, "classifier", ScheduledExecutorServiceComponentFactory.class, String.class);
    /**
     * The meta-property for the {@code threadNamePrefix} property.
     */
    private final MetaProperty<String> _threadNamePrefix = DirectMetaProperty.ofReadWrite(
        this, "threadNamePrefix", ScheduledExecutorServiceComponentFactory.class, String.class);
    /**
     * The meta-properties.
     */
    private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
        this, (DirectMetaPropertyMap) super.metaPropertyMap(),
        "classifier",
        "threadNamePrefix");

    /**
     * Restricted constructor.
     */
    protected Meta() {
    }

    @Override
    protected MetaProperty<?> metaPropertyGet(String propertyName) {
      switch (propertyName.hashCode()) {
        case -281470431// classifier
          return _classifier;
        case -1101780313// threadNamePrefix
          return _threadNamePrefix;
      }
      return super.metaPropertyGet(propertyName);
    }

    @Override
    public BeanBuilder<? extends ScheduledExecutorServiceComponentFactory> builder() {
      return new DirectBeanBuilder<ScheduledExecutorServiceComponentFactory>(new ScheduledExecutorServiceComponentFactory());
    }

    @Override
    public Class<? extends ScheduledExecutorServiceComponentFactory> beanType() {
      return ScheduledExecutorServiceComponentFactory.class;
    }

    @Override
    public Map<String, MetaProperty<?>> metaPropertyMap() {
      return _metaPropertyMap$;
    }

    //-----------------------------------------------------------------------
    /**
     * The meta-property for the {@code classifier} property.
     * @return the meta-property, not null
     */
    public final MetaProperty<String> classifier() {
      return _classifier;
    }

    /**
     * The meta-property for the {@code threadNamePrefix} property.
     * @return the meta-property, not null
     */
    public final MetaProperty<String> threadNamePrefix() {
      return _threadNamePrefix;
    }

  }

  ///CLOVER:ON
  //-------------------------- AUTOGENERATED END --------------------------
}
TOP

Related Classes of com.opengamma.component.factory.infrastructure.ScheduledExecutorServiceComponentFactory$Meta

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.