uudashr/jsmpp

esme doesn't reconnect after reset connection

Opened this issue · 0 comments

Hi all, I have a problem with reconnect. When I test code on local machine with smppSimulator - all OK (if I stop simulator and then start it, my esme will reconnect without problems)
BUT when esme work with operator and operator reset connection, esme cant reconnect...(( only some records from log and that's all....maybe thread is dying?
How can I reconnect correctly?

logs from connection with operator:

2013-04-19 14:10:25,471 [EnquireLinkSender: 572b4b6b] INFO 221 :client.gw.AutoReconnectGatewayTrx - Session state of 572b4b6b changed from BOUND_TX to CLOSED
2013-04-19 14:10:25,471 [EnquireLinkSender: 572b4b6b] INFO 252 :client.gw.AutoReconnectGatewayTrx - Session CLOSED, by OPERATOR, let's reconnect
2013-04-19 14:10:25,472 [PDUReaderWorker: org.jsmpp.session.SMPPSession@6d1dc02c] WARN 639 :jsmpp.session.SMPPSession - IOException while reading: Socket closed
2013-04-19 14:10:25,472 [PDUReaderWorker: org.jsmpp.session.SMPPSession@6d1dc02c] INFO 203 :jsmpp.session.AbstractSession - AbstractSession.close() called
2013-04-19 14:10:29,403 [CL AGW-TX] INFO 273 :client.gw.AutoReconnectGatewayTrx - closing TX session...
2013-04-19 14:10:29,403 [CL AGW-TX] INFO 203 :jsmpp.session.AbstractSession - AbstractSession.close() called

And if I restart esme, connectiong will establish without problems.
Can somebody help me?
Here part of my code:

class AutoReconnectGateway extends Thread implements Gateway

@Override
public void run(){
    logger.info("GW " + connectionType + " started!");
    String ipAddress = ssetting.getIpAddressMain();
    int port = ssetting.getPortMain();
    session = getSession(ipAddress, port);

    while (isRunning()){
        try{
            if (!isConnected()){
                reloadConnection();
                logger.info("#Try to reconnect after to " + ipAddress + ":" + port);
                session = getSession(ipAddress, port);
            }
            else{
                Utilz.sleep(5000);
            }
        }
        catch (Exception e){
            logger.error("main thread", e);
        }
    }
}

public void reloadConnection(){
    try{
        if (session != null){
            logger.info("closing " + connectionType + " session...");
            session.unbindAndClose();
            session = null;
        }
        else{
            logger.info("session " + connectionType + " already closed!");
        }
    }
    catch (Exception e){
        logger.error("reloadConnection", e);
    }
    logger.info("sleep 10 sec...");
    Utilz.sleep(10000);
}   

public synchronized SMPPSession getSession(String ip, int port){
    if (session == null || !session.getSessionState().isBound()){
        try{
            session = new SMPPSession(ip, port, bindParam);
            session.addSessionStateListener(new SessionStateListenerImpl());
            session.setMessageReceiverListener(new SMPPMessageReceiver(clientQueue, ssetting.getBindType()));
        }
        catch (Exception e){
            logger.error("new " + connectionType + " Session: ", e);
            session = null;
        }
    }

    return session;
}

public boolean isConnected(){
    if (session != null && session.getSessionState().isBound())
        return true;
    return false;
}