/** * Create a transaction ID object for the given encoded representation. * * @param encoded the encoded representation * @return the transaction ID object */ public static TransactionID createTransactionID(byte[] encoded) { final int length = encoded.length; if (length > 0) switch (encoded[0]) { case 1: { // local transaction. return new UserTransactionID(encoded.clone()); } case 2: { // XID. return new XidTransactionID(encoded.clone()); } default: { } } throw new IllegalArgumentException("Unrecognized Transaction ID format"); }
public UserTransactionID(final String name, final int uniqueId) { this(encode(name, uniqueId)); }
EJBSimpleTransactionControl(final EJBClientChannel channel) { this.channel = channel; final UserTransactionID transactionID = channel.allocateUserTransactionID(); this.transactionID = transactionID; simpleIdResolver = connection -> { if (channel.getChannel().getConnection() != connection) { throw Log.log.invalidTransactionConnection(); } return transactionID.getId(); }; }
UserTransactionID(final byte[] encodedForm) { super(encodedForm); // first byte is the header if (encodedForm[0] != 0x01) { throw wrongFormat(); } final int totalEncodedLength = encodedForm.length; // second byte of the encoded form is the length of the nodename bytes final int nodeNameLength = encodedForm[1]; if (nodeNameLength <= 0) { throw wrongFormat(); } // next bytes are the nodename try { nodeName = new String(encodedForm, 2, nodeNameLength, "UTF-8"); } catch (UnsupportedEncodingException e) { throw wrongFormat(); } if (totalEncodedLength < nodeNameLength + 4) { throw wrongFormat(); } // the rest is the unique ID //noinspection NumericOverflow this.id = (encodedForm[nodeNameLength + 2] & 0xff) << 24 | (encodedForm[nodeNameLength + 3] & 0xff) << 16 | (encodedForm[nodeNameLength + 4] & 0xff) << 8 | encodedForm[nodeNameLength + 5] & 0xff; }
os.writeByte(type); os.writeShort(invocation.getIndex()); final byte[] encoded = transactionID.getEncodedForm(); PackedInteger.writePackedInteger(os, encoded.length); os.write(encoded);
private static byte[] encode(final String name, final int uniqueId) { final byte[] nameBytes; try { nameBytes = name.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw wrongFormat(); } final int length = nameBytes.length; if (length > 255) { throw wrongFormat(); } final byte[] target = new byte[6 + length]; target[0] = 0x01; target[1] = (byte) length; System.arraycopy(nameBytes, 0, target, 2, length); target[2 + length] = (byte) (uniqueId >> 24); target[3 + length] = (byte) (uniqueId >> 16); target[4 + length] = (byte) (uniqueId >> 8); target[5 + length] = (byte) uniqueId; return target; }
os.writeByte(type); os.writeShort(invocation.getIndex()); final byte[] encoded = transactionID.getEncodedForm(); PackedInteger.writePackedInteger(os, encoded.length); os.write(encoded);
transactionSupplier = () -> new ImportResult<Transaction>(transactionServer.getOrBeginTransaction(((UserTransactionID) transactionId).getId(), 0), SubordinateTransactionControl.EMPTY, false); } else if (transactionId instanceof XidTransactionID) { transactionSupplier = () -> {
UserTransactionID(final byte[] encodedForm) { super(encodedForm); // first byte is the header if (encodedForm[0] != 0x01) { throw wrongFormat(); } final int totalEncodedLength = encodedForm.length; // second byte of the encoded form is the length of the nodename bytes final int nodeNameLength = encodedForm[1]; if (nodeNameLength <= 0) { throw wrongFormat(); } // next bytes are the nodename try { nodeName = new String(encodedForm, 2, nodeNameLength, "UTF-8"); } catch (UnsupportedEncodingException e) { throw wrongFormat(); } if (totalEncodedLength < nodeNameLength + 4) { throw wrongFormat(); } // the rest is the unique ID //noinspection NumericOverflow this.id = (encodedForm[nodeNameLength + 2] & 0xff) << 24 | (encodedForm[nodeNameLength + 3] & 0xff) << 16 | (encodedForm[nodeNameLength + 4] & 0xff) << 8 | encodedForm[nodeNameLength + 5] & 0xff; }
private TransactionID calculateTransactionId(final Transaction transaction) throws RollbackException, SystemException, InvalidTransactionException { final URI location = channel.getConnection().getPeerURI(); Assert.assertNotNull(transaction); if (transaction instanceof RemoteTransaction) { final RemoteTransaction remoteTransaction = (RemoteTransaction) transaction; remoteTransaction.setLocation(location); final SimpleIdResolver ir = remoteTransaction.getProviderInterface(SimpleIdResolver.class); if (ir == null) throw Logs.TXN.cannotEnlistTx(); return new UserTransactionID(channel.getConnection().getRemoteEndpointName(), ir.getTransactionId(channel.getConnection())); } else if (transaction instanceof LocalTransaction) { final LocalTransaction localTransaction = (LocalTransaction) transaction; final XAOutflowHandle outflowHandle = transactionContext.outflowTransaction(location, localTransaction); // always verify V1/2 outflows outflowHandle.verifyEnlistment(); return new XidTransactionID(outflowHandle.getXid()); } else { throw Logs.TXN.cannotEnlistTx(); } }
public UserTransactionID(final String name, final int uniqueId) { this(encode(name, uniqueId)); }
os.writeByte(type); os.writeShort(invocation.getIndex()); final byte[] encoded = transactionID.getEncodedForm(); PackedInteger.writePackedInteger(os, encoded.length); os.write(encoded);
writeFailedResponse(invId, e); } else if (transactionID instanceof UserTransactionID) try { final LocalTransaction localTransaction = transactionServer.removeTransaction(((UserTransactionID) transactionID).getId()); switch (code) { case Protocol.TXN_COMMIT_REQUEST: {
UserTransactionID(final byte[] encodedForm) { super(encodedForm); // first byte is the header if (encodedForm[0] != 0x01) { throw wrongFormat(); } final int totalEncodedLength = encodedForm.length; // second byte of the encoded form is the length of the nodename bytes final int nodeNameLength = encodedForm[1]; if (nodeNameLength <= 0) { throw wrongFormat(); } // next bytes are the nodename try { nodeName = new String(encodedForm, 2, nodeNameLength, "UTF-8"); } catch (UnsupportedEncodingException e) { throw wrongFormat(); } if (totalEncodedLength < nodeNameLength + 4) { throw wrongFormat(); } // the rest is the unique ID //noinspection NumericOverflow this.id = (encodedForm[nodeNameLength + 2] & 0xff) << 24 | (encodedForm[nodeNameLength + 3] & 0xff) << 16 | (encodedForm[nodeNameLength + 4] & 0xff) << 8 | encodedForm[nodeNameLength + 5] & 0xff; }
/** * Create a transaction ID object for the given encoded representation. * * @param encoded the encoded representation * @return the transaction ID object */ public static TransactionID createTransactionID(byte[] encoded) { final int length = encoded.length; if (length > 0) switch (encoded[0]) { case 1: { // local transaction. return new UserTransactionID(encoded.clone()); } case 2: { // XID. return new XidTransactionID(encoded.clone()); } default: { } } throw new IllegalArgumentException("Unrecognized Transaction ID format"); }
public UserTransactionID(final String name, final int uniqueId) { this(encode(name, uniqueId)); }
EJBSimpleTransactionControl(final EJBClientChannel channel) { this.channel = channel; final UserTransactionID transactionID = channel.allocateUserTransactionID(); this.transactionID = transactionID; simpleIdResolver = connection -> { if (channel.getChannel().getConnection() != connection) { throw Log.log.invalidTransactionConnection(); } return transactionID.getId(); }; }
private static byte[] encode(final String name, final int uniqueId) { final byte[] nameBytes; try { nameBytes = name.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { throw wrongFormat(); } final int length = nameBytes.length; if (length > 255) { throw wrongFormat(); } final byte[] target = new byte[6 + length]; target[0] = 0x01; target[1] = (byte) length; System.arraycopy(nameBytes, 0, target, 2, length); target[2 + length] = (byte) (uniqueId >> 24); target[3 + length] = (byte) (uniqueId >> 16); target[4 + length] = (byte) (uniqueId >> 8); target[5 + length] = (byte) uniqueId; return target; }
/** * Create a transaction ID object for the given encoded representation. * * @param encoded the encoded representation * @return the transaction ID object */ public static TransactionID createTransactionID(byte[] encoded) { final int length = encoded.length; if (length > 0) switch (encoded[0]) { case 1: { // local transaction. return new UserTransactionID(encoded.clone()); } case 2: { // XID. return new XidTransactionID(encoded.clone()); } default: { } } throw new IllegalArgumentException("Unrecognized Transaction ID format"); }
EJBSimpleTransactionControl(final EJBClientChannel channel) { this.channel = channel; final UserTransactionID transactionID = channel.allocateUserTransactionID(); this.transactionID = transactionID; simpleIdResolver = connection -> { if (channel.getChannel().getConnection() != connection) { throw Log.log.invalidTransactionConnection(); } return transactionID.getId(); }; }