incubator-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vin...@apache.org
Subject cvs commit: incubator-altrmi/src/java/org/apache/altrmi/generator BCELProxyGeneratorImpl.java
Date Thu, 26 Jun 2003 04:41:47 GMT
vinayc      2003/06/25 21:41:47

  Modified:    src/java/org/apache/altrmi/generator
                        BCELProxyGeneratorImpl.java
  Log:
  +ed Async support on BCEL generated stubs
  
  Revision  Changes    Path
  1.7       +230 -90   incubator-altrmi/src/java/org/apache/altrmi/generator/BCELProxyGeneratorImpl.java
  
  Index: BCELProxyGeneratorImpl.java
  ===================================================================
  RCS file: /home/cvs/incubator-altrmi/src/java/org/apache/altrmi/generator/BCELProxyGeneratorImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- BCELProxyGeneratorImpl.java	24 Feb 2003 07:14:30 -0000	1.6
  +++ BCELProxyGeneratorImpl.java	26 Jun 2003 04:41:46 -0000	1.7
  @@ -375,7 +375,7 @@
               Method[] methods = getGeneratableMethods(clazz);
               generateEqualsMethod(generatedClassName);
               for (int i = 0; i < methods.length; i++) {
  -                createInterfaceMethod(generatedClassName, methods[i]);
  +                createInterfaceMethod(generatedClassName, methods[i],interfacesToStubify[x]);
               }
   
           }
  @@ -388,7 +388,7 @@
        * @param generatedClassName the bean class name
        * @param mth the method
        */
  -    protected void createInterfaceMethod(String generatedClassName, Method mth) {
  +    protected void createInterfaceMethod(String generatedClassName, Method mth,PublicationDescriptionItem
interfaceToStubify) {
           InstructionList il = new InstructionList();
           MethodGen method =
                   new MethodGen(
  @@ -401,11 +401,12 @@
                           il,
                           m_constantsPool);
   
  +		
           //debug(getArguments(m));
   
           // **** TO Insert TEST Bytecode Inside the stub ,uncomment the subsequent lines
           //if (m_verbose)
  -        //    createTestMethod(il, "calling " + m.getName());
  +        //    createTestMethod(il, "calling " + mth.getName());
   
           /*
            *  Declaration of Arrays
  @@ -437,6 +438,39 @@
           createInterfaceMethodArgs(numberOfArguments, il, variableIndex,
                   paramTypes, generatedClassName);
   
  +		//check if its a rollback  method
  +		InstructionHandle ih_rollback =null;
  +		InstructionHandle catchHandler=null;
  +		BranchInstruction gotoCall =null;
  +		InstructionHandle ih_tryEnd =null;
  +		if(interfaceToStubify.isRollback(mth))
  +		{
  +			ih_rollback = il.append(m_factory.createLoad(Type.OBJECT, 0));
  +			il.append(
  +                m_factory.createFieldAccess(
  +                        generatedClassName,
  +                        "m_proxyHelper",
  +                        new ObjectType("org.apache.altrmi.client.ProxyHelper"),
  +                        Constants.GETFIELD));
  +			il.append(
  +                m_factory.createInvoke(
  +                        "org.apache.altrmi.client.ProxyHelper",
  +                        "rollbackAsyncRequests",
  +                        Type.VOID,
  +                        Type.NO_ARGS,
  +                        Constants.INVOKEINTERFACE));
  +			gotoCall =
  +                        m_factory.createBranchInstruction(Constants.GOTO, null);
  +            ih_tryEnd = il.append(gotoCall);
  +                
  +			catchHandler = il.append(m_factory.createStore(Type.OBJECT, ++variableIndex));
  +			il.append(m_factory.createLoad(Type.OBJECT, variableIndex));
  +			injectCommonExceptionCatchBlock(il,method,variableIndex);	
  +			--variableIndex;
  +			//createTestMethod(il,"after rollback");
  +		}
  +
  +
           /* Within the stub put the
            * Call processObjectRequest on the instance ProxyHelper held within the stub
            * Thus,
  @@ -445,27 +479,39 @@
            * try
            * {
            *      Object retVal = m_proxyHelper.processObjectRequest("foo1(int,
  -                 float, java.lang.String, java.lang.Integer)",args,argClasses);
  +         *        float, java.lang.String, java.lang.Integer)",args,argClasses);
            *      return (java.lang.String) retVal;
            * }
            *  catch (Throwable t)
  -         *     {
  +         *  {
            *         if (t instanceof RuntimeException)
            *         {
            *           throw (RuntimeException) t;
  -         *      } else if (t instanceof Error)
  +         *         } 
  +		 *         else if (t instanceof Error)
            *         {
            *                throw (Error) t;
  -         *      } else
  +         *         }
  +		 *         else
            *         {
            *                t.printStackTrace();
            *                 throw new org.apache.altrmi.client.
  -                               InvocationException("Should never get here:" +t.getMessage());
  -         *      }
  -         *     }
  +         *                      InvocationException("Should never get here:" +t.getMessage());
  +         *         }
  +         *  }
            * ================================================
            */
           InstructionHandle ihe1 = il.append(m_factory.createLoad(Type.OBJECT, 0));
  +		
  +		if(interfaceToStubify.isRollback(mth))
  +		{
  +			gotoCall.setTarget(ihe1);
  +			method.addExceptionHandler(	ih_rollback,
  +										ih_tryEnd,
  +										catchHandler,
  +										new ObjectType("java.lang.Throwable"));
  +		}
  +
           il.append(
                   m_factory.createFieldAccess(
                           generatedClassName,
  @@ -539,7 +585,40 @@
               variableIndex -= 2;
               il.append(m_factory.createLoad(Type.OBJECT, ++variableIndex));
               il.append(m_factory.createLoad(Type.OBJECT, ++variableIndex));
  -            il.append(
  +			//Check for async methods
  +			if( interfaceToStubify.isAsync(mth) )
  +			{
  +					il.append(
  +                    m_factory.createInvoke(
  +                            "org.apache.altrmi.client.ProxyHelper",
  +                            "queueAsyncRequest",
  +                            Type.VOID,
  +                            new Type[]{
  +                                Type.STRING,
  +                                new ArrayType(Type.OBJECT, 1),
  +                                new ArrayType(new ObjectType("java.lang.Class"), 1)},
  +                            Constants.INVOKEINTERFACE));
  +			
  +		      
  +			}
  +			else
  +			{
  +				if(getBCELPrimitiveType(mth.getReturnType().getName()) == Type.VOID )
  +				{
  +					il.append(
  +                    m_factory.createInvoke(
  +                            "org.apache.altrmi.client.ProxyHelper",
  +                            "processVoidRequest",
  +                            Type.VOID,
  +                            new Type[]{
  +                                Type.STRING,
  +                                new ArrayType(Type.OBJECT, 1),
  +                                new ArrayType(new ObjectType("java.lang.Class"), 1)},
  +                            Constants.INVOKEINTERFACE));
  +				}
  +				else
  +				{
  +				il.append(
                       m_factory.createInvoke(
                               "org.apache.altrmi.client.ProxyHelper",
                               "processObjectRequest",
  @@ -549,11 +628,28 @@
                                   new ArrayType(Type.OBJECT, 1),
                                   new ArrayType(new ObjectType("java.lang.Class"), 1)},
                               Constants.INVOKEINTERFACE));
  +				il.append(m_factory.createStore(Type.OBJECT, ++variableIndex));
  +				il.append(m_factory.createLoad(Type.OBJECT, variableIndex));
  +	
  +		     
  +				}
  +			}
           }
  -        il.append(m_factory.createStore(Type.OBJECT, ++variableIndex));
  -        il.append(m_factory.createLoad(Type.OBJECT, variableIndex));
   
  -        InstructionHandle ihe2;
  +		//createTestMethod(il,"after remote call");
  +		
  +		InstructionHandle ihe2;
  +		if(interfaceToStubify.isCommit(mth))
  +		{
  +			
  +			gotoCall =
  +                        m_factory.createBranchInstruction(Constants.GOTO, null);
  +			ihe2	= il.append(gotoCall);
  +			variableIndex++;
  +	
  +		}
  +		else
  +		{
           if (mth.getReturnType().isPrimitive()) {
               if (getBCELPrimitiveType(mth.getReturnType().getName()) == Type.VOID) {
                   ihe2 = il.append(m_factory.createReturn(Type.VOID));
  @@ -576,6 +672,7 @@
                       m_factory.createCheckCast(new ObjectType(mth.getReturnType().getName())));
               ihe2 = il.append(m_factory.createReturn(Type.OBJECT));
           }
  +		}
   
           InstructionHandle ihe3 =
                   il.append(m_factory.createStore(Type.OBJECT, variableIndex));
  @@ -608,85 +705,46 @@
           if (customHandler != null) {
               ifCustomExceptionBranch.setTarget(defaultExceptionHandler);
           }
  -        il.append(
  -                new INSTANCEOF(
  -                        m_constantsPool.addClass(new ObjectType("java.lang.RuntimeException"))));
  -        BranchInstruction b1 = m_factory.createBranchInstruction(Constants.IFEQ, null);
  -        il.append(b1);
  -        il.append(m_factory.createLoad(Type.OBJECT, variableIndex));
  -        il.append(
  -                m_factory.createCheckCast(new ObjectType("java.lang.RuntimeException")));
  -        il.append(InstructionConstants.ATHROW);
  -        InstructionHandle ih1 =
  -                il.append(m_factory.createLoad(Type.OBJECT, variableIndex));
  -        il.append(
  -                new INSTANCEOF(m_constantsPool.addClass(new ObjectType("java.lang.Error"))));
  -        BranchInstruction b2 = m_factory.createBranchInstruction(Constants.IFEQ, null);
  -        il.append(b2);
  -        il.append(m_factory.createLoad(Type.OBJECT, variableIndex));
  -        il.append(m_factory.createCheckCast(new ObjectType("java.lang.Error")));
  -        il.append(InstructionConstants.ATHROW);
  -        InstructionHandle ih2 =
  -                il.append(m_factory.createLoad(Type.OBJECT, variableIndex));
  -        il.append(
  -                m_factory.createInvoke(
  -                        "java.lang.Throwable",
  -                        "printStackTrace",
  -                        Type.VOID,
  -                        Type.NO_ARGS,
  -                        Constants.INVOKEVIRTUAL));
  -        il.append(
  -                m_factory.createNew(
  -                        "org.apache.altrmi.client.InvocationException"));
  -        il.append(InstructionConstants.DUP);
  -        il.append(m_factory.createNew("java.lang.StringBuffer"));
  -        il.append(InstructionConstants.DUP);
  -        il.append(new PUSH(m_constantsPool, "Should never get here: "));
  -        il.append(
  -                m_factory.createInvoke(
  -                        "java.lang.StringBuffer",
  -                        "<init>",
  -                        Type.VOID,
  -                        new Type[]{Type.STRING},
  -                        Constants.INVOKESPECIAL));
  -        il.append(m_factory.createLoad(Type.OBJECT, variableIndex));
  -        il.append(
  -                m_factory.createInvoke(
  -                        "java.lang.Throwable",
  -                        "getMessage",
  -                        Type.STRING,
  -                        Type.NO_ARGS,
  -                        Constants.INVOKEVIRTUAL));
  -        il.append(
  -                m_factory.createInvoke(
  -                        "java.lang.StringBuffer",
  -                        "append",
  -                        Type.STRINGBUFFER,
  -                        new Type[]{Type.STRING},
  -                        Constants.INVOKEVIRTUAL));
  -        il.append(
  -                m_factory.createInvoke(
  -                        "java.lang.StringBuffer",
  -                        "toString",
  -                        Type.STRING,
  -                        Type.NO_ARGS,
  -                        Constants.INVOKEVIRTUAL));
  -        il.append(
  -                m_factory.createInvoke(
  -                        "org.apache.altrmi.client.InvocationException",
  -                        "<init>",
  -                        Type.VOID,
  -                        new Type[]{Type.STRING},
  -                        Constants.INVOKESPECIAL));
  -        il.append(InstructionConstants.ATHROW);
  -
  -        b1.setTarget(ih1);
  -        b2.setTarget(ih2);
  -        method.addExceptionHandler(
  +	
  +		//add standard exception handling routine which handles any 
  +		//other exception generated during the remote call 
  +		injectCommonExceptionCatchBlock(il,method,variableIndex);
  +		
  +		method.addExceptionHandler(
                   ihe1,
                   ihe2,
                   ihe3,
                   new ObjectType("java.lang.Throwable"));
  +		
  +		//check if its a commit method
  +		if(interfaceToStubify.isCommit(mth))
  +		{
  +			InstructionHandle ih_commit= il.append(m_factory.createLoad(Type.OBJECT, 0));
  +			gotoCall.setTarget(ih_commit);
  +			il.append(
  +                m_factory.createFieldAccess(
  +                        generatedClassName,
  +                        "m_proxyHelper",
  +                        new ObjectType("org.apache.altrmi.client.ProxyHelper"),
  +                        Constants.GETFIELD));
  +			
  +			il.append(
  +                m_factory.createInvoke(
  +                        "org.apache.altrmi.client.ProxyHelper",
  +                        "commitAsyncRequests",
  +                        Type.VOID,
  +                        Type.NO_ARGS,
  +                        Constants.INVOKEINTERFACE));
  +			InstructionHandle ih_return = il.append(m_factory.createReturn(Type.VOID));
  +			catchHandler = il.append(m_factory.createStore(Type.OBJECT, variableIndex));
  +			il.append(m_factory.createLoad(Type.OBJECT, variableIndex));
  +			injectCommonExceptionCatchBlock(il,method,variableIndex);	
  +			method.addExceptionHandler(ih_commit,ih_return,catchHandler,new ObjectType("java.lang.Throwable"));
  +		}
  +		
  +
  +		
  +        
           method.setMaxStack();
           method.setMaxLocals();
           m_classGen.addMethod(method.getMethod());
  @@ -836,6 +894,88 @@
           }
       }
   
  +	/**
  +	 * Inject common exception catch blocks 
  +	 */
  +	public void injectCommonExceptionCatchBlock(InstructionList il,MethodGen method,int variableIndex)
  +	{
  +	   il.append(
  +                new INSTANCEOF(
  +                        m_constantsPool.addClass(new ObjectType("java.lang.RuntimeException"))));
  +        BranchInstruction b1 = m_factory.createBranchInstruction(Constants.IFEQ, null);
  +        il.append(b1);
  +        il.append(m_factory.createLoad(Type.OBJECT, variableIndex));
  +        il.append(
  +                m_factory.createCheckCast(new ObjectType("java.lang.RuntimeException")));
  +        il.append(InstructionConstants.ATHROW);
  +        InstructionHandle ih1 =
  +                il.append(m_factory.createLoad(Type.OBJECT, variableIndex));
  +        il.append(
  +                new INSTANCEOF(m_constantsPool.addClass(new ObjectType("java.lang.Error"))));
  +        BranchInstruction b2 = m_factory.createBranchInstruction(Constants.IFEQ, null);
  +        il.append(b2);
  +        il.append(m_factory.createLoad(Type.OBJECT, variableIndex));
  +        il.append(m_factory.createCheckCast(new ObjectType("java.lang.Error")));
  +        il.append(InstructionConstants.ATHROW);
  +        InstructionHandle ih2 =
  +                il.append(m_factory.createLoad(Type.OBJECT, variableIndex));
  +        il.append(
  +                m_factory.createInvoke(
  +                        "java.lang.Throwable",
  +                        "printStackTrace",
  +                        Type.VOID,
  +                        Type.NO_ARGS,
  +                        Constants.INVOKEVIRTUAL));
  +        il.append(
  +                m_factory.createNew(
  +                        "org.apache.altrmi.client.InvocationException"));
  +        il.append(InstructionConstants.DUP);
  +        il.append(m_factory.createNew("java.lang.StringBuffer"));
  +        il.append(InstructionConstants.DUP);
  +        il.append(new PUSH(m_constantsPool, "Should never get here: "));
  +        il.append(
  +                m_factory.createInvoke(
  +                        "java.lang.StringBuffer",
  +                        "<init>",
  +                        Type.VOID,
  +                        new Type[]{Type.STRING},
  +                        Constants.INVOKESPECIAL));
  +        il.append(m_factory.createLoad(Type.OBJECT, variableIndex));
  +        il.append(
  +                m_factory.createInvoke(
  +                        "java.lang.Throwable",
  +                        "getMessage",
  +                        Type.STRING,
  +                        Type.NO_ARGS,
  +                        Constants.INVOKEVIRTUAL));
  +        il.append(
  +                m_factory.createInvoke(
  +                        "java.lang.StringBuffer",
  +                        "append",
  +                        Type.STRINGBUFFER,
  +                        new Type[]{Type.STRING},
  +                        Constants.INVOKEVIRTUAL));
  +        il.append(
  +                m_factory.createInvoke(
  +                        "java.lang.StringBuffer",
  +                        "toString",
  +                        Type.STRING,
  +                        Type.NO_ARGS,
  +                        Constants.INVOKEVIRTUAL));
  +        il.append(
  +                m_factory.createInvoke(
  +                        "org.apache.altrmi.client.InvocationException",
  +                        "<init>",
  +                        Type.VOID,
  +                        new Type[]{Type.STRING},
  +                        Constants.INVOKESPECIAL));
  +        il.append(InstructionConstants.ATHROW);
  +
  +        b1.setTarget(ih1);
  +        b2.setTarget(ih2);
  +     
  +	}
  +	
       /**
        * Method getFreeIndexToStart.
        *     Returns the index to start allocating the subsequent stack variables
  
  
  

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


Mime
View raw message