Search in sources :

Example 1 with PersistenceRAInterface

use of org.mobicents.smsc.slee.resources.persistence.PersistenceRAInterface 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);
    }
}
Also used : PersistenceRAInterface(org.mobicents.smsc.slee.resources.persistence.PersistenceRAInterface) SmscPropertiesManagement(org.mobicents.smsc.domain.SmscPropertiesManagement) MAPDialogSms(org.mobicents.protocols.ss7.map.api.service.sms.MAPDialogSms) Sms(org.mobicents.smsc.library.Sms) ArrayList(java.util.ArrayList) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) TargetAddress(org.mobicents.smsc.library.TargetAddress) ISDNAddressString(org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString) AddressString(org.mobicents.protocols.ss7.map.api.primitives.AddressString) SmsSet(org.mobicents.smsc.library.SmsSet) CreateException(javax.slee.CreateException) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) MAPException(org.mobicents.protocols.ss7.map.api.MAPException)

Aggregations

ArrayList (java.util.ArrayList)1 CreateException (javax.slee.CreateException)1 MAPException (org.mobicents.protocols.ss7.map.api.MAPException)1 AddressString (org.mobicents.protocols.ss7.map.api.primitives.AddressString)1 ISDNAddressString (org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString)1 MAPDialogSms (org.mobicents.protocols.ss7.map.api.service.sms.MAPDialogSms)1 PersistenceException (org.mobicents.smsc.cassandra.PersistenceException)1 SmscPropertiesManagement (org.mobicents.smsc.domain.SmscPropertiesManagement)1 Sms (org.mobicents.smsc.library.Sms)1 SmsSet (org.mobicents.smsc.library.SmsSet)1 TargetAddress (org.mobicents.smsc.library.TargetAddress)1 PersistenceRAInterface (org.mobicents.smsc.slee.resources.persistence.PersistenceRAInterface)1