use of org.smpp.pdu.GenericNack in project opensmpp by OpenSmpp.
the class Receiver method receiveAsync.
/**
* This method receives a PDU from connection and stores it into
* <code>pduQueue</code>. It's called from the <code>ReceiverBase</code>'s
* p<code>process</code> method which is called in loop from
* <code>ProcessingThread</code>'s <code>run</code> method.
* <p>
* If an exception occurs during receiving, depending on type
* of the exception this method either just reports the exception to
* debug & event objects or stops processing to indicate
* that it isn't able to process the exception. The function
* <code>setTermException</code> is then called with the caught exception.
*
* @see ReceiverBase#run()
*/
protected void receiveAsync() {
PDU pdu = null;
try {
debug.write(DRXTXD2, "Receiver.receiveAsync() going to receive pdu.");
pdu = receivePDUFromConnection(connection, unprocessed);
// we must catch every exception as this is thread running
// on the background and we don't want the thread to be terminated
} catch (InvalidPDUException e) {
// thrown when enough data were received but further parsing
// required more than indicated by CommandLength, i.e. pdu is
// corrupted or further parsing didn't find terminating zero
// of a c-string i.e. pdu is corrupted
// must send generic nack anyway
event.write(e, "Receiver.receiveAsync(): received PDU is invalid.");
PDU expdu = e.getPDU();
int seqNr = expdu == null ? 0 : expdu.getSequenceNumber();
if (automaticNack) {
sendGenericNack(Data.ESME_RINVMSGLEN, seqNr);
} else {
pdu = new GenericNack(Data.ESME_RINVMSGLEN, seqNr);
}
} catch (UnknownCommandIdException e) {
// if received unknown pdu, we must send generic nack
event.write(e, "Receiver.receiveAsync(): Unknown command id.");
if (automaticNack) {
sendGenericNack(Data.ESME_RINVCMDID, e.getSequenceNumber());
} else {
pdu = new GenericNack(Data.ESME_RINVCMDID, e.getSequenceNumber());
}
} catch (TimeoutException e) {
// too long had unprocessed data
debug.write(DRXTX, "Receiver.receiveAsync() too long had an uncomplete message.");
} catch (PDUException e) {
// something wrong with the PDU
event.write(e, "Receiver.receiveAsync()");
PDU expdu = e.getPDU();
int seqNr = expdu == null ? 0 : expdu.getSequenceNumber();
if (automaticNack) {
sendGenericNack(e.getErrorCode(), seqNr);
} else {
pdu = new GenericNack(e.getErrorCode(), seqNr);
}
} catch (Exception e) {
// don't know what happen, let's end the show
event.write(e, "Receiver.receiveAsync()");
stopProcessing(e);
}
if (pdu != null) {
debug.write(DRXTX, "Receiver.receiveAsync(): PDU received, processing " + pdu.debugString());
if (asynchronous) {
process(pdu);
} else {
enqueue(pdu);
}
}
}
use of org.smpp.pdu.GenericNack in project opensmpp by OpenSmpp.
the class Receiver method sendGenericNack.
/**
* Sends <code>GenericNack</code> PDU via transmitter if there is one.
* The <code>GenericNack</code> is sent in case that the message is
* corrupted or has unknown command id. If the sending of
* <code>GenericNack</code> fails, this method calls
* <code>stopProcessing</code> and thus stops the receiving
* thread.
*
* @param commandStatus the error code
* @param sequenceNumber the sequence number of received wrong PDU
* @see GenericNack
* @see Transmitter
*/
private void sendGenericNack(int commandStatus, int sequenceNumber) {
if (transmitter != null) {
try {
GenericNack gnack = new GenericNack(commandStatus, sequenceNumber);
transmitter.send(gnack);
} catch (IOException gnacke) {
event.write(gnacke, "Receiver.run(): IOException sending generic_nack.");
} catch (Exception gnacke) {
event.write(gnacke, "Receiver.run(): an exception sending generic_nack.");
stopProcessing(gnacke);
}
}
}
Aggregations