分布式环境中动态代理的应用外文翻译 第5页
the class initializes the ORB (line 8), creates the implementation object theProxylmpl(lines 12 and 13), and makes it available to the clients by using the CORBA's naming service NameService(lines 19 and 20). The implementation object is bound to an arbitrary name (line 21), through which I can be identified by clients. Before giving the object a name, it must be first transformed into a CORBA object reference through the POA (line 15). The object adapter is obtained by referencing root POA which is always available from the ORB, and the result is narrowed down to a POA type (line 10).The object adapter is activated through the POAManager to allow for dispatching incoming request (line 23). Finally, run ( ) is called on the ORB object to allow the main thread to wait and listen for incoming requests (line 24).
Figure 19 shows the client implementation class. As in the server case, the client application first initializes the ORB and then uses CORBA's naming service to resolve the object reference (lines 9-15). The reference is of type org.omg.CORBA.Object and is narrowed down to the appropriate Java interface type with the help of ProxyFactoryWrapperHelper (line 16). ProxyFactoryWrapper interface is generated by applying the idlj tool to the idl-file of Figure 16.The tool maps an IDL interface into a Java interface with the same name and same set of methods. Having obtained the object reference with the appropriate type, we can invoke methods on the object, whose implementations are defined on the server side, as for example, createProxy (Any, Any).To invoke this method, we use the ORB to create two org.omg.CORBA.Any-objects and insert into these the appropriate serializable parameter base objects, as values using insert_Value() (lines 19-31). The result of the method invocation can be extracted from the method's return Any-type, using extract_Value ( ) and type-casting (lines 32 and 33). In our example, the result is of type java.lang.reflect.InvocationHandler and is implemented on the server by BeanProxy thus providing
Figure 19reusable behaviour. Having obtained the result, the client an create a proxy to allow for base objects customizations, as in the RMI case.
Java’s Servlets implementation
Compared to Sockets, the classes URL and URLConnection of the java.net package provide a relatively high-level mechanism and system-independent network communication for accessing resources on the Internet. These allow a client application to locate and connect to servlets on the server side. The method getConnection() of Figure 20 (line 13-22) shows an example of a client using URL and URLConnection objects to establish a connection to a Web sever. The servlet’s location on the Internet is passed as a Uniform Resource Locator (URL) parameter string (lines 6 and 14). After
Figure 20
establishing the connection, the client can utilize the URLConnection object reference to request services from the server by passing required parameters as serialized objects and admit the result by de-serializing the received data.
On the server side, the Web server acts as a servlet container supporting Java’s serverlets technology and hosts the reusable resources needed to customize the behaviour of application
Figure 21
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] 下一页