Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[etrice-users] dynamic actors

Hi Henrik,

    I now can create dynamic actors though I need to cache them and according to the event coming on TCP update their state. How do I cache them and get them back from cache based on the id  and call a method to make the transition to next state?

 

Thanks

-v

 

 

RoomModel room.basic.service.oms {

 

       import room.basic.types.* from "Types.room"

 

       import room.basic.data.* from "Order.room"

 

       ActorClass AOrderStateService {

              Interface {

                     SPP process: ProcessEvent

              }

              Structure {

                     usercode1 {

                     "import java.util.Iterator;

                     import java.util.Map.Entry;

                     import java.util.concurrent.ConcurrentHashMap;"

                     }

                     usercode2 {

                           "private ConcurrentHashMap<String, Integer> cache ;"

                     }

                     conjugated Port p0[*]: ProcessEvent

                     optional ActorRef optarray[*]: OrderStateHandler

                     ServiceImplementation of process

                     Binding p0 and optarray.p0

                     Attribute id: int32

              }

              Behavior {

                     Operation dumpTree(msg: string) {

                           "System.out.println(msg);"

                            "System.out.println(((org.eclipse.etrice.runtime.java.messaging.RTObject)getRoot()).toStringRecursive());"

                     }

                     StateMachine {

                           Transition init: initial -> Process {

                                  action {

                                         "cache = new ConcurrentHashMap<>(16,0.9f,2);"

                                         "System.out.println(\"cache initialized\");\r"

                                         ""

                                         "dumpTree(\"before creation of anything\");"

                                  }

                           }

                           Transition tr0: Process -> Process {

                                  triggers {

                                         <handleEvent: process>

                                  }

                                  action {

                                         ""

                                         "dumpTree(\"before creation of Order\");"

                                         "System.out.println(order.getId()+\" \"+order.getMsgType()+\" \"+order.getExecType());"

                                         ""

                                         ""

                                         "if(cache.containsKey(order.getId()))"

                                         "{"

                                         ""

                                         "int idx=cache.get(order.getId());"

                                        

                                         ""

                                         "}"

                                         "else{"

                                         "id++;"

                                         "optarray.createOptionalActor(\"MyOrderStateHandler\", getThread());"

                                         "cache.put(order.getId(), id);"

                                         "}"

                                         "dumpTree(\"after processing of Order\");"

                                         ""

                                  }

                           }

                           State Process

                     }

              }

       }

 

       abstract ActorClass OrderStateHandler {

              Interface {

                     Port p0: ProcessEvent

              }

              Structure {

                     external Port p0

                     Attribute id: string

                     Attribute data: Order

              }

              Behavior { }

       }

 

       ActorClass MyOrderStateHandler extends OrderStateHandler {

              Structure { }

              Behavior {

                     StateMachine {

                           Transition init: initial -> PNew {

                                  action {

                                         "System.out.println(\"???? \");

                                         "

                                  }

                                 

                           }

                           Transition tr0: PNew -> New {

                                  triggers {

                                         <handleEvent: p0 guard {

                                                "order.getMsgType().equals(\"8\") && order.getExecType().equals(\"0\")"

                                         }>

                                  }

                           }

                           Transition tr1: New -> Fill {

                                  triggers {

                                         <handleEvent: p0 guard {

                                                "order.getMsgType().equals(\"8\") && order.getExecType().equals(\"F\")"

                                         }>

                                  }

                           }

                           State PNew  {

                                  entry {

                                         "System.out.println(\"Pending NEW\");"

                                  }

                           }

                           State New {

                                  entry {

                                         "System.out.println(\"NEW\");"

                                  }

                           }

                           State Fill {

                                  entry {

                                         "System.out.println(\"Fill\");"

                                  }

                           }

                     }

              }

       }

 

      

 

       ProtocolClass ProcessEvent {

              incoming {

                     Message handleEvent(order: Order)

              }

       }

 

}

 

 

Vivek Srivastava

 


Back to the top