TestTPConversationService.java
上传用户:xfwatch
上传日期:2020-12-14
资源大小:872k
文件大小:2k
- package org.jboss.blacktie.jatmibroker.xatmi;
- import org.apache.log4j.LogManager;
- import org.apache.log4j.Logger;
- public class TestTPConversationService implements BlacktieService {
- private static final Logger log = LogManager
- .getLogger(TestTPConversationService.class);
- public Response tpservice(TPSVCINFO svcinfo) {
- try {
- log.info("testTPConversation_service");
- boolean fail = false;
- X_OCTET sendbuf = (X_OCTET) svcinfo.tpalloc("X_OCTET", null);
- if (TestTPConversation.strcmp((X_OCTET) svcinfo.getBuffer(),
- "conversate") != 0) {
- if (svcinfo.getBuffer() != null) {
- log.error("Got invalid data %s"
- + new String(((X_OCTET) svcinfo.getBuffer())
- .getByteArray()));
- } else {
- log.error("GOT A NULL");
- }
- fail = true;
- } else {
- long revent = 0;
- log.info("Chatting");
- for (int i = 0; i < TestTPConversation.interationCount; i++) {
- byte[] bytes = ("hi" + i).getBytes();
- sendbuf.setByteArray(bytes);
- // userlogc((char*) "testTPConversation_service:%s:",
- // sendbuf);
- int result = svcinfo.getSession().tpsend(sendbuf,
- bytes.length, Connection.TPRECVONLY);
- if (result != -1) {
- try {
- svcinfo.getSession().tprecv(0);
- fail = true;
- break;
- } catch (ConnectionException e) {
- Buffer rcvbuf = e.getReceived();
- if (rcvbuf != null
- && e.getEvent() == Connection.TPEV_SENDONLY) {
- if (TestTPConversation.strcmp("yo" + i, rcvbuf) != 0) {
- fail = true;
- break;
- }
- } else {
- fail = true;
- break;
- }
- }
- } else {
- fail = true;
- break;
- }
- }
- log.info("Chatted");
- }
- if (fail) {
- return new Response((short) Connection.TPESVCFAIL, 0, sendbuf,
- 0, 0);
- } else {
- byte[] bytes = ("hi" + TestTPConversation.interationCount)
- .getBytes();
- sendbuf.setByteArray(bytes);
- return new Response(Connection.TPSUCCESS, 0, sendbuf,
- bytes.length, 0);
- }
- } catch (ConnectionException e) {
- return new Response(Connection.TPFAIL, Connection.TPEITYPE, null,
- 0, 0);
- }
- }
- }