You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hivemind.apache.org by James Carman <ja...@carmanconsulting.com> on 2004/06/30 04:21:03 UTC

JDK Proxy Example...

Is there a good example of how to use a JDK proxy (or an InvocationHandler)
as an interceptor?  I couldn't find anything in the download that I have.  



---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org


RE: JDK Proxy Example...

Posted by James Carman <ja...@carmanconsulting.com>.
If you guys like my MethodInterceptor and MethodProxy approach, I could
contribute some code.  I still need to figure out how to get my
configuration rules to start setting properties on the actual instance
that's created, but other than that it works just fine.  Anyone have any
objections to the API or suggestions on how I could name it differently so
that we don't look like we're ripping off from CGLIB?  :-)



-----Original Message-----
From: Howard Lewis Ship [mailto:hlship@gmail.com] 
Sent: Wednesday, June 30, 2004 2:25 PM
To: hivemind-dev@jakarta.apache.org
Subject: Re: JDK Proxy Example...

It would be nice to scrap the current interceptors guide (which is not
only heavy on Javassist, but completely out of date) and replace it
with a similar example that used JDK proxies and discussed more
powerful techniques.

Any volunteers? I'm maxxed out.

On Wed, 30 Jun 2004 14:07:04 -0400, James Carman
<ja...@carmanconsulting.com> wrote:
> I wasn't suggesting USING CGLIB (but I can see where a new
> CglibServiceInterceptorFactory could be useful for those who are familiar
> with it) or any of the classes in it, but just to borrow some ideas from
it.
> We could re-use the InvocationDecorator classes that I presented in my
> JavaWorld article
> (http://www.javaworld.com/javaworld/jw-07-2003/jw-0718-factory.html).  It
> does essentially the same thing.  I REALLY think if you want HiveMind to
be
> accepted by the general java developer that this interceptor process needs
> to be simplified.  That's not to say that we get rid of the Javassist
stuff,
> but it shouldn't be the only mechanism supported by HiveMind
> "out-of-the-box", nor should it (IMHO) be the only approach demonstrated
in
> the documentation.  I would think that a pure Java approach should be
given
> in the documentation and put the Javassist/CGLIB like approaches in an
> "Advanced Concepts" section or something.  My $0.02, the pure Java
approach
> should be just as much of the core framework as the Javassist one.
> 
> 
> 
> 
> -----Original Message-----
> From: Howard Lewis Ship [mailto:hlship@gmail.com]
> Sent: Wednesday, June 30, 2004 12:10 PM
> To: hivemind-dev@jakarta.apache.org
> Subject: Re: JDK Proxy Example...
> 
> It's all accoding to taste and HiveMind doesn't care. I believe the
> Javassist approach is more performant, but you have to wrap your mind
> around meta- (and meta-meta-) coding.
> 
> Perhaps we should create an "examples" library (hivemind.examples) to
> contain these types of things?  I'd also like to get a "contributions"
> library (hivemind.contrib) to contain useful stuff.  However, there's
> the issue of getting a CLA for any contribution, and the necessity of
> avoiding dependencies on GPL/LGPL code (BSD, MPL, etc. are ok).
> 
> ----- Original Message -----
> From: Pablo Lalloni <pl...@afip.gov.ar>
> Date: Wed, 30 Jun 2004 12:42:13 -0300
> Subject: RE: JDK Proxy Example...
> To: hivemind-dev@jakarta.apache.org
> 
> I fully agree with James here, I've been writing some intercetpor
> stuff and it has been quite annoying compared with previous work I've
> done using Nanning and/or AspectWerkz...
> 
> I think Nanning's way to do things is very pleasant, maybe we can
> borrow some idioms from there.
> 
> I haven't used CGLIB directly but seems to be in the same direction.
> 
> El mié, 30-06-2004 a las 11:57, James Carman escribió:
> 
> Maybe we could include a factory for creating JDK proxy-like interceptors.
> Maybe borrow an idea from CGLIB (MethodInterceptor and MethodProxy for
> example).  That's how I implemented mine.  I got VERY confused when trying
> to write that javassist stuff and I'm quite an adept Java
> developer/architect.  I just don't think it's going to be an easy sell for
> people when they see that they have to write that javassist stuff when
> writing interceptors.  If they could write it in pure Java and let the
> compiler/IDE help them along, it'd be much easier, IMHO.  Right now,
there's
> nothing "baked in" that facilitates this.  I'll send you my stuff once I
get
> it working.  I'm still trying to get my contribution rules working the way
I
> want them, so you can set properties on your MethodInterceptor
> implementation.  Here's kind of what I had in mind so far...
> 
> public interface MethodInterceptor
> {
>    public Object intercept( Method method,
>                             Object[] args,
>                             MethodProxy chain ) throws Throwable;
> }
> 
> public class MethodProxy
> {
>    private final Object target;
> 
>    MethodProxy( Object target )
>    {
>        this.target = target;
>    }
> 
>    public Object invoke( Method method, Object[] args ) throws Throwable
>    {
>        return method.invoke( target, args );
>    }
> }
> 
> I want to be able to create an interceptor by doing...
> 
> interceptor (service-id="MethodInterceptor")
> {
>  method-interceptor (class="mypackage.MyInterceptorImplementation")
>  {
>    set-property (name="foo" value="bar")
>  }
> }
> 
> or something along those lines.  How does this sound?
> 
> -----Original Message-----
> From: Howard Lewis Ship [mailto:hlship@gmail.com]
> Sent: Tuesday, June 29, 2004 10:55 PM
> To: hivemind-dev@jakarta.apache.org
> Subject: Re: JDK Proxy Example...
> 
> I think some of the unit tests make use of JDK proxy instead of Javassist.
> 
> On Tue, 29 Jun 2004 22:21:03 -0400, James Carman
> <ja...@carmanconsulting.com> wrote:
> >
> > Is there a good example of how to use a JDK proxy (or an
> InvocationHandler)
> > as an interceptor?  I couldn't find anything in the download that I
have.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org
> >
> >
> 
> --
> Howard M. Lewis Ship
> Independent J2EE / Open-Source Java Consultant
> Creator, Jakarta Tapestry
> Creator, Jakarta HiveMind
> http://howardlewisship.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org
> 
> 


-- 
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Jakarta Tapestry
Creator, Jakarta HiveMind
http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org


Re: JDK Proxy Example...

Posted by Howard Lewis Ship <hl...@gmail.com>.
I'm looking forward to the article ... do you need me to proof read
it? I can spare an hour or two for a good cause!

On Wed, 30 Jun 2004 14:40:57 -0400, James Carman
<ja...@carmanconsulting.com> wrote:
> Oh, if you are asking for somebody to work on an interceptors guide, I guess
> I could just create one as part of my TSS article and we could use that.
> Any thoughts?  My article is due (1st draft) on August 1st.
> 
> 
> 
> -----Original Message-----
> From: Howard Lewis Ship [mailto:hlship@gmail.com]
> Sent: Wednesday, June 30, 2004 2:25 PM
> To: hivemind-dev@jakarta.apache.org
> Subject: Re: JDK Proxy Example...
> 
> It would be nice to scrap the current interceptors guide (which is not
> only heavy on Javassist, but completely out of date) and replace it
> with a similar example that used JDK proxies and discussed more
> powerful techniques.
> 
> Any volunteers? I'm maxxed out.
> 
> On Wed, 30 Jun 2004 14:07:04 -0400, James Carman
> <ja...@carmanconsulting.com> wrote:
> > I wasn't suggesting USING CGLIB (but I can see where a new
> > CglibServiceInterceptorFactory could be useful for those who are familiar
> > with it) or any of the classes in it, but just to borrow some ideas from
> it.
> > We could re-use the InvocationDecorator classes that I presented in my
> > JavaWorld article
> > (http://www.javaworld.com/javaworld/jw-07-2003/jw-0718-factory.html).  It
> > does essentially the same thing.  I REALLY think if you want HiveMind to
> be
> > accepted by the general java developer that this interceptor process needs
> > to be simplified.  That's not to say that we get rid of the Javassist
> stuff,
> > but it shouldn't be the only mechanism supported by HiveMind
> > "out-of-the-box", nor should it (IMHO) be the only approach demonstrated
> in
> > the documentation.  I would think that a pure Java approach should be
> given
> > in the documentation and put the Javassist/CGLIB like approaches in an
> > "Advanced Concepts" section or something.  My $0.02, the pure Java
> approach
> > should be just as much of the core framework as the Javassist one.
> >
> >
> >
> >
> > -----Original Message-----
> > From: Howard Lewis Ship [mailto:hlship@gmail.com]
> > Sent: Wednesday, June 30, 2004 12:10 PM
> > To: hivemind-dev@jakarta.apache.org
> > Subject: Re: JDK Proxy Example...
> >
> > It's all accoding to taste and HiveMind doesn't care. I believe the
> > Javassist approach is more performant, but you have to wrap your mind
> > around meta- (and meta-meta-) coding.
> >
> > Perhaps we should create an "examples" library (hivemind.examples) to
> > contain these types of things?  I'd also like to get a "contributions"
> > library (hivemind.contrib) to contain useful stuff.  However, there's
> > the issue of getting a CLA for any contribution, and the necessity of
> > avoiding dependencies on GPL/LGPL code (BSD, MPL, etc. are ok).
> >
> > ----- Original Message -----
> > From: Pablo Lalloni <pl...@afip.gov.ar>
> > Date: Wed, 30 Jun 2004 12:42:13 -0300
> > Subject: RE: JDK Proxy Example...
> > To: hivemind-dev@jakarta.apache.org
> >
> > I fully agree with James here, I've been writing some intercetpor
> > stuff and it has been quite annoying compared with previous work I've
> > done using Nanning and/or AspectWerkz...
> >
> > I think Nanning's way to do things is very pleasant, maybe we can
> > borrow some idioms from there.
> >
> > I haven't used CGLIB directly but seems to be in the same direction.
> >
> > El mié, 30-06-2004 a las 11:57, James Carman escribió:
> >
> > Maybe we could include a factory for creating JDK proxy-like interceptors.
> > Maybe borrow an idea from CGLIB (MethodInterceptor and MethodProxy for
> > example).  That's how I implemented mine.  I got VERY confused when trying
> > to write that javassist stuff and I'm quite an adept Java
> > developer/architect.  I just don't think it's going to be an easy sell for
> > people when they see that they have to write that javassist stuff when
> > writing interceptors.  If they could write it in pure Java and let the
> > compiler/IDE help them along, it'd be much easier, IMHO.  Right now,
> there's
> > nothing "baked in" that facilitates this.  I'll send you my stuff once I
> get
> > it working.  I'm still trying to get my contribution rules working the way
> I
> > want them, so you can set properties on your MethodInterceptor
> > implementation.  Here's kind of what I had in mind so far...
> >
> > public interface MethodInterceptor
> > {
> >    public Object intercept( Method method,
> >                             Object[] args,
> >                             MethodProxy chain ) throws Throwable;
> > }
> >
> > public class MethodProxy
> > {
> >    private final Object target;
> >
> >    MethodProxy( Object target )
> >    {
> >        this.target = target;
> >    }
> >
> >    public Object invoke( Method method, Object[] args ) throws Throwable
> >    {
> >        return method.invoke( target, args );
> >    }
> > }
> >
> > I want to be able to create an interceptor by doing...
> >
> > interceptor (service-id="MethodInterceptor")
> > {
> >  method-interceptor (class="mypackage.MyInterceptorImplementation")
> >  {
> >    set-property (name="foo" value="bar")
> >  }
> > }
> >
> > or something along those lines.  How does this sound?
> >
> > -----Original Message-----
> > From: Howard Lewis Ship [mailto:hlship@gmail.com]
> > Sent: Tuesday, June 29, 2004 10:55 PM
> > To: hivemind-dev@jakarta.apache.org
> > Subject: Re: JDK Proxy Example...
> >
> > I think some of the unit tests make use of JDK proxy instead of Javassist.
> >
> > On Tue, 29 Jun 2004 22:21:03 -0400, James Carman
> > <ja...@carmanconsulting.com> wrote:
> > >
> > > Is there a good example of how to use a JDK proxy (or an
> > InvocationHandler)
> > > as an interceptor?  I couldn't find anything in the download that I
> have.
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org
> > >
> > >
> >
> > --
> > Howard M. Lewis Ship
> > Independent J2EE / Open-Source Java Consultant
> > Creator, Jakarta Tapestry
> > Creator, Jakarta HiveMind
> > http://howardlewisship.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org
> >
> >
> 
> --
> Howard M. Lewis Ship
> Independent J2EE / Open-Source Java Consultant
> Creator, Jakarta Tapestry
> Creator, Jakarta HiveMind
> http://howardlewisship.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org
> 
> 


-- 
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Jakarta Tapestry
Creator, Jakarta HiveMind
http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org


RE: JDK Proxy Example...

Posted by James Carman <ja...@carmanconsulting.com>.
Oh, if you are asking for somebody to work on an interceptors guide, I guess
I could just create one as part of my TSS article and we could use that.
Any thoughts?  My article is due (1st draft) on August 1st.

-----Original Message-----
From: Howard Lewis Ship [mailto:hlship@gmail.com] 
Sent: Wednesday, June 30, 2004 2:25 PM
To: hivemind-dev@jakarta.apache.org
Subject: Re: JDK Proxy Example...

It would be nice to scrap the current interceptors guide (which is not
only heavy on Javassist, but completely out of date) and replace it
with a similar example that used JDK proxies and discussed more
powerful techniques.

Any volunteers? I'm maxxed out.

On Wed, 30 Jun 2004 14:07:04 -0400, James Carman
<ja...@carmanconsulting.com> wrote:
> I wasn't suggesting USING CGLIB (but I can see where a new
> CglibServiceInterceptorFactory could be useful for those who are familiar
> with it) or any of the classes in it, but just to borrow some ideas from
it.
> We could re-use the InvocationDecorator classes that I presented in my
> JavaWorld article
> (http://www.javaworld.com/javaworld/jw-07-2003/jw-0718-factory.html).  It
> does essentially the same thing.  I REALLY think if you want HiveMind to
be
> accepted by the general java developer that this interceptor process needs
> to be simplified.  That's not to say that we get rid of the Javassist
stuff,
> but it shouldn't be the only mechanism supported by HiveMind
> "out-of-the-box", nor should it (IMHO) be the only approach demonstrated
in
> the documentation.  I would think that a pure Java approach should be
given
> in the documentation and put the Javassist/CGLIB like approaches in an
> "Advanced Concepts" section or something.  My $0.02, the pure Java
approach
> should be just as much of the core framework as the Javassist one.
> 
> 
> 
> 
> -----Original Message-----
> From: Howard Lewis Ship [mailto:hlship@gmail.com]
> Sent: Wednesday, June 30, 2004 12:10 PM
> To: hivemind-dev@jakarta.apache.org
> Subject: Re: JDK Proxy Example...
> 
> It's all accoding to taste and HiveMind doesn't care. I believe the
> Javassist approach is more performant, but you have to wrap your mind
> around meta- (and meta-meta-) coding.
> 
> Perhaps we should create an "examples" library (hivemind.examples) to
> contain these types of things?  I'd also like to get a "contributions"
> library (hivemind.contrib) to contain useful stuff.  However, there's
> the issue of getting a CLA for any contribution, and the necessity of
> avoiding dependencies on GPL/LGPL code (BSD, MPL, etc. are ok).
> 
> ----- Original Message -----
> From: Pablo Lalloni <pl...@afip.gov.ar>
> Date: Wed, 30 Jun 2004 12:42:13 -0300
> Subject: RE: JDK Proxy Example...
> To: hivemind-dev@jakarta.apache.org
> 
> I fully agree with James here, I've been writing some intercetpor
> stuff and it has been quite annoying compared with previous work I've
> done using Nanning and/or AspectWerkz...
> 
> I think Nanning's way to do things is very pleasant, maybe we can
> borrow some idioms from there.
> 
> I haven't used CGLIB directly but seems to be in the same direction.
> 
> El mié, 30-06-2004 a las 11:57, James Carman escribió:
> 
> Maybe we could include a factory for creating JDK proxy-like interceptors.
> Maybe borrow an idea from CGLIB (MethodInterceptor and MethodProxy for
> example).  That's how I implemented mine.  I got VERY confused when trying
> to write that javassist stuff and I'm quite an adept Java
> developer/architect.  I just don't think it's going to be an easy sell for
> people when they see that they have to write that javassist stuff when
> writing interceptors.  If they could write it in pure Java and let the
> compiler/IDE help them along, it'd be much easier, IMHO.  Right now,
there's
> nothing "baked in" that facilitates this.  I'll send you my stuff once I
get
> it working.  I'm still trying to get my contribution rules working the way
I
> want them, so you can set properties on your MethodInterceptor
> implementation.  Here's kind of what I had in mind so far...
> 
> public interface MethodInterceptor
> {
>    public Object intercept( Method method,
>                             Object[] args,
>                             MethodProxy chain ) throws Throwable;
> }
> 
> public class MethodProxy
> {
>    private final Object target;
> 
>    MethodProxy( Object target )
>    {
>        this.target = target;
>    }
> 
>    public Object invoke( Method method, Object[] args ) throws Throwable
>    {
>        return method.invoke( target, args );
>    }
> }
> 
> I want to be able to create an interceptor by doing...
> 
> interceptor (service-id="MethodInterceptor")
> {
>  method-interceptor (class="mypackage.MyInterceptorImplementation")
>  {
>    set-property (name="foo" value="bar")
>  }
> }
> 
> or something along those lines.  How does this sound?
> 
> -----Original Message-----
> From: Howard Lewis Ship [mailto:hlship@gmail.com]
> Sent: Tuesday, June 29, 2004 10:55 PM
> To: hivemind-dev@jakarta.apache.org
> Subject: Re: JDK Proxy Example...
> 
> I think some of the unit tests make use of JDK proxy instead of Javassist.
> 
> On Tue, 29 Jun 2004 22:21:03 -0400, James Carman
> <ja...@carmanconsulting.com> wrote:
> >
> > Is there a good example of how to use a JDK proxy (or an
> InvocationHandler)
> > as an interceptor?  I couldn't find anything in the download that I
have.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org
> >
> >
> 
> --
> Howard M. Lewis Ship
> Independent J2EE / Open-Source Java Consultant
> Creator, Jakarta Tapestry
> Creator, Jakarta HiveMind
> http://howardlewisship.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org
> 
> 


-- 
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Jakarta Tapestry
Creator, Jakarta HiveMind
http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org


Re: JDK Proxy Example...

Posted by Howard Lewis Ship <hl...@gmail.com>.
It would be nice to scrap the current interceptors guide (which is not
only heavy on Javassist, but completely out of date) and replace it
with a similar example that used JDK proxies and discussed more
powerful techniques.

Any volunteers? I'm maxxed out.

On Wed, 30 Jun 2004 14:07:04 -0400, James Carman
<ja...@carmanconsulting.com> wrote:
> I wasn't suggesting USING CGLIB (but I can see where a new
> CglibServiceInterceptorFactory could be useful for those who are familiar
> with it) or any of the classes in it, but just to borrow some ideas from it.
> We could re-use the InvocationDecorator classes that I presented in my
> JavaWorld article
> (http://www.javaworld.com/javaworld/jw-07-2003/jw-0718-factory.html).  It
> does essentially the same thing.  I REALLY think if you want HiveMind to be
> accepted by the general java developer that this interceptor process needs
> to be simplified.  That's not to say that we get rid of the Javassist stuff,
> but it shouldn't be the only mechanism supported by HiveMind
> "out-of-the-box", nor should it (IMHO) be the only approach demonstrated in
> the documentation.  I would think that a pure Java approach should be given
> in the documentation and put the Javassist/CGLIB like approaches in an
> "Advanced Concepts" section or something.  My $0.02, the pure Java approach
> should be just as much of the core framework as the Javassist one.
> 
> 
> 
> 
> -----Original Message-----
> From: Howard Lewis Ship [mailto:hlship@gmail.com]
> Sent: Wednesday, June 30, 2004 12:10 PM
> To: hivemind-dev@jakarta.apache.org
> Subject: Re: JDK Proxy Example...
> 
> It's all accoding to taste and HiveMind doesn't care. I believe the
> Javassist approach is more performant, but you have to wrap your mind
> around meta- (and meta-meta-) coding.
> 
> Perhaps we should create an "examples" library (hivemind.examples) to
> contain these types of things?  I'd also like to get a "contributions"
> library (hivemind.contrib) to contain useful stuff.  However, there's
> the issue of getting a CLA for any contribution, and the necessity of
> avoiding dependencies on GPL/LGPL code (BSD, MPL, etc. are ok).
> 
> ----- Original Message -----
> From: Pablo Lalloni <pl...@afip.gov.ar>
> Date: Wed, 30 Jun 2004 12:42:13 -0300
> Subject: RE: JDK Proxy Example...
> To: hivemind-dev@jakarta.apache.org
> 
> I fully agree with James here, I've been writing some intercetpor
> stuff and it has been quite annoying compared with previous work I've
> done using Nanning and/or AspectWerkz...
> 
> I think Nanning's way to do things is very pleasant, maybe we can
> borrow some idioms from there.
> 
> I haven't used CGLIB directly but seems to be in the same direction.
> 
> El mié, 30-06-2004 a las 11:57, James Carman escribió:
> 
> Maybe we could include a factory for creating JDK proxy-like interceptors.
> Maybe borrow an idea from CGLIB (MethodInterceptor and MethodProxy for
> example).  That's how I implemented mine.  I got VERY confused when trying
> to write that javassist stuff and I'm quite an adept Java
> developer/architect.  I just don't think it's going to be an easy sell for
> people when they see that they have to write that javassist stuff when
> writing interceptors.  If they could write it in pure Java and let the
> compiler/IDE help them along, it'd be much easier, IMHO.  Right now, there's
> nothing "baked in" that facilitates this.  I'll send you my stuff once I get
> it working.  I'm still trying to get my contribution rules working the way I
> want them, so you can set properties on your MethodInterceptor
> implementation.  Here's kind of what I had in mind so far...
> 
> public interface MethodInterceptor
> {
>    public Object intercept( Method method,
>                             Object[] args,
>                             MethodProxy chain ) throws Throwable;
> }
> 
> public class MethodProxy
> {
>    private final Object target;
> 
>    MethodProxy( Object target )
>    {
>        this.target = target;
>    }
> 
>    public Object invoke( Method method, Object[] args ) throws Throwable
>    {
>        return method.invoke( target, args );
>    }
> }
> 
> I want to be able to create an interceptor by doing...
> 
> interceptor (service-id="MethodInterceptor")
> {
>  method-interceptor (class="mypackage.MyInterceptorImplementation")
>  {
>    set-property (name="foo" value="bar")
>  }
> }
> 
> or something along those lines.  How does this sound?
> 
> -----Original Message-----
> From: Howard Lewis Ship [mailto:hlship@gmail.com]
> Sent: Tuesday, June 29, 2004 10:55 PM
> To: hivemind-dev@jakarta.apache.org
> Subject: Re: JDK Proxy Example...
> 
> I think some of the unit tests make use of JDK proxy instead of Javassist.
> 
> On Tue, 29 Jun 2004 22:21:03 -0400, James Carman
> <ja...@carmanconsulting.com> wrote:
> >
> > Is there a good example of how to use a JDK proxy (or an
> InvocationHandler)
> > as an interceptor?  I couldn't find anything in the download that I have.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org
> >
> >
> 
> --
> Howard M. Lewis Ship
> Independent J2EE / Open-Source Java Consultant
> Creator, Jakarta Tapestry
> Creator, Jakarta HiveMind
> http://howardlewisship.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org
> 
> 


-- 
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Jakarta Tapestry
Creator, Jakarta HiveMind
http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org


RE: JDK Proxy Example...

Posted by James Carman <ja...@carmanconsulting.com>.
I wasn’t suggesting USING CGLIB (but I can see where a new
CglibServiceInterceptorFactory could be useful for those who are familiar
with it) or any of the classes in it, but just to borrow some ideas from it.
We could re-use the InvocationDecorator classes that I presented in my
JavaWorld article
(http://www.javaworld.com/javaworld/jw-07-2003/jw-0718-factory.html).  It
does essentially the same thing.  I REALLY think if you want HiveMind to be
accepted by the general java developer that this interceptor process needs
to be simplified.  That's not to say that we get rid of the Javassist stuff,
but it shouldn't be the only mechanism supported by HiveMind
"out-of-the-box", nor should it (IMHO) be the only approach demonstrated in
the documentation.  I would think that a pure Java approach should be given
in the documentation and put the Javassist/CGLIB like approaches in an
"Advanced Concepts" section or something.  My $0.02, the pure Java approach
should be just as much of the core framework as the Javassist one.


-----Original Message-----
From: Howard Lewis Ship [mailto:hlship@gmail.com] 
Sent: Wednesday, June 30, 2004 12:10 PM
To: hivemind-dev@jakarta.apache.org
Subject: Re: JDK Proxy Example...

It's all accoding to taste and HiveMind doesn't care. I believe the
Javassist approach is more performant, but you have to wrap your mind
around meta- (and meta-meta-) coding.

Perhaps we should create an "examples" library (hivemind.examples) to
contain these types of things?  I'd also like to get a "contributions"
library (hivemind.contrib) to contain useful stuff.  However, there's
the issue of getting a CLA for any contribution, and the necessity of
avoiding dependencies on GPL/LGPL code (BSD, MPL, etc. are ok).


----- Original Message -----
From: Pablo Lalloni <pl...@afip.gov.ar>
Date: Wed, 30 Jun 2004 12:42:13 -0300
Subject: RE: JDK Proxy Example...
To: hivemind-dev@jakarta.apache.org

I fully agree with James here, I've been writing some intercetpor
stuff and it has been quite annoying compared with previous work I've
done using Nanning and/or AspectWerkz...

I think Nanning's way to do things is very pleasant, maybe we can
borrow some idioms from there.

I haven't used CGLIB directly but seems to be in the same direction.

El mié, 30-06-2004 a las 11:57, James Carman escribió: 


Maybe we could include a factory for creating JDK proxy-like interceptors.
Maybe borrow an idea from CGLIB (MethodInterceptor and MethodProxy for
example).  That's how I implemented mine.  I got VERY confused when trying
to write that javassist stuff and I'm quite an adept Java
developer/architect.  I just don't think it's going to be an easy sell for
people when they see that they have to write that javassist stuff when
writing interceptors.  If they could write it in pure Java and let the
compiler/IDE help them along, it'd be much easier, IMHO.  Right now, there's
nothing "baked in" that facilitates this.  I'll send you my stuff once I get
it working.  I'm still trying to get my contribution rules working the way I
want them, so you can set properties on your MethodInterceptor
implementation.  Here's kind of what I had in mind so far...

public interface MethodInterceptor
{
    public Object intercept( Method method, 
                             Object[] args, 
                             MethodProxy chain ) throws Throwable;
}


public class MethodProxy
{
    private final Object target;

    MethodProxy( Object target )
    {
        this.target = target;
    }

    public Object invoke( Method method, Object[] args ) throws Throwable
    {
        return method.invoke( target, args );
    }
}

I want to be able to create an interceptor by doing...

interceptor (service-id="MethodInterceptor")
{
  method-interceptor (class="mypackage.MyInterceptorImplementation")
  {
    set-property (name="foo" value="bar")
  }
}

or something along those lines.  How does this sound?


-----Original Message-----
From: Howard Lewis Ship [mailto:hlship@gmail.com] 
Sent: Tuesday, June 29, 2004 10:55 PM
To: hivemind-dev@jakarta.apache.org
Subject: Re: JDK Proxy Example...

I think some of the unit tests make use of JDK proxy instead of Javassist.

On Tue, 29 Jun 2004 22:21:03 -0400, James Carman
<ja...@carmanconsulting.com> wrote:
> 
> Is there a good example of how to use a JDK proxy (or an
InvocationHandler)
> as an interceptor?  I couldn't find anything in the download that I have.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org
> 
> 



-- 
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Jakarta Tapestry
Creator, Jakarta HiveMind
http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org


Re: JDK Proxy Example...

Posted by Howard Lewis Ship <hl...@gmail.com>.
It's all accoding to taste and HiveMind doesn't care. I believe the
Javassist approach is more performant, but you have to wrap your mind
around meta- (and meta-meta-) coding.

Perhaps we should create an "examples" library (hivemind.examples) to
contain these types of things?  I'd also like to get a "contributions"
library (hivemind.contrib) to contain useful stuff.  However, there's
the issue of getting a CLA for any contribution, and the necessity of
avoiding dependencies on GPL/LGPL code (BSD, MPL, etc. are ok).


----- Original Message -----
From: Pablo Lalloni <pl...@afip.gov.ar>
Date: Wed, 30 Jun 2004 12:42:13 -0300
Subject: RE: JDK Proxy Example...
To: hivemind-dev@jakarta.apache.org

I fully agree with James here, I've been writing some intercetpor
stuff and it has been quite annoying compared with previous work I've
done using Nanning and/or AspectWerkz...

I think Nanning's way to do things is very pleasant, maybe we can
borrow some idioms from there.

I haven't used CGLIB directly but seems to be in the same direction.

El mié, 30-06-2004 a las 11:57, James Carman escribió: 


Maybe we could include a factory for creating JDK proxy-like interceptors.
Maybe borrow an idea from CGLIB (MethodInterceptor and MethodProxy for
example).  That's how I implemented mine.  I got VERY confused when trying
to write that javassist stuff and I'm quite an adept Java
developer/architect.  I just don't think it's going to be an easy sell for
people when they see that they have to write that javassist stuff when
writing interceptors.  If they could write it in pure Java and let the
compiler/IDE help them along, it'd be much easier, IMHO.  Right now, there's
nothing "baked in" that facilitates this.  I'll send you my stuff once I get
it working.  I'm still trying to get my contribution rules working the way I
want them, so you can set properties on your MethodInterceptor
implementation.  Here's kind of what I had in mind so far...

public interface MethodInterceptor
{
    public Object intercept( Method method, 
                             Object[] args, 
                             MethodProxy chain ) throws Throwable;
}


public class MethodProxy
{
    private final Object target;

    MethodProxy( Object target )
    {
        this.target = target;
    }

    public Object invoke( Method method, Object[] args ) throws Throwable
    {
        return method.invoke( target, args );
    }
}

I want to be able to create an interceptor by doing...

interceptor (service-id="MethodInterceptor")
{
  method-interceptor (class="mypackage.MyInterceptorImplementation")
  {
    set-property (name="foo" value="bar")
  }
}

or something along those lines.  How does this sound?


-----Original Message-----
From: Howard Lewis Ship [mailto:hlship@gmail.com] 
Sent: Tuesday, June 29, 2004 10:55 PM
To: hivemind-dev@jakarta.apache.org
Subject: Re: JDK Proxy Example...

I think some of the unit tests make use of JDK proxy instead of Javassist.

On Tue, 29 Jun 2004 22:21:03 -0400, James Carman
<ja...@carmanconsulting.com> wrote:
> 
> Is there a good example of how to use a JDK proxy (or an
InvocationHandler)
> as an interceptor?  I couldn't find anything in the download that I have.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org
> 
> 



-- 
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Jakarta Tapestry
Creator, Jakarta HiveMind
http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org


RE: JDK Proxy Example...

Posted by Pablo Lalloni <pl...@afip.gov.ar>.
I fully agree with James here, I've been writing some intercetpor stuff
and it has been quite annoying compared with previous work I've done
using Nanning and/or AspectWerkz...

I think Nanning's way to do things is very pleasant, maybe we can borrow
some idioms from there.

I haven't used CGLIB directly but seems to be in the same direction.

El mié, 30-06-2004 a las 11:57, James Carman escribió:

> Maybe we could include a factory for creating JDK proxy-like interceptors.
> Maybe borrow an idea from CGLIB (MethodInterceptor and MethodProxy for
> example).  That's how I implemented mine.  I got VERY confused when trying
> to write that javassist stuff and I'm quite an adept Java
> developer/architect.  I just don't think it's going to be an easy sell for
> people when they see that they have to write that javassist stuff when
> writing interceptors.  If they could write it in pure Java and let the
> compiler/IDE help them along, it'd be much easier, IMHO.  Right now, there's
> nothing "baked in" that facilitates this.  I'll send you my stuff once I get
> it working.  I'm still trying to get my contribution rules working the way I
> want them, so you can set properties on your MethodInterceptor
> implementation.  Here's kind of what I had in mind so far...
> 
> public interface MethodInterceptor
> {
>     public Object intercept( Method method, 
>                              Object[] args, 
>                              MethodProxy chain ) throws Throwable;
> }
> 
> 
> public class MethodProxy
> {
>     private final Object target;
> 
>     MethodProxy( Object target )
>     {
>         this.target = target;
>     }
> 
>     public Object invoke( Method method, Object[] args ) throws Throwable
>     {
>         return method.invoke( target, args );
>     }
> }
> 
> I want to be able to create an interceptor by doing...
> 
> interceptor (service-id="MethodInterceptor")
> {
>   method-interceptor (class="mypackage.MyInterceptorImplementation")
>   {
>     set-property (name="foo" value="bar")
>   }
> }
> 
> or something along those lines.  How does this sound?
> 
> 
> -----Original Message-----
> From: Howard Lewis Ship [mailto:hlship@gmail.com] 
> Sent: Tuesday, June 29, 2004 10:55 PM
> To: hivemind-dev@jakarta.apache.org
> Subject: Re: JDK Proxy Example...
> 
> I think some of the unit tests make use of JDK proxy instead of Javassist.
> 
> On Tue, 29 Jun 2004 22:21:03 -0400, James Carman
> <ja...@carmanconsulting.com> wrote:
> > 
> > Is there a good example of how to use a JDK proxy (or an
> InvocationHandler)
> > as an interceptor?  I couldn't find anything in the download that I have.
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org
> > 
> > 
> 

RE: JDK Proxy Example...

Posted by James Carman <ja...@carmanconsulting.com>.
Maybe we could include a factory for creating JDK proxy-like interceptors.
Maybe borrow an idea from CGLIB (MethodInterceptor and MethodProxy for
example).  That's how I implemented mine.  I got VERY confused when trying
to write that javassist stuff and I'm quite an adept Java
developer/architect.  I just don't think it's going to be an easy sell for
people when they see that they have to write that javassist stuff when
writing interceptors.  If they could write it in pure Java and let the
compiler/IDE help them along, it'd be much easier, IMHO.  Right now, there's
nothing "baked in" that facilitates this.  I'll send you my stuff once I get
it working.  I'm still trying to get my contribution rules working the way I
want them, so you can set properties on your MethodInterceptor
implementation.  Here's kind of what I had in mind so far...

public interface MethodInterceptor
{
    public Object intercept( Method method, 
                             Object[] args, 
                             MethodProxy chain ) throws Throwable;
}


public class MethodProxy
{
    private final Object target;

    MethodProxy( Object target )
    {
        this.target = target;
    }

    public Object invoke( Method method, Object[] args ) throws Throwable
    {
        return method.invoke( target, args );
    }
}

I want to be able to create an interceptor by doing...

interceptor (service-id="MethodInterceptor")
{
  method-interceptor (class="mypackage.MyInterceptorImplementation")
  {
    set-property (name="foo" value="bar")
  }
}

or something along those lines.  How does this sound?


-----Original Message-----
From: Howard Lewis Ship [mailto:hlship@gmail.com] 
Sent: Tuesday, June 29, 2004 10:55 PM
To: hivemind-dev@jakarta.apache.org
Subject: Re: JDK Proxy Example...

I think some of the unit tests make use of JDK proxy instead of Javassist.

On Tue, 29 Jun 2004 22:21:03 -0400, James Carman
<ja...@carmanconsulting.com> wrote:
> 
> Is there a good example of how to use a JDK proxy (or an
InvocationHandler)
> as an interceptor?  I couldn't find anything in the download that I have.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org
> 
> 


-- 
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Jakarta Tapestry
Creator, Jakarta HiveMind
http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org


Re: JDK Proxy Example...

Posted by Howard Lewis Ship <hl...@gmail.com>.
I think some of the unit tests make use of JDK proxy instead of Javassist.

On Tue, 29 Jun 2004 22:21:03 -0400, James Carman
<ja...@carmanconsulting.com> wrote:
> 
> Is there a good example of how to use a JDK proxy (or an InvocationHandler)
> as an interceptor?  I couldn't find anything in the download that I have.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org
> 
> 


-- 
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Jakarta Tapestry
Creator, Jakarta HiveMind
http://howardlewisship.com

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org