FileDocCategorySizeDatePackage
ProvidedServiceConfig.javaAPI DocApache Lucene 2.1.011910Wed Feb 14 10:46:06 GMT 2007org.apache.lucene.gdata.server.registry

ProvidedServiceConfig

public class ProvidedServiceConfig extends Object implements ProvidedService, ScopeVisitor
Standard implementation of {@link org.apache.lucene.gdata.server.registry.ProvidedService} to be used inside the {@link org.apache.lucene.gdata.server.registry.GDataServerRegistry}

ExtensionProfiles are used to generate and parse xml by the gdata api. For that case all methods are synchronized. This will slow down the application when performing lots of xml generation concurrently. For that case the extensionProfile for a specific service will be pooled and reused.

author
Simon Willnauer

Fields Summary
private static final Log
LOG
private static final int
DEFAULT_POOL_SIZE
private org.apache.lucene.gdata.search.config.IndexSchema
indexSchema
protected final ThreadLocal
extProfThreadLocal
private org.apache.lucene.gdata.utils.Pool
profilPool
private String
serviceName
private Class
entryType
private Class
feedType
private com.google.gdata.data.ExtensionProfile
extensionProfile
private int
poolSize
private Templates
transformerTemplate
Constructors Summary
public ProvidedServiceConfig()
Default constructor to instantiate via reflection

        try {
            GDataServerRegistry.getRegistry().registerScopeVisitor(this);
        } catch (RegistryException e) {
            throw new RuntimeException("Can not register ScopeVisitor -- "
                    + e.getMessage(), e);
        }
    
Methods Summary
private voidcreateProfilePool()

        if (LOG.isInfoEnabled())
            LOG.info("Create ExtensionProfile pool with pool size:"
                    + this.poolSize + " for service " + this.serviceName);
        this.profilPool = new SimpleObjectPool<ExtensionProfile>(this.poolSize,
                new ExtensionProfileFactory<ExtensionProfile>(
                        this.extensionProfile.getClass(),this.entryType,this.feedType));
    
public voiddestroy()

see
org.apache.lucene.gdata.server.registry.ProvidedService#destroy()

        if (this.profilPool != null)
            this.profilPool.destroy();
        if (LOG.isInfoEnabled())
            LOG.info("Destroy Service " + this.serviceName
                    + " -- release all resources");
        this.feedType = null;
        this.entryType = null;
        this.extensionProfile = null;
    
public java.lang.ClassgetEntryType()

see
org.apache.lucene.gdata.server.registry.ProvidedService#getEntryType()

        return this.entryType;
    
public com.google.gdata.data.ExtensionProfilegetExtensionProfile()

see
org.apache.lucene.gdata.server.registry.ProvidedService#getExtensionProfile()

        ExtensionProfile ext = this.extProfThreadLocal.get();
        if (ext != null) {
            return ext;
        }
        if(this.extensionProfile == null)
            return null;
        if (this.profilPool == null)
            createProfilePool();
        ext = this.profilPool.aquire();
        this.extProfThreadLocal.set(ext);
        return ext;
    
public java.lang.ClassgetFeedType()

see
org.apache.lucene.gdata.server.registry.ProvidedService#getFeedType()

        return this.feedType;
    
public org.apache.lucene.gdata.search.config.IndexSchemagetIndexSchema()

return
Returns the indexSchema.

        return this.indexSchema;
    
public java.lang.StringgetName()

see
org.apache.lucene.gdata.server.registry.ProvidedService#getName()

        return this.serviceName;
    
public intgetPoolSize()

return
Returns the poolSize.

    

             
       
        return this.poolSize;
    
public javax.xml.transform.TemplatesgetTransformTemplate()

see
org.apache.lucene.gdata.server.registry.ProvidedService#getTransformTemplate()

        
        return this.transformerTemplate;
    
public voidsetEntryType(java.lang.Class entryType)

param
entryType

        this.entryType = entryType;
    
public voidsetExtensionProfile(com.google.gdata.data.ExtensionProfile extensionProfil)

param
extensionProfil - the extension profile for this feed configuration

        if (extensionProfil == null)
            throw new IllegalArgumentException(
                    "ExtensionProfile  must not be null");
        if (this.extensionProfile != null)
            return;
        this.extensionProfile = extensionProfil;

    
public voidsetExtensionProfileClass(java.lang.Class extensionProfileClass)
TODO add comment

param
param
extensionProfileClass
throws
InstantiationException
throws
IllegalAccessException

        if (extensionProfileClass == null)
            throw new IllegalArgumentException(
                    "ExtensionProfile class must not be null");

        setExtensionProfile(extensionProfileClass.newInstance());

    
public voidsetFeedType(java.lang.Class feedType)

param
feedType The feedType to set.

        this.feedType = feedType;
    
public voidsetIndexSchema(org.apache.lucene.gdata.search.config.IndexSchema indexSchema)

param
indexSchema The indexSchema to set.

        this.indexSchema = indexSchema;
        if(this.indexSchema != null)
            this.indexSchema.setName(this.serviceName);
    
public voidsetName(java.lang.String serviceName)

param
serviceName

        this.serviceName = serviceName;
    
public voidsetPoolSize(int poolSize)

param
poolSize The poolSize to set.

        
        this.poolSize = poolSize >= DEFAULT_POOL_SIZE ? poolSize
                : DEFAULT_POOL_SIZE;
    
public voidsetXsltStylesheet(java.lang.String filename)
Sets and creates the preview transformer xslt template to provide a html formate for feeds and entries. The given file name must be available in the classpath.

param
filename - the name of the file in the classpath

        if(filename == null || filename.length() == 0){
            LOG.info("No preview stylesheet configured for service "+this.serviceName);
            return;
        }
        
        TransformerFactory factory = TransformerFactory.newInstance();
        
        try {
            this.transformerTemplate = factory.newTemplates(new StreamSource(ProvidedServiceConfig.class.getResourceAsStream(filename.startsWith("/")?filename:"/"+filename)));
        } catch (TransformerConfigurationException e) {
            throw new RuntimeException("Can not compile xslt stylesheet path: "+filename,e);
        }
        
    
public voidvisiteDestroy()

see
org.apache.lucene.gdata.server.registry.ScopeVisitor#visiteDestroy()

        /*
         * Check every thread after request destroyed to release all profiles to
         * the pool
         */
        ExtensionProfile ext = this.extProfThreadLocal.get();
        if (ext == null) {
            if(LOG.isDebugEnabled())
            LOG.debug("ThreadLocal owns no ExtensionProfile in requestDestroy for service "
                            + this.serviceName);
            return;
        }
        this.extProfThreadLocal.set(null);
        this.profilPool.release(ext);
    
public voidvisiteInitialize()

see
org.apache.lucene.gdata.server.registry.ScopeVisitor#visiteInitialize()

        if(this.profilPool == null)
            createProfilePool();
        /*
         * don't set a extension profile for each thread. The current thread
         * might use another service and does not need the extension profile of
         * this service
         */