diff --git a/Assignment-3/buyer-compare.ol b/Assignment-3/buyer-compare.ol new file mode 100644 index 0000000..f8ceb69 --- /dev/null +++ b/Assignment-3/buyer-compare.ol @@ -0,0 +1,58 @@ +from SellerShipperServiceInterfaceModule import SellerInterface +from BuyerServiceInterfaceModule import BuyerShipperInterface, BuyerSellerInterface + +include "console.iol" + +service BuyerService { + execution { single } + + outputPort Seller1 { + location: "socket://localhost:9005" + protocol: http { format = "json" } + interfaces: SellerInterface + } + + outputPort Seller2 { + location: "socket://localhost:9007" + protocol: http { format = "json" } + interfaces: SellerInterface + } + + inputPort ShipperBuyer { + location: "socket://localhost:9003" + protocol: http { format = "json" } + interfaces: BuyerShipperInterface + } + + inputPort SellerBuyer { + location: "socket://localhost:9004" + protocol: http { format = "json" } + interfaces: BuyerSellerInterface + } + + + + main { + ask@Seller1("chips") + [quote(price1)] + ask@Seller2("chips") + [quote(price2)] + if (price1 < 20 && price1 < price2) { + println@Console( "price 1 lower than 20 and price 2")() + accept@Seller1("Ok to buy chips for " + price1) + reject@Seller2("Not ok to buy chips for " + price2) + [details(invoice)] + println@Console( "Received '"+invoice+"' from Shipper!")() + } else if (price2 < 20 && price2 < price1) { + println@Console( "price 2 lower than 20 and price 1")() + reject@Seller1("Not ok to buy chips for " + price1) + accept@Seller2("Ok to buy chips for " + price2) + [details(invoice)] + println@Console( "Received '"+invoice+"' from Shipper!")() + } else { + println@Console( "Both prices too high")() + reject@Seller1("Not ok to buy chips for " + price) + reject@Seller2("Not ok to buy chips for " + price) + } + } +} \ No newline at end of file diff --git a/Assignment-3/buyer.ol b/Assignment-3/buyer.ol index 961badb..b99ae1e 100644 --- a/Assignment-3/buyer.ol +++ b/Assignment-3/buyer.ol @@ -7,7 +7,7 @@ service BuyerService { execution { single } outputPort Seller { - location: "socket://localhost:9005" + location: "socket://localhost:9007" protocol: http { format = "json" } interfaces: SellerInterface } diff --git a/Assignment-3/seller2.ol b/Assignment-3/seller2.ol new file mode 100644 index 0000000..3912866 --- /dev/null +++ b/Assignment-3/seller2.ol @@ -0,0 +1,41 @@ +from BuyerServiceInterfaceModule import BuyerSellerInterface +from SellerShipperServiceInterfaceModule import SellerInterface, ShipperInterface + +include "console.iol" + +service SellerService { + execution { concurrent } + + outputPort Buyer { + Location: "socket://localhost:9004" + Protocol: http { format = "json" } + Interfaces: BuyerSellerInterface + } + + outputPort Shipper { + Location: "socket://localhost:9006" + Protocol: http { format = "json" } + Interfaces: ShipperInterface + } + + inputPort BuyerSeller { + location: "socket://localhost:9007" + protocol: http { format = "json" } + interfaces: SellerInterface + } + + main { + [ask(product)] { + println@Console( "Price requested" )() + quote@Buyer(20) + } + [accept(order)] { + println@Console( "Accepted" )() + order@Shipper(order) + } + [reject(order)] { + println@Console( "Rejected" )() + } + } + +}