Search in sources :

Example 21 with ActiveMQException

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();
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) Filter(org.apache.activemq.artemis.core.filter.Filter) CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) NoSuchElementException(java.util.NoSuchElementException)

Example 22 with ActiveMQException

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;
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQExceptionMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ActiveMQExceptionMessage) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQInterruptedException(org.apache.activemq.artemis.api.core.ActiveMQInterruptedException) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 23 with ActiveMQException

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);
        }
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException)

Example 24 with ActiveMQException

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");
    }
}
Also used : ReplicationPageEventMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationPageEventMessage) ReplicationAddTXMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationAddTXMessage) ReplicationCommitMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationCommitMessage) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ReplicationLargeMessageWriteMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationLargeMessageWriteMessage) PacketImpl(org.apache.activemq.artemis.core.protocol.core.impl.PacketImpl) ActiveMQExceptionMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ActiveMQExceptionMessage) ReplicationDeleteTXMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationDeleteTXMessage) ReplicationLiveIsStoppingMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationLiveIsStoppingMessage) ReplicationResponseMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ReplicationResponseMessage) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) IOException(java.io.IOException)

Example 25 with ActiveMQException

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);
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) TopologyMember(org.apache.activemq.artemis.api.core.client.TopologyMember) ClusterControl(org.apache.activemq.artemis.core.server.cluster.ClusterControl)

Aggregations

ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)254 Test (org.junit.Test)139 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)121 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)84 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)79 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)78 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)59 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)54 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)45 CountDownLatch (java.util.concurrent.CountDownLatch)40 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)36 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)31 HashSet (java.util.HashSet)29 ActiveMQJAASSecurityManager (org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager)27 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)23 Role (org.apache.activemq.artemis.core.security.Role)22 ActiveMQSecurityException (org.apache.activemq.artemis.api.core.ActiveMQSecurityException)20 Set (java.util.Set)16 ActiveMQNotConnectedException (org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)16 Packet (org.apache.activemq.artemis.core.protocol.core.Packet)15