3 Replies Latest reply on Feb 12, 2004 9:14 AM by jae

    how do the proxy classes work - ie Block/BlockSupport

    jae Master

      the BlockSupport class implements all the same methods that the Block class does, yet it does not implement the Block interface.

      i also see this line of code in the BlockModule

      Block proxy = (Block) BlockSupport.CONSTRUCTOR.newInstance(new Object[]{handler});
      


      my questions are as follows:

      1) does using the proxy in this manner prevent the class from implementing the interface?

      2) how exactly does this work such that the data contained in the BlockSupport object can be extracted via the Block interface?

        • 1. Re: how do the proxy classes work - ie Block/BlockSupport
          Viet Master

          this is a dynamic proxy that wraps the block support, the handler goes through the MBean server to call the actual block.

          for instance : proxy.setSide(0) will do :

          proxy.setSide(0)
          -> invocationHandler.invoke(m, new Object[]{new Integer(0)}
          -> server.setAttribute("Side", new Integer(0));
          -> block.setSide(0)

          you would say me, what the interest of that ? instead of giving the actual reference of the block ?

          the interest is that is the you undeploy the block, it does it nicely because the proxy client does not have a reference on the class.

          • 2. Re: how do the proxy classes work - ie Block/BlockSupport
            Viet Master

            BTW, this would not prevent BlockSupport from implementing Block and we could do that indeed from the OO design standpoint, but it is not important.

            • 3. Re: how do the proxy classes work - ie Block/BlockSupport
              jae Master

              cool - thanks for that explination. i definately see the value in using the dynamic proxy. i just don't have a lot of experience using them, hence my question.

              it may be better in the long run to have the Support modules implement the interfaces b/c it would help clear up any confusion on where the implementation comes from, and also guarentee that both classes are kept in sync for new method additions.