commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Essl <christiane...@yahoo.de>
Subject [HiveMind] DeferredService performance
Date Sun, 21 Sep 2003 07:44:07 GMT
I think the Proxy created for a deferred Service is currently a bit slow, 
because each call to a Service method first checks synchronized if the 
service is there. While the Proxy is not anymore returned once the actual 
Service is loaded I think most users of the Service will still go through 
the proxy (You know: generally early Objects live longest and are most 
used).

I would suggest the proxy to implement the GoF state pattern (an idea I got 
from commons-collection FastArrayList):

You have two proxies where the outer one contains the inner one. The 
outerone just plainly gives further to a service field which is either the 
innter proxy or the actual loaded service. The inner proxy is like the 
current deferred proxy:

The code of a ready proxy would look like this: (This would of course have 
to be produced with JavaAssist):

public class OuterProxy implements ServiceInterface{

	private ServiceExtenstionPointImpl _sep;
	private InnerProxy _inner = new InnerProxy();
	private ServiceInterface _service = new InnerProxy();

	//an example method of the ServiceInterface
	public Object exampleMethod(Object arg){
		return _service.exampleMethod(arg);
	}

	//the innerproxy
	public class InnerProxy implements ServiceInterface{
		//method which loads the actual service
		private synchronized ServiceInterface getService(){
			if(_service != this)
				return _service;
			_service = _sep.constructServiceImplementation();
			return _service;			
		}

		//and the exampleMethod
		public Object exampleMethod(Object arg){
			return this.getService().exampleMethod(arg);
		}

	}
}

This also prevents the - potential - method conflict that can happen when a 
ServiceInterface implements  the SERVICE_ACCESSOR_METHOD_NAME (_service) 
method.

By the way I saw this when I was looking for a way to implement basic 
livecycle management. Have you thought of a destroy method. I think it is 
realy needed before Database, DAO, Pool, Cache, etc Services can be 
implemented.





Mime
View raw message