use of org.apache.activemq.artemis.api.core.ActiveMQInterruptedException in project activemq-artemis by apache.
the class TimedBuffer method start.
public void start() {
enterCritical(CRITICAL_PATH_START);
try {
synchronized (this) {
if (started) {
return;
}
// Need to start with the spin limiter acquired
try {
spinLimiter.acquire();
} catch (InterruptedException e) {
throw new ActiveMQInterruptedException(e);
}
timerRunnable = new CheckTimer();
timerThread = new Thread(timerRunnable, "activemq-buffer-timeout");
timerThread.start();
if (logRates) {
logRatesTimerTask = new LogRatesTimerTask();
logRatesTimer.scheduleAtFixedRate(logRatesTimerTask, 2000, 2000);
}
started = true;
}
} finally {
leaveCritical(CRITICAL_PATH_START);
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQInterruptedException in project activemq-artemis by apache.
the class ActiveMQMessageProducer method doSendx.
private void doSendx(ActiveMQDestination destination, final Message jmsMessage, final int deliveryMode, final int priority, final long timeToLive, CompletionListener completionListener) throws JMSException {
jmsMessage.setJMSDeliveryMode(deliveryMode);
jmsMessage.setJMSPriority(priority);
if (timeToLive == 0) {
jmsMessage.setJMSExpiration(0);
} else {
jmsMessage.setJMSExpiration(System.currentTimeMillis() + timeToLive);
}
if (!disableMessageTimestamp) {
jmsMessage.setJMSTimestamp(System.currentTimeMillis());
} else {
jmsMessage.setJMSTimestamp(0);
}
SimpleString address = null;
if (destination == null) {
if (defaultDestination == null) {
throw new UnsupportedOperationException("Destination must be specified on send with an anonymous producer");
}
destination = defaultDestination;
} else {
if (defaultDestination != null) {
if (!destination.equals(defaultDestination)) {
throw new UnsupportedOperationException("Where a default destination is specified " + "for the sender and a destination is " + "specified in the arguments to the send, " + "these destinations must be equal");
}
}
address = destination.getSimpleAddress();
if (!connection.containsKnownDestination(address)) {
try {
ClientSession.AddressQuery query = clientSession.addressQuery(address);
if (!query.isExists()) {
if (destination.isQueue() && query.isAutoCreateQueues()) {
clientSession.createAddress(address, RoutingType.ANYCAST, true);
if (destination.isTemporary()) {
// TODO is it right to use the address for the queue name here?
clientSession.createTemporaryQueue(address, RoutingType.ANYCAST, address);
} else {
createQueue(destination, RoutingType.ANYCAST, address, null, true, true, query.getDefaultMaxConsumers(), query.isDefaultPurgeOnNoConsumers(), query.isDefaultExclusive(), query.isDefaultLastValueQueue());
}
} else if (!destination.isQueue() && query.isAutoCreateAddresses()) {
clientSession.createAddress(address, RoutingType.MULTICAST, true);
} else if ((destination.isQueue() && !query.isAutoCreateQueues()) || (!destination.isQueue() && !query.isAutoCreateAddresses())) {
throw new InvalidDestinationException("Destination " + address + " does not exist");
}
} else {
ClientSession.QueueQuery queueQuery = clientSession.queueQuery(address);
if (queueQuery.isExists()) {
connection.addKnownDestination(address);
} else if (destination.isQueue() && query.isAutoCreateQueues()) {
if (destination.isTemporary()) {
clientSession.createTemporaryQueue(address, RoutingType.ANYCAST, address);
} else {
createQueue(destination, RoutingType.ANYCAST, address, null, true, true, query.getDefaultMaxConsumers(), query.isDefaultPurgeOnNoConsumers(), query.isDefaultExclusive(), query.isDefaultLastValueQueue());
}
}
}
} catch (ActiveMQQueueExistsException e) {
// The queue was created by another client/admin between the query check and send create queue packet
} catch (ActiveMQException e) {
throw JMSExceptionHelper.convertFromActiveMQException(e);
}
}
}
ActiveMQMessage activeMQJmsMessage;
boolean foreign = false;
// First convert from foreign message if appropriate
if (!(jmsMessage instanceof ActiveMQMessage)) {
if (jmsMessage instanceof BytesMessage) {
activeMQJmsMessage = new ActiveMQBytesMessage((BytesMessage) jmsMessage, clientSession);
} else if (jmsMessage instanceof MapMessage) {
activeMQJmsMessage = new ActiveMQMapMessage((MapMessage) jmsMessage, clientSession);
} else if (jmsMessage instanceof ObjectMessage) {
activeMQJmsMessage = new ActiveMQObjectMessage((ObjectMessage) jmsMessage, clientSession, options);
} else if (jmsMessage instanceof StreamMessage) {
activeMQJmsMessage = new ActiveMQStreamMessage((StreamMessage) jmsMessage, clientSession);
} else if (jmsMessage instanceof TextMessage) {
activeMQJmsMessage = new ActiveMQTextMessage((TextMessage) jmsMessage, clientSession);
} else {
activeMQJmsMessage = new ActiveMQMessage(jmsMessage, clientSession);
}
// Set the destination on the original message
jmsMessage.setJMSDestination(destination);
foreign = true;
} else {
activeMQJmsMessage = (ActiveMQMessage) jmsMessage;
}
if (!disableMessageID) {
// Generate a JMS id
UUID uid = UUIDGenerator.getInstance().generateUUID();
activeMQJmsMessage.getCoreMessage().setUserID(uid);
activeMQJmsMessage.resetMessageID(null);
}
if (foreign) {
jmsMessage.setJMSMessageID(activeMQJmsMessage.getJMSMessageID());
}
activeMQJmsMessage.setJMSDestination(destination);
try {
activeMQJmsMessage.doBeforeSend();
} catch (Exception e) {
JMSException je = new JMSException(e.getMessage());
je.initCause(e);
throw je;
}
if (defaultDeliveryDelay > 0) {
activeMQJmsMessage.setJMSDeliveryTime(System.currentTimeMillis() + defaultDeliveryDelay);
}
ClientMessage coreMessage = activeMQJmsMessage.getCoreMessage();
coreMessage.putStringProperty(ActiveMQConnection.CONNECTION_ID_PROPERTY_NAME, connID);
coreMessage.setRoutingType(destination.isQueue() ? RoutingType.ANYCAST : RoutingType.MULTICAST);
try {
/**
* Using a completionListener requires wrapping using a {@link CompletionListenerWrapper},
* so we avoid it if we can.
*/
if (completionListener != null) {
clientProducer.send(address, coreMessage, new CompletionListenerWrapper(completionListener, jmsMessage, this));
} else {
clientProducer.send(address, coreMessage);
}
} catch (ActiveMQInterruptedException e) {
JMSException jmsException = new JMSException(e.getMessage());
jmsException.initCause(e);
throw jmsException;
} catch (ActiveMQException e) {
throw JMSExceptionHelper.convertFromActiveMQException(e);
} catch (java.lang.IllegalStateException e) {
JMSException je = new IllegalStateException(e.getMessage());
je.setStackTrace(e.getStackTrace());
je.initCause(e);
throw je;
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQInterruptedException in project activemq-artemis by apache.
the class LargeMessageControllerImpl method waitCompletion.
/**
* @param timeWait Milliseconds to Wait. 0 means forever
* @throws ActiveMQException
*/
@Override
public synchronized boolean waitCompletion(final long timeWait) throws ActiveMQException {
if (outStream == null) {
// There is no stream.. it will never achieve the end of streaming
return false;
}
long timeOut;
// And we will check if no packets have arrived within readTimeout milliseconds
if (timeWait != 0) {
timeOut = System.currentTimeMillis() + timeWait;
} else {
timeOut = System.currentTimeMillis() + readTimeout;
}
while (!streamEnded && handledException == null) {
try {
this.wait(timeWait == 0 ? readTimeout : timeWait);
} catch (InterruptedException e) {
throw new ActiveMQInterruptedException(e);
}
if (!streamEnded && handledException == null) {
if (timeWait != 0 && System.currentTimeMillis() > timeOut) {
throw ActiveMQClientMessageBundle.BUNDLE.timeoutOnLargeMessage();
} else if (System.currentTimeMillis() > timeOut && !packetAdded) {
throw ActiveMQClientMessageBundle.BUNDLE.timeoutOnLargeMessage();
}
}
}
checkException();
return streamEnded;
}
use of org.apache.activemq.artemis.api.core.ActiveMQInterruptedException in project activemq-artemis by apache.
the class ServerLocatorImpl method doClose.
private void doClose(final boolean sendClose) {
synchronized (stateGuard) {
if (state == STATE.CLOSED) {
if (logger.isDebugEnabled()) {
logger.debug(this + " is already closed when calling closed");
}
return;
}
state = STATE.CLOSING;
}
if (latch != null)
latch.countDown();
synchronized (connectingFactories) {
for (ClientSessionFactoryInternal csf : connectingFactories) {
csf.causeExit();
}
}
if (discoveryGroup != null) {
synchronized (this) {
try {
discoveryGroup.stop();
} catch (Exception e) {
ActiveMQClientLogger.LOGGER.failedToStopDiscovery(e);
}
}
} else {
staticConnector.disconnect();
}
synchronized (connectingFactories) {
for (ClientSessionFactoryInternal csf : connectingFactories) {
csf.causeExit();
}
for (ClientSessionFactoryInternal csf : connectingFactories) {
csf.close();
}
connectingFactories.clear();
}
Set<ClientSessionFactoryInternal> clonedFactory;
synchronized (factories) {
clonedFactory = new HashSet<>(factories);
factories.clear();
}
for (ClientSessionFactoryInternal factory : clonedFactory) {
factory.causeExit();
}
for (ClientSessionFactory factory : clonedFactory) {
if (sendClose) {
try {
factory.close();
} catch (Throwable e) {
logger.debug(e.getMessage(), e);
factory.cleanup();
}
} else {
factory.cleanup();
}
}
if (shutdownPool) {
if (threadPool != null) {
threadPool.shutdown();
try {
if (!threadPool.awaitTermination(10000, TimeUnit.MILLISECONDS)) {
ActiveMQClientLogger.LOGGER.timedOutWaitingForTermination();
}
} catch (InterruptedException e) {
throw new ActiveMQInterruptedException(e);
}
}
if (scheduledThreadPool != null) {
scheduledThreadPool.shutdown();
try {
if (!scheduledThreadPool.awaitTermination(10000, TimeUnit.MILLISECONDS)) {
ActiveMQClientLogger.LOGGER.timedOutWaitingForScheduledPoolTermination();
}
} catch (InterruptedException e) {
throw new ActiveMQInterruptedException(e);
}
}
}
synchronized (stateGuard) {
state = STATE.CLOSED;
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQInterruptedException in project activemq-artemis by apache.
the class DiscoveryGroup method waitForBroadcast.
public boolean waitForBroadcast(final long timeout) {
synchronized (waitLock) {
long start = System.currentTimeMillis();
long toWait = timeout;
while (started && !received && (toWait > 0 || timeout == 0)) {
try {
waitLock.wait(toWait);
} catch (InterruptedException e) {
throw new ActiveMQInterruptedException(e);
}
if (timeout != 0) {
long now = System.currentTimeMillis();
toWait -= now - start;
start = now;
}
}
boolean ret = received;
received = false;
return ret;
}
}
Aggregations