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());
}
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);
}
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);
// }
}
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());
}
}
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);
}
Aggregations