/** * Copyright (C) 2013 - present by OpenGamma Inc. and the OpenGamma group of companies * * Please see distribution for license. */ package com.opengamma.component.factory.source; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import org.joda.beans.BeanBuilder; import org.joda.beans.BeanDefinition; import org.joda.beans.JodaBeanUtils; import org.joda.beans.MetaProperty; import org.joda.beans.PropertyDefinition; import org.joda.beans.impl.direct.DirectBeanBuilder; 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.config.ConfigSource; import com.opengamma.core.config.impl.DataConfigSourceResource; import com.opengamma.core.config.impl.DelegatingConfigSource; import com.opengamma.core.config.impl.EHCachingConfigSource; import com.opengamma.core.config.impl.NonVersionedRedisConfigSource; import com.opengamma.core.config.impl.RemoteConfigSource; import com.opengamma.master.config.ConfigMaster; import com.opengamma.master.config.impl.MasterConfigSource; import org.joda.beans.Bean; import org.joda.beans.Property; import org.joda.beans.impl.direct.DirectMetaProperty; import net.sf.ehcache.CacheManager; /** * */ @BeanDefinition public class NonVersionedRedisConfigSourceComponentFactory extends AbstractNonVersionedRedisSourceComponentFactory { @PropertyDefinition private String _userClassifier; @PropertyDefinition private ConfigMaster _userConfigMaster; @Override public void init(ComponentRepository repo, LinkedHashMap<String, String> configuration) throws Exception { ConfigSource redisSource = new NonVersionedRedisConfigSource(getRedisConnector().getJedisPool(), getRedisPrefix()); ConfigSource source = redisSource; ConfigSource userSource = initUser(repo, configuration); Map<String, ConfigSource> map = new HashMap<String, ConfigSource>(); if (userSource != null) { String scheme = repo.getInfo(getUserConfigMaster()).getAttribute(ComponentInfoAttributes.UNIQUE_ID_SCHEME); map.put(scheme, userSource); source = new EHCachingConfigSource(new DelegatingConfigSource(source, map), CacheManager.getInstance()); } ComponentInfo info = new ComponentInfo(ConfigSource.class, getClassifier()); info.addAttribute(ComponentInfoAttributes.LEVEL, userSource == null ? 1 : 2); info.addAttribute(ComponentInfoAttributes.REMOTE_CLIENT_JAVA, RemoteConfigSource.class); repo.registerComponent(info, source); if (isPublishRest()) { repo.getRestComponents().publish(info, new DataConfigSourceResource(source)); } info = new ComponentInfo(NonVersionedRedisConfigSource.class, getClassifier()); info.addAttribute(ComponentInfoAttributes.LEVEL, 1); repo.registerComponent(info, redisSource); } protected ConfigSource initUser(ComponentRepository repo, LinkedHashMap<String, String> configuration) { if (getUserConfigMaster() == null) { return null; } ConfigSource source = new MasterConfigSource(getUserConfigMaster()); if (getUserClassifier() != null) { ComponentInfo info = new ComponentInfo(ConfigSource.class, getUserClassifier()); info.addAttribute(ComponentInfoAttributes.LEVEL, 1); info.addAttribute(ComponentInfoAttributes.REMOTE_CLIENT_JAVA, RemoteConfigSource.class); repo.registerComponent(info, source); if (isPublishRest()) { repo.getRestComponents().publish(info, new DataConfigSourceResource(source)); } } return source; } //------------------------- AUTOGENERATED START ------------------------- ///CLOVER:OFF /** * The meta-bean for {@code NonVersionedRedisConfigSourceComponentFactory}. * @return the meta-bean, not null */ public static NonVersionedRedisConfigSourceComponentFactory.Meta meta() { return NonVersionedRedisConfigSourceComponentFactory.Meta.INSTANCE; } static { JodaBeanUtils.registerMetaBean(NonVersionedRedisConfigSourceComponentFactory.Meta.INSTANCE); } @Override public NonVersionedRedisConfigSourceComponentFactory.Meta metaBean() { return NonVersionedRedisConfigSourceComponentFactory.Meta.INSTANCE; } //----------------------------------------------------------------------- /** * Gets the userClassifier. * @return the value of the property */ public String getUserClassifier() { return _userClassifier; } /** * Sets the userClassifier. * @param userClassifier the new value of the property */ public void setUserClassifier(String userClassifier) { this._userClassifier = userClassifier; } /** * Gets the the {@code userClassifier} property. * @return the property, not null */ public final Property<String> userClassifier() { return metaBean().userClassifier().createProperty(this); } //----------------------------------------------------------------------- /** * Gets the userConfigMaster. * @return the value of the property */ public ConfigMaster getUserConfigMaster() { return _userConfigMaster; } /** * Sets the userConfigMaster. * @param userConfigMaster the new value of the property */ public void setUserConfigMaster(ConfigMaster userConfigMaster) { this._userConfigMaster = userConfigMaster; } /** * Gets the the {@code userConfigMaster} property. * @return the property, not null */ public final Property<ConfigMaster> userConfigMaster() { return metaBean().userConfigMaster().createProperty(this); } //----------------------------------------------------------------------- @Override public NonVersionedRedisConfigSourceComponentFactory clone() { return JodaBeanUtils.cloneAlways(this); } @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj != null && obj.getClass() == this.getClass()) { NonVersionedRedisConfigSourceComponentFactory other = (NonVersionedRedisConfigSourceComponentFactory) obj; return JodaBeanUtils.equal(getUserClassifier(), other.getUserClassifier()) && JodaBeanUtils.equal(getUserConfigMaster(), other.getUserConfigMaster()) && super.equals(obj); } return false; } @Override public int hashCode() { int hash = 7; hash = hash * 31 + JodaBeanUtils.hashCode(getUserClassifier()); hash = hash * 31 + JodaBeanUtils.hashCode(getUserConfigMaster()); return hash ^ super.hashCode(); } @Override public String toString() { StringBuilder buf = new StringBuilder(96); buf.append("NonVersionedRedisConfigSourceComponentFactory{"); int len = buf.length(); toString(buf); if (buf.length() > len) { buf.setLength(buf.length() - 2); } buf.append('}'); return buf.toString(); } @Override protected void toString(StringBuilder buf) { super.toString(buf); buf.append("userClassifier").append('=').append(JodaBeanUtils.toString(getUserClassifier())).append(',').append(' '); buf.append("userConfigMaster").append('=').append(JodaBeanUtils.toString(getUserConfigMaster())).append(',').append(' '); } //----------------------------------------------------------------------- /** * The meta-bean for {@code NonVersionedRedisConfigSourceComponentFactory}. */ public static class Meta extends AbstractNonVersionedRedisSourceComponentFactory.Meta { /** * The singleton instance of the meta-bean. */ static final Meta INSTANCE = new Meta(); /** * The meta-property for the {@code userClassifier} property. */ private final MetaProperty<String> _userClassifier = DirectMetaProperty.ofReadWrite( this, "userClassifier", NonVersionedRedisConfigSourceComponentFactory.class, String.class); /** * The meta-property for the {@code userConfigMaster} property. */ private final MetaProperty<ConfigMaster> _userConfigMaster = DirectMetaProperty.ofReadWrite( this, "userConfigMaster", NonVersionedRedisConfigSourceComponentFactory.class, ConfigMaster.class); /** * The meta-properties. */ private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap( this, (DirectMetaPropertyMap) super.metaPropertyMap(), "userClassifier", "userConfigMaster"); /** * Restricted constructor. */ protected Meta() { } @Override protected MetaProperty<?> metaPropertyGet(String propertyName) { switch (propertyName.hashCode()) { case 473030732: // userClassifier return _userClassifier; case -763459665: // userConfigMaster return _userConfigMaster; } return super.metaPropertyGet(propertyName); } @Override public BeanBuilder<? extends NonVersionedRedisConfigSourceComponentFactory> builder() { return new DirectBeanBuilder<NonVersionedRedisConfigSourceComponentFactory>(new NonVersionedRedisConfigSourceComponentFactory()); } @Override public Class<? extends NonVersionedRedisConfigSourceComponentFactory> beanType() { return NonVersionedRedisConfigSourceComponentFactory.class; } @Override public Map<String, MetaProperty<?>> metaPropertyMap() { return _metaPropertyMap$; } //----------------------------------------------------------------------- /** * The meta-property for the {@code userClassifier} property. * @return the meta-property, not null */ public final MetaProperty<String> userClassifier() { return _userClassifier; } /** * The meta-property for the {@code userConfigMaster} property. * @return the meta-property, not null */ public final MetaProperty<ConfigMaster> userConfigMaster() { return _userConfigMaster; } //----------------------------------------------------------------------- @Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 473030732: // userClassifier return ((NonVersionedRedisConfigSourceComponentFactory) bean).getUserClassifier(); case -763459665: // userConfigMaster return ((NonVersionedRedisConfigSourceComponentFactory) bean).getUserConfigMaster(); } return super.propertyGet(bean, propertyName, quiet); } @Override protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) { switch (propertyName.hashCode()) { case 473030732: // userClassifier ((NonVersionedRedisConfigSourceComponentFactory) bean).setUserClassifier((String) newValue); return; case -763459665: // userConfigMaster ((NonVersionedRedisConfigSourceComponentFactory) bean).setUserConfigMaster((ConfigMaster) newValue); return; } super.propertySet(bean, propertyName, newValue, quiet); } } ///CLOVER:ON //-------------------------- AUTOGENERATED END -------------------------- }