3 Replies Latest reply on Jun 26, 2009 10:23 AM by rschmid

    how is does seam proxy classes?

    rschmid

      seam actually proxies every class for interception. is there a difference between proxied classes and proxied classes that implement interfaces?? f.e. like in spring where a proxy instance is made implementing all interfaces specified in the class.


      has someone any performance experiences between java.lang.reflect.Proxy vs. cglib or javassist? isn't instantiation over Proxy much faster than bytecode manipulation??


      thanks in advance

        • 1. Re: how is does seam proxy classes?
          jeanluc
          seam actually proxies every class for interception.


          I suppose you actually meant only class that is a Seam component, not every class.


          is there a difference between proxied classes and proxied classes that implement interfaces?? f.e. like in spring where a proxy instance is made implementing all interfaces specified in the class.


          Cglib's proxies don't require an interface. And yes, there is a technical difference, it's not the same thing.


          has someone any performance experiences between java.lang.reflect.Proxy vs. cglib or javassist? isn't instantiation over Proxy much faster than bytecode manipulation??


          Proper benchmarking is delicate, there have been discussions on this topic here and for many the Cglib was faster. In practice, however, the design of the application will overwhelmingly influence performance. If Cglib was significantly slower, it would have been abandoned.



          A quote from Seam in Action, ch 15:



          Why doesn’t Seam support JDK dynamic proxies?
          A JDK dynamic proxy is a dynamically generated class that implements a set of inter-
          faces specified at runtime. A dynamic proxy class can’t be cast to the target bean’s
          class, nor does it provide access to the target bean (i.e., the proxied object). The
          proxy just happens to implement the same interface(s) as the target bean. Cglib prox-
          ies, on the other hand, can be treated more or less like the target bean itself. Cglib
          creates a new concrete class on the fly that is a subclass (in other words, a class
          that extends the target bean’s class). Because Seam needs direct access to the tar-
          get bean to expose it as a Seam component, it’s mandatory that the target bean be
          enhanced using Cglib rather than act through a JDK dynamic proxy.
          • 2. Re: how is does seam proxy classes?
            rschmid

            many thanks for your detailed answer.
            actually my question was a bit imprecise, it seems that you already noticed that. sorry for that, i'll try to do better:


            you can NOT proxy a class that doesn't implement an interface. (you have to make a proxy of one or more of its interface types)
            when you want to proxy a class that doesn't implement an interface you have to use byte code manipulation libraries like javassist, cglib.


            spring can make a difference between this to cases - i.e it can proxy classes using java.lang.reflect.Proxy if the bean does implement an interface - and use cglib in the other cases.


            ------------------------------------------------------


            Does seam handle this two different cases too???
            It seams not - because you get all the time (in both cases) a javassist instance that is instanceof the proxied class. I actually didn't found a conditional or decision in source code.


            if my assumption is true:
            why does seam not handle this 2 cases? it seems to complicated doing those checks all the time
            does it worth it handling this 2 cases? it seems that proxies using java.lang.reflect.Proxy is much slower (2 times) anyway
            does it perform worse if you don't implement interfaces in components? (disregarded software design principles!!!)


            • 3. Re: how is does seam proxy classes?
              rschmid

              sorry, i overread quote from sina (seam in action).
              no further answers needed.