Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Intermediate changes for some of ch-commons-util changes

  • Loading branch information...
commit dd6850835691bdfb7b531c38698af36ad647935b 1 parent 921f19f
@jjlauer jjlauer authored
View
34 src/main/java/com/cloudhopper/smpp/impl/DefaultSmppSession.java
@@ -14,15 +14,15 @@
package com.cloudhopper.smpp.impl;
-import com.cloudhopper.commons.util.windowing.ExpiredRequestListener;
-import com.cloudhopper.commons.util.windowing.MaxWindowSizeTimeoutException;
-import com.cloudhopper.commons.util.windowing.RequestAlreadyExistsException;
-import com.cloudhopper.commons.util.windowing.RequestCanceledException;
+import com.cloudhopper.commons.util.windowing.WindowListener;
+import com.cloudhopper.commons.util.windowing.OfferTimeoutException;
+import com.cloudhopper.commons.util.windowing.DuplicateKeyException;
+import com.cloudhopper.commons.util.windowing.RequestCancelledException;
import com.cloudhopper.commons.util.windowing.RequestFuture;
import com.cloudhopper.commons.util.windowing.ResponseFuture;
import com.cloudhopper.commons.util.windowing.ResponseTimeoutException;
import com.cloudhopper.commons.util.windowing.Window;
-import com.cloudhopper.commons.util.windowing.WindowEntry;
+import com.cloudhopper.commons.util.windowing.WindowFuture;
import com.cloudhopper.smpp.SmppBindType;
import com.cloudhopper.smpp.SmppConstants;
import com.cloudhopper.smpp.SmppServerSession;
@@ -65,7 +65,7 @@
*
* @author joelauer
*/
-public class DefaultSmppSession implements SmppServerSession, SmppSessionChannelListener, ExpiredRequestListener<Integer,PduRequest,PduResponse> {
+public class DefaultSmppSession implements SmppServerSession, SmppSessionChannelListener, WindowListener<Integer,PduRequest,PduResponse> {
private static final Logger logger = LoggerFactory.getLogger(DefaultSmppSession.class);
// are we an "esme" or "smsc" session type?
@@ -376,7 +376,7 @@ protected PduResponse sendRequestAndGetResponse(PduRequest requestPdu, long time
requestFuture.await();
} catch (ResponseTimeoutException e) {
throw new SmppTimeoutException(e.getMessage(), e);
- } catch (RequestCanceledException e) {
+ } catch (RequestCancelledException e) {
// the request future may have a cause set that we want to unwrap
Throwable cause = requestFuture.getCause();
if (cause != null && cause instanceof ClosedChannelException) {
@@ -430,9 +430,9 @@ protected PduResponse sendRequestAndGetResponse(PduRequest requestPdu, long time
RequestFuture<Integer,PduRequest,PduResponse> requestFuture = null;
try {
requestFuture = requestWindow.addRequest(pdu.getSequenceNumber(), pdu, timeoutInMillis, synchronous);
- } catch (RequestAlreadyExistsException e) {
+ } catch (DuplicateKeyException e) {
throw new UnrecoverablePduException(e.getMessage(), e);
- } catch (MaxWindowSizeTimeoutException e) {
+ } catch (OfferTimeoutException e) {
throw new SmppTimeoutException(e.getMessage(), e);
}
@@ -526,10 +526,10 @@ public void firePduReceived(Pdu pdu) {
// if this isn't null, we found a match to a request
int callerStatus = responseFuture.getCallerStatus();
// depending on the status of things, handle the response differently
- if (callerStatus == WindowEntry.CALLER_WAITING) {
+ if (callerStatus == WindowFuture.CALLER_WAITING) {
// do nothing -- calling thread going to process it
return;
- } else if (callerStatus == WindowEntry.CALLER_NO_WAIT) {
+ } else if (callerStatus == WindowFuture.CALLER_NOT_WAITING) {
// this was an "expected" response -- wrap it into an async response
this.sessionHandler.fireExpectedPduResponseReceived(new DefaultPduAsyncResponse(responseFuture));
return;
@@ -574,13 +574,13 @@ public void fireChannelClosed() {
// to do anything special -- however when a caller is waiting for a response
// to a request and we know the channel closed, we should check for those
// specific requests and make sure to cancel them
- if (this.requestWindow.getPendingSize() > 0) {
- logger.warn("Channel closed and requestWindow has [{}] pending requests, some may need cancelled immediately", this.requestWindow.getPendingSize());
- Map<Integer,WindowEntry<Integer,PduRequest,PduResponse>> requests = this.requestWindow.getPendingRequests();
+ if (this.requestWindow.getSize() > 0) {
+ logger.warn("Channel closed and requestWindow has [{}] pending requests, some may need cancelled immediately", this.requestWindow.getSize());
+ Map<Integer,WindowFuture<Integer,PduRequest,PduResponse>> requests = this.requestWindow.getPendingRequests();
for (Integer key : requests.keySet()) {
- WindowEntry<Integer,PduRequest,PduResponse> entry = requests.get(key);
+ WindowFuture<Integer,PduRequest,PduResponse> entry = requests.get(key);
// is the caller waiting?
- if (entry.getCallerStatus() == WindowEntry.CALLER_WAITING) {
+ if (entry.getCallerStatus() == WindowFuture.CALLER_WAITING) {
logger.warn("Caller waiting on request [{}], cancelling it with a channel closed exception", key);
try {
this.requestWindow.cancelRequest(key, new ClosedChannelException());
@@ -600,7 +600,7 @@ public void fireChannelClosed() {
}
@Override
- public void requestExpired(WindowEntry<Integer, PduRequest, PduResponse> entry) {
+ public void expired(WindowFuture<Integer, PduRequest, PduResponse> entry) {
this.sessionHandler.firePduRequestExpired(entry.getRequest());
}
View
6 src/test/java/com/cloudhopper/smpp/demo/ClientMain.java
@@ -82,7 +82,7 @@ static public void main(String[] args) throws Exception {
long startTime = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
- logger.info("Pending Requests in Window: {}", session0.getRequestWindow().getPendingSize());
+ logger.info("Pending Requests in Window: {}", session0.getRequestWindow().getSize());
String text160 = "\u20AC Lorem [ipsum] dolor sit amet, consectetur adipiscing elit. Proin feugiat, leo id commodo tincidunt, nibh diam ornare est, vitae accumsan risus lacus sed sem metus.";
byte[] textBytes = CharsetUtil.encode(text160, CharsetUtil.CHARSET_GSM);
@@ -108,8 +108,8 @@ static public void main(String[] args) throws Exception {
long stopTime = System.currentTimeMillis();
Thread.sleep(1000);
- logger.info("Final pending Requests in Window: {}", session0.getRequestWindow().getPendingSize());
- logger.info("With windowSize=" + session0.getRequestWindow().getWindowSize() + " took " + (stopTime-startTime) + " ms to process " + count + " requests");
+ logger.info("Final pending Requests in Window: {}", session0.getRequestWindow().getSize());
+ logger.info("With windowSize=" + session0.getRequestWindow().getMaxSize() + " took " + (stopTime-startTime) + " ms to process " + count + " requests");
System.out.println("Press any key to unbind and close sessions");
System.in.read();
View
4 src/test/java/com/cloudhopper/smpp/demo/RebindMain.java
@@ -74,8 +74,8 @@ public void run() {
session0.close();
- logger.info("Final pending Requests in Window: {}", session0.getRequestWindow().getPendingSize());
- logger.info("With windowSize=" + session0.getRequestWindow().getWindowSize());
+ logger.info("Final pending Requests in Window: {}", session0.getRequestWindow().getSize());
+ logger.info("With windowSize=" + session0.getRequestWindow().getMaxSize());
}
} catch (Throwable t) {
logger.error("{}", t);
View
1  src/test/java/com/cloudhopper/smpp/impl/DefaultSmppServerTest.java
@@ -549,6 +549,7 @@ public void serverNotEnoughWorkerThreadsCausesBindTimerToCloseChannel() throws E
try {
client0.bind(sessionConfig0);
+ Assert.fail();
} catch (SmppChannelException e) {
// the BindTimer should end up closing the connection since the
// worker thread were "starved"
View
12 src/test/java/com/cloudhopper/smpp/impl/DefaultSmppSessionTest.java
@@ -16,7 +16,7 @@
// third party imports
import com.cloudhopper.smpp.util.DaemonExecutors;
-import com.cloudhopper.commons.util.windowing.MaxWindowSizeTimeoutException;
+import com.cloudhopper.commons.util.windowing.OfferTimeoutException;
import com.cloudhopper.commons.util.windowing.RequestFuture;
import com.cloudhopper.commons.util.windowing.ResponseTimeoutException;
import com.cloudhopper.smpp.PduAsyncResponse;
@@ -340,7 +340,7 @@ public void windowSizeBlocksAsyncRequest() throws Exception {
RequestFuture future1 = session.sendRequestPdu(el1, 3000, true);
RequestFuture future2 = session.sendRequestPdu(el2, 3000, true);
- Assert.assertEquals(3, session.getRequestWindow().getPendingSize());
+ Assert.assertEquals(3, session.getRequestWindow().getSize());
try {
// window size of 3 is now filled up, this one should timeout
@@ -348,10 +348,10 @@ public void windowSizeBlocksAsyncRequest() throws Exception {
Assert.fail();
} catch (SmppTimeoutException e) {
Assert.assertNotNull(e.getCause());
- Assert.assertEquals(MaxWindowSizeTimeoutException.class, e.getCause().getClass());
+ Assert.assertEquals(OfferTimeoutException.class, e.getCause().getClass());
}
- Assert.assertEquals(3, session.getRequestWindow().getPendingSize());
+ Assert.assertEquals(3, session.getRequestWindow().getSize());
// now the smsc will send a response back to the second request
simulator0.sendPdu(el1Resp);
@@ -360,7 +360,7 @@ public void windowSizeBlocksAsyncRequest() throws Exception {
future1.await();
// there should be 1 slot free now in the window
- Assert.assertEquals(2, session.getRequestWindow().getPendingSize());
+ Assert.assertEquals(2, session.getRequestWindow().getSize());
// this request should now succeed
RequestFuture future3 = session.sendRequestPdu(el3, 3000, true);
@@ -376,7 +376,7 @@ public void windowSizeBlocksAsyncRequest() throws Exception {
future2.await();
future3.await();
- Assert.assertEquals(0, session.getRequestWindow().getPendingSize());
+ Assert.assertEquals(0, session.getRequestWindow().getSize());
} finally {
SmppSessionUtil.close(session);
}
Please sign in to comment.
Something went wrong with that request. Please try again.