@Override public ProtocolEngine newProtocolEngine(Broker<?> broker, ServerNetworkConnection network, AmqpPort<?> port, Transport transport, long id, final AggregateTicker aggregateTicker) { final AMQPConnection_0_8Impl protocolEngine = new AMQPConnection_0_8Impl(broker, network, port, transport, getVersion(), id, aggregateTicker); protocolEngine.create(); return protocolEngine; }
@Override public void sendConnectionCloseAsync(final CloseReason reason, final String description) stopConnection(); final int cause; switch(reason) addAsyncTask(action);
@Override public void receiveConnectionSecureOk(final byte[] response) { if(LOGGER.isDebugEnabled()) { LOGGER.debug("RECV ConnectionSecureOk[ response: ******** ] "); } assertState(ConnectionState.AWAIT_SECURE_OK); processSaslResponse(response, getSubjectCreator()); }
private void completeAndCloseAllChannels() { try { receivedCompleteAllChannels(); } finally { closeAllChannels(); } }
public void closeChannel(int channelId, int cause, String message) { final AMQChannel channel = getChannel(channelId); if (channel == null) { throw new IllegalArgumentException("Unknown channel id"); } closeChannel(channel, cause, message, true); }
assertState(ConnectionState.OPEN); final NamedAddressSpace virtualHost = getAddressSpace(); if (virtualHost == null) sendConnectionClose(ErrorCodes.COMMAND_INVALID, "Virtualhost has not yet been set. ConnectionOpen has not been called.", channelId); else if(getChannel(channelId) != null || channelAwaitingClosure(channelId)) sendConnectionClose(ErrorCodes.CHANNEL_ERROR, "Channel " + channelId + " already exists", channelId); else if(channelId > getSessionCountLimit()) sendConnectionClose(ErrorCodes.CHANNEL_ERROR, "Channel " + channelId + " cannot be created as the max allowed channel id is " + getSessionCountLimit(), channelId); channel.create(); addChannel(channel); response = getMethodRegistry().createChannelOpenOkBody(); writeFrame(response.generateFrame(channelId));
assertState(ConnectionState.AWAIT_OPEN); NamedAddressSpace addressSpace = ((AmqpPort)getPort()).getAddressSpace(virtualHostStr); sendConnectionClose(ErrorCodes.NOT_FOUND, "Unknown virtual host: '" + virtualHostName + "'", 0); String redirectHost = addressSpace.getRedirectHost(getPort()); if(redirectHost != null) sendConnectionClose(0, new AMQFrame(0, new ConnectionRedirectBody(getProtocolVersion(), AMQShortString.valueOf(redirectHost), null))); sendConnectionClose(ErrorCodes.CONNECTION_FORCED, "Virtual host '" + addressSpace.getName() + "' is not active", 0); setAddressSpace(addressSpace); MethodRegistry methodRegistry = getMethodRegistry(); AMQMethodBody responseBody = methodRegistry.createConnectionOpenOkBody(virtualHostName); writeFrame(responseBody.generateFrame(0)); _state = ConnectionState.OPEN; sendConnectionClose(ErrorCodes.ACCESS_REFUSED, "Connection refused", 0); sendConnectionClose(ErrorCodes.ACCESS_REFUSED, e.getMessage(), 0);
assertState(ConnectionState.AWAIT_TUNE_OK); long readerDelay = 1000L * getContextValue(Integer.class, AMQPConnection_0_8.PROPERTY_HEARTBEAT_TIMEOUT_FACTOR) * heartbeat; initialiseHeartbeating(writerDelay, readerDelay); int brokerFrameMax = getDefaultMaxFrameSize(); if (brokerFrameMax <= 0) sendConnectionClose(ErrorCodes.SYNTAX_ERROR, "Attempt to set max frame size to " + frameMax + " greater than the broker will allow: " sendConnectionClose(ErrorCodes.SYNTAX_ERROR, "Attempt to set max frame size to " + frameMax + " which is smaller than the specification defined minimum: " setMaxFrameSize(calculatedFrameMax);
@Override public void receiveConnectionClose(final int replyCode, final AMQShortString replyText, final int classId, final int methodId) { if(LOGGER.isDebugEnabled()) { LOGGER.debug("RECV ConnectionClose[" +" replyCode: " + replyCode + " replyText: " + replyText + " classId: " + classId + " methodId: " + methodId + " ]"); } try { if (_orderlyClose.compareAndSet(false, true)) { completeAndCloseAllChannels(); } MethodRegistry methodRegistry = getMethodRegistry(); ConnectionCloseOkBody responseBody = methodRegistry.createConnectionCloseOkBody(); writeFrame(responseBody.generateFrame(0)); } catch (Exception e) { LOGGER.error("Error closing connection for " + getRemoteAddressString(), e); } finally { closeNetworkConnection(); } }
assertState(ConnectionState.AWAIT_START_OK); sendConnectionClose(ErrorCodes.CONNECTION_FORCED, "No Sasl mechanism was specified", 0); return; SubjectCreator subjectCreator = getSubjectCreator(); _saslNegotiator = subjectCreator.createSaslNegotiator(String.valueOf(mechanism), this); if (_saslNegotiator == null) sendConnectionClose(ErrorCodes.CONNECTION_FORCED, "No SaslServer could be created for mechanism: " + mechanism, 0); setClientProperties(clientProperties); processSaslResponse(response, subjectCreator);
@Override public void closeChannelAndWriteFrame(AMQChannel channel, int cause, String message) { writeFrame(new AMQFrame(channel.getChannelId(), getMethodRegistry().createChannelCloseBody(cause, AMQShortString.validValueOf(message), _currentClassId, _currentMethodId))); closeChannel(channel, cause, message, true); }
@Override public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { if (method.getName().equals("receiveChannelCloseOk") && channelAwaitingClosure(channelId)) { closeChannelOk(channelId); } else if(method.getName().startsWith("receive")) { sendConnectionClose(ErrorCodes.CHANNEL_ERROR, "Unknown channel id: " + channelId, channelId); } else if(method.getName().equals("ignoreAllButCloseOk")) { return channelAwaitingClosure(channelId); } return null; } });
@Override public ServerChannelMethodProcessor getChannelMethodProcessor(final int channelId) assertState(ConnectionState.OPEN); ServerChannelMethodProcessor channelMethodProcessor = getChannel(channelId); if(channelMethodProcessor == null)
@Override protected void processFrame(final int channelId, final byte type, final long bodySize, final QpidByteBuffer in) throws AMQFrameDecodingException { long startTime = 0; try { if (LOGGER.isDebugEnabled()) { startTime = System.currentTimeMillis(); } AMQChannel channel = _connection.getChannel(channelId); if(channel != null) { _connection.channelRequiresSync(channel); } doProcessFrame(channelId, type, bodySize, in); } finally { if(LOGGER.isDebugEnabled()) { LOGGER.debug("Frame handled in {} ms.", (System.currentTimeMillis() - startTime)); } } }
@Override public void closeChannel(AMQChannel channel) { closeChannel(channel, 0, null, false); }
@Override public void receiveConnectionCloseOk() { if(LOGGER.isDebugEnabled()) { LOGGER.debug("RECV ConnectionCloseOk"); } closeNetworkConnection(); }
cause = ErrorCodes.INTERNAL_ERROR; addAsyncTask(new Action<AMQPConnection_0_8Impl>()
@Override public void performAction(final AMQPConnection_0_8Impl object) { int channelId = session.getChannelId(); closeChannel(channelId, cause, message); MethodRegistry methodRegistry = getMethodRegistry(); ChannelCloseBody responseBody = methodRegistry.createChannelCloseBody( cause, AMQShortString.validValueOf(message), 0, 0); writeFrame(responseBody.generateFrame(channelId)); } });
@Override public ProtocolEngine newProtocolEngine(Broker<?> broker, ServerNetworkConnection network, AmqpPort<?> port, Transport transport, long id, final AggregateTicker aggregateTicker) { final AMQPConnection_0_8Impl protocolEngine = new AMQPConnection_0_8Impl(broker, network, port, transport, getVersion(), id, aggregateTicker); protocolEngine.create(); return protocolEngine; }
@Override public ProtocolEngine newProtocolEngine(Broker<?> broker, ServerNetworkConnection network, AmqpPort<?> port, Transport transport, long id, final AggregateTicker aggregateTicker) { final AMQPConnection_0_8Impl protocolEngine = new AMQPConnection_0_8Impl(broker, network, port, transport, getVersion(), id, aggregateTicker); protocolEngine.create(); return protocolEngine; }