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

Why won't DynamicProxy's interceptor get called for *each* virtual method call?

An example explains it best : public interface IA { void foo(); void bar(); } public class A : IA { public virtual void foo(){ Console.Write("foo"); bar(); //call virtual method } public virtual void bar(){ …
Cristian Diaconescu
  • 34,633
  • 32
  • 143
  • 233
11
votes
1 answer

Usage examples for Jetty's ProxyServlet.Transparent class

I am trying to use jetty7 to build a transparent proxy setup. Idea is to hide origin servers behind the jetty server so that the incoming request can be forwarded in a transparent manner to the origin servers. I want to know if I can use jetty's…
systemboot
  • 860
  • 2
  • 8
  • 22
11
votes
1 answer

Dynamic implementation for interface/abstract class in Java

What's the de-facto solution for building dynamic implementation of interfaces and/or abstract classes? What I basically want is: interface IMyEntity { int getValue1(); void setValue1(int x); } ... class MyEntityDispatcher implements…
Andrey Agibalov
  • 7,624
  • 8
  • 66
  • 111
11
votes
3 answers

Dynamic proxy and checked exceptions

How can I make my dynamic proxy throw checked exceptions? I need a transparent wrapper for an interface which sometimes throws checked exceptions such as IOException. Is it possible without 3rd party AOP or writing my own proxy? Modifying all 20…
Konrad Garus
  • 53,145
  • 43
  • 157
  • 230
11
votes
2 answers

differences between proxy and dynamic proxy patterns

I'm trying to understand what are the differences between proxy and dynamic proxy patterns. from what I've read so far the only thing that I found out is that the proxy class byte-code is created during compile time and on dynamic proxy it's created…
Shai Zarzewski
  • 1,638
  • 3
  • 19
  • 33
10
votes
3 answers

Whats the difference between C# delegates, Dynamic Proxy, Closures and function pointers?

What are useful definitions for the common methods of passing a method or function as data, such as: Delegates Closures Function pointers Invocation by dynamic proxy and First class methods?
sal
  • 23,373
  • 15
  • 66
  • 85
8
votes
1 answer

C# Clone System.Data.Entity.DynamicProxies to the actual (non proxied) class?

Possible Duplicate: EF4 Cast DynamicProxies to underlying object I'm trying to figure out how to clone or convert a System.Data.Entity.DynamicProxies into it's actual class. Eg: System.Data.Entity.DynamicProxies.Currency_F4008E27DE_etc is the…
JK.
  • 21,477
  • 35
  • 135
  • 214
8
votes
3 answers

Multiple type parameters in Java methods, including existing classes and primitive data types

I have a class with code like the following, where I want it to be trivial to use any class/type which represents a number. I find myself defining a large amount of methods, like the following: public class Range { private BigDecimal inferior =…
Xerz
  • 314
  • 1
  • 4
  • 15
8
votes
2 answers

Proxy pattern vs. overriding

Suppose there is a interface Subject. interface Subject { void request(); } We have a RealSubject class. Suppose we want to enhance RealSubject, we can either use Proxy pattern that wraps around a RealSubject: class Proxy implements Subject { …
gineer
  • 123
  • 2
  • 7
8
votes
6 answers

how to reattach singleton Spring beans upon deserialization

I want to reinject singleton-scoped dependencies into prototype Spring beans, after they have been deserialized. Say I've got a Process bean, which depends on a Repository bean. The Repository bean is a scoped as a singleton, but the Process bean…
Ladlestein
  • 6,100
  • 2
  • 37
  • 49
8
votes
2 answers

In Java how instance of and type cast(i.e (ClassName)) works on proxy object?

Java generates a proxy class for a given interface and provides the instance of the proxy class. But when we type cast the proxy object to our specific Object, how java handles this internally? Is this treated as special scenario? For example I have…
learner
  • 625
  • 2
  • 11
  • 25
8
votes
2 answers

Understanding "proxy" arguments of the invoke method of java.lang.reflect.InvocationHandler

I would like to understand the purpose of the proxy argument of the invoke method of java.lang.reflect.InvocationHandler. How and when should it be used? What is its runtime-type? Why not use this instead?
balteo
  • 23,602
  • 63
  • 219
  • 412
7
votes
1 answer

Check Lazy Load property has loaded in EF6

I'm using class properties by reflection in some operations so when using DynamicProxy instance it causes to load entire DB. (700+ classes are related with each other). Is it possible to check if lazy load property loaded or not? Disabling dynamic…
hkutluay
  • 6,794
  • 2
  • 33
  • 53
7
votes
2 answers

Convert System.Data.Entity.DynamicProxies to (non proxy) class in C#

I am getting some data from the database and storing this in a global variable as shown: //Global Variable public static List Stuff; using (var context = new StuffContext()) { stuff = new List(); stuff = (from r in…
brian4342
  • 1,265
  • 8
  • 33
  • 69
7
votes
3 answers

Creating an INotifyPropertyChanged proxy to dispatch calls to UI thread

I would like to create a dynamic proxy for binding WinForms controls to objects changed by a different (non-GUI) thread. Such a proxy would intercept the PropertyChanged event and dispatch it using the proper SynchronizationContext. That way I could…
vgru
  • 49,838
  • 16
  • 120
  • 201
1
2
3
15 16