use of org.mobicents.smsc.domain.SmsRouteManagement in project smscgateway by RestComm.
the class SchedulerResourceAdaptor method doSetDestCluster.
private void doSetDestCluster(SmsSet smsSet) {
// Step 1: Check first if this SMS is for SMPP
SmsRouteManagement smsRouteManagement = SmsRouteManagement.getInstance();
// Quick and dirty fix for SMSC-171
String orignatingEsmeName = smsSet.getSms(0).getOrigEsmeName();
String destClusterName = smsRouteManagement.getEsmeClusterName(smsSet.getDestAddrTon(), smsSet.getDestAddrNpi(), smsSet.getDestAddr(), orignatingEsmeName, smsSet.getNetworkId());
// TODO: we possibly do not need to send a SIP-originated message back to SIP
if (destClusterName == null) {
destClusterName = smsRouteManagement.getSipClusterName(smsSet.getDestAddrTon(), smsSet.getDestAddrNpi(), smsSet.getDestAddr(), smsSet.getNetworkId());
if (destClusterName == null) {
// Step 2: If no SIP's found, its for SS7
smsSet.setType(SmType.SMS_FOR_SS7);
} else {
smsSet.setType(SmType.SMS_FOR_SIP);
}
} else {
// smsSet.setType(destClusterName != null ? SmType.SMS_FOR_ESME
// : SmType.SMS_FOR_SS7);
smsSet.setType(SmType.SMS_FOR_ESME);
}
smsSet.setDestClusterName(destClusterName);
}
use of org.mobicents.smsc.domain.SmsRouteManagement in project smscgateway by RestComm.
the class SchedulerResourceAdaptor method onTimerTick.
// /////////////////
// Helper methods //
// /////////////////
protected void onTimerTick() {
// checking if all SBBs are already running
if (!SbbStates.isAllServicesUp()) {
String s1 = SbbStates.getServicesDownList();
if (!s1.equals(shownServicesDownList) || System.currentTimeMillis() - shownServicesDownTime > 10000) {
// we are displaying this message every 10 seconds or if ServicesDownList has changed
this.tracer.info("Not all SBB are running now: " + s1);
shownServicesDownList = s1;
shownServicesDownTime = System.currentTimeMillis();
}
return;
}
try {
// garbageCollectionTime
Date current = new Date(new Date().getTime() - 1000 * 60);
if (garbageCollectionTime.before(current)) {
garbageCollectionTime = new Date();
SmsSetCache.getInstance().garbadeCollectProcessingSmsSet();
}
// checking if cassandra database is available
if (!dbOperations_C2.isDatabaseAvailable())
return;
// checking if we need to advance dueSlot
SmscPropertiesManagement smscPropertiesManagement = SmscPropertiesManagement.getInstance();
int val = smscPropertiesManagement.getSkipUnsentMessages();
if (val >= 0) {
smscPropertiesManagement.setSkipUnsentMessages(-1);
// if (smscPropertiesManagement.getDatabaseType() == DatabaseType.Cassandra_1) {
// } else {
long processedDueSlot = dbOperations_C2.c2_getCurrentDueSlot();
Date processedTime = dbOperations_C2.c2_getTimeForDueSlot(processedDueSlot);
long possibleDueSlot = dbOperations_C2.c2_getIntimeDueSlot();
// we do a possible time 10 seconds before the time that is possible for running
Date possibleTime = new Date(dbOperations_C2.c2_getTimeForDueSlot(possibleDueSlot).getTime() - 10000);
Date newTime = new Date(possibleTime.getTime() - val * 1000);
if (newTime.getTime() > processedTime.getTime()) {
long newDueSlot = dbOperations_C2.c2_getDueSlotForTime(newTime);
dbOperations_C2.c2_setCurrentDueSlot(newDueSlot);
this.tracer.warning("currentDueSlot has been changed after a user request: from " + processedTime + " to " + newTime);
} else {
this.tracer.warning("There was a user request to change currentDueSlot: from " + processedTime + " to " + newTime + ". But the new time must be after the current one and the request was rejected.");
}
// }
}
// checking if SmsRouteManagement is already started
SmsRouteManagement smsRouteManagement = SmsRouteManagement.getInstance();
if (smsRouteManagement.getSmsRoutingRule() == null)
return;
OneWaySmsSetCollection schedulableSms;
int maxCnt;
int fetchMaxRows = smscPropertiesManagement.getFetchMaxRows();
int activityCount = SmsSetCache.getInstance().getProcessingSmsSetSize();
int fetchAvailRows = smscPropertiesManagement.getMaxActivityCount() - activityCount;
maxCnt = Math.min(fetchMaxRows, fetchAvailRows);
if (fetchAvailRows <= 0) {
smscCongestionControl.registerMaxActivityCount1_0Threshold();
} else {
smscCongestionControl.registerMaxActivityCount1_0BackToNormal();
}
if (savedOneWaySmsSetCollection != null && savedOneWaySmsSetCollection.size() > 0) {
schedulableSms = savedOneWaySmsSetCollection;
} else {
// checking if SMSC is inactivated by SLEE
if (smscPropertiesManagement.isSmscStopped())
return;
// checking if SMSC is paused by a used
if (smscPropertiesManagement.isDeliveryPause())
return;
try {
if (this.tracer.isFineEnabled())
this.tracer.fine("Fetching: Starting fetching messages from database: fetchMaxRows=" + fetchMaxRows + ", activityCount=" + activityCount + ", fetchAvailRows=" + fetchAvailRows);
if (maxCnt <= 0)
return;
int readTryCount = 0;
while (true) {
schedulableSms = this.fetchSchedulable(maxCnt);
int cnt = 0;
if (schedulableSms != null)
cnt = schedulableSms.size();
readTryCount++;
if (cnt == 0 && readTryCount < 100)
// we will 100 times reread new empty due_Slot
continue;
if (this.tracer.isFineEnabled()) {
String s1 = "Fetching: Fetched " + cnt + " messages (max requested messages=" + maxCnt + ", fetched messages=" + cnt + ")";
this.tracer.fine(s1);
}
break;
}
} catch (PersistenceException e1) {
this.tracer.severe("PersistenceException when fetching SmsSet list from a database: " + e1.getMessage(), e1);
Throwable ex = e1.getCause();
if (ex != null)
this.tracer.severe("Original error: " + ex.getMessage(), ex);
return;
}
}
int count = 0;
Date curDate = new Date();
try {
while (true) {
SmsSet smsSet = schedulableSms.next();
if (smsSet == null)
break;
try {
if (!smsSet.isProcessingStarted()) {
smsSet.setProcessingStarted();
if (!doInjectSmsDatabase(smsSet, curDate, false)) {
return;
}
}
} catch (Exception e) {
this.tracer.severe("Exception when injectSms: " + e.getMessage(), e);
}
count++;
if (count >= maxCnt) {
savedOneWaySmsSetCollection = schedulableSms;
break;
}
}
} finally {
if (count > 0) {
SmscStatProvider smscStatProvider = SmscStatProvider.getInstance();
smscStatProvider.setMessageScheduledTotal(smscStatProvider.getMessageScheduledTotal() + count);
if (this.tracer.isInfoEnabled()) {
String s2 = "Fetching: Scheduled '" + count + "' out of '" + schedulableSms.size() + ", fetchMaxRows=" + fetchMaxRows + ", activityCount=" + activityCount + ", fetchAvailRows=" + fetchAvailRows + "'.";
this.tracer.info(s2);
}
} else {
if (this.tracer.isFineEnabled()) {
String s2 = "Fetching: Scheduled '" + count + "' out of '" + schedulableSms.size() + ", fetchMaxRows=" + fetchMaxRows + ", activityCount=" + activityCount + ", fetchAvailRows=" + fetchAvailRows + "'.";
this.tracer.fine(s2);
}
}
}
} catch (Throwable e1) {
this.tracer.severe("Exception in SchedulerResourceAdaptor when fetching records and issuing events: " + e1.getMessage(), e1);
}
// stat update
SmscPropertiesManagement smscPropertiesManagement = SmscPropertiesManagement.getInstance();
// if (smscPropertiesManagement.getDatabaseType() == DatabaseType.Cassandra_1) {
// } else {
long processedDueSlot = dbOperations_C2.c2_getCurrentDueSlot();
long possibleDueSlot = dbOperations_C2.c2_getIntimeDueSlot();
Date processedDate = dbOperations_C2.c2_getTimeForDueSlot(processedDueSlot);
Date possibleDate = dbOperations_C2.c2_getTimeForDueSlot(possibleDueSlot);
int lag = (int) ((possibleDate.getTime() - processedDate.getTime()) / 1000);
smscStatAggregator.updateSmscDeliveringLag(lag);
// }
}
Aggregations