use of org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException 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.xatmi.ConnectionException 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.xatmi.ConnectionException in project narayana by jbosstm.
the class ConnectionImpl method tpalloc.
/**
* Allocate a new buffer
*
* @param type
* The type of the buffer
* @param subtype
* The subtype of the buffer
* @return The new buffer
* @throws ConnectionException
* If the buffer was unknown or invalid.
* @throws ConfigurationException
*/
public Buffer tpalloc(String type, String subtype) throws ConnectionException, ConfigurationException {
if (type == null) {
throw new ConnectionException(ConnectionImpl.TPEINVAL, "No type provided");
} else {
log.debug("Initializing a new: " + type);
try {
Class clazz = Class.forName(getClass().getPackage().getName() + "." + type + "_Impl");
Constructor ctor = clazz.getConstructor(String.class);
return (Buffer) ctor.newInstance(subtype);
} catch (InvocationTargetException t) {
if (t.getCause() instanceof ConfigurationException) {
throw ((ConfigurationException) t.getCause());
}
throw new ConnectionException(ConnectionImpl.TPENOENT, "Type was not known: " + type, t);
} catch (Throwable t) {
throw new ConnectionException(ConnectionImpl.TPENOENT, "Type was not known: " + type, t);
}
}
}
use of org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException in project narayana by jbosstm.
the class BufferImpl method deserialize.
/**
* Deserialize the buffer.
*
* @param data The data to deserialize.
* @throws ConnectionException In case the data does not match the format defined.
*/
public void deserialize(byte[] data) throws ConnectionException {
currentPos = 0;
if (requiresSerialization) {
if (!deserialized && data != null) {
if (keys == null) {
throw new ConnectionException(ConnectionImpl.TPEITYPE, "Message format not provided");
}
ByteArrayInputStream bais = new ByteArrayInputStream(data);
DataInputStream dis = new DataInputStream(bais);
for (int i = 0; i < types.length; i++) {
if (!supportedTypes.contains(types[i])) {
throw new ConnectionException(ConnectionImpl.TPEITYPE, "Cannot read type from buffer " + types[i]);
}
try {
if (types[i] == int.class) {
structure.put(keys[i], readInt(dis));
} else if (types[i] == short.class) {
structure.put(keys[i], readShort(dis));
} else if (types[i] == long.class) {
structure.put(keys[i], readLong(dis));
} else if (types[i] == byte.class) {
structure.put(keys[i], readByte(dis));
} else if (types[i] == float.class) {
structure.put(keys[i], readFloat(dis));
} else if (types[i] == double.class) {
structure.put(keys[i], readDouble(dis));
} else if (types[i] == int[].class) {
int[] toRead = new int[lengths[i]];
for (int j = 0; j < lengths[i]; j++) {
toRead[j] = readInt(dis);
}
structure.put(keys[i], toRead);
} else if (types[i] == short[].class) {
short[] toRead = new short[lengths[i]];
for (int j = 0; j < lengths[i]; j++) {
toRead[j] = readShort(dis);
}
structure.put(keys[i], toRead);
} else if (types[i] == long[].class) {
long[] toRead = new long[lengths[i]];
for (int j = 0; j < lengths[i]; j++) {
toRead[j] = readLong(dis);
}
structure.put(keys[i], toRead);
} else if (types[i] == byte[].class) {
byte[] toRead = new byte[lengths[i]];
for (int j = 0; j < lengths[i]; j++) {
toRead[j] = readByte(dis);
}
structure.put(keys[i], toRead);
} else if (types[i] == float[].class) {
float[] toRead = new float[lengths[i]];
for (int j = 0; j < lengths[i]; j++) {
toRead[j] = readFloat(dis);
}
structure.put(keys[i], toRead);
} else if (types[i] == double[].class) {
double[] toRead = new double[lengths[i]];
for (int j = 0; j < lengths[i]; j++) {
toRead[j] = readDouble(dis);
}
structure.put(keys[i], toRead);
} else if (types[i] == byte[][].class) {
byte[][] toRead = new byte[counts[i]][lengths[i]];
for (int k = 0; k < counts[i]; k++) {
for (int j = 0; j < lengths[i]; j++) {
toRead[k][j] = readByte(dis);
}
}
structure.put(keys[i], toRead);
} else {
throw new ConnectionException(ConnectionImpl.TPEITYPE, "Could not deserialize: " + types[i]);
}
} catch (IOException e) {
throw new ConnectionException(ConnectionImpl.TPEITYPE, "Could not parse the value as: " + keys[i] + " was not a " + types[i] + " and even if it was an array of that type its length was not: " + lengths[i]);
}
}
}
} else {
this.data = data;
this.len = data.length;
}
deserialized = true;
}
use of org.jboss.narayana.blacktie.jatmibroker.xatmi.ConnectionException in project narayana by jbosstm.
the class BufferImpl method serialize.
/**
* Serialize the buffer.
*
* @return The byte array for sending.
* @throws ConnectionException In case the data cannot be formatted correctly
*/
public byte[] serialize() throws ConnectionException {
currentPos = 0;
byte[] toReturn = null;
if (requiresSerialization) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
for (int i = 0; i < types.length; i++) {
try {
if (types[i] == int.class) {
Integer toWrite = (Integer) structure.get(keys[i]);
if (toWrite != null) {
writeInt(dos, toWrite);
} else {
writeInt(dos, 0);
}
} else if (types[i] == short.class) {
Short toWrite = (Short) structure.get(keys[i]);
if (toWrite != null) {
writeShort(dos, toWrite);
} else {
writeShort(dos, (short) 0);
}
} else if (types[i] == long.class) {
Long toWrite = (Long) structure.get(keys[i]);
if (toWrite != null) {
writeLong(dos, toWrite);
} else {
writeLong(dos, 0);
}
} else if (types[i] == byte.class) {
Byte toWrite = (Byte) structure.get(keys[i]);
if (toWrite != null) {
writeByte(dos, toWrite);
} else {
// writeByte(dos, '\0');
writeByte(dos, (byte) 0);
}
} else if (types[i] == float.class) {
Float toWrite = (Float) structure.get(keys[i]);
if (toWrite != null) {
writeFloat(dos, toWrite);
} else {
writeFloat(dos, 0);
}
} else if (types[i] == double.class) {
Double toWrite = (Double) structure.get(keys[i]);
if (toWrite != null) {
writeDouble(dos, toWrite);
} else {
writeDouble(dos, 0);
}
} else if (types[i] == int[].class) {
int[] toWrite = (int[]) structure.get(keys[i]);
int max = 0;
if (toWrite != null) {
max = Math.min(lengths[i], toWrite.length);
for (int j = 0; j < lengths[i]; j++) {
writeInt(dos, toWrite[j]);
}
}
for (int j = max; j < lengths[i]; j++) {
writeInt(dos, 0);
}
} else if (types[i] == short[].class) {
short[] toWrite = (short[]) structure.get(keys[i]);
int max = 0;
if (toWrite != null) {
max = Math.min(lengths[i], toWrite.length);
for (int j = 0; j < lengths[i]; j++) {
writeShort(dos, toWrite[j]);
}
}
for (int j = max; j < lengths[i]; j++) {
writeShort(dos, (short) 0);
}
} else if (types[i] == long[].class) {
long[] toWrite = (long[]) structure.get(keys[i]);
int max = 0;
if (toWrite != null) {
max = Math.min(lengths[i], toWrite.length);
for (int j = 0; j < lengths[i]; j++) {
writeLong(dos, toWrite[j]);
}
}
for (int j = max; j < lengths[i]; j++) {
writeLong(dos, 0);
}
} else if (types[i] == byte[].class) {
byte[] toWrite = (byte[]) structure.get(keys[i]);
int max = 0;
if (toWrite != null) {
max = Math.min(lengths[i], toWrite.length);
for (int j = 0; j < max; j++) {
writeByte(dos, toWrite[j]);
}
}
for (int j = max; j < lengths[i]; j++) {
// writeByte(dos, '\0');
writeByte(dos, (byte) 0);
}
} else if (types[i] == float[].class) {
float[] toWrite = (float[]) structure.get(keys[i]);
int max = 0;
if (toWrite != null) {
max = Math.min(lengths[i], toWrite.length);
for (int j = 0; j < lengths[i]; j++) {
writeFloat(dos, toWrite[j]);
}
}
for (int j = max; j < lengths[i]; j++) {
writeFloat(dos, 0);
}
} else if (types[i] == double[].class) {
double[] toWrite = (double[]) structure.get(keys[i]);
int max = 0;
if (toWrite != null) {
max = Math.min(lengths[i], toWrite.length);
for (int j = 0; j < lengths[i]; j++) {
writeDouble(dos, toWrite[j]);
}
}
for (int j = max; j < lengths[i]; j++) {
writeDouble(dos, 0);
}
} else if (types[i] == byte[][].class) {
byte[][] toWrite = (byte[][]) structure.get(keys[i]);
if (toWrite != null) {
for (int k = 0; k < counts[i]; k++) {
for (int j = 0; j < lengths[i]; j++) {
writeByte(dos, toWrite[k][j]);
}
}
} else {
for (int j = 0; j < counts[i] * lengths[i]; j++) {
writeByte(dos, (byte) 0);
}
}
} else {
if (TransactionImpl.current() != null) {
try {
TransactionImpl.current().rollback_only();
} catch (TransactionException e) {
throw new ConnectionException(ConnectionImpl.TPESYSTEM, "Could not mark transaction for rollback only");
}
}
throw new ConnectionException(ConnectionImpl.TPEOTYPE, "Could not serialize: " + types[i]);
}
} catch (IOException e) {
throw new ConnectionException(ConnectionImpl.TPEOTYPE, "Could not parse the value as: " + keys[i] + " was not a " + types[i] + " and even if it was an array of that type its length was not: " + lengths[i]);
}
}
toReturn = baos.toByteArray();
} else {
toReturn = getRawData();
}
if (toReturn == null) {
toReturn = new byte[1];
}
return toReturn;
}
Aggregations