32
Práctica 3 Linda ISBC 24/11/2009

Práctica 3 Linda ISBC 24/11/2009. Aristotle MESA Publish Sincere Chaplain, Modified 6 years ago

Embed Size (px)

Citation preview

  • Slide 1

Prctica 3 Linda ISBC 24/11/2009 Slide 2 Aristotle MESA Slide 3 Problema Problema de los filsofos 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 distribucin en la mesa En la segunda parte del ejercicio habr que realizar algn 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. Slide 4 Sneca Kant Avempace Aristotle Plato Seneca Kant Model Representation: Philosopher Chopstick Classical Example The dining philosophers problem Slide 5 Classical Example: Inserting the first philosopher Avempace Slide 6 Classical Example: Inserting the first philosopher Avempace [Chopstick=Avempace] Write R[Left= Avempace, Right= Avempace] Slide 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 Slide 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 Slide 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 ? Slide 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] Slide 11 Classical Example: Inserting another philosopher Avempace [Chopstick=Avempace] Seneca R[Left= Seneca, Right= Avempace] write R[Left= Avempace, Right= Seneca] Slide 12 Classical Example: Inserting another philosopher Avempace [Chopstick=Avempace] Seneca R[Left= Seneca, Right= Avempace] write R[Left= Avempace, Right= Seneca] [Chopstick=Seneca] Slide 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] Slide 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] Slide 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] Slide 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] Slide 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] Slide 18 Linda Server en UZ Cliente Web para probar insertar, sacar o leer tuplas (KO!) http://luna3.cps.unizar.es:8080/misServlets/R Linda.html http://luna3.cps.unizar.es:8080/misServlets/R Linda.html Slide 19 Slide 20 Repositorio Slide 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 Slide 22 Clientes SOAP http://luna3.cps.unizar.es:8080/axis/RLinda.jws Generacin 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") Slide 23 Ejemplo Clientes Lisp (require :soap) (require :pxml) (load "RLClient.cl") ;; IN = TAKE, OUT = WR, RD = RD. CG-USER(19): (common-lisp-user::OUT :tuple" MESA PLATON SENECA ") (WSDL-2::|RLindaOUTResponse| (:|RLindaOUTReturn| " MESA PLATON SENECA ")) NIL # Slide 24 Cliente Lisp CG-USER(20): (common-lisp-user::RD :in0 " MESA ? ? ") (WSDL-2::|RLindaRDResponse| (:|RLindaRDReturn| " MESA AVEMPACE ARISTOTLE ")) NIL # Slide 25 Cliente Lisp CL-USER(178): (RD :tuple" MESA ") (WSDL-2::|RLindaRDResponse| (:|RLindaRDReturn| " MESA KANT GROUCHO-MARX ")) NIL # Slide 26 Cliente Lisp (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") Slide 27 Auxiliares CL-USER(181): (list2xml '("MESA" 1 ("a" "b") "c")) " MESA 1 a b c (defun 2xml (lista &optional cadena) (cond ((stringp (car lista)) (2xml (cdr lista) (concatenate 'string cadena " " (car lista) " "))) ((integerp (car lista)) (2xml (cdr lista) (concatenate 'string cadena " " (format nil "~A" (car lista)) " "))) ((eq '? (car lista)) (2xml (cdr lista) (concatenate 'string cadena " " "?" " "))) ((and (listp (car lista)) (not (endp lista))) (2xml (cdr lista) (concatenate 'string cadena " " (2xml (car lista)) " "))) ((endp lista) cadena))) (defun list2xml (lista) (concatenate 'string " " (2xml lista) " ")) Slide 28 Inicia mesa (defun inicia-mesa () (OUT :tuple" MESA PLATON SENECA ") (OUT :tuple" MESA SENECA AVEMPACE ") (OUT :tuple" MESA AVEMPACE ARISTOTLE ") (OUT :tuple" MESA ARISTOTLE KANT ") (OUT :tuple " MESA KANT GROUCHO- MARX ") (OUT :tuple " MESA GROUCHO- MARX PLATON ") ) Slide 29 Lisp example Estilo Rest (old) 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 # Slide 30 Cliente Java // Para compilar y ejecutar este cdigo Java es necesario inclur las libreras de axis1 en el classpath. Disponibles en la URL http://www.apache.org/dyn/closer.cgi/ws/axis/1_4http://www.apache.org/dyn/closer.cgi/ws/axis/1_4 Ejemplo de cliente que accede al metodo OUT import org.apache.axis.client.Call; import org.apache.axis.client.Service; import javax.xml.namespace.QName; public class client { public static void main(String [] args) { try { String endpoint = "http://luna1.cps.unizar.es:8080/axis/services/RLindaWS"; Service service = new Service(); Call call = (Call) service.createCall(); call.setTargetEndpointAddress( new java.net.URL(endpoint) ); call.setOperationName(new QName("http://soapinterop.org/", "RLindaOUT")); String value = (String) call.invoke( new Object[] { "[\"esto\",[1],\"prueba\"]" } ); System.out.println(value); } catch (Exception e) { System.err.println(e.toString()); } Slide 31 Cliente Java // Para compilar y ejecutar este cdigo Java es necesario inclur las libreras de axis1 en el classpath. // Disponibles en la URL http://www.apache.org/dyn/closer.cgi/ws/axis/1_4http://www.apache.org/dyn/closer.cgi/ws/axis/1_4 Ejemplo de cliente que accede al metodo OUT import org.apache.axis.client.Call; import org.apache.axis.client.Service; import javax.xml.namespace.QName; public class client { public static void main(String [] args) { try { String endpoint = "http://luna3.cps.unizar.es:8080/axis/services/RLindaWS"; Service service = new Service(); Call call = (Call) service.createCall(); call.setTargetEndpointAddress( new java.net.URL(endpoint) ); call.setOperationName(new QName("http://soapinterop.org/", "RLindaOUT")); String value = (String) call.invoke( new Object[] { "[\"esto\",[1],\"prueba\"]" } ); System.out.println(value); } catch (Exception e) { System.err.println(e.toString()); } Slide 32 Cliente Java Ejemplo de cliente que accede al metodo IN import org.apache.axis.client.Call; import org.apache.axis.client.Service; import javax.xml.namespace.QName; public class client { public static void main(String [] args) { try { String endpoint = "http://luna3.cps.unizar.es:8080/axis/services/RLindaWS"; Service service = new Service(); Call call = (Call) service.createCall(); call.setTargetEndpointAddress( new java.net.URL(endpoint) ); call.setOperationName(new QName("http://soapinterop.org/", "RLindaIN")); String value = (String) call.invoke( new Object[] { "[\"esto\",[\?\],\?\"]" } ); System.out.println(value); } catch (Exception e) { System.err.println(e.toString()); }