170 likes | 319 Views
Local vs. distributed Objects. Differences between local and distributed objects in: References (to objects) Activation/Deactivation Migration Persistence Latency of Requests Concurrency Communication Security. Caller. Stub. Hvad viser figuren. public class HelloWorldProxy {
E N D
Local vs. distributed Objects • Differences between local and distributed objects in: • References (to objects) • Activation/Deactivation • Migration • Persistence • Latency of Requests • Concurrency • Communication • Security
Caller Stub Hvad viser figuren public class HelloWorldProxy { public HelloWorldProxy() { } public String sayHelloWorld() { … // get a datagram socket socket = new DatagramSocket(); // send the request byte[] buf = new byte[256]; buf = methodCalled.getBytes(); InetAddress address = InetAddress.getByName("localhost"); DatagramPacket packet = new DatagramPacket(buf, buf.length, address, 4450); socket.send(packet); // get a response packet = new DatagramPacket(buf, buf.length); socket.receive(packet); response = new String(packet.getData()); } catch (Exception e) { e.printStackTrace(); } socket.close(); return response; …
Hvad viser figuren? Client Server Application Application Presentation Presentation Session Session Requests Transport Input Stream Transport Output Stream Results
Hvad viser figuren? Client Server Application Application Presentation Presentation Session Session Request Datagrams Transport Transport Result Datagrams
Called Caller Caller Called Stub Forklar figuren Caller Stub Transport Layer (e.g. TCP or UDP)
Server Stub Generation Client Stub Generation Server Coding Client Coding Forklar figuren Design Interface Definition Server Registration
IDL-Compiler Teamcl.hh Teamsv.hh Teamcl.cc Teamsv.cc Forklar figuren Team.midl Team.idl Team.java Team.wsdl included in generates reads
Hvilke teknologier bruges her 3 Client Server Legacy code on server 1 2 Registry
Forklar hvad vi kigger på • TV-Program Web service (TVPSService.class): • Java Server • C# Client (Pocket PC .NET CF) • Java Client (UNIX, LINUX, Windows) <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> <service name="TVPSService" provider="java:RPC"> <parameter name="className" value="tvps.TVPSService"/> <parameter name="allowedMethods" value="*"/> <beanMapping qname="myNS:Programme" xmlns:myNS="urn:BeanService" languageSpecificType="java:tvps.Programme"/> </service> </deployment> • Key elements: • Package of service = tvps • Class of service = tvps.TVPSService • Allowed methods = all (*) • Custom class (return parameter) = tvps.Programme
Hvad ser vi på? • Given the WSDL (-p = destination package = hello): • java org.apache.axis.wsdl.WSDL2Java http://localhost:8080/axis/HelloWorld.jws?wsdl –p hello package hello; public class HelloWorldClient { public static void main (String args[]) throws Exception { // Make a service HelloWorldService service = new HelloWorldServiceLocator(); //Now use the service to get a stub which implements the SDI HelloWorld stub = (HelloWorld) service.getHelloWorld(); String text = stub.getHelloWorldMessage("Test af OO indpakning"); System.out.println(”Recieved from server: "+text); } }
Forklar figuren Hello.java rmic Compiler HelloImpl_Stub.class HelloImpl_Skeleton.class package examples.hello; import java.rmi.Remote; import java.rmi.RemoteException; public interface Hello extends Remote { String sayHello() throws RemoteException; void someOther(String param) throws RemoteException; }
package examples.hello; import java.rmi.Naming; import java.rmi.RemoteException; import java.rmi.RMISecurityManager; import java.rmi.server.UnicastRemoteObject; public class HelloImpl extends UnicastRemoteObject implements Hello { public HelloImpl() throws RemoteException { super(); } public String sayHello() { return "Hello World! ; } public static void main(String args[]) { // Create and install a security manager //if (System.getSecurityManager() == null) { // System.setSecurityManager(new RMISecurityManager()); //} try { HelloImpl obj = new HelloImpl(); // Bind this object instance to the name "HelloServer" Naming.rebind("rmi://192.168.1.101/HelloServer", obj); System.out.println("HelloServer bound in registry"); } catch (Exception e) { System.out.println("HelloImpl err: " + e.getMessage()); e.printStackTrace(); } } } Hvad ser vi på. Forklar.
Pattern Client Server X Hvad viser figuren Client component Client Object SOAP X Server object Server component
Object = row in RDBMS table Persistence Concepts C++/Java object Storage Storage Home Objects Incarnation C++/Java object Datastore Sessions Storage Homes RDBMS Server Storage Object RDBMS Table Incarnation C++/Java object