Skip to content

Commit

Permalink
Adding of extra logging for non-connected Client ESME for 5 min
Browse files Browse the repository at this point in the history
  • Loading branch information
vetss committed Jun 14, 2017
1 parent 9f6fa38 commit 1bef51f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public Thread newThread(Runnable r) {
// configurable?
this.clientBootstrap = new DefaultSmppClient(this.executor, 25, monitorExecutor);

this.smppClientOpsThread = new SmppClientOpsThread(this.clientBootstrap, this.smppSessionHandlerInterface);
this.smppClientOpsThread = new SmppClientOpsThread(this.clientBootstrap, this.smppSessionHandlerInterface, this.esmeManagement);

(new Thread(this.smppClientOpsThread)).start();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
import java.util.Iterator;

import javolution.util.FastList;
import javolution.util.FastMap;

import org.apache.log4j.Logger;

import com.cloudhopper.smpp.PduAsyncResponse;
import com.cloudhopper.smpp.SmppSession;
import com.cloudhopper.smpp.SmppSession.Type;
import com.cloudhopper.smpp.SmppSessionConfiguration;
import com.cloudhopper.smpp.SmppSessionHandler;
import com.cloudhopper.smpp.impl.DefaultSmppClient;
Expand Down Expand Up @@ -59,14 +61,16 @@ public class SmppClientOpsThread implements Runnable {

private final DefaultSmppClient clientBootstrap;
private final SmppSessionHandlerInterface smppSessionHandlerInterface;
private final EsmeManagement esmeManagement;

/**
*
*/
public SmppClientOpsThread(DefaultSmppClient clientBootstrap,
SmppSessionHandlerInterface smppSessionHandlerInterface) {
SmppSessionHandlerInterface smppSessionHandlerInterface, EsmeManagement esmeManagement) {
this.clientBootstrap = clientBootstrap;
this.smppSessionHandlerInterface = smppSessionHandlerInterface;
this.smppSessionHandlerInterface = smppSessionHandlerInterface;
this.esmeManagement = esmeManagement;
}

/**
Expand All @@ -82,6 +86,9 @@ protected void setStarted(boolean started) {
}

protected void scheduleConnect(Esme esme) {

logger.info("Initiating a Client SMPP connection for ESME: " + esme.getName());

synchronized (this.pendingChanges) {
this.pendingChanges.add(new ChangeRequest(esme, ChangeRequest.CONNECT, System.currentTimeMillis()
+ SCHEDULE_CONNECT_DELAY));
Expand All @@ -106,6 +113,8 @@ protected void scheduleEnquireLink(Esme esme) {

@Override
public void run() {
FastMap<String, Long> startedClosedTime = new FastMap<String, Long>();

if (logger.isInfoEnabled()) {
logger.info("SmppClientOpsThread started.");
}
Expand Down Expand Up @@ -158,6 +167,33 @@ public void run() {
this.waitObject.wait(5000);
}

// checking of ESME CLOSED state - TODO: we need to refactor it after finding a reason of ESME not connecting
try {
long curTimeStamp = System.currentTimeMillis();
for (FastList.Node<Esme> n = this.esmeManagement.esmes.head(), end = this.esmeManagement.esmes.tail(); (n = n
.getNext()) != end;) {
Esme esme = n.getValue();
if (esme.getSmppSessionType() == Type.CLIENT) {
if (esme.isStarted() && esme.isClosed()) {
Long stTime = startedClosedTime.get(esme.getName());
if (stTime == null) {
startedClosedTime.put(esme.getName(), curTimeStamp);
} else {
long stTimeV = stTime;
// checking if a disconnection time > 5 min == 300 sec
if (curTimeStamp - stTimeV > 300000) {
startedClosedTime.remove(esme.getName());
logger.warn("Client ESME is not connected for 5 minutes :" + esme.getName());
}
}
} else {
startedClosedTime.remove(esme.getName());
}
}
}
} catch (Throwable e) {
}

} catch (InterruptedException e) {
logger.error("Error while looping SmppClientOpsThread thread", e);
}
Expand Down

0 comments on commit 1bef51f

Please sign in to comment.