[EMAIL PROTECTED] wrote:
Hi,

I'm trying to use the mina statemachine in a client and I'm having trouble changing states programatically. After my client connects to a server there is an initial message exchange, and then my state machine goes into a ready state. Now if my client wants to send a "request detailed info" message to the server, I would like to put the state machine into "waitingForDetails" state, so that my statemachine/iohandler will be prepared to process the messages sent back.

Could you try to explain your protocol a bit more? Can't you just add a handler method for the "request detailed info" message when in the "ready" state? Something like:

@IoHandlerTransition(on = MESSAGE_RECEIVED, in = ReadyState)
void handle(IoSession session, RequestForDetailedInfoMessage m) {
   ...
}

If you want to do a transition to a new state which handles the same message you can use StateControl.breakAndGotoNow() to immediately jump to another state.

I tried to use the StateControl.breakAndGotoNext(), but this doesn't work because the entity in the client that is initiating the send is not on the statemachine thread.
Correct, you can only call StateControl.break* from within a handler method called by the statemachine proxy. If that's not possible you need to trigger an event on the state machine by calling a method on your IoHandler, e.g. messageReceived() and pass a special message object.

I tried keying off the sent message in the statemachine using @IoHandlerTransition(on = MESSAGE_SENT,...l) to put it into the correct state but this doesn't work all the time. What I was seeing, is that sometimes my statemachine/iohandler was getting (reading) and processing a response to my request before my statemachine would process the @IoHandlerTransition(on = MESSAGE_SENT,...l), so I would be in the wrong state. Is this a bug?

No, I don't think it is. This is the way MINA works. It's not guaranteed that if you call session.write() you will get the MESSAGE_SENT event back before any other event is received.

HTH

/Niklas

Reply via email to