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.nio.ByteBuffer;
22 import java.util.Map;
23
24 import org.eclipse.aether.transfer.TransferCancelledException;
25 import org.eclipse.aether.transfer.TransferEvent;
26
27 /**
28 * A skeleton class for listeners used to monitor transport operations. Reusing common regular expression syntax, the
29 * sequence of events is generally as follows:
30 *
31 * <pre>
32 * ( STARTED PROGRESSED* )*
33 * </pre>
34 *
35 * The methods in this class do nothing.
36 */
37 public abstract class TransportListener {
38
39 /**
40 * Enables subclassing.
41 */
42 protected TransportListener() {}
43
44 /**
45 * Notifies the listener about the start of the data transfer. This event may arise more than once if the transfer
46 * needs to be restarted (e.g. after an authentication failure).
47 *
48 * @param dataOffset The byte offset in the resource at which the transfer starts, must not be negative.
49 * @param dataLength The total number of bytes in the resource or {@code -1} if the length is unknown.
50 * @throws TransferCancelledException If the transfer should be aborted.
51 */
52 public void transportStarted(long dataOffset, long dataLength) throws TransferCancelledException {}
53
54 /**
55 * Notifies the listener about some progress in the data transfer. This event may even be fired if actually zero
56 * bytes have been transferred since the last event, for instance to enable cancellation.
57 *
58 * @param data The (read-only) buffer holding the bytes that have just been tranferred, must not be {@code null}.
59 * @throws TransferCancelledException If the transfer should be aborted.
60 */
61 public void transportProgressed(ByteBuffer data) throws TransferCancelledException {}
62
63 /**
64 * Notifies the listener about the transport properties that are available for this transfer.
65 * This method is called either before or after other notifications are sent:
66 * <ul>
67 * <li>for remote put tasks this is called after {@link #transportStarted(long, long)}</li>
68 * <li>for remote peek tasks this is is the only event that is called</li>
69 * <li>for all other remote tasks this is called before {@link #transportStarted(long, long)}</li>
70 * </ul>
71 * @param transportProperties The transport properties associated with this transfer, may be empty. The keys are transporter specific and the value types are key specific.
72 * @throws TransferCancelledException If the transfer should be aborted.
73 * @since 2.0.21
74 */
75 public void transportPropertiesAvailable(Map<TransferEvent.TransportPropertyKey, Object> transportProperties)
76 throws TransferCancelledException {}
77 }