Hi guys,
I decided to migrate a part of our architecture to a state machine.
This is mostly so that I do not have to have lots of instanceof checks
in my implementation of IoHandler.messageReceived().
The state can be changed in two ways - but the utility using the
instance of the state machine and by packets coming in.
For example:
public class smClass {
@IoHandlerTransition(in = INIT, on = MESSAGE_SENT, next = LOGIN_WAIT)
public void login(String username, String password) {
sendLoginMessage(username, password);
}
@IoHandlerTransition(in = LOGIN_WAIT, on = MESSAGE_RECEIVED, next = READY)
public void loginSuccess(IoSession session, LoginSuccessMessage message) {
// received login success message
}
/** other methods which need READY state after here **/
}
public class Main {
private smClass smc;
public void main(String.. args) {
smc = new smClass();
connector = new NioSocketConnector();
connector.getFilterChain().addLast("codec",
new ProtocolCodecFilter(new CustomProtocolCodecFactory(false)));
connector.getFilterChain().addLast("logger", new LoggingFilter());
StateMachine sm = StateMachineFactory.getInstance(IoHandlerTransition.class)
.create(smClass.INIT, smc);
IoHandler ioh = new StateMachineProxyBuilder().setStateContextLookup(
new IoSessionStateContextLookup( new StateContextFactory() {
@Override public StateContext create() { return
new DefaultStateContext(); }
})).create(IoHandler.class, sm);
connector.setHandler(ioh);
ConnectFuture future = connector.connect(new InetSocketAddress(port));
future.awaitUninterruptibly(4000);
session = future.getSession()
sm.login("user", "pass");
}
}
when sm.login() is called in Main.main() the state of smClass doesn't
change. Clearly this is because the class isn't through the proxied
instance of smClass. It is not clear to me how to create a
StateMachine which can be called locally and have its state triggered
by TCP events.
any help?
Thanks,
mike
--
god loves atheists, Fact: http://www.mrwiggleslovesyou.com/comics/rehab477.jpg