Práctica 3 Linda/Jess ISBC 24/11/2008. Aristotle MESA Publicada porHeriberto Feliciano Modificado hace 2 años

1 Práctica 3 Linda/Jess ISBC 24/11/2008 ...
Author: Heriberto Feliciano
0 downloads 0 Views

1 Práctica 3 Linda/Jess ISBC 24/11/2008

3 Problema Problema de los filósofos alrededor de una mesa La mesa se representará en el espacio de tuplas con los comensales El programa deberá introducirnos como comensales en la mesa. Deberemos mostrar la distribución en la mesa En la segunda parte del ejercicio habrá que realizar algún tipo de razonamiento para elegir el lugar en el que nos sentamos, y o bien habrá que obtener permiso de un coordinador que decide a quienes les da permiso para comer evitando bloqueos.

4 Séneca Kant Avempace Aristotle Plato Seneca Kant Model Representation: Philosopher Chopstick Classical Example The dining philosophers problem

5 Classical Example: Inserting the first philosopher Avempace

6 Classical Example: Inserting the first philosopher Avempace [Chopstick=Avempace] Write R[Left= Avempace, Right= Avempace]

7 Classical Example: Inserting the first philosopher Avempace Write [Chopstick=Avempace] R[Left= Avempace, Right= Avempace] http://bubu.cps.unizar.es:/CoordinationServlethttp://bubu.cps.unizar.es:/CoordinationServlet? REQUEST= write java Avempace

8 Classical Example: Inserting the first philosopher Avempace Write [Chopstick=Avempace] R[Left= Avempace, Right= Avempace] http://bubu.cps.unizar.es:/CoordinationServlethttp://bubu.cps.unizar.es:/CoordinationServlet? REQUEST= write java Avempace

9 Classical Example: Inserting another philosopher Avempace Take Seneca [Chopstick=Avempace] R[Left= Avempace, Right= Avempace] http://bubu.cps.unizar.es:/CoordinationServlethttp://bubu.cps.unizar.es:/CoordinationServlet? REQUEST= take java ?

10 Classical Example: Inserting another philosopher Avempace [Chopstick=Avempace] Seneca R[Left= Avempace, Right= Avempace] R[Left= Avempace, Right= Seneca] R[Left= Seneca, Right= Avempace]

11 Classical Example: Inserting another philosopher Avempace [Chopstick=Avempace] Seneca R[Left= Seneca, Right= Avempace] write R[Left= Avempace, Right= Seneca]

12 Classical Example: Inserting another philosopher Avempace [Chopstick=Avempace] Seneca R[Left= Seneca, Right= Avempace] write R[Left= Avempace, Right= Seneca] [Chopstick=Seneca]

13 Classical Example: Before eating Avempace [Chopstick=Avempace] Seneca R[Left= Seneca, Right= Plato] R[Left= Avempace, Right= Seneca] [Chopstick=Seneca] Plato R[Left= Plato, Right= Avempace] [Chopstick=Plato]

14 Classical Example: Eating Avempace [Chopstick=Avempace] Seneca Take[ R[Left= Avempace, Right= ? ] ] [Chopstick=Seneca] Plato [Chopstick=Plato] Take[ R[Left= Seneca, Right= ? ] ] R[Left= Seneca, Right= Plato] R[Left= Plato, Right= Avempace] R[Left= Avempace, Right= Seneca]

15 Classical Example: Eating Avempace [Chopstick=Avempace] Seneca R[Left= Avempace, Right= Seneca] [Chopstick=Seneca] Plato [Chopstick=Plato] R[Left= Seneca, Right= Plato ] R[Left= Plato, Right= Avempace]

16 Classical Example: Eating Avempace [Chopstick=Avempace] Seneca R[Left= Avempace, Right= Seneca] [Chopstick=Seneca] Plato [Chopstick=Plato] R[Left= Seneca, Right= Plato] Take[ [Chopstick=Seneca] ] Take[ [Chopstick= Plato] ] Take[ [Chopstick= Avempace] ] Take[ [Chopstick= Seneca] ] R[Left= Plato, Right= Avempace]

17 Classical Example: Eating Avempace [Chopstick=Avempace] Seneca R[Left= Avempace, Right= Seneca] [Chopstick=Seneca] Plato [Chopstick=Plato] R[Left= Seneca, Right= Plato ] Take[ [Chopstick= Seneca] ] R[Left= Plato, Right= Avempace]

18 Linda Server en UZ Cliente Web para probar insertar, sacar o leer tuplas http://luna1.cps.unizar.es:8080/misServlets/R Linda.html http://luna1.cps.unizar.es:8080/misServlets/R Linda.html

19

20 Repositorio

21 Ejemplos Tuplas/Templates Ejemplo de OUT: Lenguaje Tupla: [[“esto”,”es”,[1],”prueba”]] Lenguaje XML: esto es 1 prueba Ejemplo de IN/RD: Lenguaje Tupla: [[“?”,”es”,[“?”],”prueba”]] Lenguaje XML: es prueba

22 Clientes SOAP http://luna1.cps.unizar.es:8080/axis/services/RLindaWS?wsdl Generación Clientes Lisp (require :soap) (use-package :net.xmp.soap) (decode-wsdl-namespaces :file "RLindaW.wsdl") (setf *wsdl* (decode-wsdl-file "RLindaW.wsdl")) make-client-interface *wsdl* 0 "RLClient.cl")

23 Ejemplo Clientes Lisp (require :soap) (require :pxml) (load "RLClient.cl") ;; IN = TAKE, OUT = WR, RD = RD. CG-USER(19): (common-lisp-user::OUT :in0 " MESA PLATON SENECA ") (WSDL-2::|RLindaOUTResponse| (:|RLindaOUTReturn| " MESA PLATON SENECA ")) NIL #

24 Cliente Lisp CG-USER(20): (common-lisp-user::RD :in0 " MESA ? ? ") (WSDL-2::|RLindaRDResponse| (:|RLindaRDReturn| " MESA AVEMPACE ARISTOTLE ")) NIL #

25 Cliente Lisp CL-USER(178): (RD :in0 " MESA ") (WSDL-2::|RLindaRDResponse| (:|RLindaRDReturn| " MESA KANT GROUCHO-MARX ")) NIL #

26 (defun RD-LST (template) (MAPCAR #'SECOND (remove-if-not #'listp (CDDAR (CDDADR (net.xml.parser:PARSE-XML (car (cdaDR (MULTIPLE-VALUE-BIND (X Y) (RD :in0 template) X))))))))) CL-USER(179): RD-LST hace un RD con un template en XML y devuelve una lista CL-USER(182): (RD-LST " MESA ? ? ") ("MESA" "KANT" "GROUCHO-MARX")

27 Lisp example CG-USER(14):(net.aserve.client:do-http-request http://bubu.cps.unizar.es:8080/CoordinationServlet :method :post http://bubu.cps.unizar.es:8080/CoordinationServlet :content-type "application/x-www-form-urlencoded" :query '(("REQUEST". " write Kant "))) "" 200 NIL #

28 Java example //servlet Address String ref = "http://bubu.cps.unizar.es:8080/CoordinationServlet"; //Request to the servlet String EncodedTLRR = java.net.URLEncoder.encode("REQUEST="+http://bubu.cps.unizar.es:8080/CoordinationServlet "=...... "); // Build connection url = new URL(ref); con = (HttpURLConnection)url.openConnection(); con.setRequestMethod("POST"); con.setDoOutput(true); con.setDoInput(true); con.setUseCaches(false); con.setAllowUserInteraction(false); con.setRequestProperty("Content-type","application/x-www-form-urlencoded"); con.setRequestProperty ("Content-length", String.valueOf(EncodedTLRR.length())); // writing parameters wr = new OutputStreamWriter(con.getOutputStream()); wr.write(EncodedTLRR); wr.flush(); wr.close(); // Read response in = new BufferedReader(new InputStreamReader (con.getInputStream())); String resultado = in.readLine(); // close connection con.disconnect();

29 Middleware Un middleware proporciona un conjunto de primitivas de comunicación de alto nivel que son requeridas para el desarrollo de aplicaciones distribuidas en red El programador es liberado de detalles relacionados con la comunicación en red, control de concurrencia y/o gestión de transacciones, y puede focalizar todo su atención en el nivel de aplicación Conceptos de partida

30 Comunicación en Servicios Web Services are defined as exchange of messages between participants. This separation of participants in a exchange is a key to decoupling applications. Service-oriented systems hide the internal abstractions that provides the service such as classes, objects, methods, or remote procedures. By avoiding any knowledge of the internal structure, it is possible to incorporate any software component or application that can be "wrapped" in message handling code that allows it to adhere to the formal service definition Web Services Architecture W3C Working Group Note 11 February 2004 http://www.w3.org/TR/ws-arch/wsa.pdf Si además, las interacciones son asíncronas, los participantes nunca comparten procesos. Esto ayuda a mantener las componentes desacopladas.

31 Vamos a ver un ejemplo ya! http://webservices.amazon.com/onca/x ml?Service=AWSECommerceService& AWSAccessKeyId=1JFWX63WKHTWX 34G4KG2&Operation=ItemSearch&Key words=Aragon&SearchIndex=Books LIBROS EN AMAZON QUE TRATAN DE ARAGON ESTILO REST de invocación de servicios WEB No hay SOAP, NI UDDI, NI WSDL!!! ¡¡¡SOLO HTTP y XML!!!

32

33 Idea clave: Intercambio de documentos documentos Los métodos de HTTP son las OPCIONES, GET (recupera documento), POST (adjunta información al recurso), PUT (almacena información), DELETE (borra el recurso indicado)

34 PARTE III. Sistema “Ideal” SOA INFRAESTRUCTURA COMÚN Middleware Tradicional gestión procesos gestión datos gestión mensajes gestión objetos gestión transacciones Web Services Middleware Ejecutor Procesos Ejecutor Protocolos Process logic Process logic Process logic... Web service Middleware WS Interface WS Interface WS Interface... External Clients Service provider Internet Broker de Mensajes Lógica de Integración Protocolos Horizontales Negocio Routing logic Mediador-Middleware conv (.NET, J2EE,...) Mediador SW INFRAESTRUCTURA COMÚN Middleware Servicios Web -XML -Protocolos Internet -Estándares -SOAP, WSDL, UDDI -Protocolos Horizontales -Orquestación, composición BPEL4WS WSCI, WS-CDL Broker de Mensajes Broker de Mensajes WS-Coordination, WS-Transaction

35 Productos/Especificaciones SOA TIBCO: Enterprise Server Bus

36 Productos/Especificaciones SOA TIBCO: Enterprise Server Bus

37 Productos/Especificaciones SOA IBM: Enterprise Server Bus

38 Productos/Especificaciones SOA IBM: Enterprise Server Bus

39 Productos/Especificaciones SOA SUN: Java™ Business Integration (JBI) 1.0

40 Productos/Especificaciones SOA http://drops.dagstuhl.de/opus/volltexte/2006/524/ Service-Oriented Computing: A Research Roadmap

41 Web Service Definition Language ( WSDL ) OperationPort Type MessageBinding PortService soporta Input & Output Ofrece Como codificar Formatos & Protocolos Como invocar Implementa WSDL ofrece el marco para definir Interface: operaciones y sus entradas y salidas (operations & input/output) Access specification: SOAP bindings (por ejemplo, RPC) Endpoint: la localización del servicio

42 Estructura principal de WSDL XML schema types definition de un mensaje Conjunto de operations protocolos de comunicación lista de binding y ports BACKUP

43 Ejemplo WSDL Method calculate Input: opname -> "+" "-" "*" "ash" "truncate" "ceiling" "factorial" "rem" "gcd" "expt" num1 -> a string of digits num2 -> a string of digits Output: calcResult -> a string of digits Method decodeNum Input: num -> a string of digits base -> an integer Output: decResult -> an array of integers example: num: "12345678901234567890" base: 10000 output: 123 4567 8901 2345 6789 Method encodeNum Input: bigits -> an array of integers base -> an integer Output: encResult -> a string of digits Sample-bignum.wsdl

44 service provider cliente servicio objeto de aplicación (cliente) objeto de aplicación proveedor servicio) stubskeleton WSDL del proveedor del servicio compilador WSDL (lado del servidor) compilador WSDL (lado del cliente) middleware basado en SOAP Mensajes SOAP generador WSDL 1 2 Utilización de WSDL (encode-wsdl-file "bignum-server.wsdl“ :servers *server*) (require :soap) (use-package :net.xmp.soap) (decode-wsdl-namespaces :file "bignum-server.wsdl") (setf *wsdl* (decode-wsdl-file "bignum-server.wsdl")) (make-client-interface *wsdl* 0 "bignum-client.cl") (require :soap) :ld bignum-client... (client-1 :|opname| "ash" :|num1| "1" :|num2| "500")... (client-5 :|num| "1234567890" :|base| 100)... (client-3 :|bigits| '(12 34 56 78 90) :|base| 100)...

45 WSDL Linda Provisional… http://luna1.cps.unizar.es:8080/axis/RLinda.jws?wsdl http://luna1.cps.unizar.es:8080/axis/RLinda.jws?wsdl

46 Sesion Linda ;; current optimization settings evaluate (EXPLAIN-COMPILER-SETTINGS). CL-USER(1): CL-USER(6): : cd D:\Lisp\WS CL-USER(6): (require :soap) ; Fast loading C:\Archivos de programa\acl80\code\SOAP.001 ;;; Installing soap patch, version 1 ; Fast loading C:\Archivos de programa\acl80\code\SOAPA.001 ;;; Installing soapa patch, version 1 ; Fast loading C:\Archivos de programa\acl80\code\SAX.fasl ; Fast loading C:\Archivos de programa\acl80\code\ASERVE.fasl ; Fast loading from bundle code\ACLDNS.fasl. ;;; Installing acldns patch, version 1 T CL-USER(7): :ld RLinda-client.cl ; Loading D:\Lisp\WS\RLinda-client.cl CL-USER(8): (CLIENT-5 :|TUPLE| " ") (WSDL-2::|outResponse| (:|outReturn| "out_OK")) NIL

47 Sesion Linda # CL-USER(9): (CLIENT-5 :|TUPLE| " ") (WSDL-2::|outResponse| (:|outReturn| "out_OK")) NIL # CL-USER(10): (CLIENT-5 :|TUPLE| " ") (WSDL-2::|outResponse| (:|outReturn| "out_OK")) NIL # CL-USER(11): (CLIENT-2 :|TEMPLATE| " ") (WSDL-2::|rdResponse| (:|rdReturn| " ")) NIL

48 Sesion Linda # CL-USER(12): (CLIENT-1 :|TEMPLATE| " ") (WSDL-2::|inResponse| (:|inReturn| " ")) NIL # CL-USER(15): (CLIENT-1 :|TEMPLATE| " ") (WSDL-2::|inResponse| (:|inReturn| " ")) NIL # CL-USER(16):

49 Nuva estructura de tuplas 3 3