Search in sources :

Example 11 with ConfigurationException

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

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

the class QueueReaperBean method start.

@PostConstruct
public void start() {
    log.info("QueueReaper Started");
    try {
        prop = new Properties();
        XMLParser.loadProperties("btconfig.xsd", "btconfig.xml", prop);
        this.interval = Integer.parseInt(prop.getProperty("QueueReaperInterval", "30")) * 1000;
        timerService.createIntervalTimer(interval, interval, new TimerConfig("queue reaper", false));
        log.info("QueueReaper create timer with " + interval + "ms");
    } catch (ConfigurationException e) {
        log.error("btconfig.xml is not valid: " + e);
    }
}
Also used : ConfigurationException(org.jboss.narayana.blacktie.jatmibroker.core.conf.ConfigurationException) TimerConfig(javax.ejb.TimerConfig) Properties(java.util.Properties) PostConstruct(javax.annotation.PostConstruct)

Example 13 with ConfigurationException

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

the class ConnectionImpl method tpconnect.

/**
 * Handle the initiation of a conversation with the server.
 *
 * @param svc
 *            The name of the service
 * @param toSend
 *            The outbound buffer
 * @param flags
 *            The flags to use
 * @return The connection descriptor
 * @throws ConnectionException
 *             If the service cannot be contacted.
 */
public Session tpconnect(String svc, Buffer toSend, int flags) throws ConnectionException {
    log.debug("tpconnect: " + svc);
    svc = svc.substring(0, Math.min(ConnectionImpl.XATMI_SERVICE_NAME_LENGTH, svc.length()));
    // Initiate the session
    svc = svc.substring(0, Math.min(ConnectionImpl.XATMI_SERVICE_NAME_LENGTH, svc.length()));
    int correlationId = 0;
    synchronized (this) {
        correlationId = nextId++;
    }
    Transport transport = getTransport(svc);
    SessionImpl session = new SessionImpl(this, svc, transport, correlationId);
    Receiver receiver = session.getReceiver();
    // TODO HANDLE TRANSACTION
    String type = null;
    String subtype = null;
    int len = 0;
    byte[] data = null;
    if (toSend != null) {
        CodecFactory factory = new CodecFactory(this);
        String coding_type = properties.getProperty("blacktie." + svc + ".coding_type");
        Codec codec = factory.getCodec(coding_type);
        data = codec.encode((BufferImpl) toSend);
        // data = toSend.serialize();
        type = toSend.getType();
        subtype = toSend.getSubtype();
        len = toSend.getLen();
    }
    String timeToLive = properties.getProperty("TimeToLive");
    int ttl = 0;
    if (timeToLive != null) {
        ttl = Integer.parseInt(timeToLive) * 1000;
    }
    log.debug("tpconnect sending data");
    session.getSender().send(receiver.getReplyTo(), (short) 0, 0, data, len, correlationId, flags | TPCONV, ttl, type, subtype);
    byte[] response = null;
    try {
        log.debug("tpconnect receiving data");
        X_OCTET_Impl odata = (X_OCTET_Impl) session.tprecv(0);
        // TODO THIS SHOULD BE A BETTER ERROR AND CHECKED IF TPCONV AND NOT
        // CONV
        response = odata.getByteArray();
        log.debug("tpconnect received data");
    } catch (ResponseException e) {
        response = ((X_OCTET_Impl) e.getReceived()).getByteArray();
        log.debug("Caught an exception with data", e);
    } catch (ConnectionException e) {
        session.close();
        throw new ConnectionException(e.getTperrno(), "Could not connect");
    } catch (ConfigurationException e) {
        session.close();
        throw new ConnectionException(ConnectionImpl.TPEOS, "Configuration exception: " + e.getMessage(), e);
    }
    byte[] ack = new byte[4];
    byte[] bytes = "ACK".getBytes();
    System.arraycopy(bytes, 0, ack, 0, 3);
    boolean connected = response == null ? false : Arrays.equals(ack, response);
    if (!connected) {
        log.error("Could not connect");
        session.close();
        throw new ConnectionException(ConnectionImpl.TPESYSTEM, "Could not connect");
    }
    session.setCreatorState(flags);
    sessions.put(correlationId, session);
    log.trace("Added session: " + correlationId);
    // Return a handle to allow the connection to send/receive data on
    log.debug("Created session: " + correlationId);
    return session;
}
Also used : ResponseException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ResponseException) Receiver(org.jboss.narayana.blacktie.jatmibroker.core.transport.Receiver) Codec(org.jboss.narayana.blacktie.jatmibroker.core.transport.Codec) ConfigurationException(org.jboss.narayana.blacktie.jatmibroker.core.conf.ConfigurationException) CodecFactory(org.jboss.narayana.blacktie.jatmibroker.codec.CodecFactory) Transport(org.jboss.narayana.blacktie.jatmibroker.core.transport.Transport) 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