Search in sources :

Example 1 with Transport

use of org.jboss.narayana.blacktie.jatmibroker.core.transport.Transport in project narayana by jbosstm.

the class ConnectionImpl method close.

/**
 * Close any resources associated with this connection
 *
 * @throws ConnectionException
 *             If an open session cannot be cancelled or disconnected.
 */
public void close() throws ConnectionException {
    log.debug("Close connection called: " + this);
    // MUST close the session first to remove the temporary queue
    SessionImpl[] sessions = new SessionImpl[this.sessions.size()];
    sessions = this.sessions.values().toArray(sessions);
    for (int i = 0; i < sessions.length; i++) {
        log.debug("closing session: " + sessions[i].getCd());
        sessions[i].tpdiscon();
        log.debug("Closed open session: " + sessions[i].getCd());
    }
    this.sessions.clear();
    log.trace("Removed all sessions");
    Receiver[] receivers = new Receiver[temporaryQueues.size()];
    receivers = temporaryQueues.values().toArray(receivers);
    for (int i = 0; i < receivers.length; i++) {
        log.debug("closing receiver");
        tpcancel(receivers[i].getCd());
        log.debug("Closed open receiver");
    }
    temporaryQueues.clear();
    log.trace("Temporary queues cleared");
    if (serviceSession != null) {
        log.debug("closing service session");
        serviceSession.close();
        serviceSession = null;
        log.debug("Closed open service session");
    }
    Iterator<Transport> transports = this.transports.values().iterator();
    while (transports.hasNext()) {
        Transport transport = transports.next();
        log.debug("closing transport");
        transport.close();
        log.debug("closed transport");
    }
    this.transports.clear();
    this.connectionFactory.removeConnection(this);
    transportFactory.close();
    log.debug("Close connection finished");
}
Also used : Receiver(org.jboss.narayana.blacktie.jatmibroker.core.transport.Receiver) Transport(org.jboss.narayana.blacktie.jatmibroker.core.transport.Transport)

Example 2 with Transport

use of org.jboss.narayana.blacktie.jatmibroker.core.transport.Transport in project narayana by jbosstm.

the class ConnectionImpl method createServiceSession.

/**
 * Used by the service side to create a session for handling the client
 * request.
 *
 * @param name
 *            The name of the service.
 * @param cd
 *            The connection descriptor
 * @param replyTo
 *            The client to respond to
 * @return The session to use for the service invocation
 * @throws ConnectionException
 *             In case the transport cannot be established.
 */
public SessionImpl createServiceSession(String name, int cd, Object replyTo) throws ConnectionException {
    log.trace("Creating the service session");
    if (serviceSession != null) {
        throw new ConnectionException(ConnectionImpl.TPEPROTO, "Second service session creation attempt, was: " + serviceSession.getCd() + " new: " + cd);
    }
    Transport transport = getTransport(name);
    serviceSession = new SessionImpl(this, transport, cd, replyTo);
    log.trace("Created the service session: " + cd);
    return serviceSession;
}
Also used : Transport(org.jboss.narayana.blacktie.jatmibroker.core.transport.Transport) ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException)

Example 3 with Transport

use of org.jboss.narayana.blacktie.jatmibroker.core.transport.Transport in project narayana by jbosstm.

the class ConnectionImplTest method test.

public void test() throws Exception {
    AtmiBrokerEnvXML xml = new AtmiBrokerEnvXML();
    Properties properties = xml.getProperties();
    TransportFactory factory = new TransportFactory(properties);
    Transport proxy = factory.createTransport();
    Sender serviceFactory = proxy.getSender("BAR", false);
    String aString = "Hello from Java Land";
    Receiver endpoint = proxy.createReceiver(1, null, null);
    serviceFactory.send(endpoint.getReplyTo(), (short) 0, 0, aString.getBytes(), aString.getBytes().length, 0, 0, 0, "X_OCTET", "");
    Message receive = endpoint.receive(0);
    assertNotNull(receive);
    String string = new String(receive.data).intern();
    String expectedResponse = "BAR SAYS HELLO";
    log.debug("Bar ServiceManager service_request response is " + string);
    log.debug("Bar ServiceManager service_request size of response is " + receive.len);
    assertEquals(string, expectedResponse);
    proxy.close();
    factory.close();
}
Also used : TransportFactory(org.jboss.narayana.blacktie.jatmibroker.core.transport.TransportFactory) Sender(org.jboss.narayana.blacktie.jatmibroker.core.transport.Sender) Message(org.jboss.narayana.blacktie.jatmibroker.core.transport.Message) Receiver(org.jboss.narayana.blacktie.jatmibroker.core.transport.Receiver) AtmiBrokerEnvXML(org.jboss.narayana.blacktie.jatmibroker.core.conf.AtmiBrokerEnvXML) Properties(java.util.Properties) Transport(org.jboss.narayana.blacktie.jatmibroker.core.transport.Transport)

Example 4 with Transport

use of org.jboss.narayana.blacktie.jatmibroker.core.transport.Transport in project narayana by jbosstm.

the class ConnectionImpl method tpacall.

/**
 * Asynchronous call
 *
 * @param svc
 *            The name of the service to call
 * @param toSend
 *            The inbound data
 * @param flags
 *            The flags to use
 * @return The connection descriptor
 * @throws ConnectionException
 *             If the service cannot be contacted.
 */
public int tpacall(String svc, Buffer toSend, int flags) throws ConnectionException {
    log.debug("tpacall");
    int toCheck = flags & ~(TPNOTRAN | TPNOREPLY | TPNOBLOCK | TPNOTIME | TPSIGRSTRT);
    if (toCheck != 0) {
        log.trace("invalid flags remain: " + toCheck);
        throw new ConnectionException(ConnectionImpl.TPEINVAL, "Invalid flags remain: " + toCheck);
    }
    svc = svc.substring(0, Math.min(ConnectionImpl.XATMI_SERVICE_NAME_LENGTH, svc.length()));
    String qtype = (String) properties.get("blacktie." + svc + ".type");
    log.debug(svc + " qtype is " + qtype + " and flags is " + flags);
    if ("topic".equals(qtype) && (flags & TPNOREPLY) == 0) {
        log.warn(svc + " type is " + qtype + " and MUST have TPNOREPLY set");
        throw new ConnectionException(ConnectionImpl.TPEINVAL, svc + " type is " + qtype + " and MUST have TPNOREPLY set");
    }
    int correlationId = 0;
    synchronized (this) {
        correlationId = ++nextId;
        log.trace("Allocated next sessionId: " + correlationId);
    }
    Transport transport = getTransport(svc);
    Receiver endpoint = transport.createReceiver(correlationId, responseMonitor, null);
    temporaryQueues.put(correlationId, endpoint);
    log.trace("Added a queue for: " + correlationId);
    // 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;
    // Don't set ttl when tpacall and TPNOREPLY set
    if (timeToLive != null && ((flags & ConnectionImpl.TPNOREPLY) != ConnectionImpl.TPNOREPLY)) {
        ttl = Integer.parseInt(timeToLive) * 1000;
        log.debug("Set ttl: " + ttl);
    }
    transport.getSender(svc, false).send(endpoint.getReplyTo(), (short) 0, 0, data, len, correlationId, flags, ttl, type, subtype);
    if ((flags & ConnectionImpl.TPNOREPLY) == ConnectionImpl.TPNOREPLY) {
        correlationId = 0;
    }
    log.debug("Returning cd: " + correlationId);
    return correlationId;
}
Also used : Codec(org.jboss.narayana.blacktie.jatmibroker.core.transport.Codec) Receiver(org.jboss.narayana.blacktie.jatmibroker.core.transport.Receiver) 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)

Example 5 with Transport

use of org.jboss.narayana.blacktie.jatmibroker.core.transport.Transport in project narayana by jbosstm.

the class ConnectionImpl method getTransport.

private Transport getTransport(String serviceName) throws ConnectionException {
    Transport toReturn = transports.get(serviceName);
    if (toReturn == null) {
        toReturn = transportFactory.createTransport();
        transports.put(serviceName, toReturn);
    }
    return toReturn;
}
Also used : Transport(org.jboss.narayana.blacktie.jatmibroker.core.transport.Transport)

Aggregations

Transport (org.jboss.narayana.blacktie.jatmibroker.core.transport.Transport)6 Receiver (org.jboss.narayana.blacktie.jatmibroker.core.transport.Receiver)4 ConnectionException (org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException)3 CodecFactory (org.jboss.narayana.blacktie.jatmibroker.codec.CodecFactory)2 Codec (org.jboss.narayana.blacktie.jatmibroker.core.transport.Codec)2 Properties (java.util.Properties)1 AtmiBrokerEnvXML (org.jboss.narayana.blacktie.jatmibroker.core.conf.AtmiBrokerEnvXML)1 ConfigurationException (org.jboss.narayana.blacktie.jatmibroker.core.conf.ConfigurationException)1 Message (org.jboss.narayana.blacktie.jatmibroker.core.transport.Message)1 Sender (org.jboss.narayana.blacktie.jatmibroker.core.transport.Sender)1 TransportFactory (org.jboss.narayana.blacktie.jatmibroker.core.transport.TransportFactory)1 ResponseException (org.jboss.narayana.blacktie.jatmibroker.xatmi.ResponseException)1