/**
* Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.component.factory.master;
import java.util.LinkedHashMap;
import java.util.Map;
import net.sf.ehcache.CacheManager;
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 com.opengamma.component.ComponentInfo;
import com.opengamma.component.ComponentRepository;
import com.opengamma.component.factory.ComponentInfoAttributes;
import com.opengamma.core.change.JmsChangeManager;
import com.opengamma.master.security.SecurityMaster;
import com.opengamma.master.security.impl.RemoteSecurityMaster;
import com.opengamma.masterdb.security.DataDbSecurityMasterResource;
import com.opengamma.masterdb.security.DbSecurityMaster;
import com.opengamma.masterdb.security.EHCachingSecurityMasterDetailProvider;
import com.opengamma.masterdb.security.SecurityMasterDetailProvider;
import com.opengamma.masterdb.security.hibernate.HibernateSecurityMasterDetailProvider;
import com.opengamma.util.jms.JmsConnector;
import com.opengamma.util.metric.OpenGammaMetricRegistry;
/**
* Component factory for the database security master.
*/
@BeanDefinition
public class DbSecurityMasterComponentFactory extends AbstractDbMasterComponentFactory {
/**
* The classifier that the factory should publish under.
*/
@PropertyDefinition(validate = "notNull")
private String _classifier;
/**
* The flag determining whether the component should be published by REST (default true).
*/
@PropertyDefinition
private boolean _publishRest = true;
/**
* The cache manager.
*/
@PropertyDefinition
private CacheManager _cacheManager;
/**
* The JMS connector.
*/
@PropertyDefinition
private JmsConnector _jmsConnector;
/**
* The JMS change manager topic.
*/
@PropertyDefinition
private String _jmsChangeManagerTopic;
/**
* The scheme used by the {@code UniqueId}.
*/
@PropertyDefinition
private String _uniqueIdScheme;
/**
* The maximum number of retries when updating.
*/
@PropertyDefinition
private Integer _maxRetries;
/**
* The detail provider.
*/
@PropertyDefinition
private Class<? extends SecurityMasterDetailProvider> _detailProvider = HibernateSecurityMasterDetailProvider.class;
//-------------------------------------------------------------------------
@Override
public void init(ComponentRepository repo, LinkedHashMap<String, String> configuration) throws Exception {
ComponentInfo info = new ComponentInfo(SecurityMaster.class, getClassifier());
// create
DbSecurityMaster master = new DbSecurityMaster(getDbConnector());
master.registerMetrics(OpenGammaMetricRegistry.getSummaryInstance(), OpenGammaMetricRegistry.getDetailedInstance(), "DbSecurityMaster-" + getClassifier());
if (getUniqueIdScheme() != null) {
master.setUniqueIdScheme(getUniqueIdScheme());
}
if (getMaxRetries() != null) {
master.setMaxRetries(getMaxRetries());
}
if (getJmsChangeManagerTopic() != null) {
JmsChangeManager cm = new JmsChangeManager(getJmsConnector(), getJmsChangeManagerTopic());
master.setChangeManager(cm);
repo.registerLifecycle(cm);
if (getJmsConnector().getClientBrokerUri() != null) {
info.addAttribute(ComponentInfoAttributes.JMS_BROKER_URI, getJmsConnector().getClientBrokerUri().toString());
}
info.addAttribute(ComponentInfoAttributes.JMS_CHANGE_MANAGER_TOPIC, getJmsChangeManagerTopic());
}
if (getDetailProvider() != null) {
SecurityMasterDetailProvider dp = getDetailProvider().newInstance();
if (getCacheManager() != null) {
master.setDetailProvider(new EHCachingSecurityMasterDetailProvider(dp, getCacheManager()));
} else {
master.setDetailProvider(dp);
}
}
checkSchema(master.getSchemaVersion(), "sec");
// register
info.addAttribute(ComponentInfoAttributes.LEVEL, 1);
info.addAttribute(ComponentInfoAttributes.REMOTE_CLIENT_JAVA, RemoteSecurityMaster.class);
info.addAttribute(ComponentInfoAttributes.UNIQUE_ID_SCHEME, master.getUniqueIdScheme());
repo.registerComponent(info, master);
// publish
if (isPublishRest()) {
repo.getRestComponents().publish(info, new DataDbSecurityMasterResource(master));
}
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code DbSecurityMasterComponentFactory}.
* @return the meta-bean, not null
*/
public static DbSecurityMasterComponentFactory.Meta meta() {
return DbSecurityMasterComponentFactory.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(DbSecurityMasterComponentFactory.Meta.INSTANCE);
}
@Override
public DbSecurityMasterComponentFactory.Meta metaBean() {
return DbSecurityMasterComponentFactory.Meta.INSTANCE;
}
@Override
protected Object propertyGet(String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case -281470431: // classifier
return getClassifier();
case -614707837: // publishRest
return isPublishRest();
case -1452875317: // cacheManager
return getCacheManager();
case -1495762275: // jmsConnector
return getJmsConnector();
case -758086398: // jmsChangeManagerTopic
return getJmsChangeManagerTopic();
case -1737146991: // uniqueIdScheme
return getUniqueIdScheme();
case -2022653118: // maxRetries
return getMaxRetries();
case -1015570078: // detailProvider
return getDetailProvider();
}
return super.propertyGet(propertyName, quiet);
}
@SuppressWarnings("unchecked")
@Override
protected void propertySet(String propertyName, Object newValue, boolean quiet) {
switch (propertyName.hashCode()) {
case -281470431: // classifier
setClassifier((String) newValue);
return;
case -614707837: // publishRest
setPublishRest((Boolean) newValue);
return;
case -1452875317: // cacheManager
setCacheManager((CacheManager) newValue);
return;
case -1495762275: // jmsConnector
setJmsConnector((JmsConnector) newValue);
return;
case -758086398: // jmsChangeManagerTopic
setJmsChangeManagerTopic((String) newValue);
return;
case -1737146991: // uniqueIdScheme
setUniqueIdScheme((String) newValue);
return;
case -2022653118: // maxRetries
setMaxRetries((Integer) newValue);
return;
case -1015570078: // detailProvider
setDetailProvider((Class<? extends SecurityMasterDetailProvider>) newValue);
return;
}
super.propertySet(propertyName, newValue, quiet);
}
@Override
protected void validate() {
JodaBeanUtils.notNull(_classifier, "classifier");
super.validate();
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
DbSecurityMasterComponentFactory other = (DbSecurityMasterComponentFactory) obj;
return JodaBeanUtils.equal(getClassifier(), other.getClassifier()) &&
JodaBeanUtils.equal(isPublishRest(), other.isPublishRest()) &&
JodaBeanUtils.equal(getCacheManager(), other.getCacheManager()) &&
JodaBeanUtils.equal(getJmsConnector(), other.getJmsConnector()) &&
JodaBeanUtils.equal(getJmsChangeManagerTopic(), other.getJmsChangeManagerTopic()) &&
JodaBeanUtils.equal(getUniqueIdScheme(), other.getUniqueIdScheme()) &&
JodaBeanUtils.equal(getMaxRetries(), other.getMaxRetries()) &&
JodaBeanUtils.equal(getDetailProvider(), other.getDetailProvider()) &&
super.equals(obj);
}
return false;
}
@Override
public int hashCode() {
int hash = 7;
hash += hash * 31 + JodaBeanUtils.hashCode(getClassifier());
hash += hash * 31 + JodaBeanUtils.hashCode(isPublishRest());
hash += hash * 31 + JodaBeanUtils.hashCode(getCacheManager());
hash += hash * 31 + JodaBeanUtils.hashCode(getJmsConnector());
hash += hash * 31 + JodaBeanUtils.hashCode(getJmsChangeManagerTopic());
hash += hash * 31 + JodaBeanUtils.hashCode(getUniqueIdScheme());
hash += hash * 31 + JodaBeanUtils.hashCode(getMaxRetries());
hash += hash * 31 + JodaBeanUtils.hashCode(getDetailProvider());
return hash ^ super.hashCode();
}
//-----------------------------------------------------------------------
/**
* Gets the classifier that the factory should publish under.
* @return the value of the property, not null
*/
public String getClassifier() {
return _classifier;
}
/**
* Sets the classifier that the factory should publish under.
* @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 flag determining whether the component should be published by REST (default true).
* @return the value of the property
*/
public boolean isPublishRest() {
return _publishRest;
}
/**
* Sets the flag determining whether the component should be published by REST (default true).
* @param publishRest the new value of the property
*/
public void setPublishRest(boolean publishRest) {
this._publishRest = publishRest;
}
/**
* Gets the the {@code publishRest} property.
* @return the property, not null
*/
public final Property<Boolean> publishRest() {
return metaBean().publishRest().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the cache manager.
* @return the value of the property
*/
public CacheManager getCacheManager() {
return _cacheManager;
}
/**
* Sets the cache manager.
* @param cacheManager the new value of the property
*/
public void setCacheManager(CacheManager cacheManager) {
this._cacheManager = cacheManager;
}
/**
* Gets the the {@code cacheManager} property.
* @return the property, not null
*/
public final Property<CacheManager> cacheManager() {
return metaBean().cacheManager().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the JMS connector.
* @return the value of the property
*/
public JmsConnector getJmsConnector() {
return _jmsConnector;
}
/**
* Sets the JMS connector.
* @param jmsConnector the new value of the property
*/
public void setJmsConnector(JmsConnector jmsConnector) {
this._jmsConnector = jmsConnector;
}
/**
* Gets the the {@code jmsConnector} property.
* @return the property, not null
*/
public final Property<JmsConnector> jmsConnector() {
return metaBean().jmsConnector().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the JMS change manager topic.
* @return the value of the property
*/
public String getJmsChangeManagerTopic() {
return _jmsChangeManagerTopic;
}
/**
* Sets the JMS change manager topic.
* @param jmsChangeManagerTopic the new value of the property
*/
public void setJmsChangeManagerTopic(String jmsChangeManagerTopic) {
this._jmsChangeManagerTopic = jmsChangeManagerTopic;
}
/**
* Gets the the {@code jmsChangeManagerTopic} property.
* @return the property, not null
*/
public final Property<String> jmsChangeManagerTopic() {
return metaBean().jmsChangeManagerTopic().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the scheme used by the {@code UniqueId}.
* @return the value of the property
*/
public String getUniqueIdScheme() {
return _uniqueIdScheme;
}
/**
* Sets the scheme used by the {@code UniqueId}.
* @param uniqueIdScheme the new value of the property
*/
public void setUniqueIdScheme(String uniqueIdScheme) {
this._uniqueIdScheme = uniqueIdScheme;
}
/**
* Gets the the {@code uniqueIdScheme} property.
* @return the property, not null
*/
public final Property<String> uniqueIdScheme() {
return metaBean().uniqueIdScheme().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the maximum number of retries when updating.
* @return the value of the property
*/
public Integer getMaxRetries() {
return _maxRetries;
}
/**
* Sets the maximum number of retries when updating.
* @param maxRetries the new value of the property
*/
public void setMaxRetries(Integer maxRetries) {
this._maxRetries = maxRetries;
}
/**
* Gets the the {@code maxRetries} property.
* @return the property, not null
*/
public final Property<Integer> maxRetries() {
return metaBean().maxRetries().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the detail provider.
* @return the value of the property
*/
public Class<? extends SecurityMasterDetailProvider> getDetailProvider() {
return _detailProvider;
}
/**
* Sets the detail provider.
* @param detailProvider the new value of the property
*/
public void setDetailProvider(Class<? extends SecurityMasterDetailProvider> detailProvider) {
this._detailProvider = detailProvider;
}
/**
* Gets the the {@code detailProvider} property.
* @return the property, not null
*/
public final Property<Class<? extends SecurityMasterDetailProvider>> detailProvider() {
return metaBean().detailProvider().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code DbSecurityMasterComponentFactory}.
*/
public static class Meta extends AbstractDbMasterComponentFactory.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", DbSecurityMasterComponentFactory.class, String.class);
/**
* The meta-property for the {@code publishRest} property.
*/
private final MetaProperty<Boolean> _publishRest = DirectMetaProperty.ofReadWrite(
this, "publishRest", DbSecurityMasterComponentFactory.class, Boolean.TYPE);
/**
* The meta-property for the {@code cacheManager} property.
*/
private final MetaProperty<CacheManager> _cacheManager = DirectMetaProperty.ofReadWrite(
this, "cacheManager", DbSecurityMasterComponentFactory.class, CacheManager.class);
/**
* The meta-property for the {@code jmsConnector} property.
*/
private final MetaProperty<JmsConnector> _jmsConnector = DirectMetaProperty.ofReadWrite(
this, "jmsConnector", DbSecurityMasterComponentFactory.class, JmsConnector.class);
/**
* The meta-property for the {@code jmsChangeManagerTopic} property.
*/
private final MetaProperty<String> _jmsChangeManagerTopic = DirectMetaProperty.ofReadWrite(
this, "jmsChangeManagerTopic", DbSecurityMasterComponentFactory.class, String.class);
/**
* The meta-property for the {@code uniqueIdScheme} property.
*/
private final MetaProperty<String> _uniqueIdScheme = DirectMetaProperty.ofReadWrite(
this, "uniqueIdScheme", DbSecurityMasterComponentFactory.class, String.class);
/**
* The meta-property for the {@code maxRetries} property.
*/
private final MetaProperty<Integer> _maxRetries = DirectMetaProperty.ofReadWrite(
this, "maxRetries", DbSecurityMasterComponentFactory.class, Integer.class);
/**
* The meta-property for the {@code detailProvider} property.
*/
@SuppressWarnings({"unchecked", "rawtypes" })
private final MetaProperty<Class<? extends SecurityMasterDetailProvider>> _detailProvider = DirectMetaProperty.ofReadWrite(
this, "detailProvider", DbSecurityMasterComponentFactory.class, (Class) Class.class);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
this, (DirectMetaPropertyMap) super.metaPropertyMap(),
"classifier",
"publishRest",
"cacheManager",
"jmsConnector",
"jmsChangeManagerTopic",
"uniqueIdScheme",
"maxRetries",
"detailProvider");
/**
* Restricted constructor.
*/
protected Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case -281470431: // classifier
return _classifier;
case -614707837: // publishRest
return _publishRest;
case -1452875317: // cacheManager
return _cacheManager;
case -1495762275: // jmsConnector
return _jmsConnector;
case -758086398: // jmsChangeManagerTopic
return _jmsChangeManagerTopic;
case -1737146991: // uniqueIdScheme
return _uniqueIdScheme;
case -2022653118: // maxRetries
return _maxRetries;
case -1015570078: // detailProvider
return _detailProvider;
}
return super.metaPropertyGet(propertyName);
}
@Override
public BeanBuilder<? extends DbSecurityMasterComponentFactory> builder() {
return new DirectBeanBuilder<DbSecurityMasterComponentFactory>(new DbSecurityMasterComponentFactory());
}
@Override
public Class<? extends DbSecurityMasterComponentFactory> beanType() {
return DbSecurityMasterComponentFactory.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 publishRest} property.
* @return the meta-property, not null
*/
public final MetaProperty<Boolean> publishRest() {
return _publishRest;
}
/**
* The meta-property for the {@code cacheManager} property.
* @return the meta-property, not null
*/
public final MetaProperty<CacheManager> cacheManager() {
return _cacheManager;
}
/**
* The meta-property for the {@code jmsConnector} property.
* @return the meta-property, not null
*/
public final MetaProperty<JmsConnector> jmsConnector() {
return _jmsConnector;
}
/**
* The meta-property for the {@code jmsChangeManagerTopic} property.
* @return the meta-property, not null
*/
public final MetaProperty<String> jmsChangeManagerTopic() {
return _jmsChangeManagerTopic;
}
/**
* The meta-property for the {@code uniqueIdScheme} property.
* @return the meta-property, not null
*/
public final MetaProperty<String> uniqueIdScheme() {
return _uniqueIdScheme;
}
/**
* The meta-property for the {@code maxRetries} property.
* @return the meta-property, not null
*/
public final MetaProperty<Integer> maxRetries() {
return _maxRetries;
}
/**
* The meta-property for the {@code detailProvider} property.
* @return the meta-property, not null
*/
public final MetaProperty<Class<? extends SecurityMasterDetailProvider>> detailProvider() {
return _detailProvider;
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}