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

GDataServerRegistry

public class GDataServerRegistry extends EntryEventMediator
The GDataServerRegistry represents the registry component of the GData Server. All provided services and server components will be registered here. The GData Server serves RSS / ATOM feeds for defined services. Each service provides n feeds of a defined subclass of {@link com.google.gdata.data.BaseFeed}. Each feed contains m entries of a defined subclass of {@link com.google.gdata.data.BaseEntry}. To generate RSS / ATOM formates a class of the type {@link com.google.gdata.data.ExtensionProfile} is also defined for a service.

The entry,feed and the ExtensionProfile classes are defined in the gdata-config.xml and will be loaded when the server starts up.

The components defined in the gdata-config.xml will also be loaded and instantiated at startup. If a component can not be loaded or an Exception occurs the server will not start up. To cause of the exception or error will be logged to the standard server output.

The GDataServerRegistry is a Singleton

author
Simon Willnauer

Fields Summary
private static GDataServerRegistry
INSTANCE
private static final Log
LOG
private ScopeVisitable
requestVisitable
private ScopeVisitable
sessionVisitable
private ScopeVisitable
contextVisitable
private List
visitorBuffer
private final Map
serviceTypeMap
private final Map
componentMap
Constructors Summary
private GDataServerRegistry()


      
        // private - singleton
    
Methods Summary
private voidconfigureComponent(ServerComponent component, ComponentType type, org.apache.lucene.gdata.server.registry.configuration.ComponentConfiguration configuration)

        PropertyInjector injector = new PropertyInjector();
        injector.setTargetObject(component);
        injector.injectProperties(configuration);
    
public voiddestroy()
Destroys the registry and release all resources

        for (ComponentBean component : this.componentMap.values()) {
            component.getObject().destroy();
        }

        flushRegistry();

    
protected voidflushRegistry()

        Collection<ProvidedService> services = this.serviceTypeMap.values();
        for (ProvidedService service : services) {
            service.destroy();
        }
        this.serviceTypeMap.clear();
        this.componentMap.clear();
    
public EntryEventMediatorgetEntryEventMediator()

see
org.apache.lucene.gdata.server.registry.EntryEventMediator#getEntryEventMediator()

        
        return this;
    
public ProvidedServicegetProvidedService(java.lang.String service)
Looks up the {@link ProvidedServiceConfig} by the given service name.

param
service
return
- the {@link ProvidedServiceConfig} or null if the no configuration for this service has been registered

        if (service == null)
            throw new IllegalArgumentException(
                    "Service is null - must not be null to get registered feed type");
        return this.serviceTypeMap.get(service);
    
public static synchronized org.apache.lucene.gdata.server.registry.GDataServerRegistrygetRegistry()

return
a Singleton registry instance

        if (INSTANCE == null)
            INSTANCE = new GDataServerRegistry();
        return INSTANCE;
    
public java.util.CollectiongetServices()

return
- all registered services

        
        return this.serviceTypeMap.values();
    
public booleanisServiceRegistered(java.lang.String service)

param
service - the name of the service
return
- true if and only if the service is registered, otherwise false.

        return this.serviceTypeMap.containsKey(service);

    
public Rlookup(java.lang.Class clazz, ComponentType compType)
This method is the main interface to the Component Lookup Service of the registry. Every GDATA - Server component like STORAGE or the INDEXER component will be accessible via this method. To get a Component from the lookup service specify the expected Class as an argument and the component type of the component to return. For a lookup of the STORAGECONTORLER the code looks like:

registryInstance.lookup(StorageController.class,ComponentType.STORAGECONTROLLER);

param
the type of the expected return value
param
clazz - Class object of the expected return value
param
compType - The component type
return
the registered component or null if the component can not looked up.

        ComponentBean bean = this.componentMap.get(compType);
        if (bean == null)
            return null;
        if (bean.getSuperType().equals(clazz))
            return (R) bean.getObject();
        return null;
    
public voidregisterComponent(java.lang.Class componentClass, org.apache.lucene.gdata.server.registry.configuration.ComponentConfiguration configuration)
All registered {@link ServerComponent} registered via this method are available via the {@link GDataServerRegistry#lookup(Class, ComponentType)} method. For each {@link ComponentType} there will be one single instance registered in the registry.

Eventually this method invokes the initialize method of the ServerComponent interface to prepare the component to be available via the lookup service

param
- The interface of the component to register
param
componentClass - a implementation of a ServerComponent interface to register in the registry
param
configuration - the component configuration {@link ComponentConfiguration}
throws
RegistryException - if the provided class does not implement the {@link ServerComponent} interface, if the mandatory annotations not visible at runtime or not set, if the super type provided by the {@link ComponentType} for the class to register is not a super type of the class or if the invocation of the {@link ServerComponent#initialize()} method throws an exception.


        if (componentClass == null)
            throw new IllegalArgumentException(
                    "component class must not be null");

        if (!ReflectionUtils.implementsType(componentClass,
                ServerComponent.class))
            throw new RegistryException(
                    "can not register component. the given class does not implement ServerComponent interface -- "
                            + componentClass.getName());
        try {

            Component annotation = componentClass
                    .getAnnotation(Component.class);
            if (annotation == null)
                throw new RegistryException(
                        "can not register component. the given class is not a component -- "
                                + componentClass.getName());
            ComponentType type = annotation.componentType();
            if (this.componentMap.containsKey(type))
                throw new RegistryException("component already registered -- "
                        + type.name());
            Class superType = type.getClass().getField(type.name())
                    .getAnnotation(SuperType.class).superType();
            if (!ReflectionUtils.isTypeOf(componentClass, superType))
                throw new RegistryException("Considered super type <"
                        + superType.getName() + "> is not a super type of <"
                        + componentClass + ">");
            ServerComponent comp = componentClass.newInstance();
            if (configuration == null) {
                if (LOG.isInfoEnabled())
                    LOG.info("no configuration for ComponentType: "
                            + type.name());
            } else
                configureComponent(comp, type, configuration);
            comp.initialize();
            ComponentBean bean = new ComponentBean(comp, superType);

            this.componentMap.put(type, bean);
            if (ReflectionUtils.implementsType(componentClass,
                    ScopeVisitor.class))
                this.registerScopeVisitor((ScopeVisitor) comp);
        } catch (Exception e) {
            throw new RegistryException("Can not register component -- "
                    + e.getMessage(), e);
        }

    
public synchronized voidregisterScopeVisitable(ScopeVisitable visitable)

param
visitable - the instance to register
throws
RegistryException
see
ScopeVisitable

        if (visitable == null)
            throw new IllegalArgumentException("visitable must not be null");

        Scope scope = visitable.getClass().getAnnotation(Scope.class);
        if (scope == null)
            throw new RegistryException("Visitable has not Scope");
        if (LOG.isInfoEnabled())
            LOG.info("Register scope visitable -- " + visitable.getClass());
        if (scope.scope() == Scope.ScopeType.REQUEST
                && this.requestVisitable == null)
            this.requestVisitable = visitable;
        else if (scope.scope() == Scope.ScopeType.SESSION
                && this.sessionVisitable == null)
            this.sessionVisitable = visitable;
        else if (scope.scope() == Scope.ScopeType.CONTEXT
                && this.contextVisitable == null)
            this.sessionVisitable = visitable;

        if (!this.visitorBuffer.isEmpty()) {

            List<ScopeVisitor> tempList = this.visitorBuffer;
            this.visitorBuffer = new ArrayList<ScopeVisitor>(5);
            for (ScopeVisitor visitor : tempList) {
                registerScopeVisitor(visitor);
            }
            tempList.clear();

        }

    
public synchronized voidregisterScopeVisitor(ScopeVisitor visitor)

param
visitor - the visitor to register
throws
RegistryException

        if (visitor == null)
            throw new IllegalArgumentException("visitor must not be null");
        Scope scope = visitor.getClass().getAnnotation(Scope.class);
        if (scope == null)
            throw new RegistryException("Visitor has not Scope");
        if (LOG.isInfoEnabled())
            LOG.info("Register scope visitor -- " + visitor.getClass());
        if (scope.scope().equals(Scope.ScopeType.REQUEST)
                && this.requestVisitable != null)
            this.requestVisitable.accept(visitor);
        else if (scope.scope() == Scope.ScopeType.SESSION
                && this.sessionVisitable != null)
            this.sessionVisitable.accept(visitor);
        else if (scope.scope() == Scope.ScopeType.CONTEXT
                && this.contextVisitable != null)
            this.sessionVisitable.accept(visitor);
        else if (!this.visitorBuffer.contains(visitor))
            this.visitorBuffer.add(visitor);
    
public voidregisterService(ProvidedService configurator)
Registers a {@link ProvidedService}

param
configurator - the configurator to register in the registry

        if (configurator == null) {
            LOG.warn("Feed configurator is null -- skip registration");
            return;
        }
        this.serviceTypeMap.put(configurator.getName(), configurator);