Questions tagged [dynamic-proxy]

A Dynamic Proxy is a class that implements a list of interfaces specified at runtime such that a method invocation through one of the interfaces on an instance of the class will be encoded and dispatched to another object through a uniform interface.

A Dynamic Proxy is a class that implements a list of interfaces specified at runtime such that a method invocation through one of the interfaces on an instance of the class will be encoded and dispatched to another object through a uniform interface. Thus, a dynamic proxy class can be used to create a type-safe proxy object for a list of interfaces without requiring pre-generation of the proxy class, such as with compile-time tools. Method invocations on an instance of a dynamic proxy class are dispatched to a single method in the instance's invocation handler, and they are encoded with a java.lang.reflect.Method object identifying the method that was invoked and an array of type Object containing the arguments.

Dynamic proxy classes are useful to an application or library that needs to provide type-safe reflective dispatch of invocations on objects that present interface APIs. For example, an application can use a dynamic proxy class to create an object that implements multiple arbitrary event listener interfaces (interfaces that extend java.util.EventListener) to process a variety of events of different types in a uniform fashion, such as by logging all such events to a file.

226 questions
7
votes
3 answers

How can I convert a dynamic proxy into a POCO?

I was trying trying to serialize a domain model and ran into an issue where I need to convert a dynamic proxy into a POCO. The issue I ran into was that circular references exist by way of virtual properties in the model. Although I attempted to use…
Travis J
  • 81,153
  • 41
  • 202
  • 273
6
votes
1 answer

Self-invocation behaviour in @Configuration vs. @Component classes

My question is about AOP Spring behaviour in case of internal method calls. @Service class Service { @Transactional public void method1() { method2(); } @Transactional public void method2() {} } If we call method1()…
xmen-5
  • 1,806
  • 1
  • 23
  • 44
6
votes
2 answers

How DispatchProxy compare to Castle DynamicProxy?

Some time ago I published an open source library which heavily relies on Castle DynamicProxy. Now that .NET Core 1.x RTM is out, I don't find how I could support .NET Core (Castle DynamicProxy still doesn't work on .NET Core...), until I met…
Matías Fidemraizer
  • 63,804
  • 18
  • 124
  • 206
6
votes
2 answers

Implementing equals() with JDK Dynamic Proxies

For the first time ever, I have to implement my own proxy classes using the standard JDK Dynamic Proxy. It works fairly well, except for one detail: the equals(...) method. Let's assume that we have a simple Interface like this, which we want to…
Martin Häusler
  • 6,544
  • 8
  • 39
  • 66
6
votes
2 answers

Json Serializing JDK Dynamic Proxy with Jackson library

I'm trying to serialize a Java Dynamic proxy using Jackson library but I get this error: public interface IPlanet { String getName(); } Planet implements IPlanet { private String name; public String getName(){return name;} public String…
carlo.polisini
  • 306
  • 4
  • 10
5
votes
5 answers

Java Annotation and Processor to mark a method as so it can be called once and only once?

I need to be able to mark methods so that they throw a RuntimeException if they are called more than once. I am trying to enforce some single assignment semantics and the number of parameters to my class is too large to put in a single constructor…
user177800
5
votes
1 answer

Performance advice for using Castle DynamicProxy in .NET web-apps

I am starting out with Castle DynamicProxy and I have this sample to track changes to properties of an object. Questions: Should I cache (in a static field) the ProxyGenerator() instance I use in AsTrackable()? I going to use in an ASP.NET…
Raghu Dodda
  • 1,505
  • 1
  • 21
  • 28
5
votes
1 answer

Cannot pass Proxy around html element to appendChild

I wrote a thin wrapper which gets passed a node created by document.createElement and adds a few methods. This wrapper is realized with a Proxy. All I do is catching some getters. return new Proxy(node, { get (target, prop) { if (prop…
Fuzzyma
  • 7,619
  • 6
  • 28
  • 60
5
votes
3 answers

Generate intercepting proxy from concrete class?

I need to create a proxy which intercepts properties in a class. I know how to create a dynamic proxy with Emit from an interface, but what if I don't have an interface? I've seen samples which use RealProxy (like this one: Is there a way to call a…
Johan Danforth
  • 4,469
  • 6
  • 37
  • 36
5
votes
2 answers

Autofac: Tips for increasing performance when using DynamicProxy?

I just start using DynamicProxy2 today. And found it caused significant performance drop. See the code below. Test1 is 10 times slower than Test2. Any tips for increasing performance when using DynamicProxy? class Program { public void Main() …
user593358
5
votes
1 answer

Dynamic Proxy - Class Loader parameter when creating a new proxy instance

I was wondering about when you call the newProxyInstance method when creating a dynamic proxy instance, what exactly is the ClassLoader argument for? public static Object newProxyInstance(ClassLoader loader, Class[] interfaces, InvocationHandler…
Joeblackdev
  • 7,217
  • 24
  • 69
  • 106
5
votes
1 answer

Call @Retryable method in a method that is annotated with @Async not working

The below @Retryable code works where there is a direct call to method, but retryable method call through @Async annotated method then throws an exception. Any suggestions ? Here is my Service Class @Service public class RetryAndRecoverService { …
5
votes
5 answers

What's the best way to implement a dynamic proxy in C#?

I've got a need to create a dynamic proxy in C#. I want this class to wrap another class, and take on it's public interface, forwarding calls for those functions: class MyRootClass { public virtual void Foo() { …
gap
  • 2,766
  • 2
  • 28
  • 37
5
votes
0 answers

How-to proxy-remote a .NET IEnumerable with fixed-size batches over the network?

.NET remoting can generate transparent proxy remotes for an interface with serializable members, such as: public interface INetworkInterface { bool login(string username, string password); bool ExecuteSomething(string command); } I'd like to…
David Jeske
  • 2,306
  • 24
  • 29
5
votes
5 answers

How to create a proxy of an interface in Java?

How can one create a proxy for an interface without creating a class that implements it? I have a concrete example: I have an interface, Contact, and need to create a proxy object that acts as a Contact. This proxy object will be used for running…
virgium03
  • 627
  • 1
  • 5
  • 14
1 2
3
15 16