View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.eclipse.aether.spi.connector.transport;
20  
21  import java.net.URI;
22  
23  import static java.util.Objects.requireNonNull;
24  
25  /**
26   * A transport task.
27   *
28   * @noextend This class is not intended to be extended by clients.
29   */
30  public abstract class TransportTask {
31  
32      static final TransportListener NOOP = new TransportListener() {};
33  
34      static final byte[] EMPTY = {};
35  
36      private URI location;
37  
38      private TransportListener listener = NOOP;
39  
40      TransportTask() {
41          // hide
42      }
43  
44      /**
45       * Gets the relative location of the affected resource in the remote repository.
46       *
47       * @return The relative location of the resource, never {@code null}.
48       */
49      public URI getLocation() {
50          return location;
51      }
52  
53      TransportTask setLocation(URI location) {
54          this.location = requireNonNull(location, "location type cannot be null");
55          return this;
56      }
57  
58      /**
59       * Gets the listener that is to be notified during the transfer.
60       *
61       * @return The listener to notify of progress, never {@code null}.
62       */
63      public TransportListener getListener() {
64          return listener;
65      }
66  
67      /**
68       * Sets the listener that is to be notified during the transfer.
69       *
70       * @param listener The listener to notify of progress, may be {@code null}.
71       * @return This task for chaining, never {@code null}.
72       */
73      TransportTask setListener(TransportListener listener) {
74          this.listener = (listener != null) ? listener : NOOP;
75          return this;
76      }
77  }