@Override public void oneway(Object o) throws IOException { try { final Command command = (Command) o; protocolConverter.onActiveMQCommand(command); } catch (JMSException e) { throw IOExceptionSupport.create(e); } }
@Override public void onWebSocketClose(int arg0, String arg1) { try { if (protocolLock.tryLock() || protocolLock.tryLock(ORDERLY_CLOSE_TIMEOUT, TimeUnit.SECONDS)) { LOG.debug("Stomp WebSocket closed: code[{}] message[{}]", arg0, arg1); protocolConverter.onStompCommand(new StompFrame(Stomp.Commands.DISCONNECT)); } } catch (Exception e) { LOG.debug("Failed to close STOMP WebSocket cleanly", e); } finally { if (protocolLock.isHeldByCurrentThread()) { protocolLock.unlock(); } } }
public StompTransportFilter(Transport next, WireFormat wireFormat, BrokerContext brokerContext) { super(next); this.protocolConverter = new ProtocolConverter(this, brokerContext); if (wireFormat instanceof StompWireFormat) { this.wireFormat = (StompWireFormat) wireFormat; } }
protected void onStompDisconnect(StompFrame command) throws ProtocolException { checkConnected(); sendToActiveMQ(connectionInfo.createRemoveCommand(), createResponseHandler(command)); sendToActiveMQ(new ShutdownInfo(), createResponseHandler(command)); connected.set(false); }
protected void onStompDisconnect(StompFrame command) throws ProtocolException { if (connected.get()) { sendToActiveMQ(connectionInfo.createRemoveCommand(), createResponseHandler(command)); sendToActiveMQ(new ShutdownInfo(), createResponseHandler(command)); connected.set(false); } }
onStompSend(command); } else if (action.startsWith(Stomp.Commands.ACK)) { onStompAck(command); } else if (action.startsWith(Stomp.Commands.NACK)) { onStompNack(command); } else if (action.startsWith(Stomp.Commands.BEGIN)) { onStompBegin(command); } else if (action.startsWith(Stomp.Commands.COMMIT)) { onStompCommit(command); } else if (action.startsWith(Stomp.Commands.ABORT)) { onStompAbort(command); } else if (action.startsWith(Stomp.Commands.SUBSCRIBE_PREFIX)) { onStompSubscribe(command); } else if (action.startsWith(Stomp.Commands.UNSUBSCRIBE_PREFIX)) { onStompUnsubscribe(command); } else if (action.startsWith(Stomp.Commands.CONNECT) || action.startsWith(Stomp.Commands.STOMP)) { onStompConnect(command); } else if (action.startsWith(Stomp.Commands.DISCONNECT)) { onStompDisconnect(command); } else { throw new ProtocolException("Unknown STOMP action: " + action, true); handleException(e, command); getStompTransport().onException(e);
protected void onStompUnsubscribe(StompFrame command) throws ProtocolException { checkConnected(); Map<String, String> headers = command.getHeaders(); Object o = headers.get(Stomp.Headers.Unsubscribe.DESTINATION); if (o != null) { destination = findTranslator(command.getHeaders().get(Stomp.Headers.TRANSFORMATION)).convertDestination(this, (String)o); info.setSubscriptionName(durable); info.setConnectionId(connectionId); sendToActiveMQ(info, createResponseHandler(command)); return; StompSubscription sub = iter.next(); if ((subscriptionId != null && subscriptionId.equals(sub.getSubscriptionId())) || (destination != null && destination.equals(sub.getDestination()))) { sendToActiveMQ(sub.getConsumerInfo().createRemoveCommand(), createResponseHandler(command)); iter.remove(); return;
protected void onStompSend(StompFrame command) throws IOException, JMSException { checkConnected(); Map<String, String> headers = command.getHeaders(); String stompTx = headers.get(Stomp.Headers.TRANSACTION); headers.remove("transaction"); ActiveMQMessage message = convertMessage(command); message.setProducerId(producerId); MessageId id = new MessageId(producerId, messageIdGenerator.getNextSequenceId()); message.setMessageId(id); message.setJMSTimestamp(System.currentTimeMillis()); if (stompTx != null) { TransactionId activemqTx = transactions.get(stompTx); if (activemqTx == null) { throw new ProtocolException("Invalid transaction id: " + stompTx); } message.setTransactionId(activemqTx); } message.onSend(); sendToActiveMQ(message, createResponseHandler(command)); }
handleException(exception, command); getStompTransport().onException(IOExceptionSupport.create(exception)); return; sendToActiveMQ(sessionInfo, null); sendToActiveMQ(producerInfo, new ResponseHandler() { @Override public void onResponse(ProtocolConverter converter, Response response) throws IOException {
void onMessageDispatch(MessageDispatch md, String ackId) throws IOException, JMSException { ActiveMQMessage message = (ActiveMQMessage)md.getMessage(); if (ackMode.equals(CLIENT_ACK) || ackMode.equals(INDIVIDUAL_ACK)) { synchronized (this) { dispatchedMessage.put(message.getMessageId(), md); } } else if (ackMode.equals(AUTO_ACK)) { MessageAck ack = new MessageAck(md, MessageAck.STANDARD_ACK_TYPE, 1); protocolConverter.getStompTransport().sendToActiveMQ(ack); } boolean ignoreTransformation = false; if (transformation != null && !( message instanceof ActiveMQBytesMessage ) ) { message.setReadOnlyProperties(false); message.setStringProperty(Stomp.Headers.TRANSFORMATION, transformation); } else { if (message.getStringProperty(Stomp.Headers.TRANSFORMATION) != null) { ignoreTransformation = true; } } StompFrame command = protocolConverter.convertMessage(message, ignoreTransformation); command.setAction(Stomp.Responses.MESSAGE); if (subscriptionId != null) { command.getHeaders().put(Stomp.Headers.Message.SUBSCRIPTION, subscriptionId); } if (ackId != null) { command.getHeaders().put(Stomp.Headers.Message.ACK_ID, ackId); } protocolConverter.getStompTransport().sendToStomp(command); }
@Override void onMessageDispatch(MessageDispatch md, String ackId) throws IOException, JMSException { if (md.getMessage() != null) { super.onMessageDispatch(md, ackId); } else { StompFrame browseDone = new StompFrame(Stomp.Responses.MESSAGE); browseDone.getHeaders().put(Stomp.Headers.Message.SUBSCRIPTION, this.getSubscriptionId()); browseDone.getHeaders().put(Stomp.Headers.Message.BROWSER, "end"); browseDone.getHeaders().put(Stomp.Headers.Message.DESTINATION, protocolConverter.findTranslator(null).convertDestination(protocolConverter, this.destination)); browseDone.getHeaders().put(Stomp.Headers.Message.MESSAGE_ID, "0"); protocolConverter.sendToStomp(browseDone); } }
protected FrameTranslator findTranslator(String header) { return findTranslator(header, null, false); }
protected void sendToActiveMQ(Command command, ResponseHandler handler) { command.setCommandId(generateCommandId()); if (handler != null) { command.setResponseRequired(true); resposeHandlers.put(Integer.valueOf(command.getCommandId()), handler); } stompTransport.sendToActiveMQ(command); }
@Override public String convertDestination(ProtocolConverter converter, Destination d) { if (d == null) { return null; } ActiveMQDestination activeMQDestination = (ActiveMQDestination)d; String physicalName = activeMQDestination.getPhysicalName(); String rc = converter.getCreatedTempDestinationName(activeMQDestination); if( rc!=null ) { return rc; } StringBuilder buffer = new StringBuilder(); if (activeMQDestination.isQueue()) { if (activeMQDestination.isTemporary()) { buffer.append("/remote-temp-queue/"); } else { buffer.append("/queue/"); } } else { if (activeMQDestination.isTemporary()) { buffer.append("/remote-temp-topic/"); } else { buffer.append("/topic/"); } } buffer.append(physicalName); return buffer.toString(); }
void onStompCommit(TransactionId transactionId) { MessageAck ack = null; synchronized (this) { for (Iterator<?> iter = dispatchedMessage.entrySet().iterator(); iter.hasNext();) { @SuppressWarnings("rawtypes") Map.Entry entry = (Entry)iter.next(); MessageDispatch msg = (MessageDispatch)entry.getValue(); if (unconsumedMessage.contains(msg)) { iter.remove(); } } // For individual Ack we already sent an Ack that will be applied on commit // we don't send a second standard Ack as that would produce an error. if (!unconsumedMessage.isEmpty() && ackMode == CLIENT_ACK) { ack = new MessageAck(unconsumedMessage.getLast(), MessageAck.STANDARD_ACK_TYPE, unconsumedMessage.size()); ack.setTransactionId(transactionId); unconsumedMessage.clear(); } } // avoid contention with onMessageDispatch if (ack != null) { protocolConverter.getStompTransport().sendToActiveMQ(ack); } }
onStompSend(command); } else if (action.startsWith(Stomp.Commands.ACK)) { onStompAck(command); } else if (action.startsWith(Stomp.Commands.NACK)) { onStompNack(command); } else if (action.startsWith(Stomp.Commands.BEGIN)) { onStompBegin(command); } else if (action.startsWith(Stomp.Commands.COMMIT)) { onStompCommit(command); } else if (action.startsWith(Stomp.Commands.ABORT)) { onStompAbort(command); } else if (action.startsWith(Stomp.Commands.SUBSCRIBE_PREFIX)) { onStompSubscribe(command); } else if (action.startsWith(Stomp.Commands.UNSUBSCRIBE_PREFIX)) { onStompUnsubscribe(command); } else if (action.startsWith(Stomp.Commands.CONNECT) || action.startsWith(Stomp.Commands.STOMP)) { onStompConnect(command); } else if (action.startsWith(Stomp.Commands.DISCONNECT)) { onStompDisconnect(command); } else { throw new ProtocolException("Unknown STOMP action: " + action, true); handleException(e, command); getStompTransport().onException(e);
protected void onStompCommit(StompFrame command) throws ProtocolException { checkConnected(); Map<String, String> headers = command.getHeaders(); String stompTx = headers.get(Stomp.Headers.TRANSACTION); if (stompTx == null) { throw new ProtocolException("Must specify the transaction you are committing"); } TransactionId activemqTx = transactions.remove(stompTx); if (activemqTx == null) { throw new ProtocolException("Invalid transaction id: " + stompTx); } for (Iterator<StompSubscription> iter = subscriptionsByConsumerId.values().iterator(); iter.hasNext();) { StompSubscription sub = iter.next(); sub.onStompCommit(activemqTx); } TransactionInfo tx = new TransactionInfo(); tx.setConnectionId(connectionId); tx.setTransactionId(activemqTx); tx.setType(TransactionInfo.COMMIT_ONE_PHASE); sendToActiveMQ(tx, createResponseHandler(command)); }
protected void onStompUnsubscribe(StompFrame command) throws ProtocolException { checkConnected(); Map<String, String> headers = command.getHeaders(); Object o = headers.get(Stomp.Headers.Unsubscribe.DESTINATION); if (o != null) { destination = findTranslator(command.getHeaders().get(Stomp.Headers.TRANSFORMATION)).convertDestination(this, (String)o, true); info.setSubscriptionName(durable); info.setConnectionId(connectionId); sendToActiveMQ(info, createResponseHandler(command)); return; StompSubscription sub = this.subscriptions.remove(subscriptionId); if (sub != null) { sendToActiveMQ(sub.getConsumerInfo().createRemoveCommand(), createResponseHandler(command)); return; StompSubscription sub = iter.next(); if (destination != null && destination.equals(sub.getDestination())) { sendToActiveMQ(sub.getConsumerInfo().createRemoveCommand(), createResponseHandler(command)); iter.remove(); return;
protected void onStompSend(StompFrame command) throws IOException, JMSException { checkConnected(); Map<String, String> headers = command.getHeaders(); String destination = headers.get(Stomp.Headers.Send.DESTINATION); if (destination == null) { throw new ProtocolException("SEND received without a Destination specified!"); } String stompTx = headers.get(Stomp.Headers.TRANSACTION); headers.remove("transaction"); ActiveMQMessage message = convertMessage(command); message.setProducerId(producerId); MessageId id = new MessageId(producerId, messageIdGenerator.getNextSequenceId()); message.setMessageId(id); if (stompTx != null) { TransactionId activemqTx = transactions.get(stompTx); if (activemqTx == null) { throw new ProtocolException("Invalid transaction id: " + stompTx); } message.setTransactionId(activemqTx); } message.onSend(); message.beforeMarshall(null); sendToActiveMQ(message, createResponseHandler(command)); }
handleException(exception, command); getStompTransport().onException(IOExceptionSupport.create(exception)); return; sendToActiveMQ(sessionInfo, null); sendToActiveMQ(producerInfo, new ResponseHandler() { @Override public void onResponse(ProtocolConverter converter, Response response) throws IOException {