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");
}
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;
}
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();
}
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;
}
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;
}
Aggregations