@Override public Window<Integer,PduRequest,PduResponse> getRequestWindow() { return getSendWindow(); }
@Override public SmppSession bind(SmppSessionConfiguration config, SmppSessionHandler sessionHandler) throws SmppTimeoutException, SmppChannelException, SmppBindException, UnrecoverablePduException, InterruptedException { DefaultSmppSession session = null; try { // connect to the remote system and create the session session = doOpen(config, sessionHandler); // try to bind to the remote system (may throw an exception) doBind(session, config, sessionHandler); } finally { // close the session if we weren't able to bind correctly if (session != null && !session.isBound()) { // make sure that the resources are always cleaned up try { session.close(); } catch (Exception e) { } } } return session; }
@Override public boolean isClosed() { if (this.defaultSmppSession != null) { return this.defaultSmppSession.isClosed(); } return true; }
@Override public SubmitSmResp submit(SubmitSm request, long timeoutInMillis) throws RecoverablePduException, UnrecoverablePduException, SmppTimeoutException, SmppChannelException, InterruptedException { assertValidRequest(request); PduResponse response = sendRequestAndGetResponse(request, timeoutInMillis); SmppSessionUtil.assertExpectedResponse(request, response); return (SubmitSmResp)response; }
@Override public void close(long arg0) { if (this.defaultSmppSession != null) { try { defaultSmppSession.close(arg0); } catch (Exception e) { logger.error(String.format("Failed to close smpp session for %s.", defaultSmppSession.getConfiguration().getName())); } } }
@Override public void serverReady(SmppSessionHandler sessionHandler) { // properly setup the session handler (to handle notifications) this.sessionHandler = sessionHandler; // send the prepared bind response try { this.sendResponsePdu(this.preparedBindResponse); } catch (Exception e) { logger.error("{}", e); } // flag the channel is ready to read this.channel.setReadable(true).awaitUninterruptibly(); this.setBound(); }
protected void stopSmppClientSession(Esme esme) { DefaultSmppSession smppSession = esme.getSmppSession(); if (smppSession != null) { if (smppSession.isBound()) { try { smppSession.unbind(5000); } catch (Exception e) { logger.error(String.format("Failed to unbind smpp client session for %s.", smppSession.getConfiguration().getName())); } } try { smppSession.close(); } catch (Exception e) { logger.error(String.format("Failed to close smpp client session for %s.", smppSession.getConfiguration().getName())); } // firing of onPduRequestTimeout() for sent messages for which we do not have responses Window<Integer, PduRequest, PduResponse> wind = smppSession.getSendWindow(); Map<Integer, WindowFuture<Integer, PduRequest, PduResponse>> futures = wind.createSortedSnapshot(); for (WindowFuture<Integer, PduRequest, PduResponse> future : futures.values()) { this.logger.warn("Firing of onPduRequestTimeout from SmppClientManagement.stopSmppClientSession() - 1: " + future.getRequest().toString()); smppSession.expired(future); } smppSession.destroy(); } }
@Override public void fireExceptionThrown(Throwable t) { if (t instanceof UnrecoverablePduException) { this.sessionHandler.fireUnrecoverablePduException((UnrecoverablePduException)t); } else if (t instanceof RecoverablePduException) { this.sessionHandler.fireRecoverablePduException((RecoverablePduException)t); } else { // during testing under high load -- java.io.IOException: Connection reset by peer // let's check to see if this session was requested to be closed if (isUnbinding() || isClosed()) { logger.debug("Unbind/close was requested, ignoring exception thrown: {}", t); } else { this.sessionHandler.fireUnknownThrowable(t); } } }
protected BaseBindResp bind(BaseBind request, long timeoutInMillis) throws RecoverablePduException, UnrecoverablePduException, SmppBindException, SmppTimeoutException, SmppChannelException, InterruptedException { assertValidRequest(request); boolean bound = false; try { this.state.set(STATE_BINDING); PduResponse response = sendRequestAndGetResponse(request, timeoutInMillis); SmppSessionUtil.assertExpectedResponse(request, response); BaseBindResp bindResponse = (BaseBindResp)response; if (bound) { setBound(); } else { try { this.close(); } catch (Exception e) { }
private void enquireLink(Esme esme) { DefaultSmppSession smppSession = esme.getSmppSession(); if (smppSession != null && smppSession.isBound() && esme.isServerBound()) { try { smppSession.enquireLink(new EnquireLink(), 10000); esme.getSystemId(), (smppSession == null ? null : smppSession.getStateName()))); smppSession.close(); } catch (Exception e) { logger.error(String.format("Failed to close smpp server session for %s.", smppSession.getConfiguration().getName())); smppSession.destroy(); return; logger.warn("Can't send ENQUIRE_LINK for ESME SystemId=" + esme.getSystemId()); try { smppSession.close(); } catch (Exception e) { logger.error(String.format("Failed to close smpp server session for %s.", smppSession.getConfiguration().getName())); smppSession.destroy();
this.countReceiveRequestPdu(requestPdu); try { long responseTime = System.currentTimeMillis() - startTime; this.countSendResponsePdu(responsePdu, responseTime, responseTime); this.sendResponsePdu(responsePdu); } catch (Exception e) { logger.error("Unable to cleanly return response PDU: {}", e); if (future != null) { logger.trace("Found a future in the window for seqNum [{}]", receivedPduSeqNum); this.countReceiveResponsePdu(responsePdu, future.getOfferToAcceptTime(), future.getAcceptToDoneTime(), (future.getAcceptToDoneTime() / future.getWindowSize())); this.countReceiveResponsePdu(responsePdu, 0, 0, 0);
@Override public void close() { close(5000); }
@Override public void fireUnknownThrowable(Throwable throwable) { DefaultSmppSession defaultSession = esme.getSmppSession(); // firing of onPduRequestTimeout() for sent messages for which we do not have responses Window<Integer, PduRequest, PduResponse> wind = defaultSession.getSendWindow(); Map<Integer, WindowFuture<Integer, PduRequest, PduResponse>> futures = wind.createSortedSnapshot(); for (WindowFuture<Integer, PduRequest, PduResponse> future : futures.values()) { tracer.warning("Firing of onPduRequestTimeout from DefaultSmppServerHandler.sessionDestroyed(): " + future.getRequest().toString()); defaultSession.expired(future); } tracer.severe("Received fireUnknownThrowable", throwable); // TODO what here? }
smppSession.close(); } catch (Exception e) { logger.error(String.format("Failed to close smpp session for %s.", smppSession.getConfiguration().getName())); smppSession.destroy();
@Override public void unbind(long timeoutInMillis) { // is this channel still open? if (this.channel.isConnected()) { this.state.set(STATE_UNBINDING); // try a "graceful" unbind by sending an "unbind" request try { sendRequestAndGetResponse(new Unbind(), timeoutInMillis); } catch (Exception e) { // not sure if an exception while attempting to unbind matters... // we are going to just print out a warning logger.warn("Did not cleanly receive an unbind response to our unbind request, safe to ignore: " + e.getMessage()); } } else { logger.info("Session channel is already closed, not going to unbind"); } // always delegate the unbind to finish up with a "close" close(timeoutInMillis); }
protected DefaultSmppSession createSession(Channel channel, SmppSessionConfiguration config, SmppSessionHandler sessionHandler) throws SmppTimeoutException, SmppChannelException, InterruptedException { DefaultSmppSession session = new DefaultSmppSession(SmppSession.Type.CLIENT, config, channel, sessionHandler, monitorExecutor); channel.getPipeline().addLast(SmppChannelConstants.PIPELINE_SESSION_PDU_DECODER_NAME, new SmppSessionPduDecoder(session.getTranscoder()));
this.countReceiveRequestPdu(requestPdu); countSendResponsePduProcessingTime(responsePdu, System.currentTimeMillis() - startTime); sendResponsePdu(responsePdu); countSendResponsePduResponseTime(responsePdu, System.currentTimeMillis() - startTime); } catch (Exception e) { logger.error("Unable to cleanly return response PDU: {}", e); if (future != null) { logger.trace("Found a future in the window for seqNum [{}]", receivedPduSeqNum); this.countReceiveResponsePdu(responsePdu, future.getOfferToAcceptTime(), future.getAcceptToDoneTime(), (future.getAcceptToDoneTime() / future.getWindowSize())); this.countReceiveResponsePdu(responsePdu, 0, 0, 0);
DefaultSmppSession session = new DefaultSmppSession(SmppSession.Type.SERVER, config, channel, this, sessionId, preparedBindResponse, interfaceVersion, monitorExecutor); session.registerMBean(configuration.getJmxDomain() + ":type=" + configuration.getName() + "Sessions,name=" + sessionId);
WindowFuture<Integer,PduRequest,PduResponse> future = sendRequestPdu(requestPdu, timeoutInMillis, true); boolean completedWithinTimeout = future.await();
@Override public boolean isUnbinding() { if (this.defaultSmppSession != null) { return this.defaultSmppSession.isUnbinding(); } return false; }