1 / 36

CS 210

CS 210. Proxy Pattern Nov 14 th , 2006. Revisit the Gumball machine example. The same example covered in the State pattern Now we want to add some monitor a collection of Gumball machines. Gumball Class. Gumball Monitor. Run the monitor. Look at Eclipse code. Role of the remote Proxy.

dionne
Download Presentation

CS 210

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. CS 210 Proxy Pattern Nov 14th, 2006

  2. Revisit the Gumball machine example • The same example covered in the State pattern • Now we want to add some monitor a collection of Gumball machines

  3. Gumball Class

  4. Gumball Monitor

  5. Run the monitor • Look at Eclipse code.

  6. Role of the remote Proxy

  7. RMI Detour in looking at Proxy Pattern

  8. Remote Methods 101

  9. How the method call happensClient calls method

  10. Client Helper forwards to service helper

  11. Service helper calls the real object

  12. Real object returns result

  13. Service helper forwards result to client helper

  14. Client helper returns result to client

  15. Steps in using Java RMI

  16. Additional steps

  17. STEP 1 Remote Interface

  18. STEP 1 Remote Interface

  19. STEP 2 Remote Implementation

  20. STEP 2 Remote Implementation

  21. STEP 3 Create Stubs & Skeletons

  22. Client talks to the stub

  23. Hooking up client and server objects

  24. Back to Gumball machine problem

  25. Gumball Machine remote interface import java.rmi.*; public interface GumballMachineRemote extends Remote { public int getCount() throws RemoteException; public String getLocation() throws RemoteException; public State getState() throws RemoteException; }

  26. State interface extends Serializable import java.io.*; public interface State extends Serializable { public void insertQuarter(); public void ejectQuarter(); public void turnCrank(); public void dispense(); }

  27. Use of keyword “transient” public class NoQuarterState implements State { transient GumballMachine gumballMachine; public NoQuarterState(GumballMachine gumballMachine) { this.gumballMachine = gumballMachine; } public void insertQuarter() { System.out.println("You inserted a quarter"); gumballMachine.setState(gumballMachine.getHasQuarterState()); } // other methods } The use of transient to to ensure that the seriolzation does not involve this object as well.

  28. More of the implementation… • Look at Eclipse for implementation of: • GumballMachineRemote • GumballTestDrive • GumballMonitor Client • GumballMonitor

  29. Proxy Pattern defined The Proxy Pattern provides a surrogate or placeholder for another object to control access to it. The proxy pattern is used to create a representative object that controls access to another object, which may be remote, expensive to create or in need of securing.

  30. Proxy Class Diagram

More Related