use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class QueueControlImpl method browse.
@Override
public CompositeData[] browse(String filter) throws Exception {
checkStarted();
clearIO();
try {
int pageSize = addressSettingsRepository.getMatch(queue.getName().toString()).getManagementBrowsePageSize();
int currentPageSize = 0;
ArrayList<CompositeData> c = new ArrayList<>();
Filter thefilter = FilterImpl.createFilter(filter);
queue.flushExecutor();
try (LinkedListIterator<MessageReference> iterator = queue.browserIterator()) {
try {
while (iterator.hasNext() && currentPageSize++ < pageSize) {
MessageReference ref = iterator.next();
if (thefilter == null || thefilter.match(ref.getMessage())) {
c.add(OpenTypeSupport.convert(ref));
}
}
} catch (NoSuchElementException ignored) {
// this could happen through paging browsing
}
CompositeData[] rc = new CompositeData[c.size()];
c.toArray(rc);
return rc;
}
} catch (ActiveMQException e) {
throw new IllegalStateException(e.getMessage());
} finally {
blockOnIO();
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class ChannelImpl method sendBlocking.
/**
* Due to networking issues or server issues the server may take longer to answer than expected.. the client may timeout the call throwing an exception
* and the client could eventually retry another call, but the server could then answer a previous command issuing a class-cast-exception.
* The expectedPacket will be used to filter out undesirable packets that would belong to previous calls.
*/
@Override
public Packet sendBlocking(final Packet packet, final int reconnectID, byte expectedPacket) throws ActiveMQException {
String interceptionResult = invokeInterceptors(packet, interceptors, connection);
if (interceptionResult != null) {
if (logger.isTraceEnabled()) {
logger.trace("RemotingConnectionID=" + (connection == null ? "NULL" : connection.getID()) + " interceptionResult=" + interceptionResult);
}
// if we don't throw an exception here the client might not unblock
throw ActiveMQClientMessageBundle.BUNDLE.interceptorRejectedPacket(interceptionResult);
}
if (closed) {
if (logger.isTraceEnabled()) {
logger.trace("RemotingConnectionID=" + (connection == null ? "NULL" : connection.getID()) + " closed.");
}
throw ActiveMQClientMessageBundle.BUNDLE.connectionDestroyed();
}
if (connection.getBlockingCallTimeout() == -1) {
if (logger.isTraceEnabled()) {
logger.trace("RemotingConnectionID=" + (connection == null ? "NULL" : connection.getID()) + " Cannot do a blocking call timeout on a server side connection");
}
throw new IllegalStateException("Cannot do a blocking call timeout on a server side connection");
}
// E.g. blocking acknowledge() from inside a message handler at some time as other operation on main thread
synchronized (sendBlockingLock) {
packet.setChannelID(id);
final ActiveMQBuffer buffer = packet.encode(connection);
lock.lock();
try {
if (failingOver) {
waitForFailOver("RemotingConnectionID=" + (connection == null ? "NULL" : connection.getID()) + " timed-out waiting for fail-over condition on blocking send");
}
response = null;
if (resendCache != null && packet.isRequiresConfirmations()) {
addResendPacket(packet);
}
checkReconnectID(reconnectID);
if (logger.isTraceEnabled()) {
logger.trace("RemotingConnectionID=" + (connection == null ? "NULL" : connection.getID()) + " Sending blocking " + packet);
}
connection.getTransportConnection().write(buffer, false, false);
long toWait = connection.getBlockingCallTimeout();
long start = System.currentTimeMillis();
while (!closed && (response == null || (response.getType() != PacketImpl.EXCEPTION && response.getType() != expectedPacket)) && toWait > 0) {
try {
sendCondition.await(toWait, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
throw new ActiveMQInterruptedException(e);
}
if (response != null && response.getType() != PacketImpl.EXCEPTION && response.getType() != expectedPacket) {
ActiveMQClientLogger.LOGGER.packetOutOfOrder(response, new Exception("trace"));
}
if (closed) {
break;
}
final long now = System.currentTimeMillis();
toWait -= now - start;
start = now;
}
if (closed && toWait > 0 && response == null) {
Throwable cause = ActiveMQClientMessageBundle.BUNDLE.connectionDestroyed();
throw ActiveMQClientMessageBundle.BUNDLE.unblockingACall(cause);
}
if (response == null) {
throw ActiveMQClientMessageBundle.BUNDLE.timedOutSendingPacket(connection.getBlockingCallTimeout(), packet.getType());
}
if (response.getType() == PacketImpl.EXCEPTION) {
final ActiveMQExceptionMessage mem = (ActiveMQExceptionMessage) response;
ActiveMQException e = mem.getException();
e.fillInStackTrace();
throw e;
}
} finally {
lock.unlock();
}
return response;
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class ActiveMQChannelHandler method exceptionCaught.
@Override
public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) throws Exception {
if (!active) {
return;
}
// We don't want to log this - since it is normal for this to happen during failover/reconnect
// and we don't want to spew out stack traces in that event
// The user has access to this exeception anyway via the ActiveMQException initial cause
ActiveMQException me = ActiveMQClientMessageBundle.BUNDLE.nettyError();
me.initCause(cause);
synchronized (listener) {
try {
listener.connectionException(channelId(ctx.channel()), me);
active = false;
} catch (Exception ex) {
ActiveMQClientLogger.LOGGER.errorCallingLifeCycleListener(ex);
}
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class ReplicationEndpoint method handlePacket.
@Override
public void handlePacket(final Packet packet) {
if (logger.isTraceEnabled()) {
logger.trace("handlePacket::handling " + packet);
}
PacketImpl response = new ReplicationResponseMessage();
final byte type = packet.getType();
try {
if (!started) {
if (logger.isTraceEnabled()) {
logger.trace("handlePacket::ignoring " + packet);
}
return;
}
if (type == PacketImpl.REPLICATION_APPEND) {
handleAppendAddRecord((ReplicationAddMessage) packet);
} else if (type == PacketImpl.REPLICATION_APPEND_TX) {
handleAppendAddTXRecord((ReplicationAddTXMessage) packet);
} else if (type == PacketImpl.REPLICATION_DELETE) {
handleAppendDelete((ReplicationDeleteMessage) packet);
} else if (type == PacketImpl.REPLICATION_DELETE_TX) {
handleAppendDeleteTX((ReplicationDeleteTXMessage) packet);
} else if (type == PacketImpl.REPLICATION_PREPARE) {
handlePrepare((ReplicationPrepareMessage) packet);
} else if (type == PacketImpl.REPLICATION_COMMIT_ROLLBACK) {
handleCommitRollback((ReplicationCommitMessage) packet);
} else if (type == PacketImpl.REPLICATION_PAGE_WRITE) {
handlePageWrite((ReplicationPageWriteMessage) packet);
} else if (type == PacketImpl.REPLICATION_PAGE_EVENT) {
handlePageEvent((ReplicationPageEventMessage) packet);
} else if (type == PacketImpl.REPLICATION_LARGE_MESSAGE_BEGIN) {
handleLargeMessageBegin((ReplicationLargeMessageBeginMessage) packet);
} else if (type == PacketImpl.REPLICATION_LARGE_MESSAGE_WRITE) {
handleLargeMessageWrite((ReplicationLargeMessageWriteMessage) packet);
} else if (type == PacketImpl.REPLICATION_LARGE_MESSAGE_END) {
handleLargeMessageEnd((ReplicationLargeMessageEndMessage) packet);
} else if (type == PacketImpl.REPLICATION_START_FINISH_SYNC) {
response = handleStartReplicationSynchronization((ReplicationStartSyncMessage) packet);
} else if (type == PacketImpl.REPLICATION_SYNC_FILE) {
handleReplicationSynchronization((ReplicationSyncFileMessage) packet);
} else if (type == PacketImpl.REPLICATION_SCHEDULED_FAILOVER) {
handleLiveStopping((ReplicationLiveIsStoppingMessage) packet);
} else if (type == PacketImpl.BACKUP_REGISTRATION_FAILED) {
handleFatalError((BackupReplicationStartFailedMessage) packet);
} else {
ActiveMQServerLogger.LOGGER.invalidPacketForReplication(packet);
}
} catch (ActiveMQException e) {
logger.warn(e.getMessage(), e);
ActiveMQServerLogger.LOGGER.errorHandlingReplicationPacket(e, packet);
response = new ActiveMQExceptionMessage(e);
} catch (Exception e) {
logger.warn(e.getMessage(), e);
ActiveMQServerLogger.LOGGER.errorHandlingReplicationPacket(e, packet);
response = new ActiveMQExceptionMessage(ActiveMQMessageBundle.BUNDLE.replicationUnhandledError(e));
}
if (response != null) {
if (logger.isTraceEnabled()) {
logger.trace("Returning " + response);
}
channel.send(response);
} else {
logger.trace("Response is null, ignoring response");
}
}
use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.
the class ClusterConnectionImpl method onConnection.
@Override
public void onConnection(ClientSessionFactoryInternal sf) {
TopologyMember localMember = getLocalMember();
if (localMember != null) {
ClusterControl clusterControl = manager.getClusterController().connectToNodeInCluster(sf);
try {
clusterControl.authorize();
clusterControl.sendNodeAnnounce(localMember.getUniqueEventID(), manager.getNodeId(), manager.getBackupGroupName(), manager.getScaleDownGroupName(), false, localMember.getLive(), localMember.getBackup());
} catch (ActiveMQException e) {
ActiveMQServerLogger.LOGGER.clusterControlAuthfailure();
}
} else {
ActiveMQServerLogger.LOGGER.noLocalMemborOnClusterConnection(this);
}
// TODO: shouldn't we send the current time here? and change the current topology?
// sf.sendNodeAnnounce(System.currentTimeMillis(),
// manager.getNodeId(),
// false,
// localMember.getConnector().a,
// localMember.getConnector().b);
}
Aggregations