Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

Split DefaultSmppSession into DefaultSmppClientSession and DefaultSmppServerSession #111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/cloudhopper/smpp/SmppClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public interface SmppClient {
* @throws InterruptedException Thrown if the calling thread is interrupted
* while we are attempting the bind.
*/
public SmppSession bind(SmppSessionConfiguration config, SmppSessionHandler sessionHandler) throws SmppTimeoutException, SmppChannelException, SmppBindException, UnrecoverablePduException, InterruptedException;
public SmppClientSession bind(SmppSessionConfiguration config, SmppSessionHandler sessionHandler) throws SmppTimeoutException, SmppChannelException, SmppBindException, UnrecoverablePduException, InterruptedException;

/**
* Destroy a client by ensuring that all session sockets are closed and all
Expand Down
82 changes: 82 additions & 0 deletions src/main/java/com/cloudhopper/smpp/SmppClientSession.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright 2015 Cloudhopper by Twitter.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.cloudhopper.smpp;

/*
* #%L
* ch-smpp
* %%
* Copyright (C) 2009 - 2015 Cloudhopper by Twitter
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/

import com.cloudhopper.smpp.pdu.BaseBind;
import com.cloudhopper.smpp.pdu.BaseBindResp;
import com.cloudhopper.smpp.pdu.SubmitSm;
import com.cloudhopper.smpp.pdu.SubmitSmResp;
import com.cloudhopper.smpp.type.RecoverablePduException;
import com.cloudhopper.smpp.type.SmppBindException;
import com.cloudhopper.smpp.type.SmppChannelException;
import com.cloudhopper.smpp.type.SmppTimeoutException;
import com.cloudhopper.smpp.type.UnrecoverablePduException;

/**
*
* @author pgoergler
*/
public interface SmppClientSession extends SmppSession {

public BaseBindResp bind(BaseBind request, long timeoutInMillis) throws RecoverablePduException, UnrecoverablePduException, SmppBindException, SmppTimeoutException, SmppChannelException, InterruptedException;

/**
* Synchronously sends a "submit" request to the remote endpoint and
* waits for up to a specified number of milliseconds for a response. The
* timeout value includes both waiting for a "window" slot, the time it
* takes to transmit the actual bytes on the socket, and for the remote
* endpoint to send a response back.
* @param request The request to send to the remote endpoint
* @param timeoutMillis The number of milliseconds to wait until a valid
* response is received.
* @return A valid response to the request
* @throws RecoverablePduException Thrown when a recoverable PDU error occurs.
* A recoverable PDU error includes the partially decoded PDU in order
* to generate a negative acknowledgement (NACK) response.
* @throws UnrecoverablePduException Thrown when an unrecoverable PDU error
* occurs. This indicates a seriours error occurred and usually indicates
* the session should be immediately terminated.
* @throws SmppTimeoutException A timeout occurred while waiting for a response
* from the remote endpoint. A timeout can either occur with an unresponse
* remote endpoint or the bytes were not written in time.
* @throws SmppChannelException Thrown when the underlying socket/channel was
* unable to write the request.
* @throws InterruptedException The calling thread was interrupted while waiting
* to acquire a lock or write/read the bytes from the socket/channel.
*/
public SubmitSmResp submit(SubmitSm request, long timeoutMillis) throws RecoverablePduException, UnrecoverablePduException, SmppTimeoutException, SmppChannelException, InterruptedException;

}
64 changes: 35 additions & 29 deletions src/main/java/com/cloudhopper/smpp/SmppSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,25 @@

import com.cloudhopper.commons.util.windowing.Window;
import com.cloudhopper.commons.util.windowing.WindowFuture;
import com.cloudhopper.smpp.impl.SmppSessionChannelListener;
import com.cloudhopper.smpp.type.SmppChannelException;
import com.cloudhopper.smpp.type.SmppTimeoutException;
import com.cloudhopper.smpp.pdu.EnquireLink;
import com.cloudhopper.smpp.pdu.EnquireLinkResp;
import com.cloudhopper.smpp.pdu.PduRequest;
import com.cloudhopper.smpp.pdu.PduResponse;
import com.cloudhopper.smpp.pdu.SubmitSm;
import com.cloudhopper.smpp.pdu.SubmitSmResp;
import com.cloudhopper.smpp.transcoder.PduTranscoder;
import com.cloudhopper.smpp.type.RecoverablePduException;
import com.cloudhopper.smpp.type.UnrecoverablePduException;
import com.cloudhopper.smpp.util.SequenceNumber;

/**
* Defines a common interface for either a Client (ESME) or Server (SMSC) SMPP
* session.
*
* @author joelauer (twitter: @jjlauer or <a href="http://twitter.com/jjlauer" target=window>http://twitter.com/jjlauer</a>)
*/
public interface SmppSession {
public interface SmppSession extends SmppSessionChannelListener {

/**
* The type of SMPP session. Will be either Server (SMSC) or Client (ESME).
Expand Down Expand Up @@ -104,6 +105,12 @@ public enum Type {
* @return The current state of the session by name such as "CLOSED"
*/
public String getStateName();

/**
* Return the sequence number object of the session
* @return
*/
public SequenceNumber getSequenceNumber();

/**
* Gets the interface version currently in use between local and remote
Expand All @@ -122,6 +129,11 @@ public enum Type {
*/
public boolean areOptionalParametersSupported();

/**
* Return the pdu Transcoder used by the session
* @return PduTranscoder
*/
public PduTranscoder getTranscoder();

/**
* Checks if the session is currently in the "OPEN" state. The "OPEN" state
Expand Down Expand Up @@ -251,32 +263,6 @@ public enum Type {
*/
public EnquireLinkResp enquireLink(EnquireLink request, long timeoutMillis) throws RecoverablePduException, UnrecoverablePduException, SmppTimeoutException, SmppChannelException, InterruptedException;

/**
* Synchronously sends a "submit" request to the remote endpoint and
* waits for up to a specified number of milliseconds for a response. The
* timeout value includes both waiting for a "window" slot, the time it
* takes to transmit the actual bytes on the socket, and for the remote
* endpoint to send a response back.
* @param request The request to send to the remote endpoint
* @param timeoutMillis The number of milliseconds to wait until a valid
* response is received.
* @return A valid response to the request
* @throws RecoverablePduException Thrown when a recoverable PDU error occurs.
* A recoverable PDU error includes the partially decoded PDU in order
* to generate a negative acknowledgement (NACK) response.
* @throws UnrecoverablePduException Thrown when an unrecoverable PDU error
* occurs. This indicates a seriours error occurred and usually indicates
* the session should be immediately terminated.
* @throws SmppTimeoutException A timeout occurred while waiting for a response
* from the remote endpoint. A timeout can either occur with an unresponse
* remote endpoint or the bytes were not written in time.
* @throws SmppChannelException Thrown when the underlying socket/channel was
* unable to write the request.
* @throws InterruptedException The calling thread was interrupted while waiting
* to acquire a lock or write/read the bytes from the socket/channel.
*/
public SubmitSmResp submit(SubmitSm request, long timeoutMillis) throws RecoverablePduException, UnrecoverablePduException, SmppTimeoutException, SmppChannelException, InterruptedException;

/**
* Main underlying method for sending a request PDU to the remote endpoint.
* If no sequence number was assigned to the PDU, this method will assign one.
Expand Down Expand Up @@ -337,4 +323,24 @@ public enum Type {
* to acquire a lock or write/read the bytes from the socket/channel.
*/
public void sendResponsePdu(PduResponse response) throws RecoverablePduException, UnrecoverablePduException, SmppChannelException, InterruptedException;

/**
* Sends a PDU request and gets a PDU response that matches its sequence #.
* NOTE: This PDU response may not be the actual response the caller was
* expecting, it needs to verify it afterwards.
* @param requestPdu
* @param timeoutInMillis
* @return
* @throws com.cloudhopper.smpp.type.RecoverablePduException
* @throws com.cloudhopper.smpp.type.UnrecoverablePduException
* @throws com.cloudhopper.smpp.type.SmppTimeoutException
* @throws com.cloudhopper.smpp.type.SmppChannelException
* @throws java.lang.InterruptedException
*/
public PduResponse sendRequestAndGetResponse(PduRequest requestPdu, long timeoutInMillis) throws RecoverablePduException, UnrecoverablePduException, SmppTimeoutException, SmppChannelException, InterruptedException;

public void registerMBean(String objectName);

public void unregisterMBean(String objectName);

}
Loading