Search in sources :

Example 1 with Sender

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

the class TransportImpl method createSender.

public Sender createSender(Object destination) throws ConnectionException {
    if (closed) {
        log.error("Already closed");
        throw new ConnectionException(Connection.TPEPROTO, "Already closed");
    }
    Sender sender;
    String callback_ior = (String) destination;
    log.debug("Creating a sender for: " + callback_ior);
    if (callback_ior.contains("IOR:")) {
        log.debug(callback_ior + " is for corba");
        throw new ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.Connection.TPESYSTEM, "Could not create a Corba sender");
    } else {
        log.debug(callback_ior + " is for socket");
        sender = new SocketSenderImpl(callback_ior);
    }
    log.debug("Created sender");
    return sender;
}
Also used : Sender(org.jboss.narayana.blacktie.jatmibroker.core.transport.Sender) ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException)

Example 2 with Sender

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

the class TransportImpl method getSender.

public Sender getSender(String serviceName, boolean conversational) throws ConnectionException {
    if (closed) {
        log.error("Already closed");
        throw new ConnectionException(Connection.TPEPROTO, "Already closed");
    }
    log.debug("Get sender: " + serviceName);
    Map<String, Sender> conversationalMap = senders.get(conversational);
    if (conversationalMap == null) {
        conversationalMap = new HashMap<String, Sender>();
        senders.put(conversational, conversationalMap);
    }
    Sender toReturn = conversationalMap.get(serviceName);
    if (toReturn == null) {
        try {
            String type = (String) properties.get("blacktie." + serviceName + ".type");
            toReturn = new StompSenderImpl(serviceName, conversational, type, conversationalMap, properties);
            conversationalMap.put(serviceName, toReturn);
        } catch (ConnectionException e) {
            throw e;
        } catch (Throwable t) {
            throw new ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.Connection.TPESYSTEM, "Could not create a service sender: " + t.getMessage(), t);
        }
    }
    return toReturn;
}
Also used : Sender(org.jboss.narayana.blacktie.jatmibroker.core.transport.Sender) StompSenderImpl(org.jboss.narayana.blacktie.jatmibroker.core.transport.hybrid.stomp.StompSenderImpl) ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException)

Example 3 with Sender

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

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

the class TestConnection method test.

public void test() throws ConnectionException, IOException {
    Receiver serviceDispatcher = serviceTransport.getReceiver("JAVA_Converse", false);
    Sender clientSender = clientTransport.getSender("JAVA_Converse", false);
    Receiver clientReceiver = clientTransport.createReceiver(1, null, null);
    clientSender.send(clientReceiver.getReplyTo(), (short) 1, 1, "hi".getBytes(), 2, 0, 0, 0, "X_OCTET", null);
    Message receive = serviceDispatcher.receive(0);
    receive.ack();
    assertTrue(receive.len == 2);
    Sender serviceSender = serviceTransport.createSender(receive.replyTo);
    Receiver serviceReceiver = serviceTransport.createReceiver(1, null, null);
    log.info("Chatting");
    for (int i = 0; i < 100; i++) {
        String toSend = String.valueOf(i);
        serviceSender.send(serviceReceiver.getReplyTo(), (short) 1, 1, toSend.getBytes(), toSend.length(), 0, 0, 0, "X_OCTET", null);
        Message receive2 = clientReceiver.receive(0);
        assertTrue(receive2.len == toSend.length());
        String received = new String(receive2.data);
        assertTrue(received + " " + toSend, received.equals(toSend));
    }
    log.info("Chatted");
}
Also used : 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)

Aggregations

Sender (org.jboss.narayana.blacktie.jatmibroker.core.transport.Sender)4 Message (org.jboss.narayana.blacktie.jatmibroker.core.transport.Message)2 Receiver (org.jboss.narayana.blacktie.jatmibroker.core.transport.Receiver)2 ConnectionException (org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException)2 Properties (java.util.Properties)1 AtmiBrokerEnvXML (org.jboss.narayana.blacktie.jatmibroker.core.conf.AtmiBrokerEnvXML)1 Transport (org.jboss.narayana.blacktie.jatmibroker.core.transport.Transport)1 TransportFactory (org.jboss.narayana.blacktie.jatmibroker.core.transport.TransportFactory)1 StompSenderImpl (org.jboss.narayana.blacktie.jatmibroker.core.transport.hybrid.stomp.StompSenderImpl)1