use of org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException in project activemq-artemis by apache.
the class ServerSessionPacketHandler method onCatchThrowableWhileHandlePacket.
private static Packet onCatchThrowableWhileHandlePacket(Throwable t, boolean requiresResponse, Packet response, ServerSession session) {
session.markTXFailed(t);
if (requiresResponse) {
ActiveMQServerLogger.LOGGER.sendingUnexpectedExceptionToClient(t);
ActiveMQException activeMQInternalErrorException = new ActiveMQInternalErrorException();
activeMQInternalErrorException.initCause(t);
response = new ActiveMQExceptionMessage(activeMQInternalErrorException);
} else {
ActiveMQServerLogger.LOGGER.caughtException(t);
}
return response;
}
use of org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException in project activemq-artemis by apache.
the class JournalStorageManager method deleteLargeMessageFile.
// This should be accessed from this package only
void deleteLargeMessageFile(final LargeServerMessage largeServerMessage) throws ActiveMQException {
if (largeServerMessage.getPendingRecordID() < 0) {
try {
// The delete file happens asynchronously
// And the client won't be waiting for the actual file to be deleted.
// We set a temporary record (short lived) on the journal
// to avoid a situation where the server is restarted and pending large message stays on forever
largeServerMessage.setPendingRecordID(storePendingLargeMessage(largeServerMessage.getMessageID(), largeServerMessage.getPendingRecordID()));
} catch (Exception e) {
throw new ActiveMQInternalErrorException(e.getMessage(), e);
}
}
final SequentialFile file = largeServerMessage.getFile();
if (file == null) {
return;
}
if (largeServerMessage.isDurable() && isReplicated()) {
readLock();
try {
if (isReplicated() && replicator.isSynchronizing()) {
synchronized (largeMessagesToDelete) {
largeMessagesToDelete.add(Long.valueOf(largeServerMessage.getMessageID()));
confirmLargeMessage(largeServerMessage);
}
return;
}
} finally {
readUnLock();
}
}
Runnable deleteAction = new Runnable() {
@Override
public void run() {
try {
readLock();
try {
if (replicator != null) {
replicator.largeMessageDelete(largeServerMessage.getMessageID(), JournalStorageManager.this);
}
file.delete();
// The confirm could only be done after the actual delete is done
confirmLargeMessage(largeServerMessage);
} finally {
readUnLock();
}
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.journalErrorDeletingMessage(e, largeServerMessage.getMessageID());
}
}
};
if (executor == null) {
deleteAction.run();
} else {
executor.execute(deleteAction);
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException in project activemq-artemis by apache.
the class LargeServerMessageImpl method validateFile.
// Private -------------------------------------------------------
public synchronized void validateFile() throws ActiveMQException {
try {
if (file == null) {
if (messageID <= 0) {
throw new RuntimeException("MessageID not set on LargeMessage");
}
file = createFile();
openFile();
bodySize = file.size();
}
} catch (Exception e) {
// TODO: There is an IO_ERROR on trunk now, this should be used here instead
throw new ActiveMQInternalErrorException(e.getMessage(), e);
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException in project activemq-artemis by apache.
the class ActiveMQPacketHandler method handleReattachSession.
private void handleReattachSession(final ReattachSessionMessage request) {
Packet response = null;
try {
if (!server.isStarted()) {
response = new ReattachSessionResponseMessage(-1, false);
}
logger.debug("Reattaching request from " + connection.getRemoteAddress());
ServerSessionPacketHandler sessionHandler = protocolManager.getSessionHandler(request.getName());
// HORNETQ-720 XXX ataylor?
if (/*!server.checkActivate() || */
sessionHandler == null) {
response = new ReattachSessionResponseMessage(-1, false);
} else {
if (sessionHandler.getChannel().getConfirmationWindowSize() == -1) {
// Even though session exists, we can't reattach since confi window size == -1,
// i.e. we don't have a resend cache for commands, so we just close the old session
// and let the client recreate
ActiveMQServerLogger.LOGGER.reattachRequestFailed(connection.getRemoteAddress());
sessionHandler.closeListeners();
sessionHandler.close();
response = new ReattachSessionResponseMessage(-1, false);
} else {
// Reconnect the channel to the new connection
int serverLastConfirmedCommandID = sessionHandler.transferConnection(connection, request.getLastConfirmedCommandID());
response = new ReattachSessionResponseMessage(serverLastConfirmedCommandID, true);
}
}
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.failedToReattachSession(e);
response = new ActiveMQExceptionMessage(new ActiveMQInternalErrorException());
}
channel1.send(response);
}
use of org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException in project activemq-artemis by apache.
the class CloseDestroyedConnectionTest method testCloseDestroyedConnection.
/*
* Closing a connection that is destroyed should cleanly close everything without throwing exceptions
*/
@Test
public void testCloseDestroyedConnection() throws Exception {
long connectionTTL = 500;
cf.setClientFailureCheckPeriod(connectionTTL / 2);
// Need to set connection ttl to a low figure so connections get removed quickly on the server
cf.setConnectionTTL(connectionTTL);
conn = cf.createConnection();
Assert.assertEquals(1, server.getRemotingService().getConnections().size());
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Give time for the initial ping to reach the server before we fail (it has connection TTL in it)
Thread.sleep(500);
String queueName = "myqueue";
Queue queue = ActiveMQJMSClient.createQueue(queueName);
super.createQueue(queueName);
sess.createConsumer(queue);
sess.createProducer(queue);
sess.createBrowser(queue);
// Now fail the underlying connection
ClientSessionInternal sessi = (ClientSessionInternal) ((ActiveMQSession) sess).getCoreSession();
RemotingConnection rc = sessi.getConnection();
rc.fail(new ActiveMQInternalErrorException());
// Now close the connection
conn.close();
long start = System.currentTimeMillis();
while (true) {
int cons = server.getRemotingService().getConnections().size();
if (cons == 0) {
break;
}
long now = System.currentTimeMillis();
if (now - start > 10000) {
throw new Exception("Timed out waiting for connections to close");
}
Thread.sleep(50);
}
}
Aggregations