use of org.jboss.narayana.blacktie.jatmibroker.core.transport.Receiver 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");
}
use of org.jboss.narayana.blacktie.jatmibroker.core.transport.Receiver in project narayana by jbosstm.
the class ConnectionImpl method tpcancel.
/**
* Cancel the outstanding asynchronous call.
*
* @param cd
* The connection descriptor
* @throws ConnectionException
* If the client cannot be cleaned up.
*/
public int tpcancel(int cd) throws ConnectionException {
log.debug("tpcancel: " + cd);
int toReturn = -1;
Receiver endpoint = temporaryQueues.remove(cd);
if (endpoint != null) {
log.debug("closing endpoint");
endpoint.close();
log.debug("endpoint closed");
toReturn = 0;
} else {
log.debug("No endpoint available");
throw new ConnectionException(ConnectionImpl.TPEBADDESC, "cd " + cd + " does not exist");
}
log.debug("tpcancel returning: " + toReturn);
return toReturn;
}
use of org.jboss.narayana.blacktie.jatmibroker.core.transport.Receiver in project narayana by jbosstm.
the class TransportImpl method getReceiver.
public Receiver getReceiver(String serviceName, boolean conversational) throws ConnectionException {
if (closed) {
log.error("Already closed");
throw new ConnectionException(Connection.TPEPROTO, "Already closed");
}
log.debug("Creating a receiver: " + serviceName);
Map<String, Receiver> conversationalMap = receivers.get(conversational);
if (conversationalMap == null) {
conversationalMap = new HashMap<String, Receiver>();
receivers.put(conversational, conversationalMap);
}
Receiver toReturn = conversationalMap.get(serviceName);
if (toReturn == null) {
try {
log.debug("Resolved destination");
String type = (String) properties.get("blacktie." + serviceName + ".type");
return new StompReceiverImpl(serviceName, conversational, type, properties);
} catch (ConnectionException e) {
throw e;
} catch (Throwable t) {
throw new ConnectionException(org.jboss.narayana.blacktie.jatmibroker.xatmi.Connection.TPESYSTEM, "Could not create the receiver on: " + serviceName, t);
}
}
return toReturn;
}
use of org.jboss.narayana.blacktie.jatmibroker.core.transport.Receiver 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();
}
use of org.jboss.narayana.blacktie.jatmibroker.core.transport.Receiver 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;
}
Aggregations