Title: Pr
1Práctica 3 Linda
2Classical Example The dining philosophers problem
Model Representation Philosopher Relation
3Problema
- 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.
4Classical Example The dining philosophers problem
Model Representation Philosopher Chopstick
Aristotle
Avempace
Plato
ltexamplePhilosophergt ltchopstickgtKantlt/chopstic
kgt lt/examplePhilosophergt
Séneca
Kant
ltexamplePhilosophergt ltchopstickgtSenecalt/chopst
ickgt lt/examplePhilosophergt
5Classical Example Inserting the first philosopher
Avempace
Tuple Space
6Classical Example Inserting the first philosopher
Avempace
Tuple Space
7Classical Example Inserting the first philosopher
Avempace
Write
Tuple Space
ChopstickAvempace
Write
http//bubu.cps.unizar.es/CoordinationServlet? RE
QUESTlt?xml version"1.0"?gt ltCoordinationServicegt
ltfunctiongtwritelt/functiongt ltclienttypegtjavalt/cli
enttypegt lttuplegt ltexamplePhilosophergt
ltchopstickgtAvempacelt/chopstickgt
lt/examplePhilosophergt lt/tuplegt lt/CoordinationServ
icegt
RLeft Avempace, Right Avempace
8Classical Example Inserting the first philosopher
Avempace
Write
Tuple Space
ChopstickAvempace
Write
http//bubu.cps.unizar.es/CoordinationServlet? RE
QUESTlt?xml version"1.0"?gt ltCoordinationServicegt
ltfunctiongtwritelt/functiongt ltclienttypegtjavalt/cli
enttypegt lttuplegt ltrelationgt
ltLeftgt Avempace lt/Leftgt
ltRightgt Avempace lt/Rightgt lt/relationgt
lt/tuplegt lt/CoordinationServicegt
RLeft Avempace, Right Avempace
9Classical Example Inserting another philosopher
Avempace
Tuple Space
ChopstickAvempace
http//bubu.cps.unizar.es/CoordinationServlet? RE
QUESTlt?xml version"1.0"?gt ltCoordinationServicegt
ltfunctiongttakelt/functiongt ltclienttypegtjavalt/clie
nttypegt lttuplegt ltrelationgt
ltLeftgt ? lt/Leftgt ltRightgt
? lt/Rightgt lt/relationgt
lt/tuplegt lt/CoordinationServicegt
RLeft Avempace, Right Avempace
Take
Seneca
10Classical Example Inserting another philosopher
Avempace
Tuple Space
ChopstickAvempace
RLeft Avempace, Right Avempace
RLeft Avempace, Right Seneca
Seneca
RLeft Seneca, Right Avempace
11Classical Example Inserting another philosopher
Avempace
Tuple Space
ChopstickAvempace
RLeft Avempace, Right Seneca
write
RLeft Seneca, Right Avempace
write
Seneca
12Classical Example Inserting another philosopher
Avempace
Tuple Space
ChopstickAvempace
RLeft Avempace, Right Seneca
ChopstickSeneca
RLeft Seneca, Right Avempace
write
Seneca
13Classical Example Before eating
Avempace
Tuple Space
ChopstickAvempace
Plato
RLeft Plato, Right Avempace
ChopstickPlato
RLeft Avempace, Right Seneca
ChopstickSeneca
RLeft Seneca, Right Plato
Seneca
14Classical Example Eating
Avempace
TakeRLeft Avempace, Right ?
Tuple Space
ChopstickAvempace
Plato
RLeft Plato, Right Avempace
ChopstickPlato
RLeft Avempace, Right Seneca
ChopstickSeneca
RLeft Seneca, Right Plato
TakeRLeft Seneca, Right ?
Seneca
15Classical Example Eating
Avempace
RLeft Avempace, Right Seneca
Tuple Space
ChopstickAvempace
Plato
RLeft Plato, Right Avempace
ChopstickPlato
RLeft Seneca, Right Plato
ChopstickSeneca
Seneca
16Classical Example Eating
Avempace
RLeft Avempace, Right Seneca
Tuple Space
ChopstickAvempace
Plato
RLeft Plato, Right Avempace
TakeChopstick Avempace
TakeChopstick Seneca
ChopstickPlato
RLeft Seneca, Right Plato
ChopstickSeneca
TakeChopstickSeneca
TakeChopstick Plato
Seneca
17Classical Example Eating
ChopstickAvempace
Avempace
RLeft Avempace, Right Seneca
Tuple Space
Plato
RLeft Plato, Right Avempace
TakeChopstick Seneca
RLeft Seneca, Right Plato
ChopstickSeneca
ChopstickPlato
Seneca
18Linda Server en UZ
- Cliente Web para probar insertar, sacar o leer
tuplas (KO!) - http//luna3.cps.unizar.es8080/misServlets/RLinda
.html
19(No Transcript)
20Repositorio
21Ejemplos Tuplas/Templates
- Ejemplo de OUT
-
- Lenguaje Tupla esto,es,1,prueba
- Lenguaje XML lttupleDescriptiongtlttuplegtlttuplegtltstr
inggtestolt/stringgtltstringgteslt/stringgt - lttuplegt1lt/tuplegtltstringgtpruebalt/string
gtlt/tuplegtlt/tuplegtlt/tupleDescriptiongt -
- Ejemplo de IN/RD
-
- Lenguaje Tupla ?,es,?,prueba
- Lenguaje XML
- lttupleDescriptiongtlttuplegtlttuplegtltwildcard /gt
ltstringgteslt/stringgt - lttuplegt ltwildcard /gtlt/tuplegt ltstringgtpruebalt/strin
ggtlt/tuplegtlt/tuplegtlt/tupleDescriptiongt -
22Clientes SOAP
- http//luna3.cps.unizar.es8080/axis/RLinda.jws
- 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")
23Ejemplo Clientes Lisp
- (require soap)
- (require pxml)
- (load "RLClient.cl")
- IN TAKE, OUT WR, RD RD.
- CG-USER(19) (common-lisp-userOUT
tuple"lttupleDescriptiongtlttuplegtltstringgtMESAlt/stri
nggtltstringgtPLATONlt/stringgtltstringgtSENECAlt/stringgtlt
/tuplegtlt/tupleDescriptiongt") - (WSDL-2RLindaOUTResponse
- (RLindaOUTReturn
- "lttupleDescriptiongtlttuplegtltstringgtMESAlt/stringgtlt
stringgtPLATONlt/stringgtltstringgtSENECAlt/stringgtlt/tup
legtlt/tupleDescriptiongt")) - NIL
- ltSOAP-ASERVE-CLIENT-STRING-IN-OUT-CONNECTOR _at_
x2104f8a2gt
24Cliente Lisp
- CG-USER(20) (common-lisp-userRD in0
"lttupleDescriptiongtlttuplegtltstringgtMESAlt/stringgtltst
ringgt?lt/stringgt - ltstringgt?lt/stringgtlt/tuplegtlt/tupleDescriptiongt")
- (WSDL-2RLindaRDResponse
- (RLindaRDReturn "lt?xml version\"1.0\"
encoding\"UTF-8\"?gt lttupleDescriptiongt lttuplegt
ltstringgtMESAlt/stringgt ltstringgtAVEMPACElt/st
ringgt ltstringgtARISTOTLElt/stringgt lt/tuplegt
lt/tupleDescriptiongt ")) - NIL
- ltSOAP-ASERVE-CLIENT-STRING-IN-OUT-CONNECTOR _at_
x217c4e62gt
25Cliente Lisp
- CL-USER(178) (RD tuple"lttupleDescriptiongtlttuplegt
ltstringgtMESAlt/stringgtltwildcard /gt - ltwildcard /gtlt/tuplegtlt/tupleDescriptiongt")
- (WSDL-2RLindaRDResponse
- (RLindaRDReturn "lt?xml version\"1.0\"
encoding\"UTF-8\"?gt lttupleDescriptiongt lttuplegt
ltstringgtMESAlt/stringgt ltstringgtKANTlt/string
gt ltstringgtGROUCHO-MARXlt/stringgt lt/tuplegt
lt/tupleDescriptiongt ")) - NIL
- ltSOAP-ASERVE-CLIENT-STRING-IN-OUT-CONNECTOR _at_
x22224ee2gt
26Cliente Lisp
- (defun RD-LST (template)
- (MAPCAR 'SECOND
- (remove-if-not 'listp
- (CDDAR
- (CDDADR
- (net.xml.parserPARSE-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 "lttupleDescriptiongtlttuplegtlts
tringgtMESAlt/stringgtltstringgt?lt/stringgt - ltstringgt?lt/stringgtlt/tuplegtlt/tupleDescripti
ongt") - ("MESA" "KANT" "GROUCHO-MARX")
27Auxiliares
- CL-USER(181) (list2xml '("MESA" 1 ("a" "b")
"c")) - "lttupleDescriptiongtlttuplegtltstringgtMESAlt/stringgtltin
tegergt1lt/integergtlttuplegtltstringgtalt/stringgtltstringgt
blt/stringgtlt/tuplegtltstringgtclt/stringgtlt/tuplegtlt/tupl
eDescriptiongt - (defun 2xml (lista optional cadena)
- (cond
- ((stringp (car lista))
- (2xml (cdr lista) (concatenate 'string cadena
"ltstringgt" (car lista) "lt/stringgt"))) - ((integerp (car lista))
- (2xml (cdr lista) (concatenate 'string cadena
"ltintegergt" (format nil "A" (car lista))
"lt/integergt"))) - ((eq '? (car lista))
- (2xml (cdr lista) (concatenate 'string cadena
"ltstringgt" "?" "lt/stringgt"))) - ((and (listp (car lista)) (not (endp lista)))
- (2xml (cdr lista) (concatenate 'string cadena
"lttuplegt" (2xml (car lista)) "lt/tuplegt"))) - ((endp lista) cadena)))
- (defun list2xml (lista)
- (concatenate 'string "lttupleDescriptiongtlttuplegt
" (2xml lista) "lt/tuplegtlt/tupleDescriptiongt"))
28Inicia mesa
- (defun inicia-mesa ()
- (OUT tuple"lttupleDescriptiongtlttuplegtltstringgtMES
Alt/stringgtltstringgtPLATONlt/stringgtltstringgtSENECAlt/s
tringgtlt/tuplegtlt/tupleDescriptiongt") - (OUT tuple"lttupleDescriptiongtlttuplegtltstringgtMES
Alt/stringgtltstringgtSENECAlt/stringgtltstringgtAVEMPACElt
/stringgtlt/tuplegtlt/tupleDescriptiongt") - (OUT tuple"lttupleDescriptiongtlttuplegtltstringgtMES
Alt/stringgtltstringgtAVEMPACElt/stringgtltstringgtARISTOT
LElt/stringgtlt/tuplegtlt/tupleDescriptiongt") - (OUT tuple"lttupleDescriptiongtlttuplegtltstringgtMES
Alt/stringgtltstringgtARISTOTLElt/stringgtltstringgtKANTlt/
stringgtlt/tuplegtlt/tupleDescriptiongt") - (OUT tuple "lttupleDescriptiongtlttuplegtltstringgtME
SAlt/stringgtltstringgtKANTlt/stringgtltstringgtGROUCHO-MA
RXlt/stringgtlt/tuplegtlt/tupleDescriptiongt") - (OUT tuple "lttupleDescriptiongtlttuplegtltstringgtME
SAlt/stringgtltstringgtGROUCHO-MARXlt/stringgtltstringgtPL
ATONlt/stringgtlt/tuplegtlt/tupleDescriptiongt") - )
29Lisp example Estilo Rest (old)
CG-USER(14)(net.aserve.clientdo-http-request
http//bubu.cps.unizar.es8080/CoordinationServlet
method post content-type "application/x-www-f
orm-urlencoded" query '(("REQUEST" . "lt?xml
version\"1.0\"?gt ltCoordinationServicegt
ltfunctiongtwritelt/functiongt lttuplegt
ltexamplePhilosophergtltchopstickgtKantlt/chopsti
ckgtlt/examplePhilosophergt lt/tuplegt lt/Coordina
tionServicegt"))) "" 200 NIL ltURI
http//bubu.cps.unizar.es8080/CoordinationServlet
gt
30Cliente Java
// Para compilar y ejecutar este código
Java es necesario incluír las librerías de axis1
en el classpath. Disponibles en la URL
http//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.setTargetEndpointAddr
ess( new java.net.URL(endpoint)
) call.setOperationName(new QName("http//soapi
nterop.org/", "RLindaOUT")) String value
(String) call.invoke( new Object
"\"esto\",1,\"prueba\"" ) System.out.prin
tln(value) catch (Exception e)
System.err.println(e.toString())
31Cliente Java
// Para compilar y ejecutar este código Java es
necesario incluír las librerías de axis1 en el
classpath. // Disponibles en la URL
http//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.setTargetEndpointAddr
ess( new java.net.URL(endpoint)
) call.setOperationName(new QName("http//soapi
nterop.org/", "RLindaOUT")) String value
(String) call.invoke( new Object
"\"esto\",1,\"prueba\"" ) System.out.prin
tln(value) catch (Exception e)
System.err.println(e.toString())
32Cliente 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.setTargetEndpointAddr
ess( new java.net.URL(endpoint)
) call.setOperationName(new QName("http//soapi
nterop.org/", "RLindaIN")) String value
(String) call.invoke( new Object
"\"esto\",\?\,\?\"" ) System.out.print
ln(value) catch (Exception e)
System.err.println(e.toString())