Search in sources :

Example 16 with FastList

use of javolution.util.FastList 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);
}
Also used : EsmeManagement(org.restcomm.smpp.EsmeManagement) Esme(org.restcomm.smpp.Esme) FastList(javolution.util.FastList) ArrayList(java.util.ArrayList) TargetAddress(org.mobicents.smsc.library.TargetAddress) ISDNAddressString(org.restcomm.protocols.ss7.map.api.primitives.ISDNAddressString) ErrorAction(org.mobicents.smsc.library.ErrorAction) MProcResult(org.mobicents.smsc.mproc.impl.MProcResult) Sms(org.mobicents.smsc.library.Sms) ErrorCode(org.mobicents.smsc.library.ErrorCode)

Example 17 with FastList

use of javolution.util.FastList in project smscgateway by RestComm.

the class DBOperations method c2_getSmppSmsRoutingRulesRange.

/**
 * Returns 100 rows of SMPP_SMS_ROUTING_RULE starting from passed lastAdress. If lastAdress, first 100 rows are returned
 *
 * @param lastAdress
 * @return
 * @throws PersistenceException
 */
public List<DbSmsRoutingRule> c2_getSmppSmsRoutingRulesRange(String lastAdress) throws PersistenceException {
    List<DbSmsRoutingRule> ress = new FastList<DbSmsRoutingRule>();
    try {
        PreparedStatement ps = lastAdress != null ? getSmppSmsRoutingRulesRange : getSmppSmsRoutingRulesRange2;
        BoundStatement boundStatement = new BoundStatement(ps);
        if (lastAdress != null) {
            boundStatement.bind(lastAdress);
        }
        ResultSet result = session.execute(boundStatement);
        int i1 = 0;
        for (Row row : result) {
            String address = row.getString(Schema.COLUMN_ADDRESS);
            String name = row.getString(Schema.COLUMN_CLUSTER_NAME);
            int networkId = row.getInt(Schema.COLUMN_NETWORK_ID);
            DbSmsRoutingRule res = new DbSmsRoutingRule(SmsRoutingRuleType.SMPP, address, networkId, name);
            if (i1 == 0) {
                i1 = 1;
                if (lastAdress == null)
                    ress.add(res);
            } else {
                ress.add(res);
            }
        }
        return ress;
    } catch (Exception e) {
        String msg = "Failed to getSmsRoutingRule DbSmsRoutingRule for all records: " + e;
        throw new PersistenceException(msg, e);
    }
}
Also used : FastList(javolution.util.FastList) ResultSet(com.datastax.driver.core.ResultSet) PreparedStatement(com.datastax.driver.core.PreparedStatement) Row(com.datastax.driver.core.Row) DbSmsRoutingRule(org.mobicents.smsc.library.DbSmsRoutingRule) BoundStatement(com.datastax.driver.core.BoundStatement) XMLStreamException(javolution.xml.stream.XMLStreamException) InvalidQueryException(com.datastax.driver.core.exceptions.InvalidQueryException)

Example 18 with FastList

use of javolution.util.FastList in project smscgateway by RestComm.

the class ChargingSbb method acceptSms.

private void acceptSms(ChargingData chargingData) throws SmscProcessingException {
    Sms sms0 = chargingData.getSms();
    if (logger.isInfoEnabled()) {
        logger.info("ChargingSbb: accessGranted for: chargingType=" + chargingData.getChargingType() + ", message=[" + sms0 + "]");
    }
    try {
        MProcResult mProcResult = MProcManagement.getInstance().applyMProcArrival(itsMProcRa, sms0, persistence);
        FastList<Sms> smss = mProcResult.getMessageList();
        if (smss != null) {
            for (FastList.Node<Sms> n = smss.head(), end = smss.tail(); (n = n.getNext()) != end; ) {
                Sms sms = n.getValue();
                TargetAddress ta = new TargetAddress(sms.getSmsSet());
                TargetAddress lock = persistence.obtainSynchroObject(ta);
                sms.setTimestampC(System.currentTimeMillis());
                try {
                    synchronized (lock) {
                        boolean storeAndForwMode = MessageUtil.isStoreAndForward(sms);
                        if (!storeAndForwMode) {
                            try {
                                this.scheduler.injectSmsOnFly(sms.getSmsSet(), true);
                            } catch (Exception e) {
                                throw new SmscProcessingException("Exception when runnung injectSmsOnFly(): " + e.getMessage(), SmppConstants.STATUS_SYSERR, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e);
                            }
                        } else {
                            if (smscPropertiesManagement.getStoreAndForwordMode() == StoreAndForwordMode.fast) {
                                try {
                                    sms.setStoringAfterFailure(true);
                                    this.scheduler.injectSmsOnFly(sms.getSmsSet(), true);
                                } catch (Exception e) {
                                    throw new SmscProcessingException("Exception when runnung injectSmsOnFly(): " + e.getMessage(), SmppConstants.STATUS_SYSERR, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e);
                                }
                            } else {
                                sms.setStored(true);
                                // if (smscPropertiesManagement.getDatabaseType() == DatabaseType.Cassandra_1) {
                                // persistence.createLiveSms(sms);
                                // persistence.setNewMessageScheduled(sms.getSmsSet(),
                                // MessageUtil.computeDueDate(MessageUtil.computeFirstDueDelay(smscPropertiesManagement.getFirstDueDelay())));
                                // } else {
                                this.scheduler.setDestCluster(sms.getSmsSet());
                                persistence.c2_scheduleMessage_ReschedDueSlot(sms, smscPropertiesManagement.getStoreAndForwordMode() == StoreAndForwordMode.fast, false);
                            // }
                            }
                        }
                    }
                } finally {
                    persistence.releaseSynchroObject(lock);
                }
            }
        }
        if (mProcResult.isMessageRejected()) {
            rejectSmsByMproc(chargingData, true);
            return;
        }
        if (mProcResult.isMessageDropped()) {
            rejectSmsByMproc(chargingData, false);
            return;
        }
        // sending success response for charging result
        if (sms0.getMessageDeliveryResultResponse() != null && sms0.getMessageDeliveryResultResponse().isOnlyChargingRequest()) {
            sms0.getMessageDeliveryResultResponse().responseDeliverySuccess();
            sms0.setTimestampB(System.currentTimeMillis());
            EventType eventTypeSuccess = null;
            String messageType = null;
            String sourceAddr = null;
            int seqNum = -1;
            switch(sms0.getOriginationType()) {
                case SMPP:
                    eventTypeSuccess = EventType.IN_SMPP_RECEIVED;
                    MessageDeliveryResultResponseInterface resp = sms0.getMessageDeliveryResultResponse();
                    messageType = resp.getMessageType();
                    seqNum = resp.getSeqNumber();
                    break;
                case HTTP:
                    eventTypeSuccess = EventType.IN_HTTP_RECEIVED;
                    messageType = CdrDetailedGenerator.CDR_MSG_TYPE_HTTP;
                    break;
                default:
                    break;
            }
            if (eventTypeSuccess != null) {
                EsmeManagement esmeManagement = EsmeManagement.getInstance();
                if (esmeManagement != null) {
                    // for testing there is no EsmeManagement
                    Esme esme = esmeManagement.getEsmeByClusterName(sms0.getOrigEsmeName());
                    // null check is for testing
                    if (esme != null) {
                        sourceAddr = esme.getRemoteAddressAndPort();
                    }
                }
                CdrDetailedGenerator.generateDetailedCdr(sms0, eventTypeSuccess, sms0.getSmsSet().getStatus(), messageType, SmppConstants.STATUS_OK, -1, sourceAddr, null, seqNum, smscPropertiesManagement.getGenerateReceiptCdr(), smscPropertiesManagement.getGenerateDetailedCdr());
            }
            sms0.setMessageDeliveryResultResponse(null);
        }
        smscStatAggregator.updateMsgInReceivedAll();
        switch(sms0.getOriginationType()) {
            case SMPP:
                smscStatAggregator.updateMsgInReceivedSmpp();
                break;
            case SS7_MO:
                smscStatAggregator.updateMsgInReceivedSs7();
                smscStatAggregator.updateMsgInReceivedSs7Mo();
                break;
            case SS7_HR:
                smscStatAggregator.updateMsgInReceivedSs7();
                smscStatAggregator.updateMsgInReceivedSs7Hr();
                break;
            case SIP:
                smscStatAggregator.updateMsgInReceivedSip();
                break;
            default:
                break;
        }
    } catch (PersistenceException e) {
        if (sms0 != null) {
            generateCDR(sms0, CdrGenerator.CDR_SUBMIT_FAILED_CHARGING, e.getMessage(), false, true);
        }
        throw new SmscProcessingException("PersistenceException when storing LIVE_SMS : " + e.getMessage(), SmppConstants.STATUS_SUBMITFAIL, MAPErrorCode.systemFailure, SmscProcessingException.HTTP_ERROR_CODE_NOT_SET, null, e);
    }
}
Also used : EsmeManagement(org.restcomm.smpp.EsmeManagement) EventType(org.mobicents.smsc.library.EventType) SmscProcessingException(org.mobicents.smsc.library.SmscProcessingException) Esme(org.restcomm.smpp.Esme) FastList(javolution.util.FastList) TargetAddress(org.mobicents.smsc.library.TargetAddress) SmscProcessingException(org.mobicents.smsc.library.SmscProcessingException) CreateException(javax.slee.CreateException) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) MessageDeliveryResultResponseInterface(org.mobicents.smsc.library.MessageDeliveryResultResponseInterface) MProcResult(org.mobicents.smsc.mproc.impl.MProcResult) Sms(org.mobicents.smsc.library.Sms) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException)

Aggregations

FastList (javolution.util.FastList)18 MProcResult (org.mobicents.smsc.mproc.impl.MProcResult)12 Sms (org.mobicents.smsc.library.Sms)10 MProcRule (org.mobicents.smsc.mproc.MProcRule)9 TargetAddress (org.mobicents.smsc.library.TargetAddress)6 MProcMessage (org.mobicents.smsc.mproc.MProcMessage)6 MProcMessageImpl (org.mobicents.smsc.mproc.impl.MProcMessageImpl)5 XMLStreamException (javolution.xml.stream.XMLStreamException)4 MProcNewMessage (org.mobicents.smsc.mproc.MProcNewMessage)4 MProcNewMessageImpl (org.mobicents.smsc.mproc.impl.MProcNewMessageImpl)4 Esme (org.restcomm.smpp.Esme)4 EsmeManagement (org.restcomm.smpp.EsmeManagement)4 BoundStatement (com.datastax.driver.core.BoundStatement)2 PreparedStatement (com.datastax.driver.core.PreparedStatement)2 ResultSet (com.datastax.driver.core.ResultSet)2 Row (com.datastax.driver.core.Row)2 InvalidQueryException (com.datastax.driver.core.exceptions.InvalidQueryException)2 FileNotFoundException (java.io.FileNotFoundException)2 ArrayList (java.util.ArrayList)2 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)2