Search in sources :

Example 1 with Buffer

use of org.jboss.narayana.blacktie.jatmibroker.xatmi.Buffer in project narayana by jbosstm.

the class TPConversationService method tpservice.

public Response tpservice(TPSVCINFO svcinfo) throws ConnectionException, ConfigurationException {
    log.info("testTPConversation_service");
    boolean fail = false;
    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();
            X_OCTET sendbuf = (X_OCTET) svcinfo.getConnection().tpalloc("X_OCTET", null);
            sendbuf.setByteArray(bytes);
            // btlogger((char*) "testTPConversation_service:%s:",
            // sendbuf);
            int result = svcinfo.getSession().tpsend(sendbuf, Connection.TPRECVONLY);
            if (result != -1) {
                try {
                    svcinfo.getSession().tprecv(0);
                    fail = true;
                    break;
                } catch (ResponseException e) {
                    if (e.getEvent() == Connection.TPEV_SENDONLY) {
                        Buffer rcvbuf = e.getReceived();
                        if (TestTPConversation.strcmp("yo" + i, rcvbuf) != 0) {
                            fail = true;
                            break;
                        }
                    } else {
                        fail = true;
                        break;
                    }
                } catch (ConnectionException e) {
                    fail = true;
                    break;
                }
            } else {
                fail = true;
                break;
            }
        }
        log.info("Chatted");
    }
    if (fail) {
        return new Response((short) Connection.TPESVCFAIL, 0, null, 0);
    } else {
        byte[] bytes = ("hi" + TestTPConversation.interationCount).getBytes();
        X_OCTET sendbuf = (X_OCTET) svcinfo.getConnection().tpalloc("X_OCTET", null);
        sendbuf.setByteArray(bytes);
        return new Response(Connection.TPSUCCESS, 0, sendbuf, 0);
    }
}
Also used : Buffer(org.jboss.narayana.blacktie.jatmibroker.xatmi.Buffer) Response(org.jboss.narayana.blacktie.jatmibroker.xatmi.Response) X_OCTET(org.jboss.narayana.blacktie.jatmibroker.xatmi.X_OCTET) ResponseException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ResponseException) ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException)

Example 2 with Buffer

use of org.jboss.narayana.blacktie.jatmibroker.xatmi.Buffer in project narayana by jbosstm.

the class ConnectionImpl method tpalloc.

/**
 * Allocate a new buffer
 *
 * @param type
 *            The type of the buffer
 * @param subtype
 *            The subtype of the buffer
 * @return The new buffer
 * @throws ConnectionException
 *             If the buffer was unknown or invalid.
 * @throws ConfigurationException
 */
public Buffer tpalloc(String type, String subtype) throws ConnectionException, ConfigurationException {
    if (type == null) {
        throw new ConnectionException(ConnectionImpl.TPEINVAL, "No type provided");
    } else {
        log.debug("Initializing a new: " + type);
        try {
            Class clazz = Class.forName(getClass().getPackage().getName() + "." + type + "_Impl");
            Constructor ctor = clazz.getConstructor(String.class);
            return (Buffer) ctor.newInstance(subtype);
        } catch (InvocationTargetException t) {
            if (t.getCause() instanceof ConfigurationException) {
                throw ((ConfigurationException) t.getCause());
            }
            throw new ConnectionException(ConnectionImpl.TPENOENT, "Type was not known: " + type, t);
        } catch (Throwable t) {
            throw new ConnectionException(ConnectionImpl.TPENOENT, "Type was not known: " + type, t);
        }
    }
}
Also used : Buffer(org.jboss.narayana.blacktie.jatmibroker.xatmi.Buffer) ConfigurationException(org.jboss.narayana.blacktie.jatmibroker.core.conf.ConfigurationException) Constructor(java.lang.reflect.Constructor) ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with Buffer

use of org.jboss.narayana.blacktie.jatmibroker.xatmi.Buffer in project narayana by jbosstm.

the class RollbackOnlyTprecvTPEVDISCONIMMService method tpservice.

public Response tpservice(TPSVCINFO svcinfo) throws ConnectionException, ConfigurationException {
    log.info("test_tprecv_TPEV_DISCONIMM_service");
    Buffer status = svcinfo.getSession().tprecv(0);
    TXINFO txinfo = new TXINFO();
    int inTx = TX.tx_info(txinfo);
    boolean rbkOnly = (txinfo.transaction_state == TX.TX_ROLLBACK_ONLY);
    log.info("status=%d, inTx=%d, rbkOnly=%d" + status + " " + inTx + " " + rbkOnly);
    return null;
}
Also used : Buffer(org.jboss.narayana.blacktie.jatmibroker.xatmi.Buffer) TXINFO(org.jboss.narayana.blacktie.jatmibroker.tx.TXINFO)

Example 4 with Buffer

use of org.jboss.narayana.blacktie.jatmibroker.xatmi.Buffer in project narayana by jbosstm.

the class TestRollbackOnly method test_tprecv_TPEV_SVCFAIL.

public void test_tprecv_TPEV_SVCFAIL() throws ConnectionException, ConfigurationException {
    log.info("test_tprecv_TPEV_SVCFAIL");
    server.tpadvertiseTestRollbackOnlyTprecvTPEVSVCFAILService();
    assertTrue(TX.tx_open() == TX.TX_OK);
    assertTrue(TX.tx_begin() == TX.TX_OK);
    Session cd = connection.tpconnect(RunServer.getServiceNameTestRollbackOnly2(), sendbuf, Connection.TPRECVONLY);
    try {
        cd.tprecv(0);
        fail("Expected e.getEvent() == Connection.TPEV_SVCFAIL");
    } catch (ResponseException e) {
        assertTrue(e.getEvent() == Connection.TPEV_SVCFAIL);
        assertTrue(e.getTperrno() == Connection.TPEEVENT);
        Buffer rcvbuf = e.getReceived();
        assertTrue(TestTPConversation.strcmp(rcvbuf, "test_tprecv_TPEV_SVCFAIL_service") == 0);
    } catch (ConnectionException e) {
        fail("Expected e.getEvent() == Connection.TPEV_SVCFAIL");
    }
    TXINFO txinfo = new TXINFO();
    int inTx = TX.tx_info(txinfo);
    log.info("inTx=" + inTx);
    assertTrue(txinfo.transaction_state == TX.TX_ROLLBACK_ONLY);
    assertTrue(TX.tx_commit() == TX.TX_ROLLBACK);
}
Also used : Buffer(org.jboss.narayana.blacktie.jatmibroker.xatmi.Buffer) ResponseException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ResponseException) ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException) Session(org.jboss.narayana.blacktie.jatmibroker.xatmi.Session)

Example 5 with Buffer

use of org.jboss.narayana.blacktie.jatmibroker.xatmi.Buffer in project narayana by jbosstm.

the class ConnectionImpl method receive.

/**
 * Retrieve a response.
 *
 * @param cd
 *            The connection descriptor
 * @param flags
 *            The flags to use
 * @return The response
 * @throws ConnectionException
 *             If the response cannot be retrieved.
 * @throws ConfigurationException
 */
private Response receive(int cd, int flags) throws ConnectionException, ConfigurationException {
    log.debug("receive: " + cd);
    Receiver endpoint = temporaryQueues.get(cd);
    if (endpoint == null) {
        throw new ConnectionException(ConnectionImpl.TPEBADDESC, "Session does not exist: " + cd);
    }
    Message message = endpoint.receive(flags);
    Buffer buffer = null;
    if (message.type != null && !message.type.equals("")) {
        CodecFactory factory = new CodecFactory(this);
        String coding_type = properties.getProperty("blacktie." + message.serviceName + ".coding_type");
        Codec codec = factory.getCodec(coding_type);
        buffer = codec.decode(message.type, message.subtype, message.data, message.len);
    // buffer = tpalloc(message.type, message.subtype, message.len);
    // buffer.deserialize(message.data);
    }
    if (message.rval == ConnectionImpl.TPFAIL) {
        if (message.rcode == ConnectionImpl.TPESVCERR) {
            throw new ResponseException(ConnectionImpl.TPESVCERR, "Got an error back from the remote service", -1, message.rcode, buffer);
        }
        throw new ResponseException(ConnectionImpl.TPESVCFAIL, "Got a fail back from the remote service", -1, message.rcode, buffer);
    } else {
        Response response = new Response(cd, message.rval, message.rcode, buffer, message.flags);
        log.debug("received returned a response? " + (response == null ? "false" : "true"));
        return response;
    }
}
Also used : Buffer(org.jboss.narayana.blacktie.jatmibroker.xatmi.Buffer) Response(org.jboss.narayana.blacktie.jatmibroker.xatmi.Response) Codec(org.jboss.narayana.blacktie.jatmibroker.core.transport.Codec) Message(org.jboss.narayana.blacktie.jatmibroker.core.transport.Message) ResponseException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ResponseException) Receiver(org.jboss.narayana.blacktie.jatmibroker.core.transport.Receiver) CodecFactory(org.jboss.narayana.blacktie.jatmibroker.codec.CodecFactory) ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException)

Aggregations

Buffer (org.jboss.narayana.blacktie.jatmibroker.xatmi.Buffer)6 ConnectionException (org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException)5 ResponseException (org.jboss.narayana.blacktie.jatmibroker.xatmi.ResponseException)3 Response (org.jboss.narayana.blacktie.jatmibroker.xatmi.Response)2 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 CodecFactory (org.jboss.narayana.blacktie.jatmibroker.codec.CodecFactory)1 ConfigurationException (org.jboss.narayana.blacktie.jatmibroker.core.conf.ConfigurationException)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 TXINFO (org.jboss.narayana.blacktie.jatmibroker.tx.TXINFO)1 Session (org.jboss.narayana.blacktie.jatmibroker.xatmi.Session)1 X_OCTET (org.jboss.narayana.blacktie.jatmibroker.xatmi.X_OCTET)1