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

org.ow2.petals.microkernel.transport.util.TransportSendContext Maven / Gradle / Ivy

There is a newer version: 4.3.0
Show newest version
/**
 * Copyright (c) 2009-2012 EBM WebSourcing, 2012-2016 Linagora
 * 
 * This program/library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 2.1 of the License, or (at your
 * option) any later version.
 * 
 * This program/library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
 * for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program/library; If not, see http://www.gnu.org/licenses/
 * for the GNU Lesser General Public License version 2.1.
 */
package org.ow2.petals.microkernel.transport.util;

import org.ow2.petals.jbi.servicedesc.endpoint.Location;
import org.ow2.petals.jbi.servicedesc.endpoint.PetalsServiceEndpoint;

/**
 * The Transport Context provides the information to transport the message
 * toward the destination with the proper protocol.
 * 
 * @author Roland NAUDIN - EBM WebSourcing
 */
public class TransportSendContext {

    /**
     * For an exchange go return to a consumer
     */
    public TransportSendContext(final Location destination) {
        this(null, destination);
    }

    /**
     * For an exchange that goes to a provider
     */
    public TransportSendContext(final PetalsServiceEndpoint endpoint) {
        this(endpoint, null);
    }

    private TransportSendContext(final PetalsServiceEndpoint endpoint, final Location destination) {
        // they can't be both null or non-null!
        this.destination = destination;
        this.endpoint = endpoint;
        this.attempt = 1;
    }

    /**
     * The destination
     */
    private final Location destination;

    /**
     * Elected endpoint (only for exchange to providers!)
     */
    private final PetalsServiceEndpoint endpoint;

    /**
     * The QOS of the transport
     */
    public String transport;

    /**
     * Number of send attempt, if a failure occurs during the transfer
     */
    public short attempt;

    /**
     * Delay between send attempt
     */
    public int delay;

    public Location getDestination() {
        if (this.endpoint != null) {
            assert this.destination == null;
            return this.endpoint.getLocation();
        } else {
            assert this.destination != null;
            return this.destination;
        }
    }

    public PetalsServiceEndpoint getEndpoint() {
        return endpoint;
    }

    @Override
    public String toString() {
        return (this.endpoint != null ? this.endpoint.toString() + " on " : "") + getDestination();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy