All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.microsoft.azure.servicebus.amqp.BaseLinkHandler Maven / Gradle / Ivy

Go to download

Java library for Azure Service Bus. Please note, a newer package com.azure:azure-messaging-servicebus for Azure Service Bus is available as of December 2020. While this package will continue to receive critical bug fixes, we strongly encourage you to upgrade. Read the migration guide at https://aka.ms/azsdk/java/migrate/sb for more details.

There is a newer version: 3.6.7
Show newest version
/*
 * Copyright (c) Microsoft. All rights reserved.
 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
 */
package com.microsoft.azure.servicebus.amqp;

import org.apache.qpid.proton.amqp.transport.*;
import org.apache.qpid.proton.engine.*;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;

public class BaseLinkHandler extends BaseHandler {
    private static final Logger TRACE_LOGGER = LoggerFactory.getLogger(BaseLinkHandler.class);

    private final IAmqpLink underlyingEntity;

    public BaseLinkHandler(final IAmqpLink amqpLink) {
        this.underlyingEntity = amqpLink;
    }

    @Override
    public void onLinkLocalClose(Event event) {
        Link link = event.getLink();
        if (link != null) {            
            TRACE_LOGGER.debug("local link close. linkName:{}", link.getName());
        }

        closeSession(link);
    }

    @Override
    public void onLinkRemoteClose(Event event) {
        final Link link = event.getLink();
        if(link != null)
        {
            TRACE_LOGGER.debug("link remote close. linkName:{}", link.getName());
            if (link.getLocalState() != EndpointState.CLOSED) {
                link.close();
            }

            ErrorCondition condition = link.getRemoteCondition();
            this.processOnClose(link, condition);
            closeSession(link);
        }        
    }

    @Override
    public void onLinkRemoteDetach(Event event) {
        final Link link = event.getLink();
        if(link != null)
        {
            TRACE_LOGGER.debug("link remote detach. linkName:{}", link.getName());
            if (link.getLocalState() != EndpointState.CLOSED) {
                link.close();
            }
            
            this.processOnClose(link, link.getRemoteCondition());
            closeSession(link);
        }
        
    }

    public void processOnClose(Link link, ErrorCondition condition) {
        if (condition != null) {
            TRACE_LOGGER.debug("linkName:{}, ErrorCondition:{}, {}", link.getName(), condition.getCondition(), condition.getDescription());
        }

        this.underlyingEntity.onClose(condition);
    }

    public void processOnClose(Link link, Exception exception) {
        this.underlyingEntity.onError(exception);
    }

    private void closeSession(Link link) {
        if (link.getSession() != null && link.getSession().getLocalState() != EndpointState.CLOSED)
            link.getSession().close();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy