📄 session.java
字号:
* @see #TYPE_MC
*/
public int getType() {
return type;
}
/**
* Opens connection and binds to SMSC using the bind method provided
* as bindReq parameter. Binds synchronously as no server pdu listener
* is provided. On details about bind see
* <a href="#bind(BindRequest,ServerPDUEventListener)">bind(BindRequest,ServerPDUEventListener)</a>.
* @see #bind(BindRequest,ServerPDUEventListener)
*/
final public BindResponse bind(BindRequest bindReq)
throws ValueNotSetException, TimeoutException, PDUException, IOException, WrongSessionStateException {
checkState(bindReq);
return bind(bindReq, null);
}
/**
* Opens connection and binds to SMSC using the bind method provided
* as <code>bindReq</code> parameter. For transmittong PDUs creates instance
* of <code>Transmitter</code> class, for receiving PDUs from SMSC
* creates instance of <code>Receiver</code> class.<br>
* Receiver starts an extra thread
* which receives PDUs from connection and puts them into a queue
* (if synchronous) or processes them using <code>pduListener</code>.
* If the bind to SMSC isn't successfull, the thread is stopped and
* the connection is closed.<br>
* If the variable <code>pduListener</code> is not <code>null</code>,
* the session is asynchronous, otherwise the session is synchronous.
* Note that the <code>bind</code> method is <emp>always</emp> synchronous,
* regardless of the value of the <code>pduListener</code> variable.
* <p>
* See "SMPP Protocol Specification 3.4, 4.1 BIND Operation."
*
* @param bindReq the bind request
*
* @exception IOException exception during communication
* @exception PDUException incorrect format of PDU
* @exception TimeoutException rest of data not received for too long time
* @exception ValueNotSetException optional param not set but requested
* @see BindRequest
* @see BindResponse
* @see BindTransmitter
* @see BindReceiver
* @see BindTransciever
*/
final public BindResponse bind(BindRequest bindReq, ServerPDUEventListener pduListener)
throws ValueNotSetException, TimeoutException, PDUException, IOException, WrongSessionStateException {
checkState(bindReq);
if (bound) {
// exception? yes, checked above
return null;
} else {
open();
transmitter = new Transmitter(connection);
receiver = new Receiver(transmitter, connection);
BindResponse bindResp = (BindResponse) send(bindReq, false);
bound = ((bindResp != null) && (bindResp.getCommandStatus() == Data.ESME_ROK));
if (!bound) {
//receiver.stop();
close();
} else {
receiver.start();
if (bindReq.isTransmitter()) {
if (bindReq.isReceiver()) {
setState(STATE_TRANSCEIVER);
} else {
setState(STATE_TRANSMITTER);
}
} else {
setState(STATE_RECEIVER);
}
setServerPDUEventListener(pduListener);
}
return bindResp;
}
}
/**
* Sends an outbind PDU over the connection. For sending outbind
* PDU the session must not be bound to smsc (!), this is the
* logic of outbind operation. Don't mess it up with receiving
* outbind PDUs from SMSC! Also this operation is only allowed when your
* session acts as SMSC (MC) session. ESMEs can't send outbinds.
* <p>
* See SMPP Protocol Specification 3.4, 4.1.7 OUTBIND Operation.
*
* @param request The outbind PDU.
*
* @exception IOException exception during communication
* @exception PDUException incorrect format of PDU
* @exception TimeoutException rest of data not received for too long time
* @exception ValueNotSetException optional param not set but requested
* (this exception doesn't apply for outbind)
* @see Outbind
* @see OutbindReceiver
*/
final public void outbind(Outbind request)
throws ValueNotSetException, TimeoutException, PDUException, IOException, WrongSessionStateException {
checkState(request);
send(request);
}
/**
* Stops <code>receiver</code> (if applicable), unbinds from SMSC
* by sending <code>Unbind</code> PDU, waits for <code>UnbindResp</code>
* and then closes the connection.<br>
* Note that the <code>unbind</code> method is <emp>always</emp> synchronous
* or asynchronous depending on the value of the <code>asynchronous</code>
* variable.
* <p>
* See "SMPP Protocol Specification 3.4, 4.2 UNBIND Operation."
*
* @return response PDU if successfully unbound, i.e. if still not bound
* after call to the method; null if unbind was not successful, i.e.
* no response has been received for unbind PDU
*
* @exception IOException exception during communication
* @exception PDUException incorrect format of PDU
* @exception TimeoutException rest of data not received for too long time
* @exception ValueNotSetException optional param not set but requested
* (this exception doesn't apply for unbind)
* @see Unbind
* @see UnbindResp
*/
final public UnbindResp unbind()
throws ValueNotSetException, TimeoutException, PDUException, IOException, WrongSessionStateException {
UnbindResp unbindResp = null;
if (bound) {
Unbind unbindReq = new Unbind();
checkState(unbindReq);
ServerPDUEventListener origListener = null;
if (asynchronous) {
// we must assign the number now as we'll start waiting for
// the response before we actually send the request
unbindReq.assignSequenceNumber();
origListener = getServerPDUEventListener();
UnbindServerPDUEventListener unbindListener =
new UnbindServerPDUEventListener(this, origListener, unbindReq);
setServerPDUEventListener(unbindListener);
synchronized (unbindListener) {
send(unbindReq);
try {
unbindListener.wait(receiver.getReceiveTimeout());
unbindResp = unbindListener.getUnbindResp();
} catch (InterruptedException e) {
// unbind reponse wasn't received in time
}
}
} else {
debug.write(DSESS, "going to unbound sync session");
unbindResp = (UnbindResp) send(unbindReq);
}
bound = (unbindResp == null);
if (!bound) {
setState(STATE_OPENED);
receiver.stop();
receiver = null;
transmitter = null;
close();
} else {
// restore the listener - unbind unsuccessfull
debug.write("Unbind unsuccessfull, restoring listener");
setServerPDUEventListener(origListener);
}
}
return unbindResp;
}
/**
* Sends GenericNack PDU provided as parameter.
* <p>
* See "SMPP Protocol Specification 3.4, 4.3 GENERIC_NACK Operation."
*
* @param response The generic nack PDU.
*
* @exception IOException exception during communication
* @exception TimeoutException rest of data not received for too long time
* @exception ValueNotSetException optional param not set but requested
* (this exception doesn't apply for genericNack)
* @see GenericNack
*/
final public void genericNack(GenericNack response)
throws ValueNotSetException, TimeoutException, IOException, WrongSessionStateException {
checkState(response);
try {
respond(response);
} catch (WrongSessionStateException e) {
debug.write("strange, generic nack thrown " + e);
debug.write("this shouldn't happend");
event.write(e, "Unexpected exeption caught");
}
}
/**
* Creates and sends <code>GenericNack</code> PDU with command status
* and sequence number provided as parameters.
* <p>
* See "SMPP Protocol Specification 3.4, 4.3 GENERIC_NACK Operation."
*
* @param commandStatus the code of error to be reported
* @param sequenceNumber the sequence number of the PDU the GenericNack
* is related to
* @exception IOException exception during communication
* @exception TimeoutException rest of data not received for too long time
* @exception ValueNotSetException optional param not set but requested
* (this exception doesn't apply for genericNack)
* @see GenericNack
*/
final public void genericNack(int commandStatus, int sequenceNumber)
throws ValueNotSetException, TimeoutException, IOException, WrongSessionStateException {
GenericNack gnack = new GenericNack(commandStatus, sequenceNumber);
checkState(gnack);
genericNack(gnack);
}
/**
* Submits provided <code>SubmitSM</code> PDU to SMSC and returns response
* to the submission.
* <p>
* See "SMPP Protocol Specification 3.4, 4.4 SUBMIT_SM Operation."
*
* @param request the pdu to be submitted
* @return correspondent response pdu
*
* @exception IOException exception during communication
* @exception PDUException incorrect format of PDU
* @exception TimeoutException rest of data not received for too long time
* @exception ValueNotSetException optional param not set but requested
* @see SubmitSM
* @see SubmitSMResp
*/
final public SubmitSMResp submit(SubmitSM request)
throws ValueNotSetException, TimeoutException, PDUException, IOException, WrongSessionStateException {
checkState(request);
return (SubmitSMResp) send(request);
}
/**
* Submits provided <code>SubmitMultiSM</code> PDU to SMSC and returns
* response to the submission.
* <p>
* See "SMPP Protocol Specification 3.4, 4.5 SUBMIT_MULTI Operation."
*
* @param request the submit multi pdu to be submitted
* @return correspondent response pdu
*
* @exception IOException exception during communication
* @exception PDUException incorrect format of PDU
* @exception TimeoutException rest of data not received for too long time
* @exception ValueNotSetException optional param not set but requested
* @see SubmitMultiSM
* @see SubmitMultiSMResp
*/
final public SubmitMultiSMResp submitMulti(SubmitMultiSM request)
throws ValueNotSetException, TimeoutException, PDUException, IOException, WrongSessionStateException {
checkState(request);
return (SubmitMultiSMResp) send(request);
}
/**
* Submits provided <code>DeliverSM</code> PDU to SMSC and returns
* response to the submission.
* <p>
* See "SMPP Protocol Specification 3.4, 4.6 DELIVER_SM Operation."
*
* @param request the deliver pdu to be submitted
* @return correspondent response pdu
*
* @exception IOException exception during communication
* @exception PDUException incorrect format of PDU
* @exception TimeoutException rest of data not received for too long time
* @exception ValueNotSetException optional param not set but requested
* @see DeliverSM
* @see DeliverSMResp
*/
final public DeliverSMResp deliver(DeliverSM request)
throws ValueNotSetException, TimeoutException, PDUException, IOException, WrongSessionStateException {
checkState(request);
return (DeliverSMResp) send(request);
}
/**
* Submits provided <code>DataSM</code> PDU to SMSC and returns
* response to the submission.
* <p>
* See "SMPP Protocol Specification 3.4, 4.7 DATA_SM Operation."
*
* @param request the data pdu to be submitted
* @return correspondent response pdu
*
* @exception IOException exception during communication
* @exception PDUException incorrect format of PDU
* @exception TimeoutException rest of data not received for too long time
* @exception ValueNotSetException optional param not set but requested
* @see DataSM
* @see DataSMResp
*/
final public DataSMResp data(DataSM request)
throws ValueNotSetException, TimeoutException, PDUException, IOException, WrongSessionStateException {
checkState(request);
return (DataSMResp) send(request);
}
/**
* Queries status of previous submission by sending the
* <code>QuerySM</code> PDU to SMSC; returns the query response.
* <p>
* See "SMPP Protocol Specification 3.4, 4.8 QUERY_SM Operation."
*
* @param request the status query pdu to be sent
* @return correspondent response pdu
*
* @exception IOException exception during communication
* @exception PDUException incorrect format of PDU
* @exception TimeoutException rest of data not received for too long time
* @exception ValueNotSetException optional param not set but requested
* @see QuerySM
* @see QuerySMResp
*/
final public QuerySMResp query(QuerySM request)
throws ValueNotSetException, TimeoutException, PDUException, IOException, WrongSessionStateException {
checkState(request);
return (QuerySMResp) send(request);
}
/**
* Cancels previously submitted message by sending <code>CancelSM</code> PDU
* to SMSC; returns response to the cancel PDU.
* <p>
* See "SMPP Protocol Specification 3.4, 4.9 CANCEL_SM Operation."
*
* @param request the cancel pdu to be sent
* @return correspondent response pdu
*
* @exception IOException exception during communication
* @exception PDUException incorrect format of PDU
* @exception TimeoutException rest of data not received for too long time
* @exception ValueNotSetException optional param not set but requested
* @see CancelSM
* @see CancelSMResp
*/
final public CancelSMResp cancel(CancelSM request)
throws ValueNotSetException, TimeoutException, PDUException, IOException, WrongSessionStateException {
checkState(request);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -