hlship 2004/05/18 19:30:54 Modified: framework/src/java/org/apache/hivemind HiveMindMessages.properties Registry.java framework/src/java/org/apache/hivemind/impl RegistryBuilder.java ImplMessages.java RegistryImpl.java framework/src/java/org/apache/hivemind/impl/servicemodel PrimitiveServiceModelFactory.java PrimitiveServiceModel.java AbstractServiceModelImpl.java PooledServiceModel.java PooledServiceModelFactory.java ThreadedServiceModel.java SingletonServiceModel.java ThreadedServiceModelFactory.java SingletonServiceModelFactory.java framework/src/java/org/apache/hivemind/internal ServiceModelFactory.java ServiceModel.java ServicePoint.java framework/src/java/org/apache/hivemind/schema/rules ServiceTranslator.java RuleUtils.java ReadAttributeRule.java ReadContentRule.java framework/src/test/hivemind/test/services InitializeMethodFailure.sdl framework/xdocs navigation.xml SymbolSources.xml framework/src/test/hivemind/test/parse TestDescriptorParser.java TestToString.java framework/src/java/org/apache/hivemind/parse DescriptorParser.java DescriptorParser.properties framework/src/java/org/apache/hivemind/servlet HiveMindFilter.java framework/src/test/hivemind/test/servlet TestHiveMindFilter.java common links.xml framework/src/test/hivemind/test TestMisc.java TestRegistryBuilder.java framework/src/descriptor/META-INF hivemodule.sdl xdocs rules.xml Added: framework/src/java/org/apache/hivemind/impl StartupImpl.java ConstructableServicePoint.java ServicePointImpl.java framework/src/java/org/apache/hivemind/impl/servicemodel SingletonInnerProxy.java framework/src/java/org/apache/hivemind/schema/rules NullTranslator.java ServicePointTranslator.java PushAttributeRule.java framework/src/test/hivemind/test/services EagerLoadPrimitive.sdl TestStartup.java TestEagerLoader.java EagerLoadSingleton.sdl StartupRunnableFixture.java EagerLoadThreaded.sdl EagerLoadPooled.sdl StartupContribution.sdl framework/xdocs EagerLoad.xml framework/src/test/hivemind/test/parse PushAttributeRule.sdl framework/src/java/org/apache/hivemind/service/impl EagerLoader.java framework/src/test/hivemind/test/rules TestPushAttributeRule.java TestServicePointTranslator.java framework/src/test/hivemind/test/services/impl StartupRunnableFixtureImpl.java LoudRunner.java Removed: framework/src/java/org/apache/hivemind/impl ServiceExtensionPointImpl.java ConstructableServiceExtensionPoint.java Log: Add support for eager loading of services. Revision Changes Path 1.14 +2 -1 jakarta-hivemind/framework/src/java/org/apache/hivemind/HiveMindMessages.properties Index: HiveMindMessages.properties =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/HiveMindMessages.properties,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- HiveMindMessages.properties 18 May 2004 15:34:00 -0000 1.13 +++ HiveMindMessages.properties 19 May 2004 02:30:52 -0000 1.14 @@ -43,6 +43,7 @@ impl.registry-shutdown=The HiveMind Registry has been shutdown. impl.no-such-service-point=Service extension point {0} does not exist. +impl.registry-already-started=The HiveMind Registry has been started. DefaultsSymbolSource.duplicate-symbol=Default for symbol ''{0}'' (at {1}) duplicates prior value (at {2}) and has been ignored. 1.4 +7 -1 jakarta-hivemind/framework/src/java/org/apache/hivemind/Registry.java Index: Registry.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/Registry.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- Registry.java 18 May 2004 15:34:00 -0000 1.3 +++ Registry.java 19 May 2004 02:30:52 -0000 1.4 @@ -62,4 +62,10 @@ */ public void shutdown(); + + /** + * Convienience for invoking [EMAIL PROTECTED] org.apache.hivemind.service.ThreadEventNotifier#fireThreadCleanup()}. + */ + + public void cleanupThread(); } 1.9 +7 -5 jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/RegistryBuilder.java Index: RegistryBuilder.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/RegistryBuilder.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- RegistryBuilder.java 18 May 2004 15:34:00 -0000 1.8 +++ RegistryBuilder.java 19 May 2004 02:30:52 -0000 1.9 @@ -339,7 +339,7 @@ // whether the service is create-on-first-reference // or create-on-first-use (deferred). - ServiceExtensionPointImpl point = new ServiceExtensionPointImpl(); + ServicePointImpl point = new ServicePointImpl(); point.setExtensionPointId(pointId); point.setLocation(sd.getLocation()); @@ -443,6 +443,8 @@ addModulesToRegistry(result); + result.startup(); + return result; } @@ -610,7 +612,7 @@ if (LOG.isDebugEnabled()) LOG.debug("Adding " + builder + " to service extension point " + pointId); - ServiceExtensionPointImpl sep = (ServiceExtensionPointImpl) _servicePoints.get(pointId); + ServicePointImpl sep = (ServicePointImpl) _servicePoints.get(pointId); if (sep == null) { @@ -643,7 +645,7 @@ if (LOG.isDebugEnabled()) LOG.debug("Adding " + id + " to service extension point " + pointId); - ServiceExtensionPointImpl sep = (ServiceExtensionPointImpl) _servicePoints.get(pointId); + ServicePointImpl sep = (ServicePointImpl) _servicePoints.get(pointId); String sourceModuleId = sourceModule.getModuleId(); @@ -700,7 +702,7 @@ Iterator i = _servicePoints.values().iterator(); while (i.hasNext()) { - ServiceExtensionPointImpl point = (ServiceExtensionPointImpl) i.next(); + ServicePointImpl point = (ServicePointImpl) i.next(); if (point.getServiceConstructor() != null) continue; 1.4 +6 -1 jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ImplMessages.java Index: ImplMessages.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ImplMessages.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ImplMessages.java 18 May 2004 15:34:00 -0000 1.3 +++ ImplMessages.java 19 May 2004 02:30:52 -0000 1.4 @@ -126,4 +126,9 @@ { return HiveMind.format("impl.no-such-service-point", serviceId); } + + public static String registryAlreadyStarted() + { + return HiveMind.getMessage("impl.registry-already-started"); + } } 1.7 +52 -4 jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/RegistryImpl.java Index: RegistryImpl.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/RegistryImpl.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- RegistryImpl.java 18 May 2004 15:34:00 -0000 1.6 +++ RegistryImpl.java 19 May 2004 02:30:52 -0000 1.7 @@ -37,6 +37,7 @@ import org.apache.hivemind.order.Orderer; import org.apache.hivemind.schema.Translator; import org.apache.hivemind.schema.rules.ClassTranslator; +import org.apache.hivemind.service.ThreadEventNotifier; import org.apache.hivemind.util.ToStringBuilder; /** @@ -74,8 +75,11 @@ private Map _translatorsCache = new HashMap(); private boolean _translatorsLoaded; + private boolean _started = false; private boolean _shutdown = false; + private ThreadEventNotifier _threadEventNotifier; + public RegistryImpl(Locale locale) { _locale = locale; @@ -93,11 +97,15 @@ public void addServicePoint(ServicePoint point) { + checkStarted(); + _servicePoints.put(point.getExtensionPointId(), point); } public void addConfigurationPoint(ConfigurationPoint point) { + checkStarted(); + _configurationPoints.put(point.getExtensionPointId(), point); } @@ -108,9 +116,8 @@ ServicePoint result = (ServicePoint) _servicePoints.get(serviceId); if (result == null) - throw new ApplicationRuntimeException( - ImplMessages.noSuchServicePoint(serviceId)); - + throw new ApplicationRuntimeException(ImplMessages.noSuchServicePoint(serviceId)); + return result; } @@ -304,6 +311,8 @@ public String valueForSymbol(String name) { + checkShutdown(); + SymbolSource[] sources = getSymbolSources(); for (int i = 0; i < sources.length; i++) @@ -383,6 +392,7 @@ _shutdownCoordinator = null; _variableSources = null; _serviceModelFactories = null; + _threadEventNotifier = null; } private void checkShutdown() @@ -391,6 +401,33 @@ throw new ApplicationRuntimeException(ImplMessages.registryShutdown()); } + private void checkStarted() + { + if (_started) + throw new IllegalStateException(ImplMessages.registryAlreadyStarted()); + } + + /** + * Starts up the Registry after all service and configuration points have been defined. + * This locks down the Registry so that no further extension points may be added. + * This method may only be invoked once. + * + * <p> + * In addition, the service <code>hivemind.Startup</code> is obtained and + * <code>run()</code> is invoked on it. This allows additional startup, provided + * in the <code>hivemind.Startup</code> configuration point, to be executed. + */ + public void startup() + { + checkStarted(); + + _started = true; + + Runnable startup = (Runnable) getService("hivemind.Startup", Runnable.class); + + startup.run(); + } + public synchronized ServiceModelFactory getServiceModelFactory(String name) { if (_serviceModelFactories == null) @@ -534,4 +571,15 @@ } } + + public synchronized void cleanupThread() + { + if (_threadEventNotifier == null) + _threadEventNotifier = + (ThreadEventNotifier) getService("hivemind.ThreadEventNotifier", + ThreadEventNotifier.class); + + _threadEventNotifier.fireThreadCleanup(); + } + } 1.1 jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/StartupImpl.java Index: StartupImpl.java =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package org.apache.hivemind.impl; import java.util.Iterator; import java.util.List; /** * Startup service for HiveMind. This implementation uses the * <code>hivemind.Startup</code> configuration point to start other * services. * * @author Howard Lewis Ship * @version $Id: StartupImpl.java,v 1.1 2004/05/19 02:30:52 hlship Exp $ */ public class StartupImpl extends BaseLocatable implements Runnable { private List _runnables; public void run() { Iterator i = _runnables.iterator(); while (i.hasNext()) { Runnable r = (Runnable) i.next(); r.run(); } } public void setRunnables(List list) { _runnables = list; } } 1.1 jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ConstructableServicePoint.java Index: ConstructableServicePoint.java =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package org.apache.hivemind.impl; import java.util.List; import org.apache.hivemind.*; import org.apache.hivemind.internal.ServicePoint; import org.apache.hivemind.internal.ServiceImplementationConstructor; /** * "Private" interface used by a [EMAIL PROTECTED] org.apache.hivemind.ServiceModel} * to access non-public information about a * [EMAIL PROTECTED] ConstructableServicePoint}, such as * its instance builder and interceptors. * * @author Howard Lewis Ship * @version $Id: ConstructableServicePoint.java,v 1.1 2004/05/19 02:30:52 hlship Exp $ */ public interface ConstructableServicePoint extends ServicePoint { /** * Returns the constructor that can create the core service implementation. */ public ServiceImplementationConstructor getServiceConstructor(); /** * Returns a list of [EMAIL PROTECTED] org.apache.hivemind.ServiceInterceptorContribution}s, * ordered according to their dependencies. May return null or an empty list. * * <p> * Note that the order is tricky! To keep any error messages while ordering * the interceptors understandable, they are ordered according into runtime * execution order. Example: If we want a logging interceptor * to operate before a security-check interceptor, we'll write the following * in the descriptor: * * <pre> * <interceptor service-id="hivemind.LoggingInterceptor" before="*"/> * <interceptor service-id="somepackage.SecurityInterceptor"/> * </pre> * * The <code>before</code> value for the first interceptor contribution * will be assigned to the contribution's * [EMAIL PROTECTED] org.apache.hivemind.ServiceInterceptorContribution#getFollowingInterceptorIds() followingInterceptorIds} * property, because all other interceptors (including the security interceptor) * should have their behavior follow the logging interceptor. * * <p> * To get this behavior, the logging interceptor will delegate to the security * interceptor, and the security interceptor will delegate to * the core service implementation. * * <p> * The trick is that interceptors are applied in reverse order: we start * with core service implementation, wrap it with the security interceptor, then * wrap that with the logging interceptor ... but that's an issue that applies * when building the interceptor stack around the core service implementation. */ public List getOrderedInterceptorContributions(); /** * Invoked by the ServiceModel when constuction information * (the builder and interceptors) is no longer needed. */ public void clearConstructorInformation(); /** * Returns the [EMAIL PROTECTED] org.apache.hivemind.impl.ShutdownCooordinator}, used by * the service model to inform proxies that the service * has shutdown. */ public ShutdownCoordinator getShutdownCoordinator(); } 1.1 jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/ServicePointImpl.java Index: ServicePointImpl.java =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package org.apache.hivemind.impl; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hivemind.*; import org.apache.hivemind.ApplicationRuntimeException; import org.apache.hivemind.ClassResolver; import org.apache.hivemind.HiveMind; import org.apache.hivemind.internal.ServiceImplementationConstructor; import org.apache.hivemind.internal.ServiceInterceptorContribution; import org.apache.hivemind.internal.ServiceModel; import org.apache.hivemind.internal.ServiceModelFactory; import org.apache.hivemind.order.Orderer; import org.apache.hivemind.schema.Schema; import org.apache.hivemind.util.ToStringBuilder; /** * Abstract implementation of [EMAIL PROTECTED] org.apache.hivemind.ServicePoint}. * Provides most of the machinery for creating new services ... subclasses * implement different service models; the service models determine when the * service is actually constructed. * * @author Howard Lewis Ship * @version $Id: ServicePointImpl.java,v 1.1 2004/05/19 02:30:52 hlship Exp $ */ public final class ServicePointImpl extends AbstractExtensionPoint implements ConstructableServicePoint { private Object _service; private boolean _building; private String _serviceInterfaceName; private Class _serviceInterface; private ServiceImplementationConstructor _serviceConstructor; private List _interceptorContributions; private boolean _interceptorsOrdered; private Schema _parametersSchema; private String _serviceModel; private ShutdownCoordinator _shutdownCoordinator; private ServiceModel _serviceModelObject; protected void extendDescription(ToStringBuilder builder) { if (_service != null) builder.append("service", _service); builder.append("serviceInterfaceName", _serviceInterfaceName); builder.append("factoryContribution", _serviceConstructor); builder.append("interceptorContributions", _interceptorContributions); builder.append("parametersSchema", _parametersSchema); builder.append("serviceModel", _serviceModel); if (_building) builder.append("building", _building); } public void addInterceptorContribution(ServiceInterceptorContribution contribution) { if (_interceptorContributions == null) _interceptorContributions = new ArrayList(); _interceptorContributions.add(contribution); } public synchronized Class getServiceInterface() { if (_serviceInterface == null) _serviceInterface = lookupServiceInterface(); return _serviceInterface; } private Class lookupServiceInterface() { ClassResolver resolver = getModule().getClassResolver(); Class result = null; try { result = resolver.findClass(_serviceInterfaceName); } catch (Exception ex) { throw new ApplicationRuntimeException( HiveMind.format( "ServiceExtensionPoint.bad-interface", _serviceInterfaceName, getExtensionPointId()), getLocation(), ex); } if (!result.isInterface()) throw new ApplicationRuntimeException( HiveMind.format( "ServiceExtensionPoint.interface-required", _serviceInterfaceName, getExtensionPointId()), getLocation(), null); return result; } public void setServiceConstructor(ServiceImplementationConstructor contribution) { _serviceConstructor = contribution; } public void setServiceInterfaceName(String string) { _serviceInterfaceName = string; } public void setParametersSchema(Schema schema) { _parametersSchema = schema; } public Schema getParametersSchema() { return _parametersSchema; } public ServiceImplementationConstructor getServiceConstructor() { return _serviceConstructor; } /** * Invoked by [EMAIL PROTECTED] #getService(Class)} to get a service implementation * from the [EMAIL PROTECTED] ServiceModel}. * * <p> * TODO: I'm concerned that this synchronized method could cause a deadlock. It would take * a LOT (mutually dependent services in multiple threads being realized at the same time). * * */ private synchronized Object getService() { if (_service == null) { if (_building) throw new ApplicationRuntimeException(ImplMessages.recursiveServiceBuild(this)); _building = true; try { ServiceModelFactory factory = getModule().getServiceModelFactory(getServiceModel()); _serviceModelObject = factory.createServiceModelForService(this); _service = _serviceModelObject.getService(); } finally { _building = false; } } return _service; } public Object getService(Class serviceInterface) { Object result = getService(); if (!serviceInterface.isAssignableFrom(result.getClass())) { throw new ApplicationRuntimeException( HiveMind.format( "BaseModule.service-wrong-interface", getExtensionPointId(), serviceInterface.getName(), _serviceInterfaceName), getLocation(), null); } return result; } public String getServiceModel() { return _serviceModel; } public void setServiceModel(String model) { _serviceModel = model; } public void clearConstructorInformation() { _serviceConstructor = null; _interceptorContributions = null; } // Hm. Does this need to be synchronized? public List getOrderedInterceptorContributions() { if (!_interceptorsOrdered) { _interceptorContributions = orderInterceptors(); _interceptorsOrdered = true; } return _interceptorContributions; } private List orderInterceptors() { if (HiveMind.isEmpty(_interceptorContributions)) return null; // Any error logging should go to the extension point // we're constructing. Log log = LogFactory.getLog(getExtensionPointId()); Orderer orderer = new Orderer( log, HiveMind.getMessage("ServiceExtensionPointImpl.interceptor-contribution")); Iterator i = _interceptorContributions.iterator(); while (i.hasNext()) { ServiceInterceptorContribution sic = (ServiceInterceptorContribution) i.next(); // Sort them into runtime excecution order. When we build // the interceptor stack we'll apply them in reverse order, // building outward from the core service implementation. orderer.add( sic, sic.getFactoryServiceId(), sic.getPrecedingInterceptorIds(), sic.getFollowingInterceptorIds()); } return orderer.getOrderedObjects(); } public ShutdownCoordinator getShutdownCoordinator() { return _shutdownCoordinator; } public void setShutdownCoordinator(ShutdownCoordinator coordinator) { _shutdownCoordinator = coordinator; } /** * Forces the service into existence. */ public void forceServiceInstantiation() { getService(); _serviceModelObject.instantiateService(); } } 1.2 +3 -3 jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/PrimitiveServiceModelFactory.java Index: PrimitiveServiceModelFactory.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/PrimitiveServiceModelFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- PrimitiveServiceModelFactory.java 13 May 2004 11:04:45 -0000 1.1 +++ PrimitiveServiceModelFactory.java 19 May 2004 02:30:53 -0000 1.2 @@ -14,7 +14,7 @@ package org.apache.hivemind.impl.servicemodel; -import org.apache.hivemind.impl.ConstructableServiceExtensionPoint; +import org.apache.hivemind.impl.ConstructableServicePoint; import org.apache.hivemind.internal.ServiceModel; import org.apache.hivemind.internal.ServiceModelFactory; @@ -27,7 +27,7 @@ public class PrimitiveServiceModelFactory implements ServiceModelFactory { - public ServiceModel createServiceModelForService(ConstructableServiceExtensionPoint servicePoint) + public ServiceModel createServiceModelForService(ConstructableServicePoint servicePoint) { return new PrimitiveServiceModel(servicePoint); } 1.4 +13 -3 jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/PrimitiveServiceModel.java Index: PrimitiveServiceModel.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/PrimitiveServiceModel.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- PrimitiveServiceModel.java 18 May 2004 15:34:01 -0000 1.3 +++ PrimitiveServiceModel.java 19 May 2004 02:30:53 -0000 1.4 @@ -14,7 +14,7 @@ package org.apache.hivemind.impl.servicemodel; -import org.apache.hivemind.impl.ConstructableServiceExtensionPoint; +import org.apache.hivemind.impl.ConstructableServicePoint; /** * Implementation of [EMAIL PROTECTED] org.apache.hivemind.ServicePoint} for the @@ -27,7 +27,7 @@ { private Object _constructedService; - public PrimitiveServiceModel(ConstructableServiceExtensionPoint servicePoint) + public PrimitiveServiceModel(ConstructableServicePoint servicePoint) { super(servicePoint); } @@ -43,4 +43,14 @@ return _constructedService; } + + /** + * Invokes [EMAIL PROTECTED] #getService()} to ensure that the core service implementation + * has been instantiated. + */ + public void instantiateService() + { + getService(); + } + } 1.4 +5 -5 jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/AbstractServiceModelImpl.java Index: AbstractServiceModelImpl.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/AbstractServiceModelImpl.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- AbstractServiceModelImpl.java 18 May 2004 15:34:01 -0000 1.3 +++ AbstractServiceModelImpl.java 19 May 2004 02:30:53 -0000 1.4 @@ -21,7 +21,7 @@ import org.apache.hivemind.ApplicationRuntimeException; import org.apache.hivemind.HiveMind; import org.apache.hivemind.events.RegistryShutdownListener; -import org.apache.hivemind.impl.ConstructableServiceExtensionPoint; +import org.apache.hivemind.impl.ConstructableServicePoint; import org.apache.hivemind.impl.ImplMessages; import org.apache.hivemind.impl.InterceptorStackImpl; import org.apache.hivemind.internal.ServiceImplementationConstructor; @@ -44,9 +44,9 @@ */ protected final Log _log; - private ConstructableServiceExtensionPoint _servicePoint; + private ConstructableServicePoint _servicePoint; - public AbstractServiceModelImpl(ConstructableServiceExtensionPoint servicePoint) + public AbstractServiceModelImpl(ConstructableServicePoint servicePoint) { _log = LogFactory.getLog(servicePoint.getExtensionPointId()); @@ -163,7 +163,7 @@ } - public ConstructableServiceExtensionPoint getServicePoint() + public ConstructableServicePoint getServicePoint() { return _servicePoint; } 1.4 +13 -3 jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/PooledServiceModel.java Index: PooledServiceModel.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/PooledServiceModel.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- PooledServiceModel.java 18 May 2004 15:34:01 -0000 1.3 +++ PooledServiceModel.java 19 May 2004 02:30:53 -0000 1.4 @@ -20,7 +20,7 @@ import org.apache.hivemind.ApplicationRuntimeException; import org.apache.hivemind.HiveMind; import org.apache.hivemind.PoolManageable; -import org.apache.hivemind.impl.ConstructableServiceExtensionPoint; +import org.apache.hivemind.impl.ConstructableServicePoint; import org.apache.hivemind.impl.ProxyUtils; import org.apache.hivemind.internal.Module; import org.apache.hivemind.service.ThreadCleanupListener; @@ -104,7 +104,7 @@ } - public PooledServiceModel(ConstructableServiceExtensionPoint servicePoint) + public PooledServiceModel(ConstructableServicePoint servicePoint) { super(servicePoint); } @@ -214,4 +214,14 @@ returnServiceToPool(pooled); } + + /** + * Invokes [EMAIL PROTECTED] #getServiceImplementationForCurrentThread()} to instantiate an instance + * of the service. + */ + public void instantiateService() + { + getServiceImplementationForCurrentThread(); + } + } 1.2 +2 -2 jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/PooledServiceModelFactory.java Index: PooledServiceModelFactory.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/PooledServiceModelFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- PooledServiceModelFactory.java 13 May 2004 11:04:45 -0000 1.1 +++ PooledServiceModelFactory.java 19 May 2004 02:30:53 -0000 1.2 @@ -14,14 +14,14 @@ package org.apache.hivemind.impl.servicemodel; -import org.apache.hivemind.impl.ConstructableServiceExtensionPoint; +import org.apache.hivemind.impl.ConstructableServicePoint; import org.apache.hivemind.internal.ServiceModel; import org.apache.hivemind.internal.ServiceModelFactory; public class PooledServiceModelFactory implements ServiceModelFactory { - public ServiceModel createServiceModelForService(ConstructableServiceExtensionPoint servicePoint) + public ServiceModel createServiceModelForService(ConstructableServicePoint servicePoint) { return new PooledServiceModel(servicePoint); } 1.4 +13 -3 jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/ThreadedServiceModel.java Index: ThreadedServiceModel.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/ThreadedServiceModel.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ThreadedServiceModel.java 18 May 2004 15:34:01 -0000 1.3 +++ ThreadedServiceModel.java 19 May 2004 02:30:53 -0000 1.4 @@ -18,7 +18,7 @@ import org.apache.hivemind.Discardable; import org.apache.hivemind.HiveMind; import org.apache.hivemind.events.RegistryShutdownListener; -import org.apache.hivemind.impl.ConstructableServiceExtensionPoint; +import org.apache.hivemind.impl.ConstructableServicePoint; import org.apache.hivemind.impl.ProxyUtils; import org.apache.hivemind.internal.Module; import org.apache.hivemind.service.ThreadCleanupListener; @@ -46,7 +46,7 @@ private Object _serviceProxy; private ThreadEventNotifier _notifier; - public ThreadedServiceModel(ConstructableServiceExtensionPoint servicePoint) + public ThreadedServiceModel(ConstructableServicePoint servicePoint) { super(servicePoint); } @@ -171,6 +171,16 @@ private void unbindServiceFromCurrentThread() { _activeService.set(null); + } + + /** + * Invokes [EMAIL PROTECTED] #getServiceImplementationForCurrentThread()} to force the creation + * of the service implementation. + */ + + public void instantiateService() + { + getServiceImplementationForCurrentThread(); } } 1.4 +43 -5 jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/SingletonServiceModel.java Index: SingletonServiceModel.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/SingletonServiceModel.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- SingletonServiceModel.java 18 May 2004 15:34:01 -0000 1.3 +++ SingletonServiceModel.java 19 May 2004 02:30:53 -0000 1.4 @@ -19,7 +19,7 @@ import org.apache.hivemind.ApplicationRuntimeException; import org.apache.hivemind.events.RegistryShutdownListener; -import org.apache.hivemind.impl.ConstructableServiceExtensionPoint; +import org.apache.hivemind.impl.ConstructableServicePoint; import org.apache.hivemind.impl.ProxyBuilder; import org.apache.hivemind.internal.ServicePoint; import org.apache.hivemind.service.BodyBuilder; @@ -44,9 +44,10 @@ protected static final String SERVICE_ACCESSOR_METHOD_NAME = "_service"; private Object _serviceProxy; + private SingletonInnerProxy _innerProxy; private Object _constructedService; - public SingletonServiceModel(ConstructableServiceExtensionPoint servicePoint) + public SingletonServiceModel(ConstructableServicePoint servicePoint) { super(servicePoint); } @@ -97,7 +98,7 @@ Constructor c = innerProxyClass.getConstructor(new Class[] { proxyClass, getClass()}); - c.newInstance(new Object[] { result, this }); + _innerProxy = (SingletonInnerProxy) c.newInstance(new Object[] { result, this }); getServicePoint().getShutdownCoordinator().addRegistryShutdownListener( (RegistryShutdownListener) result); @@ -119,7 +120,7 @@ */ private Class createSingletonProxyClass() { - ConstructableServiceExtensionPoint servicePoint = getServicePoint(); + ConstructableServicePoint servicePoint = getServicePoint(); ProxyBuilder proxyBuilder = new ProxyBuilder("SingletonProxy", servicePoint); @@ -194,10 +195,12 @@ // with the outer proxy. body.begin(); + body.addln("super();"); body.addln("_deferredProxy = $1;"); body.addln("_serviceModel = $2;"); body.addln("_deferredProxy._setInner(this);"); + body.end(); classFab.addConstructor( @@ -211,16 +214,20 @@ body.clear(); body.begin(); + body.add("if (_service == null)"); body.begin(); + body.add("_service = ("); body.add(serviceInterface.getName()); body.addln(") _serviceModel.getActualServiceImplementation();"); body.add("_deferredProxy._setInner(_service);"); + body.end(); body.add("return _service;"); + body.end(); classFab.addMethod( @@ -233,7 +240,38 @@ builder.addServiceMethods("_service()"); + // Build the implementation of interface SingletonInnerProxy + + body.clear(); + body.begin(); + + body.add("_service();"); + + body.end(); + + classFab.addMethod( + Modifier.PUBLIC | Modifier.FINAL, + "_instantiateServiceImplementation", + Void.TYPE, + null, + null, + body.toString()); + + classFab.addInterface(SingletonInnerProxy.class); + return classFab.createClass(); + } + + public void instantiateService() + { + // Ensure that the outer and inner proxies have been created + + getService(); + + // Force the inner proxy to resolve the service and install the result into + // the outer proxy. + + _innerProxy._instantiateServiceImplementation(); } } 1.2 +3 -3 jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/ThreadedServiceModelFactory.java Index: ThreadedServiceModelFactory.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/ThreadedServiceModelFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ThreadedServiceModelFactory.java 13 May 2004 11:04:45 -0000 1.1 +++ ThreadedServiceModelFactory.java 19 May 2004 02:30:53 -0000 1.2 @@ -14,7 +14,7 @@ package org.apache.hivemind.impl.servicemodel; -import org.apache.hivemind.impl.ConstructableServiceExtensionPoint; +import org.apache.hivemind.impl.ConstructableServicePoint; import org.apache.hivemind.internal.ServiceModel; import org.apache.hivemind.internal.ServiceModelFactory; @@ -27,7 +27,7 @@ public class ThreadedServiceModelFactory implements ServiceModelFactory { - public ServiceModel createServiceModelForService(ConstructableServiceExtensionPoint servicePoint) + public ServiceModel createServiceModelForService(ConstructableServicePoint servicePoint) { return new ThreadedServiceModel(servicePoint); } 1.2 +3 -3 jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/SingletonServiceModelFactory.java Index: SingletonServiceModelFactory.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/SingletonServiceModelFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SingletonServiceModelFactory.java 13 May 2004 11:04:45 -0000 1.1 +++ SingletonServiceModelFactory.java 19 May 2004 02:30:53 -0000 1.2 @@ -15,7 +15,7 @@ package org.apache.hivemind.impl.servicemodel; import org.apache.hivemind.impl.BaseLocatable; -import org.apache.hivemind.impl.ConstructableServiceExtensionPoint; +import org.apache.hivemind.impl.ConstructableServicePoint; import org.apache.hivemind.internal.ServiceModel; import org.apache.hivemind.internal.ServiceModelFactory; @@ -28,7 +28,7 @@ public class SingletonServiceModelFactory extends BaseLocatable implements ServiceModelFactory { - public ServiceModel createServiceModelForService(ConstructableServiceExtensionPoint servicePoint) + public ServiceModel createServiceModelForService(ConstructableServicePoint servicePoint) { return new SingletonServiceModel(servicePoint); } 1.1 jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/servicemodel/SingletonInnerProxy.java Index: SingletonInnerProxy.java =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package org.apache.hivemind.impl.servicemodel; /** * Interface implemented by the inner proxies used with the * [EMAIL PROTECTED] org.apache.hivemind.impl.servicemodel.SingletonServiceModel}. This allows * the service model to force the inner proxy to resolve the service implementation and * install it into the outer proxy. * * @author Howard Lewis Ship * @version $Id: SingletonInnerProxy.java,v 1.1 2004/05/19 02:30:53 hlship Exp $ */ public interface SingletonInnerProxy { public void _instantiateServiceImplementation(); } 1.2 +2 -2 jakarta-hivemind/framework/src/java/org/apache/hivemind/internal/ServiceModelFactory.java Index: ServiceModelFactory.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/internal/ServiceModelFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ServiceModelFactory.java 13 May 2004 11:04:41 -0000 1.1 +++ ServiceModelFactory.java 19 May 2004 02:30:53 -0000 1.2 @@ -14,9 +14,9 @@ package org.apache.hivemind.internal; -import org.apache.hivemind.impl.ConstructableServiceExtensionPoint; +import org.apache.hivemind.impl.ConstructableServicePoint; public interface ServiceModelFactory { - public ServiceModel createServiceModelForService(ConstructableServiceExtensionPoint servicePoint); + public ServiceModel createServiceModelForService(ConstructableServicePoint servicePoint); } 1.3 +8 -1 jakarta-hivemind/framework/src/java/org/apache/hivemind/internal/ServiceModel.java Index: ServiceModel.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/internal/ServiceModel.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ServiceModel.java 18 May 2004 15:34:00 -0000 1.2 +++ ServiceModel.java 19 May 2004 02:30:53 -0000 1.3 @@ -38,4 +38,11 @@ */ public Object getService(); + + /** + * Forces the core service implementation (and any interceptors) to be fully instantiated + * immediately, rather than waiting for the first service method invocation. This is used + * when a service needs to be "eagerly loaded" rather than "lazy loaded". + */ + public void instantiateService(); } 1.2 +9 -1 jakarta-hivemind/framework/src/java/org/apache/hivemind/internal/ServicePoint.java Index: ServicePoint.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/internal/ServicePoint.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- ServicePoint.java 18 May 2004 15:34:00 -0000 1.1 +++ ServicePoint.java 19 May 2004 02:30:53 -0000 1.2 @@ -63,4 +63,12 @@ **/ public Schema getParametersSchema(); + + /** + * Forces the service to be fully instantiated immediately, rather than + * lazily. + */ + + public void forceServiceInstantiation(); + } 1.6 +4 -2 jakarta-hivemind/framework/src/java/org/apache/hivemind/schema/rules/ServiceTranslator.java Index: ServiceTranslator.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/schema/rules/ServiceTranslator.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ServiceTranslator.java 18 May 2004 15:34:01 -0000 1.5 +++ ServiceTranslator.java 19 May 2004 02:30:53 -0000 1.6 @@ -37,7 +37,9 @@ if (HiveMind.isBlank(inputValue)) return null; - return contributingModule.getService(inputValue, propertyType); + return contributingModule.getService( + inputValue, + propertyType == null ? Object.class : propertyType); } } 1.7 +8 -3 jakarta-hivemind/framework/src/java/org/apache/hivemind/schema/rules/RuleUtils.java Index: RuleUtils.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/schema/rules/RuleUtils.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- RuleUtils.java 18 May 2004 15:34:01 -0000 1.6 +++ RuleUtils.java 19 May 2004 02:30:53 -0000 1.7 @@ -142,12 +142,17 @@ /** * Convienience for invoking - * [EMAIL PROTECTED] RegistryInfrastructure#getTranslator(String)}. + * [EMAIL PROTECTED] Module#getTranslator(String)}. + * + * @param processor the processor for the schema being converted + * @param translator the string identifying the translator to provide (may be null) + * @return a translator obtained via the contributing module, or an + * instance of [EMAIL PROTECTED] NullTranslator} */ public static Translator getTranslator(SchemaProcessor processor, String translator) { if (translator == null) - return null; + return new NullTranslator(); return processor.getContributingModule().getTranslator(translator); } 1.5 +2 -7 jakarta-hivemind/framework/src/java/org/apache/hivemind/schema/rules/ReadAttributeRule.java Index: ReadAttributeRule.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/schema/rules/ReadAttributeRule.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ReadAttributeRule.java 13 May 2004 11:04:40 -0000 1.4 +++ ReadAttributeRule.java 19 May 2004 02:30:53 -0000 1.5 @@ -77,12 +77,7 @@ Class propertyType = PropertyUtils.getPropertyType(target, _propertyName, this); Object finalValue = - _translator == null - ? value - : _translatorObject.translate( - processor.getContributingModule(), - propertyType, - value); + _translatorObject.translate(processor.getContributingModule(), propertyType, value); PropertyUtils.write(target, _propertyName, finalValue, this); 1.4 +2 -7 jakarta-hivemind/framework/src/java/org/apache/hivemind/schema/rules/ReadContentRule.java Index: ReadContentRule.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/schema/rules/ReadContentRule.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ReadContentRule.java 13 May 2004 11:04:40 -0000 1.3 +++ ReadContentRule.java 19 May 2004 02:30:53 -0000 1.4 @@ -57,12 +57,7 @@ Class propertyType = PropertyUtils.getPropertyType(target, _propertyName, this); Object finalValue = - _translator == null - ? value - : _translatorObject.translate( - processor.getContributingModule(), - propertyType, - value); + _translatorObject.translate(processor.getContributingModule(), propertyType, value); PropertyUtils.write(target, _propertyName, finalValue, this); } 1.1 jakarta-hivemind/framework/src/java/org/apache/hivemind/schema/rules/NullTranslator.java Index: NullTranslator.java =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package org.apache.hivemind.schema.rules; import org.apache.hivemind.internal.Module; import org.apache.hivemind.schema.Translator; /** * A translator that does nothing. Used in cases where no translator is supplied. * * @author Howard Lewis Ship * @version $Id: NullTranslator.java,v 1.1 2004/05/19 02:30:53 hlship Exp $ */ public class NullTranslator implements Translator { /** * Returns the inputValue. */ public Object translate(Module contributingModule, Class propertyType, String inputValue) { return inputValue; } } 1.1 jakarta-hivemind/framework/src/java/org/apache/hivemind/schema/rules/ServicePointTranslator.java Index: ServicePointTranslator.java =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package org.apache.hivemind.schema.rules; import org.apache.hivemind.internal.Module; import org.apache.hivemind.schema.Translator; /** * A custom translator (meaning: not used enough to be registered in <code>hivemind.Translators</code>. * Converts an an input value into a [EMAIL PROTECTED] org.apache.hivemind.internal.ServicePoint}. * * @author Howard Lewis Ship * @version $Id: ServicePointTranslator.java,v 1.1 2004/05/19 02:30:53 hlship Exp $ */ public class ServicePointTranslator implements Translator { public Object translate(Module contributingModule, Class propertyType, String inputValue) { return contributingModule.getServicePoint(inputValue); } } 1.1 jakarta-hivemind/framework/src/java/org/apache/hivemind/schema/rules/PushAttributeRule.java Index: PushAttributeRule.java =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package org.apache.hivemind.schema.rules; import javax.transaction.Transaction; import org.apache.hivemind.Element; import org.apache.hivemind.schema.SchemaProcessor; import org.apache.hivemind.schema.Translator; /** * A rule that reads an attribute, passes it through a translator, then pushes the result * onto the processor stack. * * @author Howard Lewis Ship * @version $Id: PushAttributeRule.java,v 1.1 2004/05/19 02:30:53 hlship Exp $ */ public class PushAttributeRule extends BaseRule { private String _attributeName; private String _translator; private Translator _translatorObject; /** * Uses the translator to convert the specified attribute into an object and pushes * that object onto the processor stack. */ public void begin(SchemaProcessor processor, Element element) { if (_translatorObject == null) _translatorObject = RuleUtils.getTranslator(processor, _translator); String attributeValue = element.getAttributeValue(_attributeName); Object finalValue = _translatorObject.translate(processor.getContributingModule(), null, attributeValue); processor.push(finalValue); } /** * Invokes [EMAIL PROTECTED] SchemaProcessor#pop()}. */ public void end(SchemaProcessor processor, Element element) { processor.pop(); } public void setAttributeName(String string) { _attributeName = string; } public void setTranslator(String string) { _translator = string; } public String getAttributeName() { return _attributeName; } public String getTranslator() { return _translator; } } 1.2 +14 -0 jakarta-hivemind/framework/src/test/hivemind/test/services/InitializeMethodFailure.sdl Index: InitializeMethodFailure.sdl =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/services/InitializeMethodFailure.sdl,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- InitializeMethodFailure.sdl 17 May 2004 21:14:22 -0000 1.1 +++ InitializeMethodFailure.sdl 19 May 2004 02:30:53 -0000 1.2 @@ -1,3 +1,17 @@ +// Copyright 2004 The Apache Software Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + module (id=hivemind.test.services version="1.0.0") { service-point (id=Runnable interface=java.lang.Runnable) 1.1 jakarta-hivemind/framework/src/test/hivemind/test/services/EagerLoadPrimitive.sdl Index: EagerLoadPrimitive.sdl =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // $Id: EagerLoadPrimitive.sdl,v 1.1 2004/05/19 02:30:53 hlship Exp $ module (id=hivemind.test.services version="1.0.0") { service-point (id=Loud interface=java.lang.Runnable) { invoke-factory (service-id=hivemind.BuilderFactory model=primitive) { construct (class=hivemind.test.services.impl.LoudRunner initialize-method=run log-property=log) } } contribution (configuration-id=hivemind.EagerLoad) { load (service-id=Loud) } } 1.1 jakarta-hivemind/framework/src/test/hivemind/test/services/TestStartup.java Index: TestStartup.java =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package hivemind.test.services; import hivemind.test.FrameworkTestCase; import hivemind.test.services.impl.StartupRunnableFixtureImpl; import java.util.ArrayList; import java.util.List; import org.apache.hivemind.impl.StartupImpl; import org.apache.hivemind.internal.RegistryInfrastructure; /** * Tests Registry startup. * * @author Howard Lewis Ship * @version $Id: TestStartup.java,v 1.1 2004/05/19 02:30:53 hlship Exp $ */ public class TestStartup extends FrameworkTestCase { public void testStartupImpl() { StartupRunnableFixture fixture = new StartupRunnableFixtureImpl(); List l = new ArrayList(); l.add(fixture); StartupImpl s = new StartupImpl(); s.setRunnables(l); s.run(); assertEquals(true, fixture.getDidRun()); } public void testStartupContribution() throws Exception { RegistryInfrastructure r = buildFrameworkRegistry("StartupContribution.sdl"); StartupRunnableFixture fixture = (StartupRunnableFixture) r.getService( "hivemind.test.services.StartupRunnableFixture", StartupRunnableFixture.class); assertEquals(true, fixture.getDidRun()); } } 1.1 jakarta-hivemind/framework/src/test/hivemind/test/services/TestEagerLoader.java Index: TestEagerLoader.java =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package hivemind.test.services; import hivemind.test.FrameworkTestCase; import java.util.ArrayList; import java.util.List; import org.apache.hivemind.internal.ServicePoint; import org.apache.hivemind.service.impl.EagerLoader; import org.easymock.MockControl; /** * Tests for the [EMAIL PROTECTED] org.apache.hivemind.service.impl.EagerLoader} service. * * @author Howard Lewis Ship * @version $Id: TestEagerLoader.java,v 1.1 2004/05/19 02:30:53 hlship Exp $ */ public class TestEagerLoader extends FrameworkTestCase { public void testEagerLoaderImpl() { EagerLoader el = new EagerLoader(); List l = new ArrayList(); MockControl control = MockControl.createStrictControl(ServicePoint.class); ServicePoint sp = (ServicePoint) control.getMock(); sp.forceServiceInstantiation(); control.replay(); l.add(sp); el.setServicePoints(l); el.run(); control.verify(); } public void testEagerLoadSingleton() throws Exception { interceptLogging("hivemind.test.services.Loud"); buildFrameworkRegistry("EagerLoadSingleton.sdl"); assertLoggedMessage("Instantiated."); } public void testEagerLoadPrimitive() throws Exception { interceptLogging("hivemind.test.services.Loud"); buildFrameworkRegistry("EagerLoadPrimitive.sdl"); assertLoggedMessage("Instantiated."); } public void testEagerLoadThreaded() throws Exception { interceptLogging("hivemind.test.services.Loud"); buildFrameworkRegistry("EagerLoadThreaded.sdl"); assertLoggedMessage("Instantiated."); } public void testEagerLoadPooled() throws Exception { interceptLogging("hivemind.test.services.Loud"); buildFrameworkRegistry("EagerLoadPooled.sdl"); assertLoggedMessage("Instantiated."); } } 1.1 jakarta-hivemind/framework/src/test/hivemind/test/services/EagerLoadSingleton.sdl Index: EagerLoadSingleton.sdl =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // $Id: EagerLoadSingleton.sdl,v 1.1 2004/05/19 02:30:53 hlship Exp $ module (id=hivemind.test.services version="1.0.0") { service-point (id=Loud interface=java.lang.Runnable) { invoke-factory (service-id=hivemind.BuilderFactory model=singleton) { construct (class=hivemind.test.services.impl.LoudRunner initialize-method=run log-property=log) } } contribution (configuration-id=hivemind.EagerLoad) { load (service-id=Loud) } } 1.1 jakarta-hivemind/framework/src/test/hivemind/test/services/StartupRunnableFixture.java Index: StartupRunnableFixture.java =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package hivemind.test.services; public interface StartupRunnableFixture extends Runnable { public boolean getDidRun(); } 1.1 jakarta-hivemind/framework/src/test/hivemind/test/services/EagerLoadThreaded.sdl Index: EagerLoadThreaded.sdl =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // $Id: EagerLoadThreaded.sdl,v 1.1 2004/05/19 02:30:53 hlship Exp $ module (id=hivemind.test.services version="1.0.0") { service-point (id=Loud interface=java.lang.Runnable) { invoke-factory (service-id=hivemind.BuilderFactory model=threaded) { construct (class=hivemind.test.services.impl.LoudRunner initialize-method=run log-property=log) } } contribution (configuration-id=hivemind.EagerLoad) { load (service-id=Loud) } } 1.1 jakarta-hivemind/framework/src/test/hivemind/test/services/EagerLoadPooled.sdl Index: EagerLoadPooled.sdl =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // $Id: EagerLoadPooled.sdl,v 1.1 2004/05/19 02:30:53 hlship Exp $ module (id=hivemind.test.services version="1.0.0") { service-point (id=Loud interface=java.lang.Runnable) { invoke-factory (service-id=hivemind.BuilderFactory model=pooled) { construct (class=hivemind.test.services.impl.LoudRunner initialize-method=run log-property=log) } } contribution (configuration-id=hivemind.EagerLoad) { load (service-id=Loud) } } 1.1 jakarta-hivemind/framework/src/test/hivemind/test/services/StartupContribution.sdl Index: StartupContribution.sdl =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. module (id=hivemind.test.services version="1.0.0") { service-point (id=StartupRunnableFixture interface=hivemind.test.services.StartupRunnableFixture) { create-instance (class=hivemind.test.services.impl.StartupRunnableFixtureImpl) } contribution (configuration-id=hivemind.Startup) { service (service-id=StartupRunnableFixture) } } 1.10 +2 -1 jakarta-hivemind/framework/xdocs/navigation.xml Index: navigation.xml =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/xdocs/navigation.xml,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- navigation.xml 17 May 2004 21:14:22 -0000 1.9 +++ navigation.xml 19 May 2004 02:30:53 -0000 1.10 @@ -40,6 +40,7 @@ <menu name="Configurations"> <item name="ApplicationDefaults" href="/ApplicationDefaults.html"/> + <item name="EagerLoad" href="/EagerLoad.html"/> <item name="FactoryDefaults" href="/FactoryDefaults.html"/> <item name="ServiceModels" href="ServiceModels.html"/> <item name="SymbolSources" href="/SymbolSources.html"/> 1.3 +2 -2 jakarta-hivemind/framework/xdocs/SymbolSources.xml Index: SymbolSources.xml =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/xdocs/SymbolSources.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- SymbolSources.xml 17 May 2004 19:48:49 -0000 1.2 +++ SymbolSources.xml 19 May 2004 02:30:53 -0000 1.3 @@ -32,7 +32,7 @@ <section name="hivemind.SymbolSources"> <p> -The <a href="&hivedoc;/config/hivemind.SymbolSource.html">SymbolSources</a> configuration +The <a href="&hivedoc;/config/hivemind.SymbolSources.html">SymbolSources</a> configuration is used to define new <a href="&apiroot;/SymbolSource.html">SymbolSource</a>s (providers of values for substitution symbols). 1.1 jakarta-hivemind/framework/xdocs/EagerLoad.xml Index: EagerLoad.xml =================================================================== <?xml version="1.0"?> <!-- $Id: EagerLoad.xml,v 1.1 2004/05/19 02:30:53 hlship Exp $ --> <!-- Copyright 2004 The Apache Software Foundation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <!DOCTYPE document [ <!ENTITY projectroot '../'> <!ENTITY % common-links SYSTEM "../../common/links.xml"> %common-links; ]> <document> <properties> <title>hivemind.EagerLoad Configuration</title> <author email="[EMAIL PROTECTED]">Howard M. Lewis Ship</author> </properties> <body> <section name="hivemind.EagerLoad"> <p> The <a href="&hivedoc;/config/hivemind.EagerLoad.html">EagerLoad</a> configuration allows services to be constructed when the Registry is first initialized. Normally, HiveMind goes to great lengths to ensure that services are only constructed when they are first needed. Eager loading is appropriate during development (to ensure that services are configured properly), and some services that are event driven may need to be instantiated early, so that they may begin receiving event notifications even before their first service method is invoked. </p> <p> Care should be taken when using services with the pooled or threaded service models to invoke <a href="ThreadEventNotifier.html">ThreadEventNotifier</a>. </p> <p> Contributions are as follows: <source> load (service-id=...) </source> </p> </section> </body> </document> 1.11 +21 -1 jakarta-hivemind/framework/src/test/hivemind/test/parse/TestDescriptorParser.java Index: TestDescriptorParser.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/parse/TestDescriptorParser.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- TestDescriptorParser.java 17 May 2004 16:57:47 -0000 1.10 +++ TestDescriptorParser.java 19 May 2004 02:30:54 -0000 1.11 @@ -38,6 +38,7 @@ import org.apache.hivemind.schema.Schema; import org.apache.hivemind.schema.rules.CreateObjectRule; import org.apache.hivemind.schema.rules.InvokeParentRule; +import org.apache.hivemind.schema.rules.PushAttributeRule; import org.apache.hivemind.schema.rules.ReadAttributeRule; import org.apache.hivemind.schema.rules.ReadContentRule; import org.apache.hivemind.schema.rules.SetPropertyRule; @@ -415,4 +416,23 @@ assertEquals("foo", rule.getPropertyName()); assertEquals("bar", rule.getValue()); } + + public void testPushAttributeRule() throws Exception + { + ModuleDescriptor md = parse("PushAttributeRule.sdl"); + + List points = md.getConfigurationPoints(); + ConfigurationPointDescriptor cpd = (ConfigurationPointDescriptor)points.get(0); + Schema s = cpd.getContributionsSchema(); + List l = s.getElementModel(); + + ElementModel em = (ElementModel)l.get(0); + + List rules = em.getRules(); + + PushAttributeRule rule = (PushAttributeRule)rules.get(0); + + assertEquals("foo", rule.getAttributeName()); + assertEquals("bar", rule.getTranslator()); + } } 1.11 +8 -38 jakarta-hivemind/framework/src/test/hivemind/test/parse/TestToString.java Index: TestToString.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/parse/TestToString.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- TestToString.java 18 May 2004 15:34:01 -0000 1.10 +++ TestToString.java 19 May 2004 02:30:54 -0000 1.11 @@ -26,7 +26,7 @@ import org.apache.hivemind.impl.InterceptorStackImpl; import org.apache.hivemind.impl.ModuleImpl; import org.apache.hivemind.impl.RegistryImpl; -import org.apache.hivemind.impl.ServiceExtensionPointImpl; +import org.apache.hivemind.impl.ServicePointImpl; import org.apache.hivemind.impl.ServiceInterceptorContributionImpl; import org.apache.hivemind.internal.Module; import org.apache.hivemind.internal.ServicePoint; @@ -39,6 +39,7 @@ import org.apache.hivemind.parse.ModuleDescriptor; import org.apache.hivemind.parse.ServicePointDescriptor; import org.apache.hivemind.schema.Schema; +import org.easymock.MockControl; /** * A cheat, for code-coverage reasons. We check that all the classes have a toString() @@ -50,43 +51,12 @@ public class TestToString extends FrameworkTestCase { - private static class MockServiceExtensionPoint implements ServicePoint - { - - public Schema getParametersSchema() - { - return null; - } - - public Object getService(Class interfaceClass) - { - return null; - } - - public Class getServiceInterface() - { - return Runnable.class; - } - - public String getExtensionPointId() - { - return null; - } - - public Module getModule() - { - return null; - } - - public Location getLocation() - { - return null; - } - - } public void testToString() { + MockControl control = MockControl.createControl(ServicePoint.class); + ServicePoint mockServicePoint = (ServicePoint) control.getMock(); + new ConfigurationPointDescriptor().toString(); new ContributionDescriptor().toString(); new ImplementationDescriptor().toString(); @@ -102,7 +72,7 @@ new ElementImpl().toString(); new AttributeImpl("foo", "bar").toString(); new ServiceInterceptorContributionImpl().toString(); - new ServiceExtensionPointImpl().toString(); - new InterceptorStackImpl(new MockServiceExtensionPoint(), null).toString(); + new ServicePointImpl().toString(); + new InterceptorStackImpl(mockServicePoint, null).toString(); } } 1.1 jakarta-hivemind/framework/src/test/hivemind/test/parse/PushAttributeRule.sdl Index: PushAttributeRule.sdl =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // $Id: PushAttributeRule.sdl,v 1.1 2004/05/19 02:30:54 hlship Exp $ module (id=hivemind.test.parse version="1.0.0") { configuration-point (id=Config) { schema { element (name = frankfurt) { rules { push-attribute (attribute=foo translator=bar) } } } } } 1.1 jakarta-hivemind/framework/src/java/org/apache/hivemind/service/impl/EagerLoader.java Index: EagerLoader.java =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package org.apache.hivemind.service.impl; import java.util.Iterator; import java.util.List; import org.apache.commons.logging.Log; import org.apache.hivemind.internal.ServicePoint; public class EagerLoader implements Runnable { private List _servicePoints; public void run() { Iterator i = _servicePoints.iterator(); while (i.hasNext()) { ServicePoint point = (ServicePoint) i.next(); point.forceServiceInstantiation(); } } public void setServicePoints(List list) { _servicePoints = list; } } 1.13 +26 -3 jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/DescriptorParser.java Index: DescriptorParser.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/DescriptorParser.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- DescriptorParser.java 17 May 2004 16:57:47 -0000 1.12 +++ DescriptorParser.java 19 May 2004 02:30:54 -0000 1.13 @@ -49,6 +49,7 @@ import org.apache.hivemind.schema.impl.SchemaImpl; import org.apache.hivemind.schema.rules.CreateObjectRule; import org.apache.hivemind.schema.rules.InvokeParentRule; +import org.apache.hivemind.schema.rules.PushAttributeRule; import org.apache.hivemind.schema.rules.ReadAttributeRule; import org.apache.hivemind.schema.rules.ReadContentRule; import org.apache.hivemind.schema.rules.SetModuleRule; @@ -506,7 +507,7 @@ if (elementName.equals("sub-module")) { - enterSubMoudle(elementName); + enterSubModule(elementName); return; } @@ -561,6 +562,12 @@ return; } + if (elementName.equals("push-attribute")) + { + enterPushAttribute(elementName); + return; + } + if (elementName.equals("custom")) { enterCustom(elementName); @@ -1130,7 +1137,23 @@ elementModel.addRule(rule); } - private void enterSubMoudle(String elementName) + private void enterPushAttribute(String elementName) + { + ElementModelImpl elementModel = (ElementModelImpl) peekObject(); + + PushAttributeRule rule = new PushAttributeRule(); + + push(elementName, rule, STATE_NO_CONTENT); + + checkAttributes(); + + rule.setAttributeName(getAttribute("attribute")); + rule.setTranslator(getAttribute("translator")); + + elementModel.addRule(rule); + } + + private void enterSubModule(String elementName) { push(elementName, null, STATE_NO_CONTENT); 1.5 +3 -1 jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/DescriptorParser.properties Index: DescriptorParser.properties =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/parse/DescriptorParser.properties,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- DescriptorParser.properties 17 May 2004 16:57:47 -0000 1.4 +++ DescriptorParser.properties 19 May 2004 02:30:54 -0000 1.5 @@ -84,3 +84,5 @@ required.set-property.property=true required.set-property.value=true +required.push-attribute.attribute=true +required.push-attribute.translator=false 1.3 +9 -16 jakarta-hivemind/framework/src/java/org/apache/hivemind/servlet/HiveMindFilter.java Index: HiveMindFilter.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/servlet/HiveMindFilter.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- HiveMindFilter.java 13 May 2004 11:04:48 -0000 1.2 +++ HiveMindFilter.java 19 May 2004 02:30:54 -0000 1.3 @@ -32,7 +32,6 @@ import org.apache.hivemind.Registry; import org.apache.hivemind.impl.DefaultClassResolver; import org.apache.hivemind.impl.RegistryBuilder; -import org.apache.hivemind.service.ThreadEventNotifier; /** * Servlet filter that constructs the Registry at startup. It ensures that each request is @@ -60,7 +59,6 @@ public static final String REQUEST_KEY = "org.apache.hivemind.RequestRegistry"; private Registry _registry; - private ThreadEventNotifier _notifier; /** * Constructs a [EMAIL PROTECTED] Registry} and stores it into the @@ -78,10 +76,6 @@ builder.processModules(resolver); _registry = builder.constructRegistry(getRegistryLocale()); - _notifier = - (ThreadEventNotifier) _registry.getService( - HiveMind.THREAD_EVENT_NOTIFIER_SERVICE, - ThreadEventNotifier.class); config.getServletContext().setAttribute(CONTEXT_KEY, _registry); } @@ -120,15 +114,14 @@ } - /** - * Cleanup the thread, ignoring any exceptions that may be thrown. - */ + /** + * Cleanup the thread, ignoring any exceptions that may be thrown. + */ private void cleanupThread() { try { - if (_notifier != null) - _notifier.fireThreadCleanup(); + _registry.cleanupThread(); } catch (Exception ex) { @@ -145,10 +138,10 @@ _registry.shutdown(); } - /** - * Returns the [EMAIL PROTECTED] Registry} that was stored as a request attribute - * in [EMAIL PROTECTED] #doFilter(ServletRequest, ServletResponse, FilterChain)}. - */ + /** + * Returns the [EMAIL PROTECTED] Registry} that was stored as a request attribute + * in [EMAIL PROTECTED] #doFilter(ServletRequest, ServletResponse, FilterChain)}. + */ public static Registry getRegistry(HttpServletRequest request) { return (Registry) request.getAttribute(REQUEST_KEY); 1.3 +4 -0 jakarta-hivemind/framework/src/test/hivemind/test/servlet/TestHiveMindFilter.java Index: TestHiveMindFilter.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/servlet/TestHiveMindFilter.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- TestHiveMindFilter.java 26 Feb 2004 23:08:01 -0000 1.2 +++ TestHiveMindFilter.java 19 May 2004 02:30:54 -0000 1.3 @@ -116,7 +116,11 @@ { Filter f = new HiveMindFilter(); + interceptLogging(HiveMindFilter.class.getName()); + f.doFilter(new MockRequest(), new MockResponse(), new MockFilterChain()); + + assertLoggedMessage("Unable to cleanup current thread"); } } 1.25 +3 -1 jakarta-hivemind/common/links.xml Index: links.xml =================================================================== RCS file: /home/cvs/jakarta-hivemind/common/links.xml,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- links.xml 17 May 2004 16:57:47 -0000 1.24 +++ links.xml 19 May 2004 02:30:54 -0000 1.25 @@ -101,3 +101,5 @@ <!ENTITY _custom '<code><custom></code>'> <!ENTITY custom '<a href="&projectroot;rules.html#custom">&_custom;</a>'> +<!ENTITY _push-attribute '<code><push-attribute></code>'> +<!ENTITY push-attribute '<a href="&projectroot;rules.html#push-attribute">&_push-attribute;</a>'> 1.1 jakarta-hivemind/framework/src/test/hivemind/test/rules/TestPushAttributeRule.java Index: TestPushAttributeRule.java =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package hivemind.test.rules; import org.apache.hivemind.Attribute; import org.apache.hivemind.impl.AttributeImpl; import org.apache.hivemind.impl.ElementImpl; import org.apache.hivemind.schema.SchemaProcessor; import org.apache.hivemind.schema.rules.PushAttributeRule; import org.apache.hivemind.test.HiveMindTestCase; import org.easymock.MockControl; public class TestPushAttributeRule extends HiveMindTestCase { public void testPushAttributeRule() { MockControl control = MockControl.createStrictControl(SchemaProcessor.class); ElementImpl element = new ElementImpl(); element.setElementName("myelement"); Attribute attribute = new AttributeImpl("fred", "flintstone"); element.addAttribute(attribute); PushAttributeRule rule = new PushAttributeRule(); rule.setAttributeName("fred"); SchemaProcessor mockProcessor = (SchemaProcessor) control.getMock(); mockProcessor.getContributingModule(); control.setReturnValue(null); mockProcessor.push("flintstone"); mockProcessor.pop(); control.setReturnValue("flintstone"); control.replay(); rule.begin(mockProcessor, element); rule.end(mockProcessor, element); control.verify(); } } 1.1 jakarta-hivemind/framework/src/test/hivemind/test/rules/TestServicePointTranslator.java Index: TestServicePointTranslator.java =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package hivemind.test.rules; import org.apache.hivemind.impl.ServicePointImpl; import org.apache.hivemind.internal.Module; import org.apache.hivemind.internal.ServicePoint; import org.apache.hivemind.schema.Translator; import org.apache.hivemind.schema.rules.ServicePointTranslator; import org.apache.hivemind.test.HiveMindTestCase; import org.easymock.MockControl; /** * Test for the [EMAIL PROTECTED] org.apache.hivemind.schema.rules.ServicePointTranslator}. * * @author Howard Lewis Ship * @version $Id: TestServicePointTranslator.java,v 1.1 2004/05/19 02:30:54 hlship Exp $ */ public class TestServicePointTranslator extends HiveMindTestCase { public void testServicePointTranslator() { // This is my first try using EasyMock. Pretty nifty stuff. MockControl control = MockControl.createStrictControl(Module.class); Module m = (Module)control.getMock(); ServicePoint sp = new ServicePointImpl(); m.getServicePoint("Fred"); control.setReturnValue(sp); control.replay(); Translator t = new ServicePointTranslator(); ServicePoint result = (ServicePoint) t.translate(m, null, "Fred"); assertSame(sp, result); control.verify(); } } 1.1 jakarta-hivemind/framework/src/test/hivemind/test/services/impl/StartupRunnableFixtureImpl.java Index: StartupRunnableFixtureImpl.java =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package hivemind.test.services.impl; import hivemind.test.services.StartupRunnableFixture; public class StartupRunnableFixtureImpl implements StartupRunnableFixture { private boolean _didRun; public void run() { _didRun = true; } public boolean getDidRun() { return _didRun; } } 1.1 jakarta-hivemind/framework/src/test/hivemind/test/services/impl/LoudRunner.java Index: LoudRunner.java =================================================================== // Copyright 2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package hivemind.test.services.impl; import org.apache.commons.logging.Log; public class LoudRunner implements Runnable { private Log _log; public void run() { _log.info("Instantiated."); } public void setLog(Log log) { _log = log; } } 1.15 +3 -3 jakarta-hivemind/framework/src/test/hivemind/test/TestMisc.java Index: TestMisc.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/TestMisc.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- TestMisc.java 18 May 2004 15:34:01 -0000 1.14 +++ TestMisc.java 19 May 2004 02:30:54 -0000 1.15 @@ -28,7 +28,7 @@ import org.apache.hivemind.impl.CreateClassServiceConstructor; import org.apache.hivemind.impl.InvokeFactoryServiceConstructor; import org.apache.hivemind.impl.ModuleImpl; -import org.apache.hivemind.impl.ServiceExtensionPointImpl; +import org.apache.hivemind.impl.ServicePointImpl; import org.apache.hivemind.impl.SystemPropertiesSymbolSource; import org.apache.hivemind.internal.Module; import org.apache.hivemind.internal.ServicePoint; @@ -97,7 +97,7 @@ public void testInvokeFactoryServiceConstructorAccessors() { Module m = new ModuleImpl(); - ServicePoint sep = new ServiceExtensionPointImpl(); + ServicePoint sep = new ServicePointImpl(); List p = new ArrayList(); InvokeFactoryServiceConstructor c = new InvokeFactoryServiceConstructor(); 1.11 +3 -20 jakarta-hivemind/framework/src/test/hivemind/test/TestRegistryBuilder.java Index: TestRegistryBuilder.java =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/TestRegistryBuilder.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- TestRegistryBuilder.java 18 May 2004 15:34:01 -0000 1.10 +++ TestRegistryBuilder.java 19 May 2004 02:30:54 -0000 1.11 @@ -38,24 +38,6 @@ */ public class TestRegistryBuilder extends FrameworkTestCase { - - public void testEmpty() throws Exception - { - RegistryBuilder b = new RegistryBuilder(); - - RegistryInfrastructure r = (RegistryInfrastructure) b.constructRegistry(Locale.getDefault()); - - try - { - r.getConfiguration("org.apache.hivemind.VariableSource"); - unreachable(); - } - catch (ApplicationRuntimeException ex) - { - assertExceptionSubstring(ex, "Configuration point org.apache.hivemind.VariableSource does not exist."); - } - } - /** * Reproduce test [EMAIL PROTECTED] hivemind.test.config.TestConfiguration#testValueVariables()} using * dynamic lookup of hivemodule resources. @@ -75,7 +57,8 @@ RegistryBuilder b = new RegistryBuilder(); b.processModules(resolver); - RegistryInfrastructure r = (RegistryInfrastructure) b.constructRegistry(Locale.getDefault()); + RegistryInfrastructure r = + (RegistryInfrastructure) b.constructRegistry(Locale.getDefault()); List l = r.getConfiguration("hivemind.test.config.Symbols"); assertEquals(1, l.size()); 1.6 +112 -2 jakarta-hivemind/framework/src/descriptor/META-INF/hivemodule.sdl Index: hivemodule.sdl =================================================================== RCS file: /home/cvs/jakarta-hivemind/framework/src/descriptor/META-INF/hivemodule.sdl,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- hivemodule.sdl 17 May 2004 21:14:22 -0000 1.5 +++ hivemodule.sdl 19 May 2004 02:30:54 -0000 1.6 @@ -652,7 +652,8 @@ translator (name=resource class=org.apache.hivemind.schema.rules.ResourceTranslator) translator (name=long class=org.apache.hivemind.schema.rules.LongTranslator) translator (name=double class=org.apache.hivemind.schema.rules.DoubleTranslator) - translator (name=smart class=org.apache.hivemind.schema.rules.SmartTranslator) + translator (name=smart class=org.apache.hivemind.schema.rules.SmartTranslator) + translator (name=service-point class=org.apache.hivemind.schema.rules.ServicePointTranslator) } service-point (id=ShutdownCoordinator interface=org.apache.hivemind.ShutdownCoordinator) @@ -666,5 +667,114 @@ log } } + } + + configuration-point (id=Startup) + { + description + { + "A configuration to which startup objects may be contributed (as objects or services). " + "Order of execution is expliclitly not defined." + } + + schema + { + element (name=service) + { + description { "Defines a service that implements the Runnable interface." } + + attribute (name=service-id) + { + description { "The name of a service implementing the Runnable interface." } + } + + rules + { + push-attribute (attribute=service-id translator=service) + invoke-parent (method=addElement) + } + } // element service + + element (name=runnable) + { + description { "Allows an instance of a class implementing Runnable to be contributed." } + + attribute (name=class) + { + description { "The name of a class implementing Runnable." } + } + + rules + { + push-attribute (attribute=class translator=object) + invoke-parent (method=addElement) + } + + } // element runnable + } // schema + } + + service-point (id=Startup interface=java.lang.Runnable) + { + description + { + "A service which isused to bootstrap HiveMind; it obtains the hivemind.Startup configuration " + "and runs each Runnable object or service within." + } + + invoke-factory (service-id=BuilderFactory) + { + construct (class=org.apache.hivemind.impl.StartupImpl) + { + set-configuration (property=runnables configuration-id=Startup) + } + } + } + + configuration-point (id=EagerLoad) + { + description + { + "Configuration to which services may be contributed. The corresponding services are instantiated " + "eagerly, as the Registry is started. The order in which services are instantiated is not specified. " + } + + schema + { + element (name=load) + { + description { "Identifies a service that will be eagerly loaded." } + + attribute (name=service-id required=true) + + rules + { + push-attribute (attribute=service-id translator=service-point) + invoke-parent (method=addElement) + } + } + } + } + + service-point (id=EagerLoad interface=java.lang.Runnable) + { + description + { + "Service that performs eager loading of other services. This service is contributed into the " + "hivemind.Startup configuration." + } + + invoke-factory (service-id=BuilderFactory model=primitive) + { + construct (class=org.apache.hivemind.service.impl.EagerLoader) + { + set-configuration (property=servicePoints configuration-id=EagerLoad) + } + } + } + + contribution (configuration-id=Startup) + { + service (service-id=EagerLoad) } } 1.20 +45 -1 jakarta-hivemind/xdocs/rules.xml Index: rules.xml =================================================================== RCS file: /home/cvs/jakarta-hivemind/xdocs/rules.xml,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- rules.xml 17 May 2004 16:57:47 -0000 1.19 +++ rules.xml 19 May 2004 02:30:54 -0000 1.20 @@ -77,6 +77,7 @@ <li>&create-object;</li> <li>&custom;</li> <li>&invoke-parent;</li> + <li>&push-attribute;</li> <li>&read-attribute;</li> <li>&read-content;</li> <li>&set-module;</li> @@ -179,6 +180,38 @@ </subsection> +<subsection name="push-attribute"> +<p> +The &_push-attribute; rule reads an attribute, converts it with a translator, and pushes the result +onto the stack. It will typically be combined with a &invoke-parent; to get the pushed value added +to the configuration point elements (or to some parent object). +</p> + + <table> + <tr> + <th>Attribute</th> + <th>Type</th> + <th>Required ?</th> + <th>Description</th> + </tr> + + <tr> + <td>attribute</td> + <td>string</td> + <td>yes</td> + <td>The name of the attribute to read.</td> + </tr> + + <tr> + <td>translator</td> + <td>string</td> + <td>no</td> + <td>See <a href="#Translators">Translators</a></td> + </tr> + </table> + +</subsection> + <subsection name="read-attribute"> <p> @@ -502,6 +535,17 @@ <p> The service translator is used to lookup a service in the registry. The input value is either a local service id +from the contributing module, or a fully qualified service id. +</p> + +</subsection> + + +<subsection name="service-point"> + +<p> +The service translator is used to lookup a service point (not a service) in the registry. +The input value is either a local service id from the contributing module, or a fully qualified service id. </p>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]