1 / 14

Proxy Pattern

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 different address space) The proxy looks like the remote object, but isn’t

Télécharger la présentation

Proxy Pattern

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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

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

  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

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

  6. RMI Service Object doBigJob() Client helper Service helper Client Object Local Heap Remote Heap

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

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

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

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

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

  12. Making a Remote Service • Make a remote Interface Defines the methods that can be called remotely Stub and Service Object will implement it • Make a Remote Implementation This is the class that does the “real work” • Rmic to generate stubs & skeletons (Server) Rmic comes with the Java SDK Implementation_stub.class Implementation_Skel.class • Start the registry (Server): rmiregistry • 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.

  14. Class diagram <<interface>> Subject request() subject RealSubject request() Proxy request()

More Related