* @return the server mina message gateway
*/
public static AbstractStampyMessageGateway initialize() {
StampyHeartbeatContainer heartbeatContainer = new HeartbeatContainer();
ServerMinaMessageGateway gateway = new ServerMinaMessageGateway();
gateway.setPort(1234);
gateway.setHeartbeat(1000);
gateway.setAutoShutdown(true);
gateway.addServiceListener(new MinaServiceAdapter() {
@Override
public void sessionDestroyed(IoSession session) throws Exception {
System.out.println("Session destroyed, exiting...");
System.exit(0);
}
});
RawServerMinaHandler handler = new RawServerMinaHandler();
handler.setHeartbeatContainer(heartbeatContainer);
handler.setGateway(gateway);
gateway.addMessageListener(new IDontNeedSecurity());
gateway.addMessageListener(new ServerMessageValidationListener());
gateway.addMessageListener(new VersionListener());
MinaLoginMessageListener login = new MinaLoginMessageListener();
login.setGateway(gateway);
login.setLoginHandler(new SystemLoginHandler());
gateway.addMessageListener(login);
MinaConnectStateListener connect = new MinaConnectStateListener();
connect.setGateway(gateway);
gateway.addMessageListener(connect);
MinaHeartbeatListener heartbeat = new MinaHeartbeatListener();
heartbeat.setHeartbeatContainer(heartbeatContainer);
heartbeat.setGateway(gateway);
gateway.addMessageListener(heartbeat);
MinaTransactionListener transaction = new MinaTransactionListener();
transaction.setGateway(gateway);
gateway.addMessageListener(transaction);
SystemAcknowledgementHandler sys = new SystemAcknowledgementHandler();
MinaAcknowledgementListenerAndInterceptor acknowledgement = new MinaAcknowledgementListenerAndInterceptor();
acknowledgement.setHandler(sys);
acknowledgement.setGateway(gateway);
acknowledgement.setAckTimeoutMillis(200);
gateway.addMessageListener(acknowledgement);
gateway.addOutgoingMessageInterceptor(acknowledgement);
MinaReceiptListener receipt = new MinaReceiptListener();
receipt.setGateway(gateway);
gateway.addMessageListener(receipt);
MinaConnectResponseListener connectResponse = new MinaConnectResponseListener();
connectResponse.setGateway(gateway);
gateway.addMessageListener(connectResponse);
gateway.setHandler(handler);
return gateway;
}