Search in sources :

Example 1 with ConfigurationException

use of org.jboss.narayana.blacktie.jatmibroker.core.conf.ConfigurationException in project narayana by jbosstm.

the class TTLService method tpservice.

public Response tpservice(TPSVCINFO svcinfo) throws ConnectionException, ConfigurationException {
    log.info("TTLService");
    X_OCTET dptr = (X_OCTET) svcinfo.getBuffer();
    String data = new String(dptr.getByteArray());
    log.info("test_ttl_service get data: " + data);
    int len = 60;
    X_OCTET toReturn = (X_OCTET) svcinfo.getConnection().tpalloc("X_OCTET", null);
    log.info("Data was: " + data);
    if (data.contains("counter")) {
        String counter = String.valueOf(n);
        toReturn.setByteArray(counter.getBytes());
        len = counter.length();
    } else {
        try {
            int timeout = 60;
            log.info("TTLService sleep for " + timeout + " seconds");
            Thread.sleep(timeout * 1000);
            log.info("TTLService slept for " + timeout + " seconds");
            toReturn.setByteArray("test_ttl_service".getBytes());
        } catch (Exception e) {
            log.error("sleep failed with " + e);
        }
        n++;
    }
    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) ConfigurationException(org.jboss.narayana.blacktie.jatmibroker.core.conf.ConfigurationException) ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException)

Example 2 with ConfigurationException

use of org.jboss.narayana.blacktie.jatmibroker.core.conf.ConfigurationException 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 ConfigurationException

use of org.jboss.narayana.blacktie.jatmibroker.core.conf.ConfigurationException in project narayana by jbosstm.

the class NBFParser method parse.

public boolean parse(byte[] buffer) throws ConfigurationException {
    boolean result = false;
    try {
        schema.newValidator().validate(new StreamSource(new ByteArrayInputStream(buffer)));
        saxParser.parse(new ByteArrayInputStream(buffer), handler);
        result = true;
    } catch (Throwable e) {
        log.error("Parser buffer failed with " + e.getMessage(), e);
        throw new ConfigurationException("Parser buffer failed with " + e.getMessage());
    }
    return result;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ConfigurationException(org.jboss.narayana.blacktie.jatmibroker.core.conf.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) StreamSource(javax.xml.transform.stream.StreamSource)

Example 4 with ConfigurationException

use of org.jboss.narayana.blacktie.jatmibroker.core.conf.ConfigurationException 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 5 with ConfigurationException

use of org.jboss.narayana.blacktie.jatmibroker.core.conf.ConfigurationException 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)

Aggregations

ConfigurationException (org.jboss.narayana.blacktie.jatmibroker.core.conf.ConfigurationException)13 ConnectionException (org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException)10 Response (org.jboss.narayana.blacktie.jatmibroker.xatmi.Response)7 X_OCTET (org.jboss.narayana.blacktie.jatmibroker.xatmi.X_OCTET)7 IOException (java.io.IOException)2 StringTokenizer (java.util.StringTokenizer)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 Constructor (java.lang.reflect.Constructor)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 UnknownHostException (java.net.UnknownHostException)1 List (java.util.List)1 Properties (java.util.Properties)1 PostConstruct (javax.annotation.PostConstruct)1 TimerConfig (javax.ejb.TimerConfig)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 StreamSource (javax.xml.transform.stream.StreamSource)1 CodecFactory (org.jboss.narayana.blacktie.jatmibroker.codec.CodecFactory)1 Codec (org.jboss.narayana.blacktie.jatmibroker.core.transport.Codec)1