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
2
votes
3 answers

In spring batch framework, what is the difference between 'lazy-init=true' and 'scope=step'?

When I defined a 'MethodInvokingFactory' bean with 'scope=step', I got an error that the type of the bean can't be determined. It worked fine when I replaced 'scope=step' with 'lazy-init=true'. As per my knowledge, both are used for the late binding…
Java Bean
  • 404
  • 1
  • 5
  • 12
2
votes
3 answers

Duck typing / dynamic proxies on existing instances of objects

I have an object handed into our library and passed through various processes. I need to attach some additional information to these objects as they pass through various stages and out the other end - a kind of dynamic decorator pattern, I guess,…
James Crowley
  • 3,911
  • 5
  • 36
  • 65
2
votes
1 answer

cglib proxy and null instance variable internals

My query is why is an instance variable null when cglib proxy with spring tries to access it inside a final method. This would mean that even if I had declared the variable directly like in the class below - class A { String prop="a"; public…
silver-soul
  • 87
  • 1
  • 8
2
votes
1 answer

Does Castle project DynamicProxy heavily use Reflection?

Does Castle project DynamicProxy heavily use Reflection ... like constantly? Or does it do up front reflection cache the data?
arkina
  • 991
  • 2
  • 11
  • 17
2
votes
1 answer

Is it possible to create dynamic proxies without having base class or interface?

Is it possible to create a dynamic proxy using common libraries like Castle Dynamic Proxy without having any base class or interface? I'm indeed interested to have dynamic on-the-fly classes in run-time.
Afshar Mohebi
  • 10,479
  • 17
  • 82
  • 126
2
votes
2 answers

Multiplexing interface method calls into a single delegate and demultiplexing

The short version of what I am looking for is this: I am looking for a mechanism which, given an interface, will dynamically generate a pair of classes for that interface, one multiplexer and one demultiplexer, which will convert calls to/from a…
Mike Nakis
  • 56,297
  • 11
  • 110
  • 142
2
votes
1 answer

Null dependencies in the proxy class

Preface: I want to proxy some classes and intercept their methods (using cglib and BeanPostProcessor). These classes are spring beans (@Service) and normally they have some dependency like a repository. Problem: When I create a proxy for a bean, the…
2
votes
1 answer

Best practice for assembly and class names when generating dynamic assemblies and types?

I'm generating a dynamic proxy in .NET with TypeBuilder and Emit and there are lots of names going on - assembly name, module name and type names. Is there a best practice or a set of general good ideas around naming of a dynamic proxy, or emitted…
Johan Danforth
  • 4,469
  • 6
  • 37
  • 36
2
votes
1 answer

Debugging dynamic proxy creation mutates invocationhandler state

Given the following dynamic java proxy with an invocation handler that has internal state which changes during invocation: import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; public class…
2
votes
1 answer

Java Dynamic Proxy

what is java dynamic proxy,lot of tutorials are there but they are confusing me ,where we are using this concept , any one explain with real world application usage
Arun
  • 1,167
  • 18
  • 37
2
votes
1 answer

Reflection-based injection vs. dynamic proxy: Practical considerations?

I'm working on some framework-ish code designed to execute a huge number of operations (hundreds of thousands), all of which use the same basic components, but need to accept operation-specific configuration data from an external source. Assume for…
Aaronaught
  • 120,909
  • 25
  • 266
  • 342
2
votes
2 answers

Using AOP techniques to intercept ADO.Net

I have quite a large code base using a variety of different ADO technologies (i.e. some EF and in some cases using ADO.Net directly). I'm wondering if there is any way to globally intercept any ADO.Net calls so that I can start auditing…
vdh_ant
  • 12,720
  • 13
  • 66
  • 86
2
votes
1 answer

Should calls on a dynamic proxy go to the method of the dynamic type or the static type?

The method-object, which the dynamic proxy receives, seems to be of the reference type instead of the object type, but only when generics are involved in the method signature. Should it work that way? Example: public class ProxyTest implements…
Olard
  • 43
  • 6
2
votes
1 answer

Async Interception using Castle dynamic proxy

I'm trying to build a dynamic http client using dynamic proxy to intercept the calls and create an http request with it. The issue i had was with Async methods: private Task PostAsync(HttpClient client, string url, HttpRequestParameters…
Erez.L
  • 77
  • 1
  • 10
2
votes
0 answers

How to use Dynamic Proxies with JSF when the method signature contains Object ... args

I'm having some trouble with Spring, JPA and Dynamic Proxy DAO classes which are initialized as Spring Beans. This particular project has been plaguing me on the persistence/transaction side for some time, and I'd like to get this nailed down once…
SplinterReality
  • 3,400
  • 1
  • 23
  • 45