Search in sources :

Example 21 with X_OCTET

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

the class AdministrationProxy method callAdminService.

private Response callAdminService(String serverName, int id, String command) throws ConnectionException, ConfigurationException {
    log.trace("callAdminService");
    command = command + "\0";
    X_OCTET sendbuf = (X_OCTET) connection.tpalloc("X_OCTET", null);
    sendbuf.setByteArray(command.getBytes());
    String service = "." + serverName + id;
    Response rcvbuf = connection.tpcall(service, sendbuf, 0);
    return rcvbuf;
}
Also used : Response(org.jboss.narayana.blacktie.jatmibroker.xatmi.Response) X_OCTET(org.jboss.narayana.blacktie.jatmibroker.xatmi.X_OCTET)

Example 22 with X_OCTET

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

the class AdministrationProxy method listServiceStatusById.

public String listServiceStatusById(String serverName, int id, String serviceName) {
    log.trace("listServiceStatusById");
    String command = "status";
    Response buf = null;
    String status = null;
    try {
        if (serviceName != null) {
            command = command + "," + serviceName + ",";
        }
        buf = callAdminService(serverName, id, command);
        if (buf != null) {
            byte[] received = ((X_OCTET) buf.getBuffer()).getByteArray();
            if (received[0] == '1') {
                status = new String(received, 1, received.length - 1);
                log.debug("status is " + status);
                return status;
            }
        }
    } catch (ConnectionException e) {
        log.error("call server " + serverName + " id " + id + " failed with " + e.getTperrno());
    } catch (Exception e) {
        log.error("response " + status + " error with " + e);
    }
    return null;
}
Also used : Response(org.jboss.narayana.blacktie.jatmibroker.xatmi.Response) X_OCTET(org.jboss.narayana.blacktie.jatmibroker.xatmi.X_OCTET) ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException) IOException(java.io.IOException) ConfigurationException(org.jboss.narayana.blacktie.jatmibroker.core.conf.ConfigurationException) ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException)

Example 23 with X_OCTET

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

the class BlacktieAdminServiceXATMI method tpservice.

public Response tpservice(TPSVCINFO svcinfo) {
    log.trace("Message received");
    X_OCTET recv = (X_OCTET) svcinfo.getBuffer();
    String string = new String(recv.getByteArray());
    StringTokenizer parameters = new StringTokenizer(string, ",", false);
    String operation = parameters.nextToken();
    byte[] toReturn = null;
    try {
        if (operation.equals("getDomainName")) {
            String response = getDomainName();
            toReturn = response.getBytes();
        } else if (operation.equals("getServerName")) {
            String serviceName = getString(parameters);
            String response = getServerName(serviceName);
            toReturn = response.getBytes();
        } else if (operation.equals("getSoftwareVersion")) {
            String response = getSoftwareVersion();
            toReturn = response.getBytes();
        } else if (operation.equals("pauseDomain")) {
            boolean response = pauseDomain();
            toReturn = convertBoolean(response);
        } else if (operation.equals("resumeDomain")) {
            boolean response = resumeDomain();
            toReturn = convertBoolean(response);
        } else if (operation.equals("listRunningServers")) {
            List<String> response = listRunningServers();
            toReturn = convertListString(response);
        } else if (operation.equals("listRunningInstanceIds")) {
            String serverName = getString(parameters);
            List<Integer> response = listRunningInstanceIds(serverName);
            toReturn = convertListInt(response);
        } else if (operation.equals("listServersStatus")) {
            String response = listServersStatus();
            toReturn = response.getBytes();
        } else if (operation.equals("listServiceStatus")) {
            String serverName = getString(parameters);
            String serviceName = getString(parameters);
            String response = listServiceStatus(serverName, serviceName);
            toReturn = response.getBytes();
        } else if (operation.equals("advertise")) {
            String serverName = getString(parameters);
            String serviceName = getString(parameters);
            boolean response = advertise(serverName, serviceName);
            toReturn = convertBoolean(response);
        } else if (operation.equals("unadvertise")) {
            String serverName = getString(parameters);
            String serviceName = getString(parameters);
            boolean response = unadvertise(serverName, serviceName);
            toReturn = convertBoolean(response);
        } else if (operation.equals("shutdown")) {
            String serverName = getString(parameters);
            int id = getInt(parameters);
            Boolean shutdown = shutdown(serverName, id);
            toReturn = convertBoolean(shutdown);
        } else if (operation.equals("getServiceCounterById")) {
            String serverName = getString(parameters);
            int id = getInt(parameters);
            String serviceName = getString(parameters);
            long response = getServiceCounterById(serverName, id, serviceName);
            toReturn = convertLong(response);
        } else if (operation.equals("getServiceCounter")) {
            String serverName = getString(parameters);
            String serviceName = getString(parameters);
            long response = getServiceCounter(serverName, serviceName);
            toReturn = convertLong(response);
        } else if (operation.equals("getErrorCounter")) {
            String serverName = getString(parameters);
            String serviceName = getString(parameters);
            long response = getErrorCounter(serverName, serviceName);
            toReturn = convertLong(response);
        } else if (operation.equals("reloadDomain")) {
            boolean response = reloadDomain();
            toReturn = convertBoolean(response);
        } else if (operation.equals("reloadServer")) {
            String serverName = getString(parameters);
            boolean response = reloadServer(serverName);
            toReturn = convertBoolean(response);
        } else if (operation.equals("listServiceStatusById")) {
            String serverName = getString(parameters);
            int id = getInt(parameters);
            String serviceName = getString(parameters);
            String response = listServiceStatusById(serverName, id, serviceName);
            toReturn = response.getBytes();
        } else if (operation.equals("getDomainStatus")) {
            boolean response = getDomainStatus();
            toReturn = convertBoolean(response);
        } else if (operation.equals("getResponseTime")) {
            String serverName = getString(parameters);
            String serviceName = getString(parameters);
            String times = getResponseTime(serverName, serviceName);
            toReturn = times.getBytes();
        } else if (operation.equals("getQueueDepth")) {
            String serverName = getString(parameters);
            String serviceName = getString(parameters);
            int depth = getQueueDepth(serverName, serviceName);
            toReturn = (new StringBuffer().append(depth)).toString().getBytes();
        } else if (operation.equals("getServerVersionById")) {
            String serverName = getString(parameters);
            int id = getInt(parameters);
            String response = getServerVersionById(serverName, id);
            toReturn = response.getBytes();
        } else {
            log.error("Unknown operation: " + operation);
            return new Response(Connection.TPFAIL, 0, null, 0);
        }
        X_OCTET buffer = (X_OCTET) svcinfo.getConnection().tpalloc("X_OCTET", null);
        buffer.setByteArray(toReturn);
        log.debug("Responding");
        return new Response(Connection.TPSUCCESS, 0, buffer, 0);
    } catch (ConnectionException e) {
        return new Response(Connection.TPFAIL, 0, null, 0);
    } catch (IOException e) {
        return new Response(Connection.TPFAIL, 0, null, 0);
    } catch (ConfigurationException e) {
        return new Response(Connection.TPFAIL, 0, null, 0);
    }
}
Also used : IOException(java.io.IOException) Response(org.jboss.narayana.blacktie.jatmibroker.xatmi.Response) X_OCTET(org.jboss.narayana.blacktie.jatmibroker.xatmi.X_OCTET) StringTokenizer(java.util.StringTokenizer) ConfigurationException(org.jboss.narayana.blacktie.jatmibroker.core.conf.ConfigurationException) List(java.util.List) ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException)

Example 24 with X_OCTET

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

the class CommandHandler method invoke.

public Object invoke(Object proxy, Method method, Object[] args) throws ConfigurationException, ConnectionException, CommandFailedException, ParserConfigurationException, SAXException, IOException {
    if (connection == null) {
        ConnectionFactory cf = ConnectionFactory.getConnectionFactory();
        connection = cf.getConnection();
    }
    StringBuffer command = new StringBuffer(method.getName());
    command.append(',');
    if (args != null) {
        for (int i = 0; i < args.length; i++) {
            if (args[i] == null) {
                args[i] = "";
            }
            command.append(args[i].toString());
            command.append(',');
        }
    }
    X_OCTET sendbuf = (X_OCTET) connection.tpalloc("X_OCTET", null);
    sendbuf.setByteArray(command.toString().getBytes());
    Response received = connection.tpcall("BTDomainAdmin", sendbuf, 0);
    X_OCTET rcvbuf = (X_OCTET) received.getBuffer();
    Class<?> returnType = method.getReturnType();
    byte[] byteArray = rcvbuf.getByteArray();
    ;
    if (returnType == Boolean.class) {
        if (byteArray[0] == 1) {
            return true;
        } else {
            return false;
        }
    } else if (returnType == Long.class) {
        return convertLong(byteArray);
    } else if (returnType == String.class) {
        return new String(byteArray);
    } else if (returnType == java.util.List.class) {
        String listTerminator = BlacktieAdministration.LIST_TERMINATOR;
        String string = new String(byteArray);
        StringTokenizer outParameters = new StringTokenizer(string, "," + "", false);
        if (!method.getName().equals("listRunningInstanceIds")) {
            List<String> toReturn = new ArrayList<String>();
            while (outParameters.hasMoreTokens()) {
                String nextToken = outParameters.nextToken();
                if (!nextToken.equals(listTerminator)) {
                    toReturn.add(nextToken);
                }
            }
            return toReturn;
        } else {
            List<Integer> toReturn = new ArrayList<Integer>();
            while (outParameters.hasMoreTokens()) {
                String nextToken = outParameters.nextToken();
                if (!nextToken.equals(listTerminator)) {
                    toReturn.add(Integer.parseInt(nextToken));
                }
            }
            return toReturn;
        }
    } else if (returnType == org.w3c.dom.Element.class) {
        StringReader sreader = new StringReader(new String(byteArray));
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder parser = factory.newDocumentBuilder();
        Document doc = parser.parse(new InputSource(sreader));
        return doc.getDocumentElement();
    } else {
        log.error("Could not handle response type: " + returnType);
        throw new CommandFailedException(-1);
    }
// java.util.List<Integer>
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Document(org.w3c.dom.Document) Response(org.jboss.narayana.blacktie.jatmibroker.xatmi.Response) X_OCTET(org.jboss.narayana.blacktie.jatmibroker.xatmi.X_OCTET) ConnectionFactory(org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionFactory) StringTokenizer(java.util.StringTokenizer) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) List(java.util.List)

Example 25 with X_OCTET

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

the class AdministrationTest method callAdmin.

private String callAdmin(String command, char expect) throws Exception {
    int sendlen = command.length() + 1;
    X_OCTET sendbuf = (X_OCTET) connection.tpalloc("X_OCTET", null);
    sendbuf.setByteArray(command.getBytes());
    Response buf = connection.tpcall(service, sendbuf, 0);
    assertTrue(buf != null);
    byte[] received = ((X_OCTET) buf.getBuffer()).getByteArray();
    assertTrue(received[0] == expect);
    return new String(received, 1, received.length - 1);
}
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)29 X_OCTET (org.jboss.narayana.blacktie.jatmibroker.xatmi.X_OCTET)29 ConnectionException (org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException)9 ConfigurationException (org.jboss.narayana.blacktie.jatmibroker.core.conf.ConfigurationException)8 StringTokenizer (java.util.StringTokenizer)3 IOException (java.io.IOException)2 List (java.util.List)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 Buffer (org.jboss.narayana.blacktie.jatmibroker.xatmi.Buffer)1 ConnectionFactory (org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionFactory)1 ResponseException (org.jboss.narayana.blacktie.jatmibroker.xatmi.ResponseException)1 X_COMMON (org.jboss.narayana.blacktie.jatmibroker.xatmi.X_COMMON)1 X_C_TYPE (org.jboss.narayana.blacktie.jatmibroker.xatmi.X_C_TYPE)1 Document (org.w3c.dom.Document)1 InputSource (org.xml.sax.InputSource)1