use of org.jboss.narayana.blacktie.jatmibroker.xatmi.Response in project narayana by jbosstm.
the class ConnectionImpl method tpgetrply.
/**
* Get the reply for an asynchronous call.
*
* @param cd
* The connection descriptor to use
* @param flags
* The flags to use
* @return The response from the server
* @throws ConnectionException
* If the service cannot be contacted.
* @throws ConfigurationException
*/
public Response tpgetrply(int cd, int flags) throws ConnectionException, ConfigurationException {
log.debug("tpgetrply: " + cd);
int toCheck = flags & ~(TPGETANY | TPNOCHANGE | TPNOBLOCK | TPNOTIME | TPSIGRSTRT);
if (toCheck != 0) {
log.trace("invalid flags remain: " + toCheck);
throw new ConnectionException(ConnectionImpl.TPEINVAL, "Invalid flags remain: " + toCheck);
}
synchronized (tpGetAnySessions) {
if ((flags & ConnectionImpl.TPGETANY) == ConnectionImpl.TPGETANY) {
if ((flags & ConnectionImpl.TPNOBLOCK) != ConnectionImpl.TPNOBLOCK) {
int timeout = 0;
if ((flags & ConnectionImpl.TPNOTIME) != ConnectionImpl.TPNOTIME) {
timeout = Integer.parseInt(properties.getProperty("ReceiveTimeout")) * 1000 + Integer.parseInt(properties.getProperty("TimeToLive")) * 1000;
}
if (tpGetAnySessions.size() == 0) {
try {
tpGetAnySessions.wait(timeout);
} catch (InterruptedException e) {
throw new ConnectionException(ConnectionImpl.TPESYSTEM, "Could not wait", e);
}
}
if (tpGetAnySessions.size() == 0) {
throw new ConnectionException(ConnectionImpl.TPETIME, "No message arrived");
}
} else if (tpGetAnySessions.size() == 0) {
throw new ConnectionException(ConnectionImpl.TPEBLOCK, "No message arrived");
}
cd = tpGetAnySessions.remove(0);
}
}
Response toReturn = receive(cd, flags);
tpcancel(cd);
log.debug("tpgetrply returning: " + toReturn);
return toReturn;
}
use of org.jboss.narayana.blacktie.jatmibroker.xatmi.Response in project narayana by jbosstm.
the class SpecQuickstartTwoService method tpservice.
public Response tpservice(TPSVCINFO svcinfo) throws ConnectionException {
log.info("inquiry_svc");
short rval;
/* extract initial typed buffer sent as part of tpconnect() */
X_C_TYPE ptr = (X_C_TYPE) svcinfo.getBuffer();
/*
* Parse input string, ptr->input, and retrieve records. Return 10 records at a time to client. Records are placed in
* ptr->output, an array of account records.
*/
for (int i = 0; i < 5; i++) {
/* gather from DBMS next 10 records into ptr->output array */
svcinfo.getSession().tpsend(ptr, Connection.TPSIGRSTRT);
}
// TODO DO OK AND FAIL
if (ptr.getInt("failTest") == 0) {
rval = Connection.TPSUCCESS;
} else {
rval = Connection.TPFAIL;
/* global transaction will not commit */
}
/* terminate connection */
return new Response(rval, 0, null, 0);
}
use of org.jboss.narayana.blacktie.jatmibroker.xatmi.Response in project narayana by jbosstm.
the class TPGetRplyTPNOBLOCKService method tpservice.
public Response tpservice(TPSVCINFO svcinfo) throws ConnectionException, ConfigurationException {
String response = "test_tpgetrply_TPNOBLOCK";
log.info(response);
int sendlen = response.length() + 1;
X_OCTET toReturn = (X_OCTET) svcinfo.getConnection().tpalloc("X_OCTET", null);
toReturn.setByteArray(response.getBytes());
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
log.error("Was interrupted");
}
return new Response(Connection.TPSUCCESS, 0, toReturn, 0);
}
use of org.jboss.narayana.blacktie.jatmibroker.xatmi.Response in project narayana by jbosstm.
the class TPCallXCommonService method tpservice.
public Response tpservice(TPSVCINFO svcinfo) throws ConnectionException, ConfigurationException {
log.info("test_tpcall_x_common_service");
boolean ok = false;
X_COMMON dptr = (X_COMMON) svcinfo.getBuffer();
if (dptr.getLong("acct_no") == 12345678 && dptr.getShort("amount") == 50) {
ok = true;
}
int len = 60;
X_OCTET toReturn = (X_OCTET) svcinfo.getConnection().tpalloc("X_OCTET", null);
if (ok) {
toReturn.setByteArray("tpcall_x_common".getBytes());
} else {
toReturn.setByteArray("fail".getBytes());
}
return new Response(Connection.TPSUCCESS, 22, toReturn, 0);
}
use of org.jboss.narayana.blacktie.jatmibroker.xatmi.Response in project narayana by jbosstm.
the class RollbackOnlyTpcallTPETIMEService method tpservice.
public Response tpservice(TPSVCINFO svcinfo) throws ConnectionException, ConfigurationException {
log.info("RollbackOnlyTpcallTPETIMEService");
try {
int timeout = 60;
log.info("RollbackOnlyTpcallTPETIMEService, sleeping for " + timeout + " seconds");
Thread.sleep(timeout * 1000);
log.info("RollbackOnlyTpcallTPETIMEService, slept for " + timeout + " seconds");
int len = 60;
X_OCTET toReturn = (X_OCTET) svcinfo.getConnection().tpalloc("X_OCTET", null);
toReturn.setByteArray("test_tpcall_TPETIME_service".getBytes());
return new Response(Connection.TPSUCCESS, 0, toReturn, 0);
} catch (InterruptedException e) {
return new Response(Connection.TPFAIL, 0, null, 0);
}
}
Aggregations