This tests the ability of I3 to realize service composition in which the receving node decides the routing of a packet. First, all nodes insert their own trigger. Then, node 0 creates an packet containing an empty sentence (""), and sends it to I3 with an identifier stack containing the triggers of service nodes 1, 2, 3, 4 and then node 0. I3 then routes the packet to each of those triggers in that order. Each service node adds some words to the sentence ands sends it back to I3 with the same identifier stack it received. When it returns to node 0 it displays the sentence it received and starts again.
Public Member Functions | |
void | initializeApp (int stage) |
App initialization - should be overwritten by application. | |
void | initializeI3 () |
Application I3 initialize - should be overwritten by application. | |
void | deliver (I3Trigger &trigger, I3IdentifierStack &stack, cMessage *msg) |
Delivers packets coming from I3 - should be overwritten by application. | |
void | handleTimerEvent (cMessage *msg) |
Handles timers - should be overwritten by application. | |
void | createMessage () |
Public Attributes | |
int | myIndex |
cMessage * | sendPacketTimer |
Static Private Attributes | |
static int | index = 0 |
void I3Composite::initializeApp | ( | int | stage | ) | [virtual] |
App initialization - should be overwritten by application.
I3 related commands should go in initializeI3.
stage | Initialization stage passed from initialize() |
Reimplemented from I3BaseApp.
void I3Composite::initializeI3 | ( | ) | [virtual] |
Application I3 initialize - should be overwritten by application.
Reimplemented from I3BaseApp.
00064 { 00065 if (myIndex == 0) { 00066 sendPacketTimer = new cMessage("packet timer"); 00067 scheduleAt(simulation.simTime() + 50, sendPacketTimer); 00068 } 00069 00070 ostringstream os; 00071 os << "Composite " << myIndex; 00072 00073 I3Identifier identifier(os.str()); 00074 insertTrigger(identifier); 00075 }
void I3Composite::deliver | ( | I3Trigger & | trigger, | |
I3IdentifierStack & | stack, | |||
cMessage * | msg | |||
) | [virtual] |
Delivers packets coming from I3 - should be overwritten by application.
trigger | Application trigger to which the packet was sent | |
stack | Identifier stack passed from I3 | |
msg | Arriving message |
Reimplemented from I3BaseApp.
00108 { 00109 I3CompositeMessage *cmsg = check_and_cast<I3CompositeMessage*>(msg); 00110 00111 switch (myIndex) { 00112 case 0: 00113 { 00114 string final = "Final sentence: " + cmsg->sentence; 00115 parentModule()->bubble(final.c_str()); 00116 delete msg; 00117 createMessage(); 00118 return; 00119 } 00120 case 1: 00121 parentModule()->bubble("Adding 'He pounds'"); 00122 cmsg->sentence += "He pounds "; 00123 break; 00124 case 2: 00125 parentModule()->bubble("Adding 'his fists'"); 00126 cmsg->sentence += "his fists "; 00127 break; 00128 case 3: 00129 parentModule()->bubble("Adding 'against'"); 00130 cmsg->sentence += "against "; 00131 break; 00132 case 4: 00133 parentModule()->bubble("Adding 'the posts'"); 00134 cmsg->sentence += "the posts "; 00135 break; 00136 default: 00137 delete msg; 00138 return; 00139 } 00140 sendPacket(stack, cmsg); 00141 }
void I3Composite::handleTimerEvent | ( | cMessage * | msg | ) | [virtual] |
Handles timers - should be overwritten by application.
msg | Timer to be handled |
Reimplemented from I3BaseApp.
00099 { 00100 if (myIndex == 0) { // only the first node 00101 parentModule()->bubble("Starting chain!"); 00102 createMessage(); 00103 } 00104 delete msg; 00105 }
void I3Composite::createMessage | ( | ) |
00077 { 00078 I3CompositeMessage *cmsg = new I3CompositeMessage(); 00079 00080 cmsg->sentence = ""; 00081 00082 I3Identifier id0("Composite 0"), 00083 id1("Composite 1"), 00084 id2("Composite 2"), 00085 id3("Composite 3"), 00086 id4("Composite 4"); 00087 00088 I3IdentifierStack stack; 00089 stack.push(id0); 00090 stack.push(id4); 00091 stack.push(id3); 00092 stack.push(id2); 00093 stack.push(id1); 00094 00095 sendPacket(stack, cmsg); 00096 }
int I3Composite::index = 0 [static, private] |
cMessage* I3Composite::sendPacketTimer |