Presentation is loading. Please wait.

Presentation is loading. Please wait.

Proxy Pattern. What’s a Proxy? A remote proxy acts as a local representative of a remote object Remote Object: instantiated in a different JVM heap (a.

Similar presentations


Presentation on theme: "Proxy Pattern. What’s a Proxy? A remote proxy acts as a local representative of a remote object Remote Object: instantiated in a different JVM heap (a."— Presentation transcript:

1 Proxy Pattern

2 What’s a Proxy? A remote proxy acts as a local representative of a remote object Remote Object: instantiated in a different JVM heap (a different address space) The proxy looks like the remote object, but isn’t The proxy takes method calls and handles all the details of network communication to the remote object A remote proxy acts as a local representative of a remote object Remote Object: instantiated in a different JVM heap (a different address space) The proxy looks like the remote object, but isn’t The proxy takes method calls and handles all the details of network communication to the remote object

3 What’s a Proxy? Client Code Proxy Local HeapRemote Heap Remote Object

4 RMI Luckily, we don’t have to write the code to handle network communications RMI: Remote Method Invocation Java provides packages that we can easily use to make our current code ready for network communication with very few changes The book provides a very detailed guide to this process Luckily, we don’t have to write the code to handle network communications RMI: Remote Method Invocation Java provides packages that we can easily use to make our current code ready for network communication with very few changes The book provides a very detailed guide to this process

5 RMI Client Object Client helper Local HeapRemote Heap Service Object Service helper Proxy, pretends to be the actual service. Packs requests and handles network communications Unpacks requests from client helper; calls requests on the Service Object

6 RMI Client Object Client helper Local HeapRemote Heap Service Object Service helper doBigJob()

7 RMI Client Object Client helper Local HeapRemote Heap Service Object Service helper doBigJob() Client helper packages up the info about the method call (Serializable) & ships it over the network “client wants to call a method”

8 RMI Client Object Client helper Local HeapRemote Heap Service Object Service helper Service helper packs the result and handles network communications result

9 RMI Client Object Client helper Local HeapRemote Heap Service Object Service helper Client helper unpacks the result and passes it back to the Client Object packaged result

10 RMI Client Object Client helper Local HeapRemote Heap Service Object Service helper The Client Object doesn’t know it isn’t talking to the Service Object in its own heap! result

11 RMI Client Object Client helper Local HeapRemote Heap Service Object Service helper Newer versions of Java don’t require an explicit skeleton object, but something is still taking care of the skeleton behavior. RMI STUB RMI SKELETO N

12 Making a Remote Service 1.Make a remote Interface Defines the methods that can be called remotely Stub and Service Object will implement it 2.Make a Remote Implementation This is the class that does the “real work” 3.Rmic to generate stubs & skeletons (Server) Rmic comes with the Java SDK Implementation_stub.class Implementation_Skel.class 4.Start the registry (Server): rmiregistry 5.Start the remote service (server) Needs to be in a separate thread from the rmiregistry 1.Make a remote Interface Defines the methods that can be called remotely Stub and Service Object will implement it 2.Make a Remote Implementation This is the class that does the “real work” 3.Rmic to generate stubs & skeletons (Server) Rmic comes with the Java SDK Implementation_stub.class Implementation_Skel.class 4.Start the registry (Server): rmiregistry 5.Start the remote service (server) Needs to be in a separate thread from the rmiregistry

13 Back to the Pattern DEFINITION: The Proxy Pattern provides a surrogate or placeholder for another object to control access to it. DEFINITION: The Proxy Pattern provides a surrogate or placeholder for another object to control access to it.

14 Class diagram > Subject request() RealSubject request() Proxy request() subject


Download ppt "Proxy Pattern. What’s a Proxy? A remote proxy acts as a local representative of a remote object Remote Object: instantiated in a different JVM heap (a."

Similar presentations


Ads by Google