Search in sources :

Example 1 with ConfirmMessageInSendingPool

use of org.mobicents.smsc.slee.services.deliverysbb.ConfirmMessageInSendingPool in project smscgateway by RestComm.

the class RxSmppServerSbb method onSendPduStatusLocal.

private void onSendPduStatusLocal(final SendPduStatus event, final ActivityContextInterface aci) {
    if (logger.isFineEnabled())
        logger.fine("onSendPduStatusParent - refire to RxSmppServerChildSbb : activity=" + aci.getActivity());
    RxSmppServerChildLocalObject rxSmppServerSbbLocalObject = this.getRxSmppServerChildSbbObject();
    if (rxSmppServerSbbLocalObject != null) {
        ActivityContextInterface act = getSchedulerActivityContextInterface();
        if (act != null) {
            try {
                act.attach(rxSmppServerSbbLocalObject);
                SendPduStatus2 event2 = new SendPduStatus2(event.getException(), event.getRequest(), event.getResponse(), event.getSystemId(), event.isSuccess());
                SmsSet smsSet = getSmsSet();
                Pdu pduEvent = event.getRequest();
                if (event.getResponse() != null)
                    pduEvent = event.getResponse();
                EsmeManagement esmeManagement = EsmeManagement.getInstance();
                Boolean destAddressLimitationEnabled = false;
                if (esmeManagement != null && smsSet != null) {
                    Esme esme = esmeManagement.getEsmeByName(smsSet.getDestEsmeName());
                    if (esme != null) {
                        destAddressLimitationEnabled = esme.getDestAddrSendLimit() != 0;
                    }
                }
                int realID = -1;
                SentItemsList list = null;
                if (destAddressLimitationEnabled) {
                    list = retreiveSentChunks();
                    for (int i = 0; i < list.getSentList().size(); i++) {
                        if (list.getSentList().get(i).getRemoteSequenceNumber() == pduEvent.getSequenceNumber()) {
                            realID = list.getSentList().get(i).getLocalSequenceNumber();
                            break;
                        }
                    }
                } else {
                    realID = pduEvent.getSequenceNumber();
                }
                ConfirmMessageInSendingPool confirmMessageInSendingPool = null;
                if (realID != -1)
                    confirmMessageInSendingPool = getMessageInSendingPoolBySeqNumber(realID);
                fireSendPduStatusChild(event2, act, null);
            } catch (IllegalStateException e) {
                if (logger.isInfoEnabled())
                    logger.info("onSendPduStatus - IllegalStateException (activity is ending - dropping a SLEE event because it is not needed) : new activity=" + act.getActivity() + ", event=" + event);
            }
        }
    }
}
Also used : Pdu(com.cloudhopper.smpp.pdu.Pdu) EsmeManagement(org.restcomm.smpp.EsmeManagement) SentItemsList(org.mobicents.smsc.slee.services.deliverysbb.SentItemsList) ActivityContextInterface(javax.slee.ActivityContextInterface) SendPduStatus2(org.mobicents.smsc.slee.resources.scheduler.SendPduStatus2) Esme(org.restcomm.smpp.Esme) ConfirmMessageInSendingPool(org.mobicents.smsc.slee.services.deliverysbb.ConfirmMessageInSendingPool) SmsSet(org.mobicents.smsc.library.SmsSet)

Example 2 with ConfirmMessageInSendingPool

use of org.mobicents.smsc.slee.services.deliverysbb.ConfirmMessageInSendingPool in project smscgateway by RestComm.

the class RxSmppServerSbb method handleResponse.

/**
 * Processing of a positive delivery response to smpp destination.
 *
 * @param event
 * @throws Exception
 */
private void handleResponse(BaseSmResp event) throws Exception {
    long ts = System.currentTimeMillis();
    if (isDeliveringEnded()) {
        if (logger.isFineEnabled()) {
            this.logger.fine("SMPP Response received when DeliveringEnded state: status=" + event.getCommandStatus());
        }
    }
    if (isDeliveringEnded()) {
        logger.info("RxSmppServerSbb.handleResponse(): received submit/deliver_sm_response but delivery process is already ended, dropping of a response");
        return;
    }
    SmsSet smsSet = getSmsSet();
    if (smsSet == null) {
        logger.severe("RxSmppServerSbb.handleResponse(): CMP smsSet is missed");
        markDeliveringIsEnded(true);
        return;
    }
    int status = event.getCommandStatus();
    if (status == 0) {
        smscStatAggregator.updateMsgOutSentAll();
        smscStatAggregator.updateMsgOutSentSmpp();
        boolean destAddressLimitationEnabled = false;
        EsmeManagement esmeManagement = EsmeManagement.getInstance();
        Esme esme = esmeManagement.getEsmeByClusterName(smsSet.getDestClusterName());
        if (esme != null) {
            destAddressLimitationEnabled = esme.getDestAddrSendLimit() != 0;
        }
        int realID = -1;
        Boolean sentListChanged = false;
        SentItemsList list = null;
        if (destAddressLimitationEnabled) {
            list = retreiveSentChunks();
            for (int i = 0; i < list.getSentList().size(); i++) {
                if (list.getSentList().get(i).getRemoteSequenceNumber() == event.getSequenceNumber()) {
                    realID = list.getSentList().get(i).getLocalSequenceNumber();
                    list.getSentList().remove(i);
                    sentListChanged = true;
                    break;
                }
            }
        } else {
            realID = event.getSequenceNumber();
        }
        ConfirmMessageInSendingPool confirmMessageInSendingPool = null;
        if (realID != -1)
            confirmMessageInSendingPool = confirmMessageInSendingPool(realID);
        if (realID == -1 || !confirmMessageInSendingPool.sequenceNumberFound) {
            this.logger.severe("RxSmppServerSbb.handleResponse(): no sms in MessageInSendingPool: UnconfirmedCnt=" + this.getUnconfirmedMessageCountInSendingPool() + ", sequenceNumber=" + event.getSequenceNumber() + ", realID=" + realID + ", confirmMessageInSendingPool=" + confirmMessageInSendingPool);
            this.onDeliveryError(smsSet, ErrorAction.temporaryFailure, ErrorCode.SC_SYSTEM_ERROR, "Received undefined SequenceNumber: " + event.getSequenceNumber() + ", SmsSet=" + smsSet, EventType.OUT_SMPP_ERROR, realID);
            if (sentListChanged)
                setSentChunks(list);
            return;
        }
        Sms sms = confirmMessageInSendingPool.sms;
        if (sms != null) {
            sms.setTimestampC(System.currentTimeMillis());
        }
        if (destAddressLimitationEnabled) {
            ChunkDataList dataList = retreivePendingChunks();
            if (dataList != null && !dataList.getPendingList().isEmpty()) {
                // so checking if has window
                if (list.getSentList().size() < esme.getDestAddrSendLimit()) {
                    ChunkData current = dataList.getPendingList().remove(0);
                    setPendingChunks(dataList);
                    if (current != null) {
                        SentItem newItem = sendNextChunk(current, smsSet, esme);
                        SentItemsList sentChunks = retreiveSentChunks();
                        sentChunks.getSentList().add(newItem);
                        sentListChanged = true;
                    }
                }
            }
        }
        if (sentListChanged)
            setSentChunks(list);
        if (!confirmMessageInSendingPool.confirmed) {
            this.generateCDR(sms, CdrGenerator.CDR_PARTIAL_ESME, CdrGenerator.CDR_SUCCESS_NO_REASON, true, false, event.getSequenceNumber());
            String messageType = esme.getSmppSessionType() == Type.CLIENT ? CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITSM : CdrDetailedGenerator.CDR_MSG_TYPE_DELIVERSM;
            this.generateDetailedCDR(sms, EventType.OUT_SMPP_SENT, sms.getSmsSet().getStatus(), messageType, status, esme.getRemoteAddressAndPort(), event.getSequenceNumber());
            return;
        }
        // firstly we store remote messageId if sms has a request to delivery receipt
        String clusterName = smsSet.getDestClusterName();
        String dlvMessageId = event.getMessageId();
        sms.setDlvMessageId(dlvMessageId);
        // if (MessageUtil.isDeliveryReceiptRequest(sms)) {
        // SmsSetCache.getInstance().putDeliveredRemoteMsgIdValue(dlvMessageId, clusterName, sms.getMessageId(), 30);
        // }
        // current message is sent
        // firstly sending of a positive response for transactional mode
        sendTransactionalResponseSuccess(sms);
        // mproc rules applying for delivery phase
        this.applyMprocRulesOnSuccess(sms, ProcessingType.SMPP);
        // Processing succeeded
        sms.getSmsSet().setStatus(ErrorCode.SUCCESS);
        this.postProcessSucceeded(sms, dlvMessageId, clusterName);
        // success CDR generating
        boolean isPartial = MessageUtil.isSmsNotLastSegment(sms);
        this.generateCDR(sms, isPartial ? CdrGenerator.CDR_PARTIAL_ESME : CdrGenerator.CDR_SUCCESS_ESME, CdrGenerator.CDR_SUCCESS_NO_REASON, confirmMessageInSendingPool.splittedMessage, true, event.getSequenceNumber());
        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();
        }
        if (messageType == null) {
            if (event.getCommandId() == SmppConstants.CMD_ID_DELIVER_SM_RESP) {
                messageType = CdrDetailedGenerator.CDR_MSG_TYPE_DELIVERSM;
            } else {
                messageType = CdrDetailedGenerator.CDR_MSG_TYPE_SUBMITSM;
            }
        }
        this.generateDetailedCDR(sms, EventType.OUT_SMPP_SENT, sms.getSmsSet().getStatus(), messageType, status, remoteAddr, event.getSequenceNumber());
        // adding a success receipt if it is needed
        this.generateSuccessReceipt(smsSet, sms);
        if (this.getUnconfirmedMessageCountInSendingPool() == 0) {
            // all sent messages are confirmed - we are sending new message set
            TargetAddress lock = persistence.obtainSynchroObject(new TargetAddress(smsSet));
            try {
                synchronized (lock) {
                    // marking the message in cache as delivered
                    this.commitSendingPoolMsgCount();
                    ts = warnIfLong(logger, ts, "handleResponse/status=0/in-lock/commitSendingPoolMsgCount");
                    // now we are trying to sent other messages
                    if (this.getTotalUnsentMessageCount() > 0) {
                        try {
                            this.sendDeliverSm(smsSet);
                            ts = warnIfLong(logger, ts, "handleResponse/status=0/in-lock/sendDeliverSm");
                            return;
                        } catch (SmscProcessingException e) {
                            SbbStatsUtils.handleProcessingException(e, getDefaultSbbUsageParameterSet());
                            String s = "SmscProcessingException when sending next sendDeliverSm()=" + e.getMessage() + ", Message=" + sms;
                            logger.severe(s, e);
                            this.onDeliveryError(smsSet, ErrorAction.temporaryFailure, ErrorCode.SC_SYSTEM_ERROR, s, EventType.OUT_SMPP_ERROR, event.getSequenceNumber());
                        }
                    }
                    // no more messages to send - remove smsSet
                    smsSet.setStatus(ErrorCode.SUCCESS);
                    this.markDeliveringIsEnded(true);
                }
            } finally {
                persistence.releaseSynchroObject(lock);
            }
        }
    } else {
        ErrorAction errorAction = ErrorAction.permanentFailure;
        smsSet.setSmppCommandStatus(status);
        if (status == SmppConstants.STATUS_THROTTLED || status == SmppConstants.STATUS_X_T_APPN || status == SmppConstants.STATUS_SYSERR || status == SmppConstants.STATUS_INVBNDSTS || status == SmppConstants.STATUS_MSGQFUL)
            errorAction = ErrorAction.temporaryFailure;
        logger.warning("RxSmppServerSbb.handleResponse(): error code response received: status=" + status + ", errorAction=" + errorAction + ", smsSet=" + smsSet);
        this.onDeliveryError(smsSet, errorAction, ErrorCode.SC_SYSTEM_ERROR, event.getName() + " has a bad status: " + status, EventType.OUT_SMPP_REJECTED, event.getSequenceNumber());
    }
}
Also used : EsmeManagement(org.restcomm.smpp.EsmeManagement) ChunkData(org.mobicents.smsc.slee.services.deliverysbb.ChunkData) Esme(org.restcomm.smpp.Esme) SmscProcessingException(org.mobicents.smsc.library.SmscProcessingException) TargetAddress(org.mobicents.smsc.library.TargetAddress) ChunkDataList(org.mobicents.smsc.slee.services.deliverysbb.ChunkDataList) ConfirmMessageInSendingPool(org.mobicents.smsc.slee.services.deliverysbb.ConfirmMessageInSendingPool) SentItemsList(org.mobicents.smsc.slee.services.deliverysbb.SentItemsList) ErrorAction(org.mobicents.smsc.library.ErrorAction) Sms(org.mobicents.smsc.library.Sms) SentItem(org.mobicents.smsc.slee.services.deliverysbb.SentItem) SmsSet(org.mobicents.smsc.library.SmsSet)

Aggregations

SmsSet (org.mobicents.smsc.library.SmsSet)2 ConfirmMessageInSendingPool (org.mobicents.smsc.slee.services.deliverysbb.ConfirmMessageInSendingPool)2 SentItemsList (org.mobicents.smsc.slee.services.deliverysbb.SentItemsList)2 Esme (org.restcomm.smpp.Esme)2 EsmeManagement (org.restcomm.smpp.EsmeManagement)2 Pdu (com.cloudhopper.smpp.pdu.Pdu)1 ActivityContextInterface (javax.slee.ActivityContextInterface)1 ErrorAction (org.mobicents.smsc.library.ErrorAction)1 Sms (org.mobicents.smsc.library.Sms)1 SmscProcessingException (org.mobicents.smsc.library.SmscProcessingException)1 TargetAddress (org.mobicents.smsc.library.TargetAddress)1 SendPduStatus2 (org.mobicents.smsc.slee.resources.scheduler.SendPduStatus2)1 ChunkData (org.mobicents.smsc.slee.services.deliverysbb.ChunkData)1 ChunkDataList (org.mobicents.smsc.slee.services.deliverysbb.ChunkDataList)1 SentItem (org.mobicents.smsc.slee.services.deliverysbb.SentItem)1