001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.eclipse.aether.spi.connector.transport;
020
021import java.net.URI;
022
023import static java.util.Objects.requireNonNull;
024
025/**
026 * A transport task.
027 *
028 * @noextend This class is not intended to be extended by clients.
029 */
030public abstract class TransportTask {
031
032    static final TransportListener NOOP = new TransportListener() {};
033
034    static final byte[] EMPTY = {};
035
036    private URI location;
037
038    private TransportListener listener = NOOP;
039
040    TransportTask() {
041        // hide
042    }
043
044    /**
045     * Gets the relative location of the affected resource in the remote repository.
046     *
047     * @return The relative location of the resource, never {@code null}.
048     */
049    public URI getLocation() {
050        return location;
051    }
052
053    TransportTask setLocation(URI location) {
054        this.location = requireNonNull(location, "location type cannot be null");
055        return this;
056    }
057
058    /**
059     * Gets the listener that is to be notified during the transfer.
060     *
061     * @return The listener to notify of progress, never {@code null}.
062     */
063    public TransportListener getListener() {
064        return listener;
065    }
066
067    /**
068     * Sets the listener that is to be notified during the transfer.
069     *
070     * @param listener The listener to notify of progress, may be {@code null}.
071     * @return This task for chaining, never {@code null}.
072     */
073    TransportTask setListener(TransportListener listener) {
074        this.listener = (listener != null) ? listener : NOOP;
075        return this;
076    }
077}