/** * Write the booleans that this object uses to a BooleanStream */ public void looseMarshal(OpenWireFormat wireFormat, Object o, DataOutput dataOut) throws IOException { MessageId info = (MessageId)o; super.looseMarshal(wireFormat, o, dataOut); looseMarshalCachedObject(wireFormat, (DataStructure)info.getProducerId(), dataOut); looseMarshalLong(wireFormat, info.getProducerSequenceId(), dataOut); looseMarshalLong(wireFormat, info.getBrokerSequenceId(), dataOut); } }
@Override public long[] getStoreSequenceId(TransactionContext c, ActiveMQDestination destination, MessageId messageID) throws SQLException, IOException { PreparedStatement s = null; ResultSet rs = null; try { s = c.getConnection().prepareStatement(this.statements.getFindMessageSequenceIdStatement()); s.setString(1, messageID.getProducerId().toString()); s.setLong(2, messageID.getProducerSequenceId()); s.setString(3, destination.getQualifiedName()); rs = s.executeQuery(); if (!rs.next()) { return new long[]{0,0}; } return new long[]{rs.getLong(1), rs.getLong(2)}; } finally { close(rs); close(s); } }
/** * Write the booleans that this object uses to a BooleanStream */ public int tightMarshal1(OpenWireFormat wireFormat, Object o, BooleanStream bs) throws IOException { MessageId info = (MessageId)o; int rc = super.tightMarshal1(wireFormat, o, bs); rc += tightMarshalCachedObject1(wireFormat, (DataStructure)info.getProducerId(), bs); rc += tightMarshalLong1(wireFormat, info.getProducerSequenceId(), bs); rc += tightMarshalLong1(wireFormat, info.getBrokerSequenceId(), bs); return rc + 0; }
@Override public void doUpdateMessage(TransactionContext c, ActiveMQDestination destination, MessageId id, byte[] data) throws SQLException, IOException { PreparedStatement s = null; try { s = c.getConnection().prepareStatement(this.statements.getUpdateMessageStatement()); setBinaryData(s, 1, data); s.setString(2, id.getProducerId().toString()); s.setLong(3, id.getProducerSequenceId()); s.setString(4, destination.getQualifiedName()); if (s.executeUpdate() != 1) { throw new IOException("Could not update message: " + id + " in " + destination); } } finally { close(s); } }
/** * Write the booleans that this object uses to a BooleanStream */ public int tightMarshal1(OpenWireFormat wireFormat, Object o, BooleanStream bs) throws IOException { MessageId info = (MessageId)o; int rc = super.tightMarshal1(wireFormat, o, bs); rc += tightMarshalCachedObject1(wireFormat, (DataStructure)info.getProducerId(), bs); rc+=tightMarshalLong1(wireFormat, info.getProducerSequenceId(), bs); rc+=tightMarshalLong1(wireFormat, info.getBrokerSequenceId(), bs); return rc + 0; }
@Override public byte[] doGetMessage(TransactionContext c, MessageId id) throws SQLException, IOException { PreparedStatement s = null; ResultSet rs = null; try { s = c.getConnection().prepareStatement(this.statements.getFindMessageStatement()); s.setString(1, id.getProducerId().toString()); s.setLong(2, id.getProducerSequenceId()); rs = s.executeQuery(); if (!rs.next()) { return null; } return getBinaryData(rs, 1); } finally { close(rs); close(s); } }
/** * Write the booleans that this object uses to a BooleanStream */ public void looseMarshal(OpenWireFormat wireFormat, Object o, DataOutput dataOut) throws IOException { MessageId info = (MessageId)o; super.looseMarshal(wireFormat, o, dataOut); looseMarshalCachedObject(wireFormat, (DataStructure)info.getProducerId(), dataOut); looseMarshalLong(wireFormat, info.getProducerSequenceId(), dataOut); looseMarshalLong(wireFormat, info.getBrokerSequenceId(), dataOut); } }
/** * mark this message as being received * * @param id */ public void rollback(final MessageId id) { if (id != null) { ProducerId pid = id.getProducerId(); if (pid != null) { BitArrayBin bab = map.get(pid.toString()); if (bab != null) { bab.setBit(id.getProducerSequenceId(), false); modified = true; } } } }
/** * Write the booleans that this object uses to a BooleanStream */ public void looseMarshal(OpenWireFormat wireFormat, Object o, DataOutput dataOut) throws IOException { MessageId info = (MessageId)o; super.looseMarshal(wireFormat, o, dataOut); looseMarshalCachedObject(wireFormat, (DataStructure)info.getProducerId(), dataOut); looseMarshalLong(wireFormat, info.getProducerSequenceId(), dataOut); looseMarshalLong(wireFormat, info.getBrokerSequenceId(), dataOut); } }
s.setString(2, messageID.getProducerId().toString()); s.setLong(3, messageID.getProducerSequenceId()); s.setString(4, destination.getQualifiedName()); s.setLong(5, expiration);
/** * Write the booleans that this object uses to a BooleanStream */ public void looseMarshal(OpenWireFormat wireFormat, Object o, DataOutput dataOut) throws IOException { MessageId info = (MessageId)o; super.looseMarshal(wireFormat, o, dataOut); looseMarshalCachedObject(wireFormat, (DataStructure)info.getProducerId(), dataOut); looseMarshalLong(wireFormat, info.getProducerSequenceId(), dataOut); looseMarshalLong(wireFormat, info.getBrokerSequenceId(), dataOut); } }
@Override public byte[] doGetMessage(TransactionContext c, MessageId id) throws SQLException, IOException { PreparedStatement s = null; ResultSet rs = null; try { s = c.getConnection().prepareStatement(statements.getFindMessageStatement()); s.setString(1, id.getProducerId().toString()); s.setLong(2, id.getProducerSequenceId()); rs = s.executeQuery(); if (!rs.next()) { return null; } Blob blob = rs.getBlob(1); try(InputStream is = blob.getBinaryStream(); ByteArrayOutputStream os = new ByteArrayOutputStream((int)blob.length())) { int ch; while ((ch = is.read()) >= 0) { os.write(ch); } return os.toByteArray(); } } finally { close(rs); close(s); } }
/** * Write the booleans that this object uses to a BooleanStream */ public int tightMarshal1(OpenWireFormat wireFormat, Object o, BooleanStream bs) throws IOException { MessageId info = (MessageId)o; int rc = super.tightMarshal1(wireFormat, o, bs); rc += tightMarshalCachedObject1(wireFormat, (DataStructure)info.getProducerId(), bs); rc+=tightMarshalLong1(wireFormat, info.getProducerSequenceId(), bs); rc+=tightMarshalLong1(wireFormat, info.getBrokerSequenceId(), bs); return rc + 0; }
@Override public void doAddMessage(TransactionContext c, long sequence, MessageId messageID, ActiveMQDestination destination, byte[] data, long expiration, byte priority, XATransactionId xid) throws SQLException, IOException { PreparedStatement s = null; try { // Add the Blob record. s = c.getConnection().prepareStatement(statements.getAddMessageStatement()); s.setLong(1, sequence); s.setString(2, messageID.getProducerId().toString()); s.setLong(3, messageID.getProducerSequenceId()); s.setString(4, destination.getQualifiedName()); s.setLong(5, expiration); s.setLong(6, priority); if (s.executeUpdate() != 1) { throw new IOException("Failed to add broker message: " + messageID + " in container."); } s.close(); // Select the blob record so that we can update it. updateBlob(c.getConnection(), statements.getFindMessageByIdStatement(), sequence, data); if (xid != null) { byte[] xidVal = xid.getEncodedXidBytes(); xidVal[0] = '+'; updateBlob(c.getConnection(), statements.getFindXidByIdStatement(), sequence, xidVal); } } finally { close(s); } }
/** * Write the booleans that this object uses to a BooleanStream */ public int tightMarshal1(OpenWireFormat wireFormat, Object o, BooleanStream bs) throws IOException { MessageId info = (MessageId)o; int rc = super.tightMarshal1(wireFormat, o, bs); rc += tightMarshalCachedObject1(wireFormat, (DataStructure)info.getProducerId(), bs); rc += tightMarshalLong1(wireFormat, info.getProducerSequenceId(), bs); rc += tightMarshalLong1(wireFormat, info.getBrokerSequenceId(), bs); return rc + 0; }
/** * Checks if this messageId has been seen before * * @param id * @return true if the message is a duplicate */ public boolean isDuplicate(final MessageId id) { boolean answer = false; if (id != null) { ProducerId pid = id.getProducerId(); if (pid != null) { BitArrayBin bab = map.get(pid.toString()); if (bab == null) { bab = new BitArrayBin(auditDepth); map.put(pid.toString(), bab); modified = true; } answer = bab.setBit(id.getProducerSequenceId(), true); } } return answer; }
/** * Write the booleans that this object uses to a BooleanStream */ public void looseMarshal(OpenWireFormat wireFormat, Object o, DataOutput dataOut) throws IOException { MessageId info = (MessageId)o; super.looseMarshal(wireFormat, o, dataOut); looseMarshalCachedObject(wireFormat, (DataStructure)info.getProducerId(), dataOut); looseMarshalLong(wireFormat, info.getProducerSequenceId(), dataOut); looseMarshalLong(wireFormat, info.getBrokerSequenceId(), dataOut); } }
/** * Check the MessageId is in order * * @param id * * @return true if the id is in order */ public boolean isInOrder(final MessageId id) { boolean answer = false; if (id != null) { ProducerId pid = id.getProducerId(); if (pid != null) { BitArrayBin bab = map.get(pid.toString()); if (bab == null) { bab = new BitArrayBin(auditDepth); map.put(pid.toString(), bab); modified = true; } answer = bab.isInOrder(id.getProducerSequenceId()); } } return answer; }
/** * Write the booleans that this object uses to a BooleanStream */ public void looseMarshal(OpenWireFormat wireFormat, Object o, DataOutput dataOut) throws IOException { MessageId info = (MessageId)o; super.looseMarshal(wireFormat, o, dataOut); looseMarshalCachedObject(wireFormat, (DataStructure)info.getProducerId(), dataOut); looseMarshalLong(wireFormat, info.getProducerSequenceId(), dataOut); looseMarshalLong(wireFormat, info.getBrokerSequenceId(), dataOut); } }
private LocalTransactionId beginLocalTransaction(int numDestinations, ConnectionContext connectionContext, Message message) throws Exception { LocalTransactionId result = null; if (transactedSend && numDestinations > 1 && message.isPersistent() && message.getTransactionId() == null) { result = new LocalTransactionId(new ConnectionId(message.getMessageId().getProducerId().toString()), message.getMessageId().getProducerSequenceId()); connectionContext.getBroker().beginTransaction(connectionContext, result); connectionContext.setTransaction(connectionContext.getTransactions().get(result)); message.setTransactionId(result); } return result; }