From: hammett <ha...@uo...> - 2004-10-26 01:38:46
|
Hello! I was thinking about it again, and now its safe to allow non-virtual methods in the classes being proxied as just one instance will exist. The result is: non-virtual methods wont be intercepted... What are your thoughts? -- Cheers, hammett http://www.digitalcraftsmen.com.br/~hammett |
From: <hen...@gm...> - 2004-10-26 15:32:17
|
I like this way more than throw an exception or ignore the method On Mon, 25 Oct 2004 22:38:25 -0700, hammett <ha...@uo...> wrote: > Hello! >=20 > I was thinking about it again, and now its safe to allow non-virtual meth= ods > in the classes being proxied as just one instance will exist. The result = is: > non-virtual methods wont be intercepted... >=20 > What are your thoughts? >=20 > -- > Cheers, > hammett > http://www.digitalcraftsmen.com.br/~hammett >=20 > ------------------------------------------------------- > This SF.net email is sponsored by: IT Product Guide on ITManagersJournal > Use IT products in your business? Tell us what you think of them. Give us > Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out mo= re > http://productguide.itmanagersjournal.com/guidepromo.tmpl > _______________________________________________ > Aspectsharp-users mailing list > Asp...@li... > https://lists.sourceforge.net/lists/listinfo/aspectsharp-users >=20 --=20 Cheers, Henry Concei=E7=E3o |
From: Deyan P. <de...@ho...> - 2004-10-26 17:14:13
|
Hi, I also don't have a problem with this scenario. There is, of course, a fundamental problem - that there is no other nice way to generate proxies but to create subclasses (which override base classes methods) .. and that C# doesn't have all class methods virtual by default, but we have to live with that ;) Br, Deyan ----- Original Message ----- From: "Henry Conceição" <hen...@gm...> To: "hammett" <ha...@uo...> Cc: <asp...@li...> Sent: Tuesday, October 26, 2004 5:32 PM Subject: Re: [Aspectsharp-users] Non-virtual methods again I like this way more than throw an exception or ignore the method On Mon, 25 Oct 2004 22:38:25 -0700, hammett <ha...@uo...> wrote: > Hello! > > I was thinking about it again, and now its safe to allow non-virtual methods > in the classes being proxied as just one instance will exist. The result is: > non-virtual methods wont be intercepted... > > What are your thoughts? > > -- > Cheers, > hammett > http://www.digitalcraftsmen.com.br/~hammett > > ------------------------------------------------------- > This SF.net email is sponsored by: IT Product Guide on ITManagersJournal > Use IT products in your business? Tell us what you think of them. Give us > Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more > http://productguide.itmanagersjournal.com/guidepromo.tmpl > _______________________________________________ > Aspectsharp-users mailing list > Asp...@li... > https://lists.sourceforge.net/lists/listinfo/aspectsharp-users > -- Cheers, Henry Conceição ------------------------------------------------------- This SF.net email is sponsored by: IT Product Guide on ITManagersJournal Use IT products in your business? Tell us what you think of them. Give us Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more http://productguide.itmanagersjournal.com/guidepromo.tmpl _______________________________________________ Aspectsharp-users mailing list Asp...@li... https://lists.sourceforge.net/lists/listinfo/aspectsharp-users |
From: Mike D. <mik...@gm...> - 2004-10-26 20:23:17
|
+1 - to allowing non-virtual methods and not intercepting them Keep up the good work! Mike On Tue, 26 Oct 2004 12:32:10 -0300, Henry Concei=E7=E3o <hen...@gm...> wrote: > I like this way more than throw an exception or ignore the method >=20 >=20 >=20 >=20 > On Mon, 25 Oct 2004 22:38:25 -0700, hammett <ha...@uo...> wrote: > > Hello! > > > > I was thinking about it again, and now its safe to allow non-virtual me= thods > > in the classes being proxied as just one instance will exist. The resul= t is: > > non-virtual methods wont be intercepted... > > > > What are your thoughts? > > > > -- > > Cheers, > > hammett > > http://www.digitalcraftsmen.com.br/~hammett > > > > ------------------------------------------------------- > > This SF.net email is sponsored by: IT Product Guide on ITManagersJourna= l > > Use IT products in your business? Tell us what you think of them. Give = us > > Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out = more > > http://productguide.itmanagersjournal.com/guidepromo.tmpl > > _______________________________________________ > > Aspectsharp-users mailing list > > Asp...@li... > > https://lists.sourceforge.net/lists/listinfo/aspectsharp-users > > >=20 >=20 > -- > Cheers, > Henry Concei=E7=E3o >=20 >=20 >=20 >=20 > ------------------------------------------------------- > This SF.net email is sponsored by: IT Product Guide on ITManagersJournal > Use IT products in your business? Tell us what you think of them. Give us > Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out mo= re > http://productguide.itmanagersjournal.com/guidepromo.tmpl > _______________________________________________ > Aspectsharp-users mailing list > Asp...@li... > https://lists.sourceforge.net/lists/listinfo/aspectsharp-users > |
From: hammett <ha...@uo...> - 2004-10-27 01:29:34
|
Ok, guys. I've changed to ignore non-virtual and sealed methods. Test cases are passing. Its on the svn. -- Cheers, hammett http://www.digitalcraftsmen.com.br/~hammett ----- Original Message ----- From: "Mike Doerfler" <mik...@gm...> |
From: Deyan P. <de...@ho...> - 2004-10-27 11:02:07
|
Hi, I have been playing with the new IInvocation, and I noticed that both properties IInvocation.Proxy and IInvocation.InvocationTarget are the same. What's there meaning, btw? What is bothering me is that there is no way to substitute the real object in the PreProcess method of my Interceptor, which is a part of the object lazy-loading process... I see that NHibernate also has this problem, as it retrieves the real object from the db and delegates (using runtime reflection) the calls to it. I would like to execute the methods on the real object without runtime reflection, which means that either I can substitte the real object (perhaps this is the IInvocation.InvocationTarget which has only a getter) - this I think is not possible, or populate the properties of the proxy from the db at runtime, and then take advantage of the Dynamic Proxy new calling infrastructure. Hammett, Mike, what do you think about this? Mike, don't you have a problem with the Method.Invoke on the real object(AvalonLazyInitializer.Invoke, the case when result==InvokeImplementation), which means that a lazy-loaded object always uses reflection (during it's whole lifetime) when a method/property is called on it? 10x and br, Deyan ----- Original Message ----- From: "hammett" <ha...@uo...> To: <asp...@li...> Sent: Tuesday, October 26, 2004 7:38 AM Subject: [Aspectsharp-users] Non-virtual methods again > Hello! > > I was thinking about it again, and now its safe to allow non-virtual methods > in the classes being proxied as just one instance will exist. The result is: > non-virtual methods wont be intercepted... > > What are your thoughts? > > -- > Cheers, > hammett > http://www.digitalcraftsmen.com.br/~hammett > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: IT Product Guide on ITManagersJournal > Use IT products in your business? Tell us what you think of them. Give us > Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more > http://productguide.itmanagersjournal.com/guidepromo.tmpl > _______________________________________________ > Aspectsharp-users mailing list > Asp...@li... > https://lists.sourceforge.net/lists/listinfo/aspectsharp-users > |
From: hammett <ha...@uo...> - 2004-10-27 14:16:15
|
Hello Deyan, > I have been playing with the new IInvocation, and I noticed that both > properties IInvocation.Proxy and IInvocation.InvocationTarget are the > same. > What's there meaning, btw? The target means: when I invoke proceed, which object will receive the execution; and the proxy is the proxy itself. When proxying a class, both values will be the same. When intercepting interfaces (using ProxyGenerator.CreateProxy) then the values will be different. > What is bothering me is that there is no way to substitute the real object > in the PreProcess method of my Interceptor, which is a part of the object > lazy-loading process... Well, this is easy to fix. We can make the InvocationTarget writable, but then the Proceed in the SameClassInvocation must be changed to something like: public override object Proceed(params object[] args) { object value = null; if (TargetInvocation == Proxy) { value = call.Call( args ); } else { value = Method.Invoke( InvocationTarget, args ); } return value; } Because there is no wasy to use the delegate to invoke the method somewhere else. I could even generate two different delegates: one to invoke the base() and one to invoke anotherobject() but in this case I must know the Type of the anotherobject during the object generation, something like: private void callback_1(int x) { base.DoSomething(x); } private void otherobjectcallback(int x) { // This is generated by // gen.Emit( OpCodes.callvirt, typeof(target).GetMethod("DoSomething", new type[] { typeof(int) } ); target.DoSomething(x); } > I see that NHibernate also has this problem, as it > retrieves the real object from the db and delegates (using runtime > reflection) the calls to it. I would like to execute the methods on the > real > object without runtime reflection, which means that either I can substitte > the real object (perhaps this is the IInvocation.InvocationTarget which > has > only a getter) - this I think is not possible, or populate the properties > of > the proxy from the db at runtime, and then take advantage of the Dynamic > Proxy new calling infrastructure. Can you expose your code somewhere so we can see exactly the problem? It will be easier to picture the solution... -- Cheers, hammett http://www.digitalcraftsmen.com.br/~hammett |
From: Deyan P. <de...@ho...> - 2004-10-28 07:45:08
|
Hi, Obviously my reply from yesterday with an attachment was blocked. So I send another one, this time I have placed my test project on the web: http://www20.brinkster.com/deyanp/dynproxy/DynamicProxyAvalonTest.zip 10x, hammett, and sorry to bother you with this. Br, Deyan ----- Original Message ----- From: "hammett" <ha...@uo...> To: <asp...@li...> Sent: Wednesday, October 27, 2004 8:15 PM Subject: Re: [Aspectsharp-users] IInvocation.Proxy and IInvocation.InvocationTarget > Hello Deyan, > > > I have been playing with the new IInvocation, and I noticed that both > > properties IInvocation.Proxy and IInvocation.InvocationTarget are the > > same. > > What's there meaning, btw? > > The target means: when I invoke proceed, which object will receive the > execution; and the proxy is the proxy itself. When proxying a class, both > values will be the same. When intercepting interfaces (using > ProxyGenerator.CreateProxy) then the values will be different. > > > What is bothering me is that there is no way to substitute the real object > > in the PreProcess method of my Interceptor, which is a part of the object > > lazy-loading process... > > Well, this is easy to fix. We can make the InvocationTarget writable, but > then the Proceed in the SameClassInvocation must be changed to something > like: > > public override object Proceed(params object[] args) > { > object value = null; > if (TargetInvocation == Proxy) > { > value = call.Call( args ); > } > else > { > value = Method.Invoke( InvocationTarget, args ); > } > return value; > } > > Because there is no wasy to use the delegate to invoke the method somewhere > else. I could even generate two different delegates: one to invoke the > base() and one to invoke anotherobject() but in this case I must know the > Type of the anotherobject during the object generation, something like: > > private void callback_1(int x) > { > base.DoSomething(x); > } > > private void otherobjectcallback(int x) > { > // This is generated by > // gen.Emit( OpCodes.callvirt, typeof(target).GetMethod("DoSomething", new > type[] { typeof(int) } ); > target.DoSomething(x); > } > > > > I see that NHibernate also has this problem, as it > > retrieves the real object from the db and delegates (using runtime > > reflection) the calls to it. I would like to execute the methods on the > > real > > object without runtime reflection, which means that either I can substitte > > the real object (perhaps this is the IInvocation.InvocationTarget which > > has > > only a getter) - this I think is not possible, or populate the properties > > of > > the proxy from the db at runtime, and then take advantage of the Dynamic > > Proxy new calling infrastructure. > > Can you expose your code somewhere so we can see exactly the problem? > It will be easier to picture the solution... > > -- > Cheers, > hammett > http://www.digitalcraftsmen.com.br/~hammett > > > > > ------------------------------------------------------- > This SF.Net email is sponsored by: > Sybase ASE Linux Express Edition - download now for FREE > LinuxWorld Reader's Choice Award Winner for best database on Linux. > http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click > _______________________________________________ > Aspectsharp-users mailing list > Asp...@li... > https://lists.sourceforge.net/lists/listinfo/aspectsharp-users > |
From: hammett <ha...@uo...> - 2004-10-28 14:06:50
|
Hello Deyan Very interesting piece of code. So, you return a place holder with lazy load. Is it something that the user can turn on and off? About the code, I've implemented the writable InvocationTarget and changed your code interceptor to: public class MyInterceptor : IInterceptor { private LoadObjectDelegate _loadObjectDelegate; private int _id; private bool isLoaded; private object newtarget; public MyInterceptor(LoadObjectDelegate loadObjectDelegate, int id) { _loadObjectDelegate = loadObjectDelegate; _id = id; } public object Intercept( IInvocation invocation, params object[] args) { if(invocation.Method.Name.Equals("get_ID")) { return _id; } if (!isLoaded) { newtarget = _loadObjectDelegate( _id ); isLoaded = true; } invocation.InvocationTarget = newtarget; return invocation.Proceed(args); } } The results were Loop1000DynamicProxyTest: 125 Loop1000 NoProxy Test: 16 Loop1000DynamicProxyTest: 47 Loop1000 NoProxy Test: 0 (using Environment.TickCount instead of DateTime.Now) From my standpoint this is good. The first one takes more time because the proxy code generation. After that, it will use the cached type. Now, a better test will be to implement a simple but functional Materialize method, to load it from the database and check if the lazy load is really effective. If the proxy overhead is really making the overall process too slow, we can tweak it as you wish :-) I'm commiting the changes to SVN right now. -- Cheers, hammett http://www.digitalcraftsmen.com.br/~hammett ----- Original Message ----- From: "Deyan Petrov" <de...@ho...> To: <asp...@li...> Sent: Thursday, October 28, 2004 12:45 AM Subject: Re: [Aspectsharp-users] IInvocation.Proxy and IInvocation.InvocationTarget |
From: Deyan P. <de...@ho...> - 2004-10-28 15:48:08
|
Hi hammett, Great, thanks a lot for the modification!!! Now it looks really great. I have currently implemented a project with explicit proxies for lazy-loading, and I am thinking of replacing them with the more transparent Dynamic Proxies, that's why I am delving into the stuff... I did some tests and the results are a little bit strange ... I have changed the retrieval of the objects, so that they are loaded from the db now. The full code is here: http://www20.brinkster.com/deyanp/dynproxy/DynamicProxyAvalonTest.zip Class1.cs looks now like this: using System; namespace DynamicProxyAvalonTest { class Class1 { [STAThread] static void Main(string[] args) { Test(1000, 1, true); Test(1000, 1, false); Test(1000, 1, true); Test(1000, 1, false); Test(1000, 1, true); Test(1000, 1, false); Test(1000, 1, true); Test(1000, 1, false); Test(1000, 100, true); Test(1000, 100, false); Test(1000, 100, true); Test(1000, 100, false); Test(1000, 100, true); Test(1000, 100, false); Test(1000, 100, true); Test(1000, 100, false); Test(1000, 1000, true); Test(1000, 1000, false); Test(1000, 1000, true); Test(1000, 1000, false); Test(1000, 1000, true); Test(1000, 1000, false); Test(1000, 1000, true); Test(1000, 1000, false); Console.ReadLine(); } public static void Test(int maxi, int maxj, bool useProxy) { int start = Environment.TickCount; int i = 0; int j = 0; for(i=0;i<maxi;i++) { //useProxy=true lazy-loads the referenced country //a dynamic proxy is stuffed in //altogether 2 db calls: 1 for the user //and later 1 for the country //useProxy=false eager-loads the referenced country //the country is directly retrieved from the db upon retrieval of the user //in a separate db call //altogether 2 db calls: 1 for the user //and immediately another 1 for the country User user = UserDA.Select(1830, useProxy); for(j=0;j<maxj;j++) { int d = user.ID; string n = user.Name; if(user.Country != null) { int d2 = user.Country.ID; string n2 = user.Country.Name; } } } int end = Environment.TickCount; Console.WriteLine(String.Format("Loop[i={0},j={1}] useProxy={2} Test:\t\t\t{3}", i, j, useProxy, end - start)); } } } The results are the following: Loop[i=1000,j=1] useProxy=True Test: 1219 Loop[i=1000,j=1] useProxy=False Test: 781 Loop[i=1000,j=1] useProxy=True Test: 890 Loop[i=1000,j=1] useProxy=False Test: 782 Loop[i=1000,j=1] useProxy=True Test: 890 Loop[i=1000,j=1] useProxy=False Test: 813 Loop[i=1000,j=1] useProxy=True Test: 906 Loop[i=1000,j=1] useProxy=False Test: 812 Loop[i=1000,j=100] useProxy=True Test: 1485 Loop[i=1000,j=100] useProxy=False Test: 734 Loop[i=1000,j=100] useProxy=True Test: 1406 Loop[i=1000,j=100] useProxy=False Test: 719 Loop[i=1000,j=100] useProxy=True Test: 1406 Loop[i=1000,j=100] useProxy=False Test: 766 Loop[i=1000,j=100] useProxy=True Test: 1437 Loop[i=1000,j=100] useProxy=False Test: 766 Loop[i=1000,j=1000] useProxy=True Test: 5859 Loop[i=1000,j=1000] useProxy=False Test: 813 Loop[i=1000,j=1000] useProxy=True Test: 5859 Loop[i=1000,j=1000] useProxy=False Test: 813 Loop[i=1000,j=1000] useProxy=True Test: 5843 Loop[i=1000,j=1000] useProxy=False Test: 922 Loop[i=1000,j=1000] useProxy=True Test: 6031 Loop[i=1000,j=1000] useProxy=False Test: 891 It seems that the inner loop causes performance problems - if the value is 1 then there is almost no difference between the proxy and no proxy versions, but if it is 1000, then the difference is 6x. Let me know what you think about this, if you find time for that. I will continue investigating the issue tomorrow. Best regards, Deyan |
From: hammett <ha...@uo...> - 2004-10-28 17:54:48
|
Hello Deyan, I'd like to see the code, but I'm having problems downloading the zip file now.. I'll check it again tonight. By now, I imagine some tweaks that we can try. -- Cheers, hammett http://www.digitalcraftsmen.com.br/~hammett ----- Original Message ----- From: "Deyan Petrov" <de...@ho...> To: <asp...@li...> Sent: Thursday, October 28, 2004 8:48 AM Subject: Re: [Aspectsharp-users] IInvocation.Proxy and IInvocation.InvocationTarget |
From: Deyan P. <de...@ho...> - 2004-10-29 06:47:11
|
Hi hammett, Ok, sorry, the correct link to the new source is: http://www20.brinkster.com/deyanp/dynproxy/DynamicProxyAvalonTest2.zip Br, Deyan ----- Original Message ----- From: "hammett" <ha...@uo...> To: <asp...@li...> Sent: Thursday, October 28, 2004 11:54 PM Subject: Re: [Aspectsharp-users] IInvocation.Proxy and IInvocation.InvocationTarget > Hello Deyan, > > I'd like to see the code, but I'm having problems downloading the zip file > now.. > I'll check it again tonight. By now, I imagine some tweaks that we can try. > > -- > Cheers, > hammett > http://www.digitalcraftsmen.com.br/~hammett > > > ----- Original Message ----- > From: "Deyan Petrov" <de...@ho...> > To: <asp...@li...> > Sent: Thursday, October 28, 2004 8:48 AM > Subject: Re: [Aspectsharp-users] IInvocation.Proxy and > IInvocation.InvocationTarget > > > > > > ------------------------------------------------------- > This Newsletter Sponsored by: Macrovision > For reliable Linux application installations, use the industry's leading > setup authoring tool, InstallShield X. Learn more and evaluate > today. http://clk.atdmt.com/MSI/go/ins0030000001msi/direct/01/ > _______________________________________________ > Aspectsharp-users mailing list > Asp...@li... > https://lists.sourceforge.net/lists/listinfo/aspectsharp-users > |
From: hammett <ha...@uo...> - 2004-10-29 15:41:33
|
Hello Deyan, I've spent an hour in optimization, but I think you wont benefit from it. The last optimization is to avoid instantiate the delegates, so, for each delegate generated we create a instance field and initialize if in the constructor. It made a hell of difference in my performance test Execution took 156 // interface proxy using reflection Execution took 110 Execution took 125 Execution took 125 Execution took 62 // class proxy Execution took 47 Execution took 47 Execution took 47 Deyan, I think one thing you can try before we step a little further is to compile everything to Release. In debug mode the DynamicProxy writes the assembly to the disk and no code optimization is applied by C# compiler too. I've noticed some time differences amongst Debug and Release compilation. If you still experiencing poor results, we'll go a step further creating delegates to an inner type. This will be a hack, thus I'd like to avoid it. but I also would like to see good results, so I'm willing to implement it if it's really necessary. -- Cheers, hammett http://www.digitalcraftsmen.com.br/~hammett ----- Original Message ----- From: "Deyan Petrov" <de...@ho...> To: <asp...@li...> Sent: Thursday, October 28, 2004 11:47 PM Subject: Re: [Aspectsharp-users] IInvocation.Proxy and IInvocation.InvocationTarget > Hi hammett, > > Ok, sorry, the correct link to the new source is: > > http://www20.brinkster.com/deyanp/dynproxy/DynamicProxyAvalonTest2.zip > > > Br, > Deyan > > > ----- Original Message ----- > From: "hammett" <ha...@uo...> > To: <asp...@li...> > Sent: Thursday, October 28, 2004 11:54 PM > Subject: Re: [Aspectsharp-users] IInvocation.Proxy and > IInvocation.InvocationTarget > > >> Hello Deyan, >> >> I'd like to see the code, but I'm having problems downloading the zip >> file >> now.. >> I'll check it again tonight. By now, I imagine some tweaks that we can > try. >> >> -- >> Cheers, >> hammett >> http://www.digitalcraftsmen.com.br/~hammett >> >> >> ----- Original Message ----- >> From: "Deyan Petrov" <de...@ho...> >> To: <asp...@li...> >> Sent: Thursday, October 28, 2004 8:48 AM >> Subject: Re: [Aspectsharp-users] IInvocation.Proxy and >> IInvocation.InvocationTarget >> >> >> >> >> >> ------------------------------------------------------- >> This Newsletter Sponsored by: Macrovision >> For reliable Linux application installations, use the industry's leading >> setup authoring tool, InstallShield X. Learn more and evaluate >> today. http://clk.atdmt.com/MSI/go/ins0030000001msi/direct/01/ >> _______________________________________________ >> Aspectsharp-users mailing list >> Asp...@li... >> https://lists.sourceforge.net/lists/listinfo/aspectsharp-users >> > > > ------------------------------------------------------- > This Newsletter Sponsored by: Macrovision > For reliable Linux application installations, use the industry's leading > setup authoring tool, InstallShield X. Learn more and evaluate > today. http://clk.atdmt.com/MSI/go/ins0030000001msi/direct/01/ > _______________________________________________ > Aspectsharp-users mailing list > Asp...@li... > https://lists.sourceforge.net/lists/listinfo/aspectsharp-users > |
From: hammett <ha...@uo...> - 2004-10-29 18:00:37
|
I was just watching Simpsons (third season) and thinking about this problem when I realised that we both were using the wrong approach :-) How a mixin would solve this problem: 1. Create a proxy for Contry, for example, and mix a Materialize mixin 2. In your Interceptor, if not loaded, you can cast the proxy to the mixin interface and execute the Materialize 3. The Materialize will populate the proxy fields. No second country object... 4. Done! What you think about it, Deyan? The problem: only Aspect# today is capable of dealing with mixins, and we need to refactor it to use the new dynamic proxy interfaces and strategies. On the other hand I think nothing stop us of provide mixin capabilities directly in DynamicProxy, and we can make the Aspect# code simpler. I think I can do it in about one hour, more or less... Henry, do you have anything against that? After all, you are the author of the original mixin code... -- Cheers, hammett http://www.digitalcraftsmen.com.br/~hammett |
From: Deyan P. <de...@ho...> - 2004-11-12 17:53:10
|
Hi hammett, Sorry for the late response, but I was so busy that couldn't find time to look at the interesting stuff you've implemented :( About the mixins - I looked at the new mixin testcases you've included and I am afraid I don't understand how they can solve my problem .. If I create a MaterializeMixin with Materialize(int id) method, then I mix that one with the Country class, and in the interceptor call ((IMaterializable)invocation.Proxy).Materialize(_id); then how does this Materialize method fill the properties of the Country class (I am not good with aspect terminology, but I assume that "mixin" means that the methods of the classes are merged together, right?)? I can't write in the MaterializeMixin something like: ((Country)this)._population = 1234455; //for example, if we have private int _population; in the Country class because it doesn't compile.. Please correct me if I am wrong, but in fact the proxy (by definition) shouldn't populate itself, it should just materialize a inner (Country) object, and then delegate all method invocations to the inner object, without using reflection of course ... A simple delegation costs nothing that's why the DynamicProxyAvalonTest should deliver comparable results if the counter of the inner loop is increased ... Br, Deyan ----- Original Message ----- From: "hammett" <ha...@uo...> To: <asp...@li...> Sent: Friday, October 29, 2004 10:59 PM Subject: Re: [Aspectsharp-users] IInvocation.Proxy and IInvocation.InvocationTarget > I was just watching Simpsons (third season) and thinking about this problem > when I realised that we both were using the wrong approach :-) > > How a mixin would solve this problem: > > 1. Create a proxy for Contry, for example, and mix a Materialize mixin > 2. In your Interceptor, if not loaded, you can cast the proxy to the mixin > interface and execute the Materialize > 3. The Materialize will populate the proxy fields. No second country > object... > 4. Done! > > What you think about it, Deyan? > > The problem: only Aspect# today is capable of dealing with mixins, and we > need to refactor it to use the new dynamic proxy interfaces and strategies. > On the other hand I think nothing stop us of provide mixin capabilities > directly in DynamicProxy, and we can make the Aspect# code simpler. I think > I can do it in about one hour, more or less... > > Henry, do you have anything against that? After all, you are the author of > the original mixin code... > > -- > Cheers, > hammett > http://www.digitalcraftsmen.com.br/~hammett > > > > > > ------------------------------------------------------- > This SF.Net email is sponsored by: > Sybase ASE Linux Express Edition - download now for FREE > LinuxWorld Reader's Choice Award Winner for best database on Linux. > http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click > _______________________________________________ > Aspectsharp-users mailing list > Asp...@li... > https://lists.sourceforge.net/lists/listinfo/aspectsharp-users > |
From: hammett <ha...@uo...> - 2004-11-12 18:56:52
|
Hi Deyan, > About the mixins - I looked at the new mixin testcases you've included and > I > am afraid I don't understand how they can solve my problem .. If I create > a > MaterializeMixin with Materialize(int id) method, then I mix that one with > the Country class, and in the interceptor call > ((IMaterializable)invocation.Proxy).Materialize(_id); Yep.. > then how does this Materialize method fill the properties of the Country > class (I am not good with aspect terminology, but I assume that "mixin" > means that the methods of the classes are merged together, right?)? I > can't > write in the MaterializeMixin something like: The mixins interfaces are exposed by the proxy class, but the invocations on these methods (provided that the interceptor calls Proceed) delegates the invocation the the mixin instance. In your case it will be something like: class CountryProxy : Country, IMaterialize { private IMaterialize materialize; public CountryProxy( object[] mixins ) { this.materialize = (IMaterialize) mixins[0]; } } (This is a simplification, but depicts the essential pieces) > because it doesn't compile.. You have to define a protocol to allow the mixin to receive the proxy interface if they want. I decided to not put it there as it will overlap Aspect#'s protocol. Btw, you can see how Aspect# solves the same problem: http://cvs.sourceforge.net/viewcvs.py/aspectsharp/AspectSharp2/src/AspectSharpTests/MixinTests/MixinTestCase.cs?rev=1.5&view=auto See the MixinProxyAware test case. How this was implemented... Well, Aspect# adds a layer between itself and the DynamicProxy, so it can initialize the mixins: http://cvs.sourceforge.net/viewcvs.py/aspectsharp/AspectSharp2/src/AspectSharp/Core/Proxy/DefaultProxyFactory.cs?rev=1.6&view=auto See the InitializeMixins methods. Its very simple, really.. But if you dont want to use mixin, you implementation of IInterceptor could have an IMaterialize instance and could populate the proxy as well. > Please correct me if I am wrong, but in fact the proxy (by definition) > shouldn't populate itself, it should just materialize a inner (Country) > object, and then delegate all method invocations to the inner object, > without using reflection of course ... A simple delegation costs nothing > that's why the DynamicProxyAvalonTest should deliver comparable results if > the counter of the inner loop is increased ... Well, it doesn't have to be this way. I think my suggestion will have a better performance and its better than having two objects.. Believe, you can run into serious trouble with delegation if one of the methods is not virtual, like: class Country { public virtual String Name ... public virtual String Code .. public void SomeBusinessMethod(). } As this last method is not intercepted, the invocation would took place in a different instance with unpredictable results (Wow! I always wanted to say that one piece of my code could generate unpredictable results :-) ) Thats why I've changed so the IInvocationHandler to IInterceptor and added the Proceed.. The rationale is: you can delegate your calls to some other object, but we hope that you know the implications. The usual use won't do something like that. We can work on this one more time, if you send me again the code. -- Cheers, hammett http://www.digitalcraftsmen.com.br/~hammett |