Search in sources :

Example 1 with SmscPropertiesManagement

use of org.mobicents.smsc.domain.SmscPropertiesManagement in project smscgateway by RestComm.

the class TxSmppServerSbbTest method testSubmitSm_createSmsEvent.

@Test(groups = { "TxSmppServer" })
public void testSubmitSm_createSmsEvent() throws Exception {
    if (!this.cassandraDbInited)
        return;
    this.smppSess = new SmppSessionsProxy();
    this.sbb.setSmppServerSessions(smppSess);
    TxSmppServerSbb.smscPropertiesManagement.setSmppEncodingForUCS2(SmppEncoding.Utf8);
    SmscPropertiesManagement spm = SmscPropertiesManagement.getInstance("Test");
    String sMsgA = "������Hel";
    // only message part
    Charset utf8 = Charset.forName("UTF-8");
    ByteBuffer bb = utf8.encode(sMsgA);
    byte[] aMsgA = new byte[bb.limit()];
    bb.get(aMsgA);
    Charset ucs2 = Charset.forName("UTF-16BE");
    bb = ucs2.encode(sMsgA);
    byte[] aMsgAA = new byte[bb.limit()];
    bb.get(aMsgAA);
    com.cloudhopper.smpp.pdu.SubmitSm event = new com.cloudhopper.smpp.pdu.SubmitSm();
    Address addr = new Address();
    addr.setNpi((byte) 1);
    addr.setTon((byte) 1);
    addr.setAddress("2222");
    event.setSourceAddress(addr);
    Address addr2 = new Address();
    addr2.setNpi((byte) 1);
    addr2.setTon((byte) 1);
    addr2.setAddress("5555");
    event.setDestAddress(addr2);
    event.setDataCoding((byte) 8);
    event.setShortMessage(aMsgA);
    Esme origEsme = new Esme();
    TargetAddress ta = ta1;
    Sms sms = this.sbb.createSmsEvent(event, origEsme, ta, this.pers);
    assertEquals(sms.getShortMessageText(), sMsgA);
    // message part and UDH
    byte[] udh = new byte[] { 0x05, 0x00, 0x03, 0x29, 0x02, 0x02 };
    byte[] aMsgB = new byte[aMsgA.length + udh.length];
    System.arraycopy(udh, 0, aMsgB, 0, udh.length);
    System.arraycopy(aMsgA, 0, aMsgB, udh.length, aMsgA.length);
    event = new com.cloudhopper.smpp.pdu.SubmitSm();
    event.setSourceAddress(addr);
    event.setDestAddress(addr2);
    event.setDataCoding((byte) 8);
    event.setShortMessage(aMsgB);
    event.setEsmClass(SmppConstants.ESM_CLASS_UDHI_MASK);
    sms = this.sbb.createSmsEvent(event, origEsme, ta, this.pers);
    assertEquals(sms.getShortMessageText(), sMsgA);
    assertEquals(sms.getShortMessageBin(), udh);
    // binary GSM8
    String s1 = "Optic xxx";
    Charset iso = Charset.forName("ISO-8859-1");
    byte[] aMsgC = s1.getBytes(iso);
    byte[] aMsgCC = new byte[aMsgC.length + udh.length];
    System.arraycopy(udh, 0, aMsgCC, 0, udh.length);
    System.arraycopy(aMsgC, 0, aMsgCC, udh.length, aMsgC.length);
    event = new com.cloudhopper.smpp.pdu.SubmitSm();
    event.setSourceAddress(addr);
    event.setDestAddress(addr2);
    event.setDataCoding((byte) 4);
    event.setShortMessage(aMsgCC);
    event.setEsmClass(SmppConstants.ESM_CLASS_UDHI_MASK);
    sms = this.sbb.createSmsEvent(event, origEsme, ta, this.pers);
    assertEquals(sms.getShortMessageText(), s1);
    assertEquals(sms.getShortMessageBin(), udh);
    // GSM7
    event = new com.cloudhopper.smpp.pdu.SubmitSm();
    event.setSourceAddress(addr);
    event.setDestAddress(addr2);
    event.setDataCoding((byte) 0);
    event.setShortMessage(aMsgC);
    sms = this.sbb.createSmsEvent(event, origEsme, ta, this.pers);
    assertEquals(sms.getShortMessageText(), s1);
    assertNull(sms.getShortMessageBin());
}
Also used : TargetAddress(org.mobicents.smsc.library.TargetAddress) Address(com.cloudhopper.smpp.type.Address) Esme(org.restcomm.smpp.Esme) Charset(java.nio.charset.Charset) TargetAddress(org.mobicents.smsc.library.TargetAddress) SmppSessionsProxy(org.mobicents.smsc.slee.resources.persistence.SmppSessionsProxy) ByteBuffer(java.nio.ByteBuffer) SubmitSm(com.cloudhopper.smpp.pdu.SubmitSm) SubmitSm(com.cloudhopper.smpp.pdu.SubmitSm) SmscPropertiesManagement(org.mobicents.smsc.domain.SmscPropertiesManagement) Sms(org.mobicents.smsc.library.Sms) Test(org.testng.annotations.Test)

Example 2 with SmscPropertiesManagement

use of org.mobicents.smsc.domain.SmscPropertiesManagement in project smscgateway by RestComm.

the class SchedulerResourceAdaptor method raActive.

@Override
public void raActive() {
    clearActivityCount();
    SmscPropertiesManagement smscPropertiesManagement = SmscPropertiesManagement.getInstance();
    this.dbOperations_C2 = DBOperations.getInstance();
    if (!this.dbOperations_C2.isStarted()) {
        throw new RuntimeException("DBOperations_2 not started yet!");
    }
    scheduler = Executors.newScheduledThreadPool(1);
    long timerDur = smscPropertiesManagement.getFetchPeriod();
    long maxTimerDur = this.dbOperations_C2.getSlotMSecondsTimeArea() * 2 / 3;
    if (timerDur > maxTimerDur)
        timerDur = maxTimerDur;
    scheduler.scheduleAtFixedRate(new TickTimerTask(), 500, timerDur, TimeUnit.MILLISECONDS);
    if (tracer.isInfoEnabled()) {
        tracer.info("SchedulerResourceAdaptor " + raContext.getEntityName() + " Activated");
    }
    smscPropertiesManagement.setSmscStopped(false);
}
Also used : SmscPropertiesManagement(org.mobicents.smsc.domain.SmscPropertiesManagement)

Example 3 with SmscPropertiesManagement

use of org.mobicents.smsc.domain.SmscPropertiesManagement 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);
// }
}
Also used : SmscPropertiesManagement(org.mobicents.smsc.domain.SmscPropertiesManagement) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) SmscStatProvider(org.mobicents.smsc.domain.SmscStatProvider) Date(java.util.Date) SleeEndpoint(javax.slee.resource.SleeEndpoint) SmsSet(org.mobicents.smsc.library.SmsSet) RollbackException(javax.transaction.RollbackException) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) NotSupportedException(javax.transaction.NotSupportedException) SystemException(javax.transaction.SystemException) InvalidConfigurationException(javax.slee.resource.InvalidConfigurationException) HeuristicMixedException(javax.transaction.HeuristicMixedException) SmsRouteManagement(org.mobicents.smsc.domain.SmsRouteManagement)

Example 4 with SmscPropertiesManagement

use of org.mobicents.smsc.domain.SmscPropertiesManagement in project smscgateway by RestComm.

the class SchedulerResourceAdaptor method raInactive.

@Override
public void raInactive() {
    if (tracer.isInfoEnabled()) {
        tracer.info("Starting of inactivating SchedulerResourceAdaptor RA Entity " + this.raContext.getEntityName());
    }
    SmscPropertiesManagement smscPropertiesManagement = SmscPropertiesManagement.getInstance();
    smscPropertiesManagement.setSmscStopped(true);
    for (int i1 = 0; i1 < 60; i1++) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (SmsSetCache.getInstance().getProcessingSmsSetSize() == 0)
            break;
    }
    if (tracer.isInfoEnabled()) {
        tracer.info("Finishing of inactivating SchedulerResourceAdaptor RA Entity " + this.raContext.getEntityName());
    }
}
Also used : SmscPropertiesManagement(org.mobicents.smsc.domain.SmscPropertiesManagement) SleeEndpoint(javax.slee.resource.SleeEndpoint)

Example 5 with SmscPropertiesManagement

use of org.mobicents.smsc.domain.SmscPropertiesManagement in project smscgateway by RestComm.

the class SchedulerResourceAdaptor method doInjectSmsOnFly.

public void doInjectSmsOnFly(SmsSet smsSet, boolean callFromSbb) throws Exception {
    SmscPropertiesManagement smscPropertiesManagement = SmscPropertiesManagement.getInstance();
    if (!dbOperations_C2.c2_checkProcessingSmsSet(smsSet))
        return;
    // }
    doInjectSms(smsSet, callFromSbb);
}
Also used : SmscPropertiesManagement(org.mobicents.smsc.domain.SmscPropertiesManagement)

Aggregations

SmscPropertiesManagement (org.mobicents.smsc.domain.SmscPropertiesManagement)36 Test (org.testng.annotations.Test)27 SmsSet (org.mobicents.smsc.library.SmsSet)25 ArrayList (java.util.ArrayList)23 Sms (org.mobicents.smsc.library.Sms)23 MAPDialogSmsProxy (org.mobicents.smsc.slee.resources.persistence.MAPDialogSmsProxy)22 MAPServiceSmsProxy (org.mobicents.smsc.slee.resources.persistence.MAPServiceSmsProxy)22 SmsSetEvent (org.mobicents.smsc.slee.services.smpp.server.events.SmsSetEvent)22 UUID (java.util.UUID)20 SmsProxy (org.mobicents.smsc.slee.resources.persistence.SmsProxy)20 ISDNAddressStringImpl (org.mobicents.protocols.ss7.map.primitives.ISDNAddressStringImpl)19 ISDNAddressString (org.mobicents.protocols.ss7.map.api.primitives.ISDNAddressString)17 MAPApplicationContextVersion (org.mobicents.protocols.ss7.map.api.MAPApplicationContextVersion)16 IMSI (org.mobicents.protocols.ss7.map.api.primitives.IMSI)16 LocationInfoWithLMSI (org.mobicents.protocols.ss7.map.api.service.sms.LocationInfoWithLMSI)16 SendRoutingInfoForSMResponse (org.mobicents.protocols.ss7.map.api.service.sms.SendRoutingInfoForSMResponse)16 IMSIImpl (org.mobicents.protocols.ss7.map.primitives.IMSIImpl)16 LocationInfoWithLMSIImpl (org.mobicents.protocols.ss7.map.service.sms.LocationInfoWithLMSIImpl)16 SendRoutingInfoForSMResponseImpl (org.mobicents.protocols.ss7.map.service.sms.SendRoutingInfoForSMResponseImpl)16 MAPTestEvent (org.mobicents.smsc.slee.resources.persistence.MAPDialogSmsProxy.MAPTestEvent)15