use of org.mobicents.smsc.library.TargetAddress in project smscgateway by RestComm.
the class DeliveryCommonSbb method sendNewGeneratedMessage.
// *********
// sending of generated messages (delivery receipts and messages that were generated by mproc rules)
private void sendNewGeneratedMessage(Sms sms, TargetAddress ta) {
boolean storeAndForwMode = MessageUtil.isStoreAndForward(sms);
TargetAddress lock = SmsSetCache.getInstance().addSmsSet(ta);
try {
synchronized (lock) {
if (!storeAndForwMode) {
try {
this.scheduler.injectSmsOnFly(sms.getSmsSet(), true);
} catch (Exception e) {
this.logger.severe("Exception when runnung injectSmsOnFly() for receipt in sendNewGeneratedMessage(): " + e.getMessage(), e);
}
} else {
if (smscPropertiesManagement.getStoreAndForwordMode() == StoreAndForwordMode.fast) {
try {
sms.setStoringAfterFailure(true);
this.scheduler.injectSmsOnFly(sms.getSmsSet(), true);
} catch (Exception e) {
this.logger.severe("Exception when runnung injectSmsOnFly() for receipt in sendNewGeneratedMessage(): " + e.getMessage(), e);
}
} else {
sms.setStored(true);
this.scheduler.setDestCluster(sms.getSmsSet());
try {
persistence.c2_scheduleMessage_ReschedDueSlot(sms, smscPropertiesManagement.getStoreAndForwordMode() == StoreAndForwordMode.fast, true);
} catch (PersistenceException e) {
this.logger.severe("PersistenceException when running c2_scheduleMessage_ReschedDueSlot() in sendNewGeneratedMessage()" + e.getMessage(), e);
}
}
}
}
} finally {
SmsSetCache.getInstance().removeSmsSet(lock);
}
}
use of org.mobicents.smsc.library.TargetAddress in project smscgateway by RestComm.
the class DeliveryCommonSbb method generateSuccessReceipt.
// *********
// delivery receipts generating
/**
* Generating of a success receipt for a delivered message
*
* @param smsSet
* @param sms
*/
protected void generateSuccessReceipt(SmsSet smsSet, Sms sms) {
if (!smscPropertiesManagement.getReceiptsDisabling()) {
// SMPP delivery receipt
int registeredDelivery = sms.getRegisteredDelivery();
if (MessageUtil.isReceiptOnSuccess(registeredDelivery)) {
TargetAddress ta = new TargetAddress(sms.getSourceAddrTon(), sms.getSourceAddrNpi(), sms.getSourceAddr(), smsSet.getNetworkId());
Sms receipt = MessageUtil.createReceiptSms(sms, true, ta, smscPropertiesManagement.getOrigNetworkIdForReceipts());
this.sendNewGeneratedMessage(receipt, ta);
}
// SMS-STATUS-REPORT
if (sms.isStatusReportRequest()) {
TargetAddress ta = new TargetAddress(sms.getSourceAddrTon(), sms.getSourceAddrNpi(), sms.getSourceAddr(), smsSet.getNetworkId());
Sms smsStatusReport = MessageUtil.createSmsStatusReport(sms, true, ta, smscPropertiesManagement.getOrigNetworkIdForReceipts());
this.sendNewGeneratedMessage(smsStatusReport, ta);
}
}
}
use of org.mobicents.smsc.library.TargetAddress in project smscgateway by RestComm.
the class DeliveryCommonSbb method generateFailureReceipts.
/**
* Generating of failure receipts for permanent failed messages
*
* @param smsSet
* @param lstPermFailured
*/
protected void generateFailureReceipts(SmsSet smsSet, ArrayList<Sms> lstPermFailured, String extraString) {
if (!smscPropertiesManagement.getReceiptsDisabling()) {
for (Sms sms : lstPermFailured) {
// SMPP delivery receipt
int registeredDelivery = sms.getRegisteredDelivery();
if (MessageUtil.isReceiptOnFailure(registeredDelivery)) {
TargetAddress ta = new TargetAddress(sms.getSourceAddrTon(), sms.getSourceAddrNpi(), sms.getSourceAddr(), smsSet.getNetworkId());
Sms receipt = MessageUtil.createReceiptSms(sms, false, ta, smscPropertiesManagement.getOrigNetworkIdForReceipts(), extraString);
this.sendNewGeneratedMessage(receipt, ta);
this.logger.info("Adding an failire receipt: source=" + receipt.getSourceAddr() + ", dest=" + receipt.getSmsSet().getDestAddr());
}
// SMS-STATUS-REPORT
if (sms.isStatusReportRequest()) {
TargetAddress ta = new TargetAddress(sms.getSourceAddrTon(), sms.getSourceAddrNpi(), sms.getSourceAddr(), smsSet.getNetworkId());
Sms smsStatusReport = MessageUtil.createSmsStatusReport(sms, false, ta, smscPropertiesManagement.getOrigNetworkIdForReceipts());
this.sendNewGeneratedMessage(smsStatusReport, ta);
this.logger.info("Adding an failire SMS-STATUS-REPORT: source=" + smsStatusReport.getSourceAddr() + ", dest=" + smsStatusReport.getSmsSet().getDestAddr());
}
}
}
}
use of org.mobicents.smsc.library.TargetAddress in project smscgateway by RestComm.
the class DeliveryCommonSbb method endDeliveryAfterValidityPeriod.
/**
* Finishing delivering of a message which validity period is over at the start of delivery time.
*
* @param sms
* @param processingType
* @param dlvMessageId
* @param dlvDestId
*/
protected void endDeliveryAfterValidityPeriod(Sms sms, ProcessingType processingType, String dlvMessageId, String dlvDestId) {
// ending of delivery process in this SBB
ErrorCode smStatus = ErrorCode.VALIDITY_PERIOD_EXPIRED;
ErrorAction errorAction = ErrorAction.permanentFailure;
String reason = "Validity period is expired";
smsSet.setStatus(smStatus);
StringBuilder sb = new StringBuilder();
sb.append("onDeliveryError: errorAction=validityExpired");
sb.append(", smStatus=");
sb.append(smStatus);
sb.append(", targetId=");
sb.append(smsSet.getTargetId());
sb.append(", smsSet=");
sb.append(smsSet);
sb.append(", reason=");
sb.append(reason);
if (this.logger.isInfoEnabled())
this.logger.info(sb.toString());
// mproc rules applying for delivery phase
MProcResult mProcResult = MProcManagement.getInstance().applyMProcDelivery(itsMProcRa, sms, true, processingType);
if (mProcResult.isMessageIsRerouted()) {
// we do not reroute a message with expired validity period
sb = new StringBuilder();
sb.append("Can not reroute of a message with expired ValidityPeriod, sms=");
sb.append(sms);
this.logger.warning(sb.toString());
}
FastList<Sms> addedMessages = mProcResult.getMessageList();
if (addedMessages != null) {
for (FastList.Node<Sms> n = addedMessages.head(), end = addedMessages.tail(); (n = n.getNext()) != end; ) {
Sms smst = n.getValue();
TargetAddress ta = new TargetAddress(smst.getSmsSet().getDestAddrTon(), smst.getSmsSet().getDestAddrNpi(), smst.getSmsSet().getDestAddr(), smst.getSmsSet().getNetworkId());
this.sendNewGeneratedMessage(smst, ta);
if (this.logger.isInfoEnabled()) {
sb = new StringBuilder();
sb.append("Posting of a new message after PermFailure-ValidityPeriod: targetId=");
sb.append(smst.getSmsSet().getTargetId());
sb.append(", sms=");
sb.append(smst);
this.logger.info(sb.toString());
}
}
}
ArrayList<Sms> lstPermFailured = new ArrayList<Sms>();
lstPermFailured.add(sms);
// sending of a failure response for transactional mode
this.sendTransactionalResponseFailure(lstPermFailured, null, errorAction, null);
// Processing messages that were temp or permanent failed or rerouted
this.postProcessPermFailures(lstPermFailured, dlvMessageId, dlvDestId);
// generating CDRs for permanent failure messages
this.generateCDRs(lstPermFailured, CdrGenerator.CDR_FAILED, reason);
EsmeManagement esmeManagement = EsmeManagement.getInstance();
if (esmeManagement != null) {
Esme esme = null;
if (smsSet.getDestClusterName() != null) {
esme = esmeManagement.getEsmeByClusterName(smsSet.getDestClusterName());
}
String messageType = null;
String remoteAddr = null;
if (esme != null) {
messageType = esme.getSmppSessionType() == Type.CLIENT ? CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITSM : CdrDetailedGenerator.CDR_MSG_TYPE_DELIVERSM;
remoteAddr = esme.getRemoteAddressAndPort();
}
this.generateDetailedCDRs(lstPermFailured, EventType.VALIDITY_PERIOD_TIMEOUT, smStatus, messageType, remoteAddr, -1);
}
// sending of failure delivery receipts
this.generateFailureReceipts(smsSet, lstPermFailured, null);
}
use of org.mobicents.smsc.library.TargetAddress in project smscgateway by RestComm.
the class DeliveryCommonSbb method obtainNextMessage.
/**
* Arrange a new message sending pool with only one message in it. If no pending message then no message will be arranged to
* a message sending pool. Previous arranging pool will be removed by this operation and pending messages in it will be
* marked as already processed. If you need to arrange more than one message in message sending pool you can use
* obtainNextMessagesSendingPool() method. Messages with expired ValidityPeriod are not added to a sendingPoolMsg but are
* processed as perm failed.
*
* @param processingType
* @return a message for sending or null if no more message to send
*/
protected Sms obtainNextMessage(ProcessingType processingType) {
commitSendingPoolMsgCount();
if (smsSet != null) {
Sms sms = null;
// ***** lock ******
TargetAddress lock = persistence.obtainSynchroObject(new TargetAddress(smsSet));
try {
synchronized (lock) {
int addedMessageCnt = 0;
int gotMessageCnt = 0;
int sendingPoolMsgCount = this.getTotalUnsentMessageCount();
for (int i1 = 0; i1 < sendingPoolMsgCount; i1++) {
if (addedMessageCnt >= 1) {
break;
}
gotMessageCnt++;
sms = smsSet.getSms(currentMsgNum + i1);
if (sms == null) {
this.logger.severe("RxSmpp obtainNextMessage() error: sms is not found num=" + i1 + " from " + sendingPoolMsgCount + ", smsSet=" + smsSet);
break;
}
if (sms.getValidityPeriod() != null && sms.getValidityPeriod().getTime() <= System.currentTimeMillis()) {
this.endDeliveryAfterValidityPeriod(sms, processingType, null, null);
sms = null;
} else {
boolean res1 = applyMProcPreDelivery(sms, processingType);
if (!res1) {
sms = null;
} else {
addedMessageCnt++;
sms.setDeliveryCount(sms.getDeliveryCount() + 1);
smsSet.markSmsAsDelivered(currentMsgNum + i1);
smsSet.addMessageToSendingPool(sms);
}
}
}
if (gotMessageCnt > 0) {
currentMsgNum += gotMessageCnt;
this.setCurrentMsgNum(currentMsgNum);
}
sequenceNumbers = null;
sequenceNumbersExtra = null;
this.rescheduleDeliveryTimer(sendingPoolMsgCount);
}
} finally {
persistence.releaseSynchroObject(lock);
}
return sms;
} else
return null;
}
Aggregations