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

📄 pdureceiver.java

📁 Logica lastest SMPP API
💻 JAVA
字号:
package com.smpp.server;

import com.logica.smpp.Session;
import com.logica.smpp.debug.Debug;
import com.logica.smpp.debug.Event;
import com.logica.smpp.pdu.DeliverSM;
import com.logica.smpp.pdu.PDU;
import com.logica.smpp.pdu.SubmitSMResp;
import com.logica.smpp.util.Queue;

public class PDUReceiver implements Runnable {
	private Session session = null;

	private GatewayProperties gp = null;

	private Event event;

	private Debug debug;

	private Queue responseQueue;

	private String processingClass;

	public static void main(String[] args) {

	}

	public PDUReceiver(GatewayProperties gp1, Session session1) {
		gp = gp1;
		processingClass = gp.getProcessingClass();
		session = session1;
		event = gp.getEvent();
		debug = gp.getDebug();
		ResponseQueue rq = ResponseQueue.getResponseQueue();
		responseQueue = rq.getQueue();
	}

	public void run() {
		System.out.println("**********Receiver Started***************");
		while (true) {

			PDU pdu = receive();
			if (pdu != null) {
				if (pdu instanceof DeliverSM) {
					Message requestMessage = new Message((DeliverSM) pdu);
					Object object = createObject(processingClass);
					if (object instanceof MORequestProcessor) {
						MORequestProcessor morp = (MORequestProcessor) object;
						morp.process(requestMessage);

					} else {
						System.out
								.println("Processor Not defined for this request");
					}

				} else {
					SubmitSMResp s = (SubmitSMResp) pdu;
					responseQueue.enqueue(s);

					// System.out.println("PDU Queud by receiver
					// :"+pdu.debugString());
					// System.out.println("PDU class
					// :"+pdu.getClass().getName());

				}
			}
			try {
				Thread.sleep(2);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	private PDU receive() {
		PDU pdu = null;
		// System.out.println("About to receive");
		// debug.enter(this, "SMPPSender.receive()");
		try {
			pdu = session.receive();
			// pdu = session.getReceiver().receive();
			if (pdu != null) {
				pdu.debugString();
				// System.out.println("Received PDU " + pdu.debugString());
			} else {
				// System.out.println("No PDU received this time.");
			}

		} catch (Exception e) {
			event.write(e, "");
			debug.write("Receiving failed. " + e);
			//System.out.println("Receiving failed. " + e);
		} finally {
			// debug.exit(this);
		}
		return pdu;
	}

	static Object createObject(String className) {
		Object object = null;
		try {
			Class classDefinition = Class.forName(className);
			object = classDefinition.newInstance();
		} catch (InstantiationException e) {
			System.out.println(e);
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return object;
	}

}

⌨️ 快捷键说明

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