We are using a mina state machine and during session open event handling
@IoHandlerTransition(on = SESSION_OPENED) we connect a vm pipe acceptor.
Just after connecting we receive a null pointer exception in
StateMachine.java handle() method :
private void handle(State state, Event event) {
...
for (Transition t : state.getTransitions()) { <-- state = null
causing the exception
..
}
When events are queued the initial/start state in not always set that's
cause the problem. In my case session created/opened events generated by
the connection to the vm acceptor are queued and processed later without
initial state set.
public void handle(Event event) {
StateContext context = event.getContext();
synchronized (context) {
LinkedList<Event> eventQueue = eventQueueThreadLocal.get();
eventQueue.addLast(event);
if (processingThreadLocal.get()) {
/*
* This thread is already processing an event. Queue
this
* event.
*/
if (log.isDebugEnabled()) {
log.debug("State machine called recursively. Queuing
event " + event
+ " for later processing.");
}
} else {
processingThreadLocal.set(true);
try {
if (context.getCurrentState() == null) { <--
initial state only set when event in not queued
context.setCurrentState(startState);
}
processEvents(eventQueue);
} finally {
processingThreadLocal.set(false);
}
}
}
}
}
I made locally the following modif :
public void handle(Event event) {
StateContext context = event.getContext();
synchronized (context) {
LinkedList<Event> eventQueue = eventQueueThreadLocal.get();
eventQueue.addLast(event);
if (context.getCurrentState() == null) {
context.setCurrentState(startState);
}
if (processingThreadLocal.get()) {
/*
* This thread is already processing an event. Queue
this
* event.
*/
if (log.isDebugEnabled()) {
log.debug("State machine called recursively. Queuing
event " + event
+ " for later processing.");
}
} else {
processingThreadLocal.set(true);
try {
processEvents(eventQueue);
} finally {
processingThreadLocal.set(false);
}
}
}
}
}
With this modif, the initial/start state is always set even if the event
are queued. It works well, no more null pointer exception.
Could some mina state machine expert validate my modif and if correct
apply it ?
Thanks.
Fred.