private void closeChildren() throws ActiveMQException { Set<ClientConsumerInternal> consumersClone = cloneConsumers(); for (ClientConsumer consumer : consumersClone) { consumer.close(); } Set<ClientProducerInternal> producersClone = cloneProducers(); for (ClientProducer producer : producersClone) { producer.close(); } }
@Override public ClientConsumer createConsumer(final SimpleString queueName, final SimpleString filterString, final boolean browseOnly) throws ActiveMQException { return createConsumer(queueName, filterString, consumerWindowSize, consumerMaxRate, browseOnly); }
/** * @param queueName * @param filterString * @param windowSize * @param browseOnly * @return * @throws ActiveMQException */ private ClientConsumer internalCreateConsumer(final SimpleString queueName, final SimpleString filterString, final int windowSize, final int maxRate, final boolean browseOnly) throws ActiveMQException { checkClosed(); ClientConsumerInternal consumer = sessionContext.createConsumer(queueName, filterString, windowSize, maxRate, ackBatchSize, browseOnly, executor, flowControlExecutor); addConsumer(consumer); // Now we send window size credits to start the consumption // We even send it if windowSize == -1, since we need to start the // consumer // TODO: this could semantically change on other servers. I know for instance on stomp this is just an ignore if (windowSize != 0) { sessionContext.sendConsumerCredits(consumer, windowSize); } return consumer; }
@Override public void deleteQueue(final SimpleString queueName) throws ActiveMQException { checkClosed(); startCall(); try { sessionContext.deleteQueue(queueName); } finally { endCall(); } }
@Override public synchronized void cleanUp(boolean failingOver) throws ActiveMQException { if (closed) { return; } synchronized (producerCreditManager) { producerCreditManager.close(); } cleanUpChildren(); doCleanup(failingOver); }
@Override public void end(final Xid xid, final int flags) throws XAException { if (logger.isTraceEnabled()) { logger.trace("Calling end:: " + convert(xid) + ", flags=" + convertTXFlag(flags)); checkXA(); rollback(false, false); } catch (Throwable ignored) { logger.debug("Error on rollback during end call!", ignored); flushAcks(); startCall(); try { sessionContext.xaEnd(xid, flags); } finally { endCall();
public void rollback(final boolean isLastMessageAsDelivered, final boolean waitConsumers) throws ActiveMQException { if (logger.isTraceEnabled()) { logger.trace("calling rollback(isLastMessageAsDelivered=" + isLastMessageAsDelivered + ")"); } checkClosed(); // We do a "JMS style" rollback where the session is stopped, and the buffer is cancelled back // first before rolling back // This ensures messages are received in the same order after rollback w.r.t. to messages in the buffer // For core we could just do a straight rollback, it really depends if we want JMS style semantics or not... boolean wasStarted = started; if (wasStarted) { stop(); } // We need to make sure we don't get any inflight messages for (ClientConsumerInternal consumer : cloneConsumers()) { consumer.clear(waitConsumers); } // Acks must be flushed here *after connection is stopped and all onmessages finished executing flushAcks(); sessionContext.simpleRollback(isLastMessageAsDelivered); if (wasStarted) { start(); } rollbackOnly = false; }
private ClientProducer internalCreateProducer(final SimpleString address, final int maxRate) throws ActiveMQException { checkClosed(); ClientProducerInternal producer = new ClientProducerImpl(this, address, maxRate == -1 ? null : new TokenBucketLimiterImpl(maxRate, false), autoCommitSends && blockOnNonDurableSend, autoCommitSends && blockOnDurableSend, autoGroup, groupID == null ? null : new SimpleString(groupID), minLargeMessageSize, sessionContext); addProducer(producer); return producer; }
public void stop(final boolean waitForOnMessage) throws ActiveMQException { checkClosed(); if (started) { for (ClientConsumerInternal clientConsumerInternal : cloneConsumers()) { clientConsumerInternal.stop(waitForOnMessage); } sessionContext.sessionStop(); started = false; } }
@Override public void forget(final Xid xid) throws XAException { checkXA(); startCall(); try { sessionContext.xaForget(xid); } catch (XAException xae) { throw xae; } catch (Throwable t) { // This could occur if the TM interrupts the thread XAException xaException = new XAException(XAException.XAER_RMFAIL); xaException.initCause(t); throw xaException; } finally { endCall(); } }
@Override public void commit(boolean block) throws ActiveMQException { checkClosed(); rollbackOnFailover(true); flushAcks(); rollbackOnFailover(true); rollbackOnFailover(false); } else { throw e; rollbackOnFailover(false);
@Override public ClientConsumer createConsumer(final String queueName, final String filterString, final int windowSize, final int maxRate, final boolean browseOnly) throws ActiveMQException { return createConsumer(SimpleString.toSimpleString(queueName), SimpleString.toSimpleString(filterString), windowSize, maxRate, browseOnly); }
@Override public void start(final Xid xid, final int flags) throws XAException { if (logger.isTraceEnabled()) { logger.trace("Calling start:: " + convert(xid) + " clientXID=" + xid + " flags = " + convertTXFlag(flags)); checkXA();
@Override public boolean setTransactionTimeout(final int seconds) throws XAException { checkXA(); try { return sessionContext.configureTransactionTimeout(seconds); } catch (Throwable t) { markRollbackOnly(); // The TM will ignore any errors from here, if things are this screwed up we mark rollbackonly // This could occur if the TM interrupts the thread XAException xaException = new XAException(XAException.XAER_RMFAIL); xaException.initCause(t); throw xaException; } }
@Override public void connectionFailed(final ActiveMQException me, boolean failedOver) { try { cleanUp(false); } catch (Exception e) { ActiveMQClientLogger.LOGGER.failedToCleanupSession(e); } }
private ClientSession createSessionInternal(final String username, final String password, final boolean xa, final boolean autoCommitSends, final boolean autoCommitAcks, final boolean preAcknowledge, final int ackBatchSize) throws ActiveMQException { String name = UUIDGenerator.getInstance().generateStringUUID(); SessionContext context = createSessionChannel(name, username, password, xa, autoCommitSends, autoCommitAcks, preAcknowledge); ClientSessionInternal session = new ClientSessionImpl(this, name, username, password, xa, autoCommitSends, autoCommitAcks, preAcknowledge, serverLocator.isBlockOnAcknowledge(), serverLocator.isAutoGroup(), ackBatchSize, serverLocator.getConsumerWindowSize(), serverLocator.getConsumerMaxRate(), serverLocator.getConfirmationWindowSize(), serverLocator.getProducerWindowSize(), serverLocator.getProducerMaxRate(), serverLocator.isBlockOnNonDurableSend(), serverLocator.isBlockOnDurableSend(), serverLocator.isCacheLargeMessagesClient(), serverLocator.getMinLargeMessageSize(), serverLocator.isCompressLargeMessage(), serverLocator.getInitialMessagePacketSize(), serverLocator.getGroupID(), context, orderedExecutorFactory.getExecutor(), orderedExecutorFactory.getExecutor(), orderedExecutorFactory.getExecutor()); synchronized (sessions) { if (closed || !clientProtocolManager.isAlive()) { session.close(); return null; } sessions.add(session); } return session; }
@Override public boolean isSameRM(final XAResource xares) throws XAException { checkXA(); if (forceNotSameRM) { return false; } ClientSessionInternal other = getSessionInternalFromXAResource(xares); if (other == null) { return false; } String liveNodeId = sessionFactory.getLiveNodeId(); String otherLiveNodeId = ((ClientSessionFactoryInternal) other.getSessionFactory()).getLiveNodeId(); if (liveNodeId != null && otherLiveNodeId != null) { return liveNodeId.equals(otherLiveNodeId); } //we shouldn't get here, live node id should always be set return sessionFactory == other.getSessionFactory(); }
@Override public int getTransactionTimeout() throws XAException { checkXA(); try { return sessionContext.recoverSessionTimeout(); } catch (Throwable t) { // This could occur if the TM interrupts the thread XAException xaException = new XAException(XAException.XAER_RMFAIL); xaException.initCause(t); throw xaException; } }