⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 connection.java

📁 开放源码的smpp协议开发包
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    /**     * Set the default alphabet of the SMSC this <code>Connection</code> is     * communicating with. Each SMSC has its own default alphabet it uses. When     * messages arrive and announce themselves with a data coding value of zero,     * that means the message is encoded in the SMSC's default alphabet. The     * smppapi assumes the GSM default alphabet as it's default alphabet. By     * setting the default alphabet on the <code>Connection</code> all packets     * returned by {@link #newInstance(int)}will use the Connection's default     * alphabet plus any packets read from the wire with a data coding value of     * zero will have their default alphabet initialised appropriately.     *      * @param alphabet     *            the alphabet to use as the default for this connection (may be     *            <code>null</code> in which case the API falls back to using     *            its own internal default).     */    public void setDefaultAlphabet(AlphabetEncoding alphabet) {        this.defaultAlphabet = alphabet;    }    /**     * Get the current alphabet this <code>Connection</code> is using as its     * default.     *      * @return the default alphabet for this <code>Connection</code>.     */    public AlphabetEncoding getDefaultAlphabet() {        return (defaultAlphabet);    }    /**     * Set the state of this ESME.     *      * @see ie.omk.smpp.Connection#getState     */    private synchronized void setState(int state) {        logger.info("Setting state " + state);        this.state = state;    }    /**     * Set the SMPP version this connection will use. Setting the version is     * only a valid operation before the connection is bound. Any attempt to set     * the version after binding to the SMSC will result in an exception being     * thrown.     *      * @param version     *            the SMPP version to use.     * @throws ie.omk.smpp.version.VersionException     *             if an attempt is made to set the version of the connection     *             after binding to the SMSC.     * @see ie.omk.smpp.version.SMPPVersion     */    public void setVersion(SMPPVersion version) throws VersionException {        if (getState() != UNBOUND)            throw new VersionException("Cannot set SMPP version after binding");        if (version == null)            this.interfaceVersion = SMPPVersion.getDefaultVersion();        else            this.interfaceVersion = version;    }    /**     * Get the SMPP version in use by this connection. The version in use by the     * connection <b>may </b> be different to that specified before the bind     * operation as binding to the SMSC may result in an alternative SMPP     * version being negotiated. For instance, if the client sends a bind packet     * to the SMSC specifying that it supports SMPP version 3.4 but the SMSC     * returns a bind_resp stating it supports version 3.3, the Connection     * automatically sets it's internal version to use down to 3.3.     */    public SMPPVersion getVersion() {        return (interfaceVersion);    }    /**     * Get the current state of the ESME. One of UNBOUND, BINDING, BOUND or     * UNBINDING.     */    public synchronized int getState() {        return (this.state);    }    /**     * Method to open the link to the SMSC. This method will connect the     * underlying SmscLink object if necessary and reset the sequence numbering     * scheme to the beginning.     *      * @throws java.io.IOException     *             if an i/o error occurs while opening the connection.     */    protected void openLink() throws java.io.IOException {        if (!this.link.isConnected()) {            logger.info("Opening network link.");            this.link.open();            if (this.seqNumScheme != null)                this.seqNumScheme.reset();        } else {            logger.debug("openLink called, link already open");        }    }    /**     * Close the underlying network link to the SMSC. This method calls the     * underlying link's <code>close</code> method to actually shutdown the     * network connection to the SMSC.     *      * @throws ie.omk.smpp.IllegalStateException     *             if an attempt is made to close the connection while bound to     *             the SMSC.     * @throws java.io.IOException     *             if an I/O exception occurs while trying to close the link.     * @see ie.omk.smpp.net.SmscLink#close     */    public void closeLink() throws IOException {        if (getState() != UNBOUND)            throw new IllegalStateException(                    "Cannot close the link while bound to the SMSC");        if (this.link.isConnected()) {            logger.info("Shutting down the network link");            this.link.close();        } else {            logger.debug("closeLink called on an unopen connection");        }    }    /**     * Get the interface version.     *      * @see #setInterfaceVersion(SMPPVersion)     */    public SMPPVersion getInterfaceVersion() {        return (this.interfaceVersion);    }    /**     * Set the desired interface version for this connection. The default     * version is 3.4. The bind operation may negotiate an eariler version of     * the protocol if the SC does not understand the version sent by the ESME.     * This API will not support any version eariler than SMPP v3.3. The     * interface version is encoded as follows: <table border="1"     * cellspacing="1" cellpadding="1">     * <tr>     * <th>SMPP version</th>     * <th>Version value</th>     * </tr>     * <tr>     * <td>v3.4</td>     * <td>0x34</td>     * </tr>     * <tr>     * <td>v3.3</td>     * <td>0x33</td>     * </tr>     * <tr>     * <td colspan="2" align="center"><i>All other values reserved. </i></td>     * </tr>     * </table>     */    public void setInterfaceVersion(SMPPVersion interfaceVersion) {        logger.info("setInterfaceVersion " + interfaceVersion);        this.interfaceVersion = interfaceVersion;        this.supportOptionalParams = interfaceVersion.isSupportOptionalParams();    }    /**     * Set the behaviour of automatically acking ENQUIRE_LINK's from the SMSC     * (only valid in <b>asynchronous </b> mode). By default, the listener     * thread will automatically ack an enquire_link message from the Smsc so as     * not to lose the connection. This can be turned off with this method.     *      * @param b     *            true to activate automatic acknowledgment, false to disable     */    public void autoAckLink(boolean b) {        this.ackQryLinks = b;    }    /**     * Set the behaviour of automatically acking Deliver_Sm's from the Smsc     * (only valid in <b>asynchronous </b> mode). By default the listener thread     * will <b>not </b> acknowledge a message. Applications which are using the     * synchronous mode of communication will always have to handle enquire link     * requests themselves.     *      * @param b     *            true to activate this function, false to deactivate.     */    public void autoAckMessages(boolean b) {        this.ackDeliverSm = b;    }    /**     * Check is this connection automatically acking Enquire link requests in     * asynchronous mode.     */    public boolean isAckingLinks() {        return (ackQryLinks);    }    /**     * Check is this connection automatically acking delivered messages     */    public boolean isAckingMessages() {        return (ackDeliverSm);    }    /**     * Acknowledge a DeliverSM command received from the Smsc.     *      * @param rq     *            The deliver_sm request to respond to.     * @throws java.io.IOException     *             If an I/O error occurs writing the response packet to the     *             network connection.     */    public void ackDeliverSm(DeliverSM rq) throws java.io.IOException {        DeliverSMResp rsp = new DeliverSMResp(rq);        sendResponse(rsp);        logger.info("deliver_sm_resp sent.");    }    /**     * Send an smpp request to the SMSC. No fields in the SMPPRequest packet     * will be altered except possibly the sequence number. The sequence number     * will be assigned the next number as defined by this Connection's sequence     * numbering scheme. If the sequence numbering scheme class is     * <code>null</code> for this Connection, no number will be assigned. By     * default, the {@link ie.omk.smpp.util.DefaultSequenceScheme}class is used     * to assign sequence numbers to packets. <br />     * <b>IMPORTANT </b>: You <i>must </i> use the <code>bind</code> and     * <code>unbind</code> methods to carry out those operations. Attempting     * to send an bind or unbind packet using this method will result in an     * <code>UnsupportedOperationException</code> being thrown.     *      * @param r     *            The request packet to send to the SMSC     * @return The response packet returned by the SMSC, or null if asynchronous     *         communication is being used.     * @throws java.lang.NullPointerException     *             if <code>r</code> is null.     * @throws java.net.SocketTimeoutException     *             If a socket timeout occurs while waiting for a response     *             packet. (Only in synchronized mode).     * @throws java.io.IOException     *             If an I/O error occurs while writing the request packet to     *             the network connection.     * @throws ie.omk.smpp.UnsupportedOperationException     *             If this connection type does not support operation     *             <code>r</code>. For example, a receiver link does not     *             support the submit_sm operation.     * @throws ie.omk.smpp.AlreadyBoundException     *             If the request type is a bind packet and this connection is     *             already bound.     * @throws ie.omk.smpp.message.SMPPProtocolException     *             If synchronous communications is in use and the incoming     *             response packet violates the SMPP specification, this     *             exception will be thrown.     * @see #setSeqNumScheme     */    public SMPPResponse sendRequest(SMPPRequest r)            throws java.net.SocketTimeoutException, java.io.IOException,            AlreadyBoundException, VersionException, SMPPProtocolException,            UnsupportedOperationException {        SMPPResponse resp = null;        int id = r.getCommandId();        if (this.state != BOUND)            throw new NotBoundException("Must be bound to the SMSC before "                    + "sending packets");        // Force applications to use bind and unbind        if (id == SMPPPacket.BIND_RECEIVER || id == SMPPPacket.BIND_TRANSCEIVER                || id == SMPPPacket.BIND_TRANSMITTER || id == SMPPPacket.UNBIND) {            throw new UnsupportedOperationException(                    "You must use the bind and unbind methods to send those requests");        }        // Very few request types allowed by a receiver connection.        if (connectionType == RECEIVER) {            if (id != SMPPPacket.ENQUIRE_LINK)                throw new UnsupportedOperationException(                        "Operation not permitted over receiver connection");        }        return (sendRequestInternal(r));    }    /**     * Send a request to the SMSC. XXX complete javadoc for this method.     *      * @throws ie.omk.smpp.version.VersionException     *             if the version in use does not support the request being     *             sent.     */    protected SMPPResponse sendRequestInternal(SMPPRequest r)            throws java.net.SocketTimeoutException, java.io.IOException,            AlreadyBoundException, VersionException, SMPPProtocolException {        SMPPResponse resp = null;        int id = r.getCommandId();        if (link == null)            throw new IOException("No SMSC connection.");        // Check the command is supported by the interface version..        if (!this.interfaceVersion.isSupported(id)) {            throw new VersionException("Command ID 0x"                    + Integer.toHexString(id) + " is not supported by SMPP "                    + this.interfaceVersion);        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -