cziegeler 2004/03/13 05:56:51
Modified: fortress/container/src/impl/org/apache/avalon/fortress/impl/handler
AbstractComponentHandler.java
fortress/container/src/impl/org/apache/avalon/fortress/impl/lookup
FortressServiceManager.java
FortressServiceSelector.java
fortress/container/src/impl/org/apache/avalon/fortress/impl/factory
BCELWrapperGenerator.java
Added: fortress/container/src/impl/org/apache/avalon/fortress/impl/handler
AbstractReleasableComponent.java
ReleasableComponent.java
Log:
Improve performance of lookups/releases. Wrapped components are
not put into the hash map anymore. The hash map is used to get
the component handler for releasing the component.
Revision Changes Path
1.19 +7 -2
avalon/fortress/container/src/impl/org/apache/avalon/fortress/impl/handler/AbstractComponentHandler.java
Index: AbstractComponentHandler.java
===================================================================
RCS file:
/home/cvs/avalon/fortress/container/src/impl/org/apache/avalon/fortress/impl/handler/AbstractComponentHandler.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- AbstractComponentHandler.java 28 Feb 2004 15:16:25 -0000 1.18
+++ AbstractComponentHandler.java 13 Mar 2004 13:56:51 -0000 1.19
@@ -243,7 +243,12 @@
{
try
{
- return m_factory.newInstance();
+ final Object component = m_factory.newInstance();
+ if ( component instanceof ReleasableComponent )
+ {
+ ((ReleasableComponent) component).initialize( this );
+ }
+ return component;
}
catch ( final Exception e )
{
1.1
avalon/fortress/container/src/impl/org/apache/avalon/fortress/impl/handler/AbstractReleasableComponent.java
Index: AbstractReleasableComponent.java
===================================================================
/*
* Copyright 2003-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.avalon.fortress.impl.handler;
import org.apache.avalon.framework.service.ServiceException;
/**
* Base Implementation for a releasable component.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
* @version CVS $Revision: 1.1 $ $Date: 2004/03/13 13:56:51 $
* @since 1.2
*/
public class AbstractReleasableComponent implements ReleasableComponent
{
private boolean initialized = false;
private ComponentHandler handler;
public void initialize(ComponentHandler handler)
throws Exception
{
if ( this.initialized )
{
throw new ServiceException(this.toString(), "Handable component is
already initialized.");
}
if ( handler == null )
{
throw new ServiceException(this.toString(), "Handler is required.");
}
this.handler = handler;
this.initialized = true;
}
/* (non-Javadoc)
* @see
org.apache.avalon.fortress.impl.handler.HandableComponent#put(java.lang.Object)
*/
public void put( )
{
if ( this.initialized )
{
this.handler.put( this );
}
}
}
1.1
avalon/fortress/container/src/impl/org/apache/avalon/fortress/impl/handler/ReleasableComponent.java
Index: ReleasableComponent.java
===================================================================
/*
* Copyright 2003-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.avalon.fortress.impl.handler;
/**
* This interfaces marks a component that can be released without
* using the corresponding ComponentHandler.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Avalon Development Team</a>
* @version CVS $Revision: 1.1 $ $Date: 2004/03/13 13:56:51 $
* @since 1.2
*/
public interface ReleasableComponent
{
/**
* Initialize this component with the corresponding component handler.
* @param handler The component handler used to put this component back again
* @throws ServiceException If the component is already initialized or the
* handler is missing
*/
void initialize(ComponentHandler handler)
throws Exception;
/**
* Puts the reference back in the ComponentHandler according to the
* policy of the implementation.
* In fact this calls the put method on the ComponentHandler
*/
void put( );
}
1.21 +14 -2
avalon/fortress/container/src/impl/org/apache/avalon/fortress/impl/lookup/FortressServiceManager.java
Index: FortressServiceManager.java
===================================================================
RCS file:
/home/cvs/avalon/fortress/container/src/impl/org/apache/avalon/fortress/impl/lookup/FortressServiceManager.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- FortressServiceManager.java 28 Feb 2004 15:16:25 -0000 1.20
+++ FortressServiceManager.java 13 Mar 2004 13:56:51 -0000 1.21
@@ -20,6 +20,7 @@
import org.apache.avalon.fortress.Container;
import org.apache.avalon.fortress.impl.AbstractContainer;
import org.apache.avalon.fortress.impl.handler.ComponentHandler;
+import org.apache.avalon.fortress.impl.handler.ReleasableComponent;
import org.apache.avalon.framework.component.ComponentSelector;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
@@ -97,7 +98,12 @@
final ComponentHandler handler = (ComponentHandler) result;
final Object component = handler.get();
- m_used.put( new ComponentKey( component ), handler );
+ // we only have to keep track of components that don't implement
+ // the ReleasableComponent interface
+ if ( !(component instanceof ReleasableComponent) )
+ {
+ m_used.put( new ComponentKey( component ), handler );
+ }
return component;
}
catch ( final ServiceException ce )
@@ -128,6 +134,12 @@
public void release( final Object component )
{
+ // Is this a releasable component ?
+ if ( component instanceof ReleasableComponent )
+ {
+ ((ReleasableComponent)component).put();
+ return;
+ }
final ComponentHandler handler = (ComponentHandler) m_used.remove( new
ComponentKey( component ) );
if ( null == handler )
{
1.18 +14 -2
avalon/fortress/container/src/impl/org/apache/avalon/fortress/impl/lookup/FortressServiceSelector.java
Index: FortressServiceSelector.java
===================================================================
RCS file:
/home/cvs/avalon/fortress/container/src/impl/org/apache/avalon/fortress/impl/lookup/FortressServiceSelector.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- FortressServiceSelector.java 28 Feb 2004 15:16:25 -0000 1.17
+++ FortressServiceSelector.java 13 Mar 2004 13:56:51 -0000 1.18
@@ -19,6 +19,7 @@
import org.apache.avalon.fortress.Container;
import org.apache.avalon.fortress.impl.handler.ComponentHandler;
+import org.apache.avalon.fortress.impl.handler.ReleasableComponent;
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceSelector;
@@ -70,7 +71,12 @@
{
final ComponentHandler handler = getHandler( hint );
final Object component = handler.get();
- m_used.put( new ComponentKey( component ), handler );
+ // we only have to keep track of components that don't implement
+ // the ReleasableComponent interface
+ if ( !(component instanceof ReleasableComponent) )
+ {
+ m_used.put( new ComponentKey( component ), handler );
+ }
return component;
}
catch ( final ServiceException ce )
@@ -92,6 +98,12 @@
public void release( final Object component )
{
+ // Is this a releasable component ?
+ if ( component instanceof ReleasableComponent )
+ {
+ ((ReleasableComponent)component).put();
+ return;
+ }
final ComponentHandler handler =
(ComponentHandler) m_used.remove( new ComponentKey( component ) );
if ( null != handler )
1.17 +1 -1
avalon/fortress/container/src/impl/org/apache/avalon/fortress/impl/factory/BCELWrapperGenerator.java
Index: BCELWrapperGenerator.java
===================================================================
RCS file:
/home/cvs/avalon/fortress/container/src/impl/org/apache/avalon/fortress/impl/factory/BCELWrapperGenerator.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- BCELWrapperGenerator.java 28 Feb 2004 15:16:25 -0000 1.16
+++ BCELWrapperGenerator.java 13 Mar 2004 13:56:51 -0000 1.17
@@ -50,7 +50,7 @@
/**
* The name of the superclass of the wrapper class to be generated.
*/
- private static final String WRAPPER_SUPERCLASS_NAME = "java.lang.Object";
+ private static final String WRAPPER_SUPERCLASS_NAME =
"org.apache.avalon.fortress.impl.handler.AbstractReleasableComponent";
/**
* The name of the interface each generated wrapper class has to implement.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]