Search in sources :

Example 31 with Response

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;
}
Also used : Response(org.jboss.narayana.blacktie.jatmibroker.xatmi.Response) ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException)

Example 32 with Response

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);
}
Also used : Response(org.jboss.narayana.blacktie.jatmibroker.xatmi.Response) X_C_TYPE(org.jboss.narayana.blacktie.jatmibroker.xatmi.X_C_TYPE)

Example 33 with Response

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);
}
Also used : Response(org.jboss.narayana.blacktie.jatmibroker.xatmi.Response) X_OCTET(org.jboss.narayana.blacktie.jatmibroker.xatmi.X_OCTET)

Example 34 with Response

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);
}
Also used : Response(org.jboss.narayana.blacktie.jatmibroker.xatmi.Response) X_OCTET(org.jboss.narayana.blacktie.jatmibroker.xatmi.X_OCTET) X_COMMON(org.jboss.narayana.blacktie.jatmibroker.xatmi.X_COMMON)

Example 35 with Response

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);
    }
}
Also used : Response(org.jboss.narayana.blacktie.jatmibroker.xatmi.Response) X_OCTET(org.jboss.narayana.blacktie.jatmibroker.xatmi.X_OCTET)

Aggregations

Response (org.jboss.narayana.blacktie.jatmibroker.xatmi.Response)35 X_OCTET (org.jboss.narayana.blacktie.jatmibroker.xatmi.X_OCTET)29 ConnectionException (org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException)12 ConfigurationException (org.jboss.narayana.blacktie.jatmibroker.core.conf.ConfigurationException)8 StringTokenizer (java.util.StringTokenizer)3 X_C_TYPE (org.jboss.narayana.blacktie.jatmibroker.xatmi.X_C_TYPE)3 IOException (java.io.IOException)2 List (java.util.List)2 Buffer (org.jboss.narayana.blacktie.jatmibroker.xatmi.Buffer)2 ResponseException (org.jboss.narayana.blacktie.jatmibroker.xatmi.ResponseException)2 X_COMMON (org.jboss.narayana.blacktie.jatmibroker.xatmi.X_COMMON)2 StringReader (java.io.StringReader)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 CodecFactory (org.jboss.narayana.blacktie.jatmibroker.codec.CodecFactory)1 Codec (org.jboss.narayana.blacktie.jatmibroker.core.transport.Codec)1 Message (org.jboss.narayana.blacktie.jatmibroker.core.transport.Message)1 Receiver (org.jboss.narayana.blacktie.jatmibroker.core.transport.Receiver)1