Draw on the right, write (Umple) model code on the left. Analyse models and generate code. This tool stores your data in cookies and on a server. I understand. Click to learn about privacy. Download Donate For help: User manual Ask questions Report issue
// Umple/UML system representing simulation of telephone calls between several parties // This system actually runs and contains a state machine of a phone call. // It runs best on a Mac since it calls a Mac system function for simulated voices // Compile it using Umple and then run it using java class PhoneSystemSimulation { singleton; // lazy PhoneLine[] lines; 1 -- * PhoneLine lines; after constructor { addLine(new PhoneLine("line1","Alex",this)); addLine(new PhoneLine("line2","Thomas",this)); addLine(new PhoneLine("line3","Victoria",this)); addLine(new PhoneLine("line4","Samantha ",this)); addLine(new PhoneLine("line5","Karen",this)); } static PhoneSystemSimulation s; public static void main(String [ ] args) { s = getInstance(); PhoneLine lineA; PhoneLine lineB; int choiceA, choiceB; while(true) { // Randomly choose who initiates choiceA = (int)Math.floor(Math.random()*5); choiceB = (choiceA + 1 + (int)Math.floor(Math.random()*4)) % 5; lineA = s.getLine(choiceA); lineB = s.getLine(choiceB); // Initate a call lineA.startDialing(); lineA.pause(200); lineA.setOtherParty(lineB); lineA.completeNumber(); lineA.p(); lineB.p(); // Will be done by tracing associations // The other party can choose whether to pick up or not. if(Math.random() > 0.5) { lineB.pickUp(); // While talking either party can hang up if(Math.random() > 0.5) { lineA.hangUp(); lineB.hangUp(); // assuming it doesn't forget } else { lineB.hangUp(); lineA.hangUp(); // assuming it doesn't forget } } else { // Hang up while waiting and the other will too lineA.hangUp(); } } } } class PhoneLine { depend java.io.IOException; id; voice; 0..1 self otherParty; trace waitForHook, ringing record id; const String Click="click"; const String Dial="dial"; const String Beep="beep"; const String Hello="hello"; const String RingRing="ring ring"; state { onHook { entry / { if(getOtherParty() != null) { getOtherParty().otherPartyHangUp(); } setOtherParty(null); p(); } startDialing -> dialing; incomingCall -> ringing; } ringing { entry / {say(RingRing);} pickUp -> / {getOtherParty().otherPartyPickUp();} communicating; otherPartyHangUp -> onHook; autoPickup -> / {getOtherParty().otherPartyPickUp();} communicating; } communicating { entry / {say(Hello+getOtherParty().getId());} hangUp -> / {say(Click);} onHook; otherPartyHangUp -> waitForHook; putOnHold -> onHold; } onHold { hangUp -> / {say(Click);} onHook; otherPartyHangUp -> waitForHook; takeOffHold -> communicating; } dialing { entry / {say(Dial);} completeNumber -> waitingForConnection; hangUp -> / {say(Click);} onHook; } waitingForConnection { entry / {getOtherParty().incomingCall();} otherPartyPickUp -> communicating; hangUp -> / {say(Click);} onHook; timeOut -> onHook; } waitForHook { entry / {say(Beep);} hangUp -> / {say(Click);} onHook; } } String toString() { return getId(); } void p() { // System.out.println(" other party of "+getId()+"="+getOtherParty()); } void say(String s) { try { Runtime.getRuntime().exec("say "+getId()+" "+s+" -v "+getVoice()); } catch (IOException e) {} pause(2000); } void pause(long ms) { try { Thread.currentThread().sleep(ms);//sleep for 1000 ms } catch(InterruptedException ie){ } } } strictness ignore 1007; //$?[End_of_model]$? /* @@@skipjavacompile @@@skipphpcompile @@@skippythoncompile only compiles on Mac */