Sunday, September 5, 2010

Java application developers to use agent technology in

If you need for: to create in the run-time interfaces to achieve a given set of classes, pay attention to this class is created at run time, you will need to use JAVA in the proxy class to achieve your requirements. Agent class provides the ability to create classes at run time, this new class to achieve your specified interface. Of course you can not be achieved in the run-time interface to the methods defined in the new code, but to provide a call processor to achieve. Call the processor to achieve the object of class InvocationHandler interface, this interface is only one way:

The following is quoted fragment:
Object invoke (Object proxy, Method mtd, Object [] args)
One proxy is the proxy object; mtd is to describe the methods of the class of object, this object implement its invoke (Object obj, Object [] args) method can call the package in Mthod object method; args parameter of this method is the storage array .

The establishment of proxy object: Use Proxy class newProxyInstance method, the format is as follows:
The following is quoted fragment:
Object proxy = Proxy.newProxyInstance (null, interfaces, handler);
The first parameter is a class loader, where the default loader, said with a null; second parameter is an array of Class, which each element is an interface that is used to specify a group to achieve interface, even if only one interface to have to pass through the array; third parameter is the call processor.

In the proxy object method call, the call processor will automatically invoke method calls, method calls and parameters are automatically passed to the method of jmtdt args inboke form parameters, but also with the parameter array args parameter to call mtd object specified method.

Agent Application: Method call trace (to track the object to be packaged into a proxy class object); to provide a remote method call routing; user interface events associated with the action (C # in a similar function).

No comments:

Post a Comment