@Override public String toString() { if (key == null) { if (textView != null) { if (textView.startsWith("ID:")) { key = textView; } else { key = "ID:" + textView; } } else { key = producerId.toString() + ":" + producerSequenceId; } } return key; }
public String toProducerKey() { if (textView == null) { return toString(); } else { return producerId.toString() + ":" + producerSequenceId; } }
@Override public String getProducerId() { if (info != null) { return info.getProducerId().toString(); } return "NOTSET"; }
public long getLastSeqId(ProducerId id) { long result = -1; BitArrayBin bab = map.get(id.toString()); if (bab != null) { result = bab.getLastSetIndex(); } return result; }
@Override public long doGetLastProducerSequenceId(TransactionContext c, ProducerId id) throws SQLException, IOException { PreparedStatement s = null; ResultSet rs = null; try { s = c.getConnection().prepareStatement(this.statements.getLastProducerSequenceIdStatement()); s.setString(1, id.toString()); rs = s.executeQuery(); long seq = -1; if (rs.next()) { seq = rs.getLong(1); } return seq; } finally { close(rs); close(s); } }
@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); } }
@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); } }
String safeProducerId = asID(producerId.toString());
@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); } }
@Override public void doAddMessageReference(TransactionContext c, long sequence, MessageId messageID, ActiveMQDestination destination, long expirationTime, String messageRef) throws SQLException, IOException { PreparedStatement s = c.getAddMessageStatement(); try { if (s == null) { s = c.getConnection().prepareStatement(this.statements.getAddMessageStatement()); if (this.batchStatements) { c.setAddMessageStatement(s); } } s.setLong(1, messageID.getBrokerSequenceId()); s.setString(2, messageID.getProducerId().toString()); s.setLong(3, messageID.getProducerSequenceId()); s.setString(4, destination.getQualifiedName()); s.setLong(5, expirationTime); s.setString(6, messageRef); if (this.batchStatements) { s.addBatch(); } else if (s.executeUpdate() != 1) { throw new SQLException("Failed add a message"); } } finally { if (!this.batchStatements) { s.close(); } } }
s.setString(2, messageID.getProducerId().toString()); s.setLong(3, messageID.getProducerSequenceId()); s.setString(4, destination.getQualifiedName());
@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); } }
/** * 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; }
public static ObjectName createProducerName(String brokerObjectName, String connectionClientId, ProducerInfo producerInfo) throws MalformedObjectNameException { String objectNameStr = brokerObjectName; if (producerInfo.getDestination() == null) { objectNameStr += ",endpoint=dynamicProducer"; } else { objectNameStr += createDestinationProperties(producerInfo.getDestination()) + ",endpoint=Producer"; } objectNameStr += ",clientId=" + JMXSupport.encodeObjectNamePart(connectionClientId); objectNameStr += ",producerId=" + JMXSupport.encodeObjectNamePart(producerInfo.getProducerId().toString()); return new ObjectName(objectNameStr); }
/** * 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; }
@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); } }
/** * 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; } } } }
@Override public void fastProducer(ConnectionContext context, ProducerInfo producerInfo, ActiveMQDestination destination) { super.fastProducer(context, producerInfo, destination); try { if (!AdvisorySupport.isAdvisoryTopic(destination)) { ActiveMQTopic topic = AdvisorySupport.getFastProducerAdvisoryTopic(destination); ActiveMQMessage advisoryMessage = new ActiveMQMessage(); advisoryMessage.setStringProperty(AdvisorySupport.MSG_PROPERTY_PRODUCER_ID, producerInfo.getProducerId().toString()); fireAdvisory(context, topic, producerInfo, null, advisoryMessage); } } catch (Exception e) { handleFireFailure("fast producer", e); } }
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; }
@Override public String getProducerId() { if (info != null) { return info.getProducerId().toString(); } return "NOTSET"; }