| RoomModel org.eclipse.etrice.examples.dynamicactors2 { |
| |
| import room.basic.types.* from "../../../org.eclipse.etrice.modellib.java/model/Types.room" |
| |
| LogicalSystem LS { |
| SubSystemRef main: Main |
| } |
| |
| SubSystemClass Main { |
| ActorRef appl: Appl |
| |
| LogicalThread dflt_thread |
| } |
| |
| ActorClass Appl { |
| Structure { |
| ActorRef cont: Container |
| } |
| Behavior { } |
| } |
| |
| ActorClass Container { |
| Structure { |
| conjugated Port p0: PC |
| |
| Attribute counter: int32 = "0" |
| |
| optional ActorRef opt: Optional |
| |
| Binding p0 and opt.p0 |
| } |
| Behavior { |
| // this method prints the passed message and then dumps the object tree consisting of actors and ports |
| Operation printMemory(msg: string) ''' |
| System.out.println(msg); |
| System.out.println("memory,"+(counter++)+","+Runtime.getRuntime().freeMemory());''' |
| |
| StateMachine { |
| Transition init: initial -> CreateOptional2 { |
| action ''' |
| long lDateTime = new java.util.Date().getTime(); |
| System.out.println("begin: " + lDateTime); |
| printMemory("initial");''' |
| } |
| Transition tr0: CreateOptional2 -> CreateOptional1 { |
| triggers { |
| <hello: p0> |
| } |
| action ''' |
| System.out.println(transitionData+"\n"); |
| opt.destroyOptionalActor(); |
| printMemory("after deletion of Optional2");''' } |
| Transition tr2: CreateOptional1 -> cp cp0 { |
| triggers { |
| <hello: p0> |
| } |
| action ''' |
| System.out.println(transitionData+"\n"); |
| opt.destroyOptionalActor(); |
| printMemory("after deletion of Optional1");''' } |
| Transition tr1: cp cp0 -> CreateOptional2 |
| Transition tr3: cp cp0 -> Done { |
| cond '''counter>1200''' |
| action ''' |
| long lDateTime = new java.util.Date().getTime(); |
| System.out.println("end: " + lDateTime);''' |
| } |
| ChoicePoint cp0 |
| State CreateOptional2 { |
| entry ''' |
| opt.createOptionalActor("Optional2", getThread()); |
| p0.sayHello(); |
| printMemory("after creation of Optional2");''' |
| } |
| State CreateOptional1 { |
| entry ''' |
| opt.createOptionalActor("Optional1", getThread()); |
| p0.sayHello(); |
| printMemory("after creation of Optional1");''' |
| } |
| State Done { |
| entry '''System.out.println("Done, enter 'quit' to exit"); ''' |
| } |
| } |
| } |
| } |
| |
| // the class that is referenced as optional by the Container |
| // since it is abstract it just serves as an interface |
| abstract ActorClass Optional { |
| Interface { |
| Port p0: PC |
| } |
| Structure { } |
| Behavior { } |
| } |
| |
| // a sub class of Optional which is valid as optional actor |
| ActorClass Optional1 extends Optional { |
| Structure { |
| ActorRef sub1: AC1 |
| Binding p0 and sub1.p0 |
| } |
| Behavior { } |
| } |
| |
| // a sub class of Optional which is valid as optional actor |
| ActorClass Optional2 extends Optional { |
| Structure { |
| ActorRef sub2: AC2 |
| Binding p0 and sub2.p0 |
| } |
| Behavior { } |
| } |
| |
| // the following actor classes are part of the possible optional instance sub trees |
| |
| ActorClass AC1 { |
| Interface { |
| Port p0: PC |
| } |
| Structure { |
| external Port p0 |
| } |
| Behavior { |
| StateMachine { |
| Transition init: initial -> Ready { } |
| Transition tr0: Ready -> Ready { |
| triggers { |
| <sayHello: p0> |
| } |
| action '''p0.hello("this is AC1, instance "+getInstancePath());''' |
| } |
| State Ready |
| } |
| } |
| } |
| |
| ActorClass AC2 { |
| Interface { |
| Port p0: PC |
| } |
| Structure { |
| ActorRef deep_sub: AC3 |
| Binding p0 and deep_sub.p0 |
| } |
| Behavior { } |
| } |
| |
| ActorClass AC3 { |
| Interface { |
| Port p0: PC |
| } |
| Structure { |
| external Port p0 |
| } |
| Behavior { |
| StateMachine { |
| Transition init: initial -> Ready { } |
| Transition tr0: Ready -> Ready { |
| triggers { |
| <sayHello: p0> |
| } |
| action '''p0.hello("this is AC3, instance "+getInstancePath());''' |
| } |
| State Ready |
| } |
| } |
| } |
| |
| // a simple protocol that is used to demonstrate that actors are connected |
| ProtocolClass PC { |
| incoming { |
| Message sayHello() |
| } |
| outgoing { |
| Message hello(string) |
| } |
| } |
| } |