001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.activemq.transport.amqp;
018
019import java.io.IOException;
020
021import org.apache.activemq.command.Command;
022
023/**
024 * Interface that defines the API for any AMQP protocol converter ised to
025 * map AMQP mechanincs to ActiveMQ and back.
026 */
027public interface AmqpProtocolConverter {
028
029    /**
030     * A new incoming data packet from the remote peer is handed off to the
031     * protocol converter for porcessing.  The type can vary and be either an
032     * AmqpHeader at the handshake phase or a byte buffer containing the next
033     * incoming frame data from the remote.
034     *
035     * @param data
036     *        the next incoming data object from the remote peer.
037     *
038     * @throws Exception if an error occurs processing the incoming data packet.
039     */
040    void onAMQPData(Object data) throws Exception;
041
042    /**
043     * Called when the transport detects an exception that the converter
044     * needs to respond to.
045     *
046     * @param error
047     *        the error that triggered this call.
048     */
049    void onAMQPException(IOException error);
050
051    /**
052     * Incoming Command object from ActiveMQ.
053     *
054     * @param command
055     *        the next incoming command from the broker.
056     *
057     * @throws Exception if an error occurs processing the command.
058     */
059    void onActiveMQCommand(Command command) throws Exception;
060
061    /**
062     * On changes to the transport tracing options the Protocol Converter
063     * should update its internal state so that the proper AMQP data is
064     * logged.
065     */
066    void updateTracer();
067
068    /**
069     * Perform any keep alive processing for the connection such as sending
070     * empty frames or closing connections due to remote end being inactive
071     * for to long.
072     *
073     * @returns the amount of milliseconds to wait before performaing another check.
074     *
075     * @throws IOException if an error occurs on writing heatbeats to the wire.
076     */
077    long keepAlive() throws IOException;
078
079}