You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by do...@apache.org on 2002/07/12 03:18:44 UTC
cvs commit: jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/services/connection AdaptingComponentManager.java AbstractHandlerFactory.java AbstractService.java
donaldp 2002/07/11 18:18:44
Modified: src/java/org/apache/avalon/cornerstone/services/connection
AbstractHandlerFactory.java AbstractService.java
Added: src/java/org/apache/avalon/cornerstone/services/connection
AdaptingComponentManager.java
Log:
Update to decouple from ServiceManager but still support CM for backwards compatability
Revision Changes Path
1.6 +17 -34 jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/services/connection/AbstractHandlerFactory.java
Index: AbstractHandlerFactory.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/services/connection/AbstractHandlerFactory.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AbstractHandlerFactory.java 16 Mar 2002 00:18:35 -0000 1.5
+++ AbstractHandlerFactory.java 12 Jul 2002 01:18:44 -0000 1.6
@@ -7,17 +7,16 @@
*/
package org.apache.avalon.cornerstone.services.connection;
-import org.apache.avalon.framework.activity.Initializable;
-import org.apache.avalon.framework.component.Component;
-import org.apache.avalon.framework.component.ComponentException;
-import org.apache.avalon.framework.component.ComponentManager;
-import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.container.ContainerUtil;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
/**
* Helper class to extend to create handler factorys.
@@ -26,21 +25,21 @@
*/
public abstract class AbstractHandlerFactory
extends AbstractLogEnabled
- implements Component, Contextualizable, Composable, Configurable, ConnectionHandlerFactory
+ implements Contextualizable, Serviceable, Configurable, ConnectionHandlerFactory
{
- protected Context m_context;
- protected ComponentManager m_componentManager;
- protected Configuration m_configuration;
+ private Context m_context;
+ private ServiceManager m_serviceManager;
+ private Configuration m_configuration;
public void contextualize( final Context context )
{
m_context = context;
}
- public void compose( final ComponentManager componentManager )
- throws ComponentException
+ public void service( final ServiceManager serviceManager )
+ throws ServiceException
{
- m_componentManager = componentManager;
+ m_serviceManager = serviceManager;
}
public void configure( final Configuration configuration )
@@ -59,28 +58,12 @@
throws Exception
{
final ConnectionHandler handler = newHandler();
-
- setupLogger( handler );
-
- if( handler instanceof Contextualizable )
- {
- ( (Contextualizable)handler ).contextualize( m_context );
- }
-
- if( handler instanceof Composable )
- {
- ( (Composable)handler ).compose( m_componentManager );
- }
-
- if( handler instanceof Configurable )
- {
- ( (Configurable)handler ).configure( m_configuration );
- }
-
- if( handler instanceof Initializable )
- {
- ( (Initializable)handler ).initialize();
- }
+ ContainerUtil.enableLogging( handler, getLogger() );
+ ContainerUtil.contextualize( handler, m_context );
+ ContainerUtil.service( handler, m_serviceManager );
+ ContainerUtil.compose( handler, new AdaptingComponentManager( m_serviceManager ) );
+ ContainerUtil.configure( handler, m_configuration );
+ ContainerUtil.initialize( handler );
return handler;
}
1.12 +28 -30 jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/services/connection/AbstractService.java
Index: AbstractService.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/services/connection/AbstractService.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- AbstractService.java 20 May 2002 04:13:23 -0000 1.11
+++ AbstractService.java 12 Jul 2002 01:18:44 -0000 1.12
@@ -7,27 +7,28 @@
*/
package org.apache.avalon.cornerstone.services.connection;
+import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
-import java.io.IOException;
import org.apache.avalon.cornerstone.services.sockets.ServerSocketFactory;
import org.apache.avalon.cornerstone.services.sockets.SocketManager;
import org.apache.avalon.cornerstone.services.threads.ThreadManager;
import org.apache.avalon.excalibur.thread.ThreadPool;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
-import org.apache.avalon.framework.component.ComponentException;
-import org.apache.avalon.framework.component.ComponentManager;
-import org.apache.avalon.framework.component.Composable;
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.container.ContainerUtil;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.Logger;
-import org.apache.avalon.phoenix.BlockContext;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.avalon.framework.component.ComponentException;
/**
* Helper class to create protocol services.
@@ -36,7 +37,7 @@
*/
public abstract class AbstractService
extends AbstractLogEnabled
- implements Contextualizable, Composable, Configurable, Initializable, Disposable
+ implements Contextualizable, Serviceable, Configurable, Initializable, Disposable
{
protected ConnectionManager m_connectionManager;
protected SocketManager m_socketManager;
@@ -65,52 +66,47 @@
public void enableLogging( final Logger logger )
{
super.enableLogging( logger );
- setupLogger( m_factory );
+ ContainerUtil.enableLogging( m_factory, logger );
}
public void contextualize( final Context context )
throws ContextException
{
- if( m_factory instanceof Contextualizable )
- {
- ( (Contextualizable)m_factory ).contextualize( context );
- }
+ ContainerUtil.contextualize( m_factory, context );
}
- public void compose( final ComponentManager componentManager )
- throws ComponentException
+ public void service( final ServiceManager serviceManager )
+ throws ServiceException
{
- m_connectionManager = (ConnectionManager)componentManager.lookup( ConnectionManager.ROLE );
- m_socketManager = (SocketManager)componentManager.lookup( SocketManager.ROLE );
- if ( null != getThreadPoolName() )
+ m_connectionManager = (ConnectionManager)serviceManager.lookup( ConnectionManager.ROLE );
+ m_socketManager = (SocketManager)serviceManager.lookup( SocketManager.ROLE );
+ if( null != getThreadPoolName() )
{
m_threadManager =
- (ThreadManager)componentManager.lookup( ThreadManager.ROLE );
+ (ThreadManager)serviceManager.lookup( ThreadManager.ROLE );
m_threadPool = m_threadManager.getThreadPool( getThreadPoolName() );
}
-
- if( m_factory instanceof Composable )
+ ContainerUtil.service( m_factory, serviceManager );
+ try
+ {
+ ContainerUtil.compose( m_factory, new AdaptingComponentManager( serviceManager ) );
+ }
+ catch( final ComponentException ce )
{
- ( (Composable)m_factory ).compose( componentManager );
+ throw new ServiceException( ce.getMessage(), ce );
}
}
public void configure( final Configuration configuration )
throws ConfigurationException
{
- if( m_factory instanceof Configurable )
- {
- ( (Configurable)m_factory ).configure( configuration );
- }
+ ContainerUtil.configure( m_factory, configuration );
}
public void initialize()
throws Exception
{
- if( m_factory instanceof Initializable )
- {
- ( (Initializable)m_factory ).initialize();
- }
+ ContainerUtil.initialize( m_factory );
if( null == m_connectionName )
{
@@ -160,7 +156,8 @@
}
catch( final Exception e )
{
- getLogger().warn( "Error disconnecting", e );
+ final String message = "Error disconnecting";
+ getLogger().warn( message, e );
}
try
@@ -169,7 +166,8 @@
}
catch( final IOException ioe )
{
- getLogger().warn( "Error closing server socket", ioe );
+ final String message = "Error closing server socket";
+ getLogger().warn( message, ioe );
}
}
}
1.1 jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/services/connection/AdaptingComponentManager.java
Index: AdaptingComponentManager.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.avalon.cornerstone.services.connection;
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.ServiceException;
/**
* A simple component manager that adapts from a {@link ServiceManager}
* to a {@link ComponentManager}.
*
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
* @version $Revision: 1.1 $ $Date: 2002/07/12 01:18:44 $
*/
class AdaptingComponentManager
implements ComponentManager
{
private final ServiceManager m_serviceManager;
AdaptingComponentManager( final ServiceManager serviceManager )
{
if( null == serviceManager )
{
throw new NullPointerException( "serviceManager" );
}
m_serviceManager = serviceManager;
}
public Component lookup( final String role )
throws ComponentException
{
try
{
return (Component)m_serviceManager.lookup( role );
}
catch( final ServiceException se )
{
throw new ComponentException( se.getMessage(), se );
}
}
public boolean hasComponent( final String role )
{
return m_serviceManager.hasService( role );
}
public void release( final Component component )
{
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>