use of org.mobicents.smsc.cassandra.PersistenceException in project smscgateway by RestComm.
the class ChargingSbb method rejectSmsByDiameter.
private void rejectSmsByDiameter(ChargingData chargingData, RoCreditControlAnswer evt) throws SmscProcessingException {
Sms sms = chargingData.getSms();
if (logger.isInfoEnabled()) {
logger.info("ChargingSbb: accessRejected for: resultCode =" + (evt != null ? evt.getResultCode() : "timeout") + ", chargingType=" + chargingData.getChargingType() + ", message=[" + sms + "]");
}
try {
// sending of a failure response for transactional mode / delaying for charging result
MessageDeliveryResultResponseInterface.DeliveryFailureReason delReason = MessageDeliveryResultResponseInterface.DeliveryFailureReason.invalidDestinationAddress;
if (sms.getMessageDeliveryResultResponse() != null) {
sms.getMessageDeliveryResultResponse().responseDeliveryFailure(delReason, null);
sms.setMessageDeliveryResultResponse(null);
}
sms.getSmsSet().setStatus(ErrorCode.OCS_ACCESS_NOT_GRANTED);
boolean storeAndForwMode = MessageUtil.isStoreAndForward(sms);
if (storeAndForwMode) {
sms.setStored(true);
}
// if (smscPropertiesManagement.getDatabaseType() == DatabaseType.Cassandra_1) {
// persistence.archiveFailuredSms(sms);
// } else {
String sourceAddrAndPort = null;
String messageType = null;
EventType eventType = null;
switch(sms.getOriginationType()) {
case SMPP:
EsmeManagement esmeManagement = EsmeManagement.getInstance();
Esme esme = null;
if (esmeManagement != null)
esme = esmeManagement.getEsmeByClusterName(sms.getOrigEsmeName());
eventType = EventType.IN_SMPP_REJECT_DIAMETER;
if (esme != null) {
sourceAddrAndPort = esme.getRemoteAddressAndPort();
// shouldn't have null value
messageType = esme.getSmppSessionType() == Type.CLIENT ? CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITSM : CdrDetailedGenerator.CDR_MSG_TYPE_DELIVERSM;
}
break;
case HTTP:
messageType = CdrDetailedGenerator.CDR_MSG_TYPE_HTTP;
eventType = EventType.IN_HTTP_REJECT_DIAMETER;
break;
default:
break;
}
if (eventType != null) {
CdrDetailedGenerator.generateDetailedCdr(sms, eventType, sms.getSmsSet().getStatus(), messageType, 0, -1, sourceAddrAndPort, null, -1, smscPropertiesManagement.getGenerateReceiptCdr(), smscPropertiesManagement.getGenerateDetailedCdr());
}
if (MessageUtil.isNeedWriteArchiveMessage(sms, smscPropertiesManagement.getGenerateArchiveTable())) {
persistence.c2_createRecordArchive(sms, null, null, !smscPropertiesManagement.getReceiptsDisabling(), smscPropertiesManagement.getIncomeReceiptsProcessing());
}
// }
smscStatAggregator.updateMsgInRejectedAll();
// TODO: if CCR gives some response verbal reject reason
// we need replace CdrGenerator.CDR_SUCCESS_NO_REASON with this
// reason
CdrGenerator.generateCdr(sms, CdrGenerator.CDR_OCS_REJECTED, CdrGenerator.CDR_SUCCESS_NO_REASON, smscPropertiesManagement.getGenerateReceiptCdr(), MessageUtil.isNeedWriteArchiveMessage(sms, smscPropertiesManagement.getGenerateCdr()), false, true, smscPropertiesManagement.getCalculateMsgPartsLenCdr(), smscPropertiesManagement.getDelayParametersInCdr());
} catch (PersistenceException e) {
throw new SmscProcessingException("PersistenceException when storing into Archive rejected by OCS message : " + e.getMessage(), SmppConstants.STATUS_SUBMITFAIL, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e);
}
}
use of org.mobicents.smsc.cassandra.PersistenceException 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);
// }
}
use of org.mobicents.smsc.cassandra.PersistenceException in project smscgateway by RestComm.
the class AlertSbb method setupAlert.
private void setupAlert(ISDNAddressString msisdn, AddressString serviceCentreAddress, int networkId) {
PersistenceRAInterface pers = this.getStore();
SmscPropertiesManagement smscPropertiesManagement = SmscPropertiesManagement.getInstance();
// checking if SMSC is paused
if (smscPropertiesManagement.isDeliveryPause())
return;
// checking if database is available
if (!pers.isDatabaseAvailable())
return;
int addrTon = msisdn.getAddressNature().getIndicator();
int addrNpi = msisdn.getNumberingPlan().getIndicator();
String addr = msisdn.getAddress();
TargetAddress lock = pers.obtainSynchroObject(new TargetAddress(addrTon, addrNpi, addr, networkId));
try {
synchronized (lock) {
try {
long dueSlot = 0;
SmsSet smsSet0 = new SmsSet();
smsSet0.setDestAddr(addr);
smsSet0.setDestAddrNpi(addrNpi);
smsSet0.setDestAddrTon(addrTon);
smsSet0.setNetworkId(networkId);
SmsSet smsSet1 = SmsSetCache.getInstance().getProcessingSmsSet(smsSet0.getTargetId());
if (smsSet1 != null) {
// message is already in process
if (logger.isInfoEnabled()) {
logger.info(String.format("\nReceived AlertServiceCentre for MSISDN=%s but the delivering for this dest is already in progress", addr));
}
return;
}
dueSlot = pers.c2_getDueSlotForTargetId(smsSet0.getTargetId());
if (dueSlot != 0 && dueSlot > pers.c2_getCurrentDueSlot() && pers.c2_checkDueSlotWritingPossibility(dueSlot) == dueSlot) {
pers.c2_registerDueSlotWriting(dueSlot);
try {
if (dueSlot != 0 && dueSlot > pers.c2_getCurrentDueSlot()) {
SmsSet smsSet = pers.c2_getRecordListForTargeId(dueSlot, smsSet0.getTargetId());
if (smsSet != null) {
if (logger.isInfoEnabled()) {
logger.info(String.format("\nReceived AlertServiceCentre for MSISDN=%s, SmsSet was loaded with %d messages", addr, smsSet.getSmsCount()));
}
for (int i1 = 0; i1 < smsSet.getSmsCount(); i1++) {
Sms sms = smsSet.getSms(i1);
sms.setInvokedByAlert(true);
}
ArrayList<SmsSet> lstS = new ArrayList<SmsSet>();
lstS.add(smsSet);
ArrayList<SmsSet> lst = pers.c2_sortRecordList(lstS);
if (lst.size() > 0) {
smsSet = lst.get(0);
smsSet.setProcessingStarted();
this.scheduler.injectSmsDatabase(smsSet);
}
} else {
if (logger.isInfoEnabled()) {
logger.info(String.format("\nReceived AlertServiceCentre for MSISDN=%s, dueSlot was scheduled but no SmsSet was loaded", addr));
}
}
} else {
if (logger.isInfoEnabled()) {
logger.info(String.format("\nReceived AlertServiceCentre for MSISDN=%s but no dueSlot was scheduled or the scheduled dueSlot will come soon - 2", addr));
}
}
} finally {
pers.c2_unregisterDueSlotWriting(dueSlot);
}
} else {
if (logger.isInfoEnabled()) {
logger.info(String.format("\nReceived AlertServiceCentre for MSISDN=%s but no dueSlot was scheduled or the scheduled dueSlot will come soon - 1", addr));
}
}
} catch (PersistenceException e) {
this.logger.severe("PersistenceException when setupAlert()" + e.getMessage(), e);
} catch (Exception e) {
this.logger.severe("Exception when setupAlert()" + e.getMessage(), e);
}
}
} finally {
pers.releaseSynchroObject(lock);
}
}
use of org.mobicents.smsc.cassandra.PersistenceException in project smscgateway by RestComm.
the class PersistenceRAInterfaceProxy method obtainLiveSms.
public Sms obtainLiveSms(long dueSlot, String targetId, UUID id) throws PersistenceException {
try {
String s1 = "select * from \"SLOT_MESSAGES_TABLE" + this.getTableName(dueSlot) + "\" where \"DUE_SLOT\"=? and \"TARGET_ID\"=? and \"ID\"=?;";
PreparedStatement ps = session.prepare(s1);
BoundStatement boundStatement = new BoundStatement(ps);
boundStatement.bind(dueSlot, targetId, id);
ResultSet rs = session.execute(boundStatement);
SmsSet smsSet = null;
Row row2 = null;
for (Row row : rs) {
smsSet = this.createSms(row, null, true, true, true, true, true, false);
row2 = row;
break;
}
if (smsSet == null || smsSet.getSmsCount() == 0)
return null;
else {
smsSet.setAlertingSupported(row2.getBool(Schema.COLUMN_ALERTING_SUPPORTED));
smsSet.setStatus(ErrorCode.fromInt(row2.getInt(Schema.COLUMN_SM_STATUS)));
return smsSet.getSms(0);
}
} catch (Exception e) {
int ggg = 0;
ggg = 0;
return null;
}
}
use of org.mobicents.smsc.cassandra.PersistenceException in project smscgateway by RestComm.
the class DeliveryCommonSbb method postProcessTempFailures.
/**
* Processing messages that were failed temporary and will be rescheduled (sms.inSystem=sent in live database, message
* rescheduling).
*
* @param smsSet
* @param lstTempFailured
* @param int newDueDelay
* @param newDueDate
* @param isCheckScheduleDeliveryTimeNeeded true if we need to schedule messages for time to the nearest
* ScheduleDeliveryTime (for SS7 network case)
*/
protected void postProcessTempFailures(SmsSet smsSet, ArrayList<Sms> lstTempFailured, int newDueDelay, Date newDueDate, boolean isCheckScheduleDeliveryTimeNeeded) {
try {
if (isCheckScheduleDeliveryTimeNeeded)
newDueDate = MessageUtil.checkScheduleDeliveryTime(lstTempFailured, newDueDate);
smsSet.setDueDate(newDueDate);
smsSet.setDueDelay(newDueDelay);
long dueSlot = persistence.c2_getDueSlotForTime(newDueDate);
for (Sms sms : lstTempFailured) {
persistence.c2_scheduleMessage_NewDueSlot(sms, dueSlot, null, smscPropertiesManagement.getStoreAndForwordMode() == StoreAndForwordMode.fast);
}
} catch (PersistenceException e) {
this.logger.severe("PersistenceException when DeliveryCommonSbb.postProcessTempFailures()" + e.getMessage(), e);
}
}
Aggregations