Research Article

CAMeL: A Self-Adaptive Framework for Enriching Context-Aware Middlewares with Machine Learning Capabilities

Listing 3

An example of control component able to take decision based on the current context.
(1)@Component
(2)@Provides (specifications = RoutesBuilder.class)
(3)public class Controller extends RouteBuilder {
(4) …
(5)public void configure () throws Exception {
(6)  //state automata defintion
(7)  StateMachineBuilder <StateMachine, State, String, Context> bld = StateMachineBuilderImpl.newStateMachineBuilder (StateMachine.class, State.class, String.class, Context.class);
(8)  //definitions of the states and state transitions
(9)  bld.externalTransition ().from (State.A).to (State.B).on (“People”);
(10)  bld.externalTransition ().from (State.B).to (State.C).on (“Crowd”);
(11)  bld.externalTransition ().from (State.B).to (State.A).on (“No_Crowd”);
(12)  bld.externalTransition ().from (State.C).to (State.A).on (“No_Crowd”);
(13)  stateMachine = builder.newStateMachine (State.Start);
(14)  stateMachine.setInstanceFactory (instanceFactory);
(15)  from (labelQueue).process (new LabelProcessor ());
(16) }
(17) …
(18)}
(19)public class StateMachine extends AbstractStateMachine <StateMachine, State, String, Context> {
(20)private InstanceFactory instanceFactory;
(21)public void transitFromAToBOnPeople (ControllerState from, ControllerState to, String event, ControllerContext ctx) throws Exception {
(22)  //destroy Audio Sensor and Voice Classifier
(23)  instanceFactory.disposeInstance (“sensor.Audio”, “audio”);
(24)  instanceFactory.disposeInstance (“classifier.Voice”, “voice_classifie”);
(25)  //create Camera Sensor and Human Body Classifier
(26)  instanceFactory.createInstance (“sensor.CameraSensor”, “CameraSensor”);
(27)  instanceFactory.createInstance (“classifier.HumanBodyDetector”, “HumanBodyDetector”);
(28) }
(30)}