/** * Wait for a message. * @param msgevent The message event. */ public IMessageEvent waitForReply(IMessageEvent msgevent, long timeout) { // Ensure that the message event is registered and waitqueue is established. Otherwise // a message loss could happen. Object rmevent = ((ElementFlyweight)msgevent).getHandle(); if(!MessageEventRules.containsRegisteredMessageEvents(getState(), getRCapability(), rmevent)) throw new RuntimeException("Message event not registered: "+rmevent); if(!isEventRegisteredInWaitqueue(rmevent)) throw new RuntimeException("Messages to be used in waitForReply() have to be registered" + "in the event in the waitqueue before(!) being sent: "+rmevent); // Todo: check thread access. Object wa = getState().createObject(OAVBDIRuntimeModel.waitabstraction_type); SFlyweightFunctionality.addReply(wa, (ElementFlyweight)msgevent, getState(), getRCapability()); return (IMessageEvent)PlanRules.waitForWaitAbstraction(wa, timeout, getState(), getRCapability(), getRPlan()); }