Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package it.unica.co2.progettoco2;
- import static it.unica.co2.api.contract.utils.ContractFactory.*;
- import java.util.Base64;
- import java.util.Base64.Encoder;
- import co2api.ContractException;
- import co2api.ContractExpiredException;
- import co2api.Message;
- import co2api.Session;
- import co2api.TST;
- import co2api.TimeExpiredException;
- import it.unica.co2.api.contract.Contract;
- import it.unica.co2.api.process.Participant;
- import it.unica.co2.api.process.SkipMethod;
- import it.unica.co2.honesty.HonestyChecker;
- public class Store extends Participant {
- private static final long serialVersionUID = 1L;
- private static final String username = "65006@co2.unica.it";
- private static final String password = "65006";
- protected Store() {
- super(username, password);
- }
- int itemPrice = 50;
- Contract cb = externalSum().add("order", internalSum().add("abort").add("amount", externalSum().add("pay")));
- Contract ic = internalSum().add("req", externalSum().add("ok").add("no"));
- @Override
- public void run() {
- /*System.out.println(ic.toTST());
- System.out.println(cb.toTST());*/
- Session<TST> s = tellAndWait(cb);
- s.waitForReceive("order");
- if(itemPrice < 100){
- s.sendIfAllowed("amount", itemPrice);
- s.waitForReceive("pay");
- }
- else{
- try{
- Session<TST> s2 = tellAndWait(ic);
- s2.sendIfAllowed("req", itemPrice);
- Message msg = s2.waitForReceive("ok", "no");
- if(msg.getLabel().equals("ok")){
- s.sendIfAllowed("amount", itemPrice);
- s.waitForReceive("pay");
- }
- else{
- s.sendIfAllowed("abort");
- }
- }catch(ContractExpiredException e){
- s.sendIfAllowed("abort");
- }
- }
- }
- public static void main(String[] args) {
- HonestyChecker.isHonest(Store.class);
- //new Store().run();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement