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.protocol;
018
019import org.apache.activemq.command.ActiveMQDestination;
020import org.apache.activemq.command.LocalTransactionId;
021import org.apache.qpid.proton.amqp.transport.ErrorCondition;
022import org.apache.qpid.proton.engine.Delivery;
023
024/**
025 * Interface used to define the operations needed to implement an AMQP
026 * Link based endpoint, i.e. Sender, Receiver or Coordinator.
027 */
028public interface AmqpLink extends AmqpResource {
029
030    /**
031     * Close the Link with an error indicating the reson for the close.
032     *
033     * @param error
034     *        the error that prompted the close.
035     */
036    void close(ErrorCondition error);
037
038    /**
039     * Request from the remote peer to detach this resource.
040     */
041    void detach();
042
043    /**
044     * Handles an incoming flow control.
045     *
046     * @throws Excption if an error occurs during the flow processing.
047     */
048    void flow() throws Exception;
049
050    /**
051     * Called when a new Delivery arrives for the given Link.
052     *
053     * @param delivery
054     *        the newly arrived delivery on this link.
055     *
056     * @throws Exception if an error occurs while processing the new Delivery.
057     */
058    void delivery(Delivery delivery) throws Exception;
059
060    /**
061     * Handle work necessary on commit of transacted resources associated with
062     * this Link instance.
063     *
064     * @param txnId
065     *      The Transaction ID being committed.
066     *
067     * @throws Exception if an error occurs while performing the commit.
068     */
069    void commit(LocalTransactionId txnId) throws Exception;
070
071    /**
072     * Handle work necessary on rollback of transacted resources associated with
073     * this Link instance.
074     *
075     * @param txnId
076     *      The Transaction ID being rolled back.
077     *
078     * @throws Exception if an error occurs while performing the rollback.
079     */
080    void rollback(LocalTransactionId txnId) throws Exception;
081
082    /**
083     * @return the ActiveMQDestination that this link is servicing.
084     */
085    public ActiveMQDestination getDestination();
086
087    /**
088     * Sets the ActiveMQDestination that this link will be servicing.
089     *
090     * @param destination
091     *        the ActiveMQDestination that this link services.
092     */
093    public void setDestination(ActiveMQDestination destination);
094
095    /**
096     * Adds a new Runnable that is called on close of this link.
097     *
098     * @param action
099     *        a Runnable that will be executed when the link closes or detaches.
100     */
101    public void addCloseAction(Runnable action);
102
103}