avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mcconn...@apache.org
Subject cvs commit: avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/impl BlockInvocationHandler.java DefaultBlock.java DefaultServiceManager.java
Date Mon, 15 Mar 2004 12:58:43 GMT
mcconnell    2004/03/15 04:58:43

  Modified:    merlin/activation/impl/src/java/org/apache/avalon/activation/impl
                        DefaultBlock.java DefaultServiceManager.java
  Added:       merlin/activation/impl/src/java/org/apache/avalon/activation/impl
                        BlockInvocationHandler.java
  Log:
  Separate the BlocvkInvocationHander from DefaultBlock and update the DefaultServiceManager
to intercept release of references which are in effect releases of singleton block references.
  
  Revision  Changes    Path
  1.3       +1 -106    avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/impl/DefaultBlock.java
  
  Index: DefaultBlock.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/impl/DefaultBlock.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DefaultBlock.java	8 Mar 2004 11:28:35 -0000	1.2
  +++ DefaultBlock.java	15 Mar 2004 12:58:43 -0000	1.3
  @@ -198,111 +198,6 @@
           return (Class[]) list.toArray( new Class[0] );
       }
   
  -   /**
  -    * This makes a dynamic proxy for an object.  The object can be represented
  -    * by one, some or all of it's interfaces.
  -    */
  -    final class BlockInvocationHandler
  -        implements InvocationHandler
  -    {
  -        private final DefaultBlock m_block;
  -        private final Logger m_logger;
  -
  -       /**
  -        * Create a proxy invocation handler.
  -        *
  -        * @param block the underlying block implementation
  -        * @exception if an invocation handler establishment error occurs
  -        */
  -        protected BlockInvocationHandler( final Logger logger, 
  -                                          final DefaultBlock block )
  -            throws Exception
  -        {
  -            if( block == null )
  -            {
  -                throw new NullPointerException( "block" );
  -            }
  -
  -            m_block = block;
  -            m_logger = logger;
  -        }
  -
  -        /**
  -         * Invoke the specified method on underlying object.
  -         * This is called by the proxy object.
  -         *
  -         * @param proxy the proxy object
  -         * @param method the method invoked on proxy object
  -         * @param args the arguments supplied to method
  -         * @return the return value of method
  -         * @throws Throwable if an error occurs
  -         */
  -        public Object invoke( final Object proxy,
  -                final Method method,
  -                final Object[] args )
  -                throws Throwable
  -        {
  -            if( proxy == null ) throw new NullPointerException( "proxy" );
  -            if( method == null ) throw new NullPointerException( "method" );
  -
  -            //
  -            // if the invocation is against java.lang.Object then
  -            // delegate the operation to the block
  -            //
  -
  -            final ContainmentModel model = getContainmentModel();
  -            Class source = method.getDeclaringClass();
  -            ServiceModel service = model.getServiceModel( source );
  -            if( null == service )
  -            {
  -                final String error = 
  -                 "Unable to resolve an provider for the class ["
  -                 + source.getName() 
  -                 + "].";
  -                throw new IllegalStateException( error );
  -            }
  -
  -            DeploymentModel provider = service.getServiceProvider();
  -
  -            //
  -            // resolve the service object from the appliance
  -            // and delegate the invocation to that provider
  -            //
  -
  -            try
  -            {
  -                Object object = provider.resolve();
  -                return method.invoke( object, args );
  -            }
  -            catch( UndeclaredThrowableException e )
  -            {
  -                Throwable cause = e.getUndeclaredThrowable();
  -                if( cause != null ) throw cause;
  -                final String error = 
  -                  "Delegation error raised by: " + m_block;
  -                throw new ApplianceException( error, e );
  -            }
  -            catch( InvocationTargetException e )
  -            {
  -                Throwable cause = e.getTargetException();
  -                if( cause != null ) throw cause;
  -                final String error = 
  -                  "Delegation error raised by: " + m_block;
  -                throw new ApplianceException( error, e );
  -            }
  -            catch( Throwable e )
  -            {
  -                final String error =
  -                  "Composite service resolution failure for the class: '" 
  -                  + method.getDeclaringClass()
  -                  + "' for operation: '" + method.getName()
  -                  + "' in appliance: " + m_block;
  -                throw new ApplianceException( error, e );
  -            }
  -        }
  -    }
  -
  -
       //-------------------------------------------------------------------
       // Object
       //-------------------------------------------------------------------
  
  
  
  1.5       +13 -4     avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/impl/DefaultServiceManager.java
  
  Index: DefaultServiceManager.java
  ===================================================================
  RCS file: /home/cvs/avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/impl/DefaultServiceManager.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DefaultServiceManager.java	8 Mar 2004 11:28:35 -0000	1.4
  +++ DefaultServiceManager.java	15 Mar 2004 12:58:43 -0000	1.5
  @@ -20,6 +20,7 @@
   import java.util.Map;
   import java.util.Hashtable;
   import java.lang.reflect.Proxy;
  +import java.lang.reflect.InvocationHandler;
   
   import org.apache.avalon.activation.TransientApplianceException;
   
  @@ -254,11 +255,19 @@
   
           if( Proxy.isProxyClass( instance.getClass() ) )
           {
  -            ApplianceInvocationHandler handler = 
  -              (ApplianceInvocationHandler) 
  +            InvocationHandler handler = 
                   Proxy.getInvocationHandler( instance );
  -            handler.release();
  -            return;
  +            if( handler instanceof ApplianceInvocationHandler )
  +            { 
  +                ApplianceInvocationHandler aic = 
  +                  (ApplianceInvocationHandler) handler;
  +                aic.release();
  +                return;
  +            }
  +            else if( handler instanceof BlockInvocationHandler )
  +            {
  +                return;
  +            }
           }
   
           //
  
  
  
  1.1                  avalon/merlin/activation/impl/src/java/org/apache/avalon/activation/impl/BlockInvocationHandler.java
  
  Index: BlockInvocationHandler.java
  ===================================================================
  /* 
   * Copyright 2004 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.activation.impl;
  
  import java.lang.reflect.InvocationHandler;
  import java.lang.reflect.InvocationTargetException;
  import java.lang.reflect.Method;
  import java.lang.reflect.Proxy;
  import java.lang.reflect.UndeclaredThrowableException;
  
  import org.apache.avalon.activation.ApplianceException;
  import org.apache.avalon.activation.ApplianceRuntimeException;
  
  import org.apache.avalon.composition.model.DeploymentModel;
  import org.apache.avalon.composition.model.ContainmentModel;
  import org.apache.avalon.composition.model.ServiceModel;
  
  import org.apache.avalon.framework.logger.Logger;
  
  /**
   * This makes a dynamic proxy for an object.  The object can be represented
   * by one, some or all of it's interfaces.
   */
  final class BlockInvocationHandler implements InvocationHandler
  {
      private final DefaultBlock m_block;
      private final Logger m_logger;
  
     /**
      * Create a proxy invocation handler.
      *
      * @param block the underlying block implementation
      * @exception if an invocation handler establishment error occurs
      */
      protected BlockInvocationHandler( 
        final Logger logger, final DefaultBlock block )
        throws Exception
      {
          if( block == null )
          {
              throw new NullPointerException( "block" );
          }
  
          m_block = block;
          m_logger = logger;
      }
  
     /**
      * Invoke the specified method on underlying object.
      * This is called by the proxy object.
      *
      * @param proxy the proxy object
      * @param method the method invoked on proxy object
      * @param args the arguments supplied to method
      * @return the return value of method
      * @throws Throwable if an error occurs
      */
      public Object invoke( final Object proxy,
              final Method method,
              final Object[] args )
              throws Throwable
      {
          if( proxy == null ) throw new NullPointerException( "proxy" );
          if( method == null ) throw new NullPointerException( "method" );
  
          final ContainmentModel model = m_block.getContainmentModel();
          Class source = method.getDeclaringClass();
          ServiceModel service = model.getServiceModel( source );
          if( null == service )
          {
              final String error = 
               "Unable to resolve an provider for the class ["
               + source.getName() 
               + "].";
              throw new IllegalStateException( error );
          }
  
          DeploymentModel provider = service.getServiceProvider();
  
          //
          // resolve the service object from the appliance
          // and delegate the invocation to that provider
          //
  
          try
          {
              Object object = provider.resolve();
              return method.invoke( object, args );
          }
          catch( UndeclaredThrowableException e )
          {
              Throwable cause = e.getUndeclaredThrowable();
              if( cause != null ) throw cause;
              final String error = 
                "Delegation error raised by: " + m_block;
              throw new ApplianceException( error, e );
          }
          catch( InvocationTargetException e )
          {
              Throwable cause = e.getTargetException();
              if( cause != null ) throw cause;
              final String error = 
                "Delegation error raised by: " + m_block;
              throw new ApplianceException( error, e );
          }
          catch( Throwable e )
          {
              final String error =
                "Composite service resolution failure for the class: '" 
                + method.getDeclaringClass()
                + "' for operation: '" + method.getName()
                + "' in appliance: " + m_block;
              throw new ApplianceException( error, e );
          }
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org


Mime
View raw message