public void process(VirtualHost virtualHost, ServerMessage message) { String exchangeName = message.getMessageHeader().getReplyToExchange(); String routingKey = message.getMessageHeader().getReplyToRoutingKey(); IApplicationRegistry appRegistry = virtualHost.getApplicationRegistry(); QMFService service = appRegistry.getQMFService(); QMFPackage qmfPackage = service.getPackage(_packageName); QMFClass qmfClass = qmfPackage.getQMFClass(_className); QMFCommand[] commands = new QMFCommand[2]; commands[0] = new QMFSchemaResponseCommand(this, qmfClass); commands[1] = new QMFCommandCompletionCommand(this); Exchange exchange = virtualHost.getExchangeRegistry().getExchange(exchangeName); for (QMFCommand cmd : commands) { QMFMessage responseMessage = new QMFMessage(routingKey, cmd); ArrayList<? extends BaseQueue> queues = exchange.route(responseMessage); for (BaseQueue q : queues) { try { q.enqueue(responseMessage); } catch (AMQException e) { e.printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } } } }
public void createBrokerConnection( final String transport, final String host, final int port, final boolean durable, final String authMechanism, final String username, final String password) { VirtualHost vhost = _instance.getVirtualHostRegistry().getDefaultVirtualHost(); vhost.createBrokerConnection( transport, host, port, "", durable, authMechanism, username, password); }
@Override protected void setState(State state) { super.setState(state); if (state == State.OPEN) { if (_onOpenTask != null) { _onOpenTask.run(); } _actor.message( ConnectionMessages.OPEN(getClientId(), "0-10", getClientVersion(), true, true, true)); getVirtualHost().getConnectionRegistry().registerConnection(this); } if (state == State.CLOSE_RCVD || state == State.CLOSED || state == State.CLOSING) { if (_virtualHost != null) { _virtualHost.getConnectionRegistry().deregisterConnection(this); } } if (state == State.CLOSED) { logClosed(); } }
public void registerMessageReceived(long messageSize, long timestamp) { _messagesReceived.registerEvent(1L, timestamp); _dataReceived.registerEvent(messageSize, timestamp); _virtualHost.registerMessageReceived(messageSize, timestamp); }
public void registerMessageDelivered(long messageSize) { _messagesDelivered.registerEvent(1L); _dataDelivered.registerEvent(messageSize); _virtualHost.registerMessageDelivered(messageSize); }
public void methodReceived(AMQStateManager stateManager, ExchangeDeclareBody body, int channelId) throws AMQException { AMQProtocolSession session = stateManager.getProtocolSession(); VirtualHost virtualHost = session.getVirtualHost(); ExchangeRegistry exchangeRegistry = virtualHost.getExchangeRegistry(); ExchangeFactory exchangeFactory = virtualHost.getExchangeFactory(); final AMQChannel channel = session.getChannel(channelId); if (channel == null) { throw body.getChannelNotFoundException(channelId); } final AMQShortString exchangeName = body.getExchange(); if (_logger.isDebugEnabled()) { _logger.debug( "Request to declare exchange of type " + body.getType() + " with name " + exchangeName); } synchronized (exchangeRegistry) { Exchange exchange = exchangeRegistry.getExchange(exchangeName); if (exchange == null) { if (body.getPassive() && ((body.getType() == null) || body.getType().length() == 0)) { throw body.getChannelException( AMQConstant.NOT_FOUND, "Unknown exchange: " + exchangeName); } else if (exchangeName.startsWith("amq.")) { throw body.getConnectionException( AMQConstant.NOT_ALLOWED, "Attempt to declare exchange: " + exchangeName + " which begins with reserved prefix 'amq.'."); } else if (exchangeName.startsWith("qpid.")) { throw body.getConnectionException( AMQConstant.NOT_ALLOWED, "Attempt to declare exchange: " + exchangeName + " which begins with reserved prefix 'qpid.'."); } else { try { exchange = exchangeFactory.createExchange( exchangeName == null ? null : exchangeName.intern(), body.getType() == null ? null : body.getType().intern(), body.getDurable(), body.getAutoDelete(), body.getTicket()); exchangeRegistry.registerExchange(exchange); if (exchange.isDurable()) { virtualHost.getMessageStore().createExchange(exchange); } } catch (AMQUnknownExchangeType e) { throw body.getConnectionException( AMQConstant.COMMAND_INVALID, "Unknown exchange: " + exchangeName, e); } } } else if (!exchange.getTypeShortString().equals(body.getType()) && !((body.getType() == null || body.getType().length() == 0) && body.getPassive())) { throw new AMQConnectionException( AMQConstant.NOT_ALLOWED, "Attempt to redeclare exchange: " + exchangeName + " of type " + exchange.getTypeShortString() + " to " + body.getType() + ".", body.getClazz(), body.getMethod(), body.getMajor(), body.getMinor(), null); } } if (!body.getNowait()) { MethodRegistry methodRegistry = session.getMethodRegistry(); AMQMethodBody responseBody = methodRegistry.createExchangeDeclareOkBody(); channel.sync(); session.writeFrame(responseBody.generateFrame(channelId)); } }