Search in sources :

Example 16 with Response

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

the class BlacktieStompAdministrationService method tpservice.

public Response tpservice(TPSVCINFO svcinfo) {
    log.debug("Message received");
    X_OCTET recv = (X_OCTET) svcinfo.getBuffer();
    String string = new String(recv.getByteArray());
    StringTokenizer st = new StringTokenizer(string, ",", false);
    String operation = st.nextToken();
    String serverName = st.nextToken();
    String serviceName = st.nextToken();
    byte[] success = new byte[1];
    String server = null;
    try {
        if (serviceName.indexOf(".") > -1) {
            server = serviceName.substring(1);
            server = server.replaceAll("[0-9]", "");
        } else {
            ServerInfo info = SERVICE_OWNERS.get(serviceName);
            if (info == null) {
                server = serverName;
            } else {
                server = info.name;
            }
        }
        if (server != null && server.equals(serverName)) {
            log.trace("Service " + serviceName + " exists for server: " + server);
            if (operation.equals("tpadvertise")) {
                log.trace("Advertising: " + serviceName);
                boolean conversational = st.nextToken().equals("1");
                String type = st.nextToken();
                String version = st.nextToken();
                success[0] = (byte) deployQueue(serviceName, serverName, conversational, type, version);
                log.trace("Advertised: " + serviceName);
            } else if (operation.equals("decrementconsumer")) {
                log.trace("Decrement consumer: " + serviceName);
                success[0] = (byte) decrementConsumer(serviceName);
                log.trace("Decremented consumer: " + serviceName);
            } else {
                log.error("Unknown operation " + operation);
                success[0] = 0;
            }
        } else {
            log.error("Service " + serviceName + " already exists for a different server (" + server + ")");
            success[0] = 0;
        }
        X_OCTET buffer = (X_OCTET) svcinfo.getConnection().tpalloc("X_OCTET", null);
        buffer.setByteArray(success);
        log.debug("Responding");
        return new Response(Connection.TPSUCCESS, 0, buffer, 0);
    } catch (ConnectionException e) {
        return new Response(Connection.TPFAIL, 0, null, 0);
    } catch (ConfigurationException e) {
        return new Response(Connection.TPFAIL, 0, null, 0);
    } catch (UnknownHostException 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) StringTokenizer(java.util.StringTokenizer) UnknownHostException(java.net.UnknownHostException) ConfigurationException(org.jboss.narayana.blacktie.jatmibroker.core.conf.ConfigurationException) ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException)

Example 17 with Response

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

the class AdministrationProxy method getServiceCounterById.

public long getServiceCounterById(String serverName, int id, String serviceName) {
    log.trace("getServiceCounterById");
    long counter = 0;
    String command = "counter," + serviceName + ",";
    try {
        Response buf = callAdminService(serverName, id, command);
        if (buf != null) {
            byte[] received = ((X_OCTET) buf.getBuffer()).getByteArray();
            counter = Long.parseLong(new String(received, 1, received.length - 1));
        }
    } catch (ConnectionException e) {
        log.error("call server " + serverName + " id " + id + " failed with " + e.getTperrno());
    } catch (ConfigurationException e) {
        log.error("call server " + serverName + " id " + id + " failed with configuration exception", e);
    }
    return counter;
}
Also used : Response(org.jboss.narayana.blacktie.jatmibroker.xatmi.Response) X_OCTET(org.jboss.narayana.blacktie.jatmibroker.xatmi.X_OCTET) ConfigurationException(org.jboss.narayana.blacktie.jatmibroker.core.conf.ConfigurationException) ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException)

Example 18 with Response

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

the class AdministrationProxy method getErrorCounterById.

public long getErrorCounterById(String serverName, int id, String serviceName) {
    log.trace("getErrorCounterById");
    long counter = 0;
    String command = "error_counter," + serviceName + ",";
    try {
        Response buf = callAdminService(serverName, id, command);
        if (buf != null) {
            byte[] received = ((X_OCTET) buf.getBuffer()).getByteArray();
            counter = Long.parseLong(new String(received, 1, received.length - 1));
        }
    } catch (ConnectionException e) {
        log.error("call server " + serverName + " id " + id + " failed with " + e.getTperrno());
    } catch (ConfigurationException e) {
        log.error("call server " + serverName + " id " + id + " failed with configuration exception", e);
    }
    return counter;
}
Also used : Response(org.jboss.narayana.blacktie.jatmibroker.xatmi.Response) X_OCTET(org.jboss.narayana.blacktie.jatmibroker.xatmi.X_OCTET) ConfigurationException(org.jboss.narayana.blacktie.jatmibroker.core.conf.ConfigurationException) ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException)

Example 19 with Response

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

the class AdministrationProxy method getResponseTimeById.

public String getResponseTimeById(String serverName, int id, String serviceName) {
    log.trace("getResponseTimeById");
    String command = "responsetime," + serviceName + ",";
    log.trace("response command is " + command);
    try {
        Response buf = callAdminService(serverName, id, command);
        if (buf != null) {
            byte[] received = ((X_OCTET) buf.getBuffer()).getByteArray();
            String result = new String(received, 1, received.length - 1);
            log.trace("response result is " + result);
            return result;
        }
    } catch (ConnectionException e) {
        log.error("call server " + serverName + " id " + id + " failed with " + e.getTperrno(), e);
    } catch (RuntimeException e) {
        log.error("Could not get response time from server: " + e.getMessage(), e);
        throw e;
    } catch (ConfigurationException e) {
        log.error("call server " + serverName + " id " + id + " failed with configuration exception", e);
    }
    return null;
}
Also used : Response(org.jboss.narayana.blacktie.jatmibroker.xatmi.Response) X_OCTET(org.jboss.narayana.blacktie.jatmibroker.xatmi.X_OCTET) ConfigurationException(org.jboss.narayana.blacktie.jatmibroker.core.conf.ConfigurationException) ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException)

Example 20 with Response

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

the class BlacktieStompAdministrationServiceTest method processStompCommand.

private void processStompCommand(String command, int expectation) throws ConnectionException, ConfigurationException {
    byte[] toSend = command.getBytes();
    X_OCTET buffer = (X_OCTET) connection.tpalloc("X_OCTET", null);
    buffer.setByteArray(toSend);
    Response response = connection.tpcall("BTStompAdmin", buffer, 0);
    byte[] responseData = ((X_OCTET) response.getBuffer()).getByteArray();
    assertEquals(expectation, responseData[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