Java developers in the use of agent technology

Author:Anonymous    Updated:2008-10-9 12:34:48

f you need this: In the run-time to create a group to achieve a given type of interface, pay attention to this category is created in the run-time, you need to use JAVA in the class of agent to reach you.

 Acting Class in the run-time to provide the ability to create a category, this new category you can achieve the specified interface.  Of course you can not run in order to achieve the interface of the new code approach defined, but rather a call processor to achieve. InvocationHandler Call InvocationHandler the processor to achieve the target of a class interface, the interface is only one way:

 The following is quoted fragment:
Object invoke(Object proxy,Method mtd,Object[] args) Object invoke (Object proxy, Method mtd, Object [] args)

Which is a proxy agent object; mtd method is described in the category of object, the object of its implementation of the invoke (Object obj, Object [] args) can call in the package Mthod object of ways; args storage is the parameter of this method Array.

newProxyActing to build objects: the use of the Proxy Class newProxyInstance method, the format is as follows:

The following is quoted fragment:

Object proxy=Proxy.newProxyInstance(null,interfaces,handler); Object proxy = Proxy.newProxyInstance (null, interfaces, handler);

 The first of these parameters is a class loader, where the use of default loader, said null; The second parameter is an array of Class, which is an interface for each element, which is used to achieve the designation of a group of Interface, even if there is only one interface to go through the array to pass; the third parameter is the call processor.

 Acting in the object call method, invoke the method of Processor call will be automatically called, is called the method and parameters of the automatic transmission to the inboke method jmtdt args in the form of parameters, but also with args parameter array of parameters to call mtd Object specified.

Deputy application: tracking method invocation (to the track of objects packed into a type of proxy object); to provide long-distance call routing; user interface events associated with the action (C # in a similar function).

Previous:NO
Next:Aggregate net orders
User Reviews
Related Articles
Recommended article
AD