|
16 | 16 | package org.datatransferproject.spi.transfer.provider; |
17 | 17 |
|
18 | 18 | import java.util.Optional; |
| 19 | +import java.util.UUID; |
19 | 20 | import org.datatransferproject.types.common.ExportInformation; |
20 | | -import org.datatransferproject.types.transfer.auth.AuthData; |
21 | 21 | import org.datatransferproject.types.common.models.DataModel; |
22 | | - |
23 | | -import java.util.UUID; |
| 22 | +import org.datatransferproject.types.transfer.auth.AuthData; |
24 | 23 |
|
25 | 24 | /** |
26 | | - * Exports data from a source service. |
| 25 | + * Exporters produce data from some source/origin service. |
| 26 | + * |
| 27 | + * <p>Exporter classes are typically the concrete meeting point between DTP framework and a third |
| 28 | + * party API, but specifically: when DTP needs to <bold>read</bold> data from a service, its an |
| 29 | + * Exporter that does that reading. This is in contrast to {@link Importer}s which write that same |
| 30 | + * data. |
| 31 | + * |
| 32 | + * <h3>API for `Export#export` calls |
| 33 | + * |
| 34 | + * <p>DTP copiers can will call `export` in three key ways: |
| 35 | + * |
| 36 | + * <ol> |
| 37 | + * <li>to start a new transfer job for a user's whole library, indicated by an Optional.empty() |
| 38 | + * for ExportInformation; expected return: |
| 39 | + * <ul> |
| 40 | + * <li>a resource container for anything that's ready for export. |
| 41 | + * <li>a continuation data for any new resources discovered (aka "sub" resources). |
| 42 | + * <li>a ResultType of END if no further continuation data is passed. (this should coincide |
| 43 | + * with the absence of continuation data; if this isn't true, then DTP's behavior is |
| 44 | + * undefined) |
| 45 | + * </ul> |
| 46 | + * <li>to continue paging through a listing of items (aka "sub" resources), as indicated by one's |
| 47 | + * own previous return of a ContinuationData. |
| 48 | + * <li>to start a new transfer job for a subset of whole library, indicated by a null for |
| 49 | + * Optional<ExportInformation> (not to be confused with the first case above); expected |
| 50 | + * return: contract as first case |
| 51 | + * </ol> |
| 52 | + * |
| 53 | + * <p>The recursive nature of this API--that one's own returns are partially used for one's own |
| 54 | + * subsequent calls--means each Exporter is free to design the exact types and contents of those |
| 55 | + * objects freely, without interference. That means to make an exporter maintainable, an exporter |
| 56 | + * **must** carefully document the above cases, but replace the high-level description with the |
| 57 | + * concrete types and what they indicate for the particular libraries the exporter is designed for. |
| 58 | + * |
| 59 | + * <h3>Stateful APIs |
| 60 | + * |
| 61 | + * <p>A word on the implied contract of DTP imports and exporters (aka adapters). DTP adapters have |
| 62 | + * two states to track: |
| 63 | + * |
| 64 | + * <ol> |
| 65 | + * <li>construction-time state when DTP itself starts and the owning extension constructs its |
| 66 | + * class |
| 67 | + * <li>per-transfer-job state when DTP calls the exporter's `export` method to start a new job |
| 68 | + * </ol> |
| 69 | + * |
| 70 | + * </lp> |
| 71 | + * |
| 72 | + * <p>The former state is infrastructure-sensitive (like what JobStore backend is available), where |
| 73 | + * the latter's state is user-sensitive. This means the design of DTP adapters, largely copy/pasted |
| 74 | + * patterns out of a the same small seed of adapters, is constantly trying to protect against a |
| 75 | + * hypothetical future where where a DTP server could concurrently ask the same Exporter to handle |
| 76 | + * distinct transfer jobs (currently handle distinct `export` calls). |
| 77 | + * |
| 78 | + * <p>However this can be misleading and confusing: some classes uses a map, some classes refuse to |
| 79 | + * store any user-sensitive state on the instance altogether and just have **all** their internal |
| 80 | + * methods repeat the same parameters to pass around. Some have a mix where of repeating |
| 81 | + * parameter-passing **and** try to carefully use `volatile` and `synchronized` keyword to store |
| 82 | + * data on their own instance. |
27 | 83 | */ |
28 | 84 | public interface Exporter<A extends AuthData, T extends DataModel> { |
29 | | - // TODO: reconsider this model - can we avoid sending AuthData with every export call? |
| 85 | + // TODO: reconsider this model - can we avoid sending AuthData with every |
| 86 | + // export call? Example: given the two state-management modes described in |
| 87 | + // javadoc above, we could have an `Exporter` isntance for the infrastructure |
| 88 | + // state, and an `JobExport` instance (that said Exporter constructs) that |
| 89 | + // contains all the per-transfer state like AuthData and JobId; in such a |
| 90 | + // case the new API on this interface would be `getJobExporter(jobId, |
| 91 | + // authData)` that does the construction for us, and we call export() on |
| 92 | + // _that_ instead (with _only_ ExportInformation as the input paramter). |
30 | 93 |
|
31 | 94 | /** |
32 | 95 | * Performs an export operation, starting from the data specified by the continuation. |
|
0 commit comments