|
21 | 21 |
|
22 | 22 | import com.google.api.services.storage.model.StorageObject; |
23 | 23 | import com.google.common.base.MoreObjects; |
| 24 | +import com.google.gcloud.RestorableState; |
24 | 25 | import com.google.gcloud.RetryHelper; |
25 | 26 | import com.google.gcloud.spi.StorageRpc; |
26 | 27 |
|
@@ -49,26 +50,28 @@ class BlobWriteChannelImpl implements BlobWriteChannel { |
49 | 50 | private boolean isOpen = true; |
50 | 51 | private int chunkSize = DEFAULT_CHUNK_SIZE; |
51 | 52 |
|
52 | | - private StorageRpc storageRpc; |
53 | | - private StorageObject storageObject; |
| 53 | + private final StorageRpc storageRpc; |
| 54 | + private final StorageObject storageObject; |
54 | 55 |
|
55 | 56 | BlobWriteChannelImpl(StorageOptions options, BlobInfo blobInfo, |
56 | 57 | Map<StorageRpc.Option, ?> optionsMap) { |
57 | 58 | this.options = options; |
58 | 59 | this.blobInfo = blobInfo; |
59 | | - initTransients(); |
| 60 | + storageRpc = options.storageRpc(); |
| 61 | + storageObject = blobInfo.toPb(); |
60 | 62 | uploadId = storageRpc.open(storageObject, optionsMap); |
61 | 63 | } |
62 | 64 |
|
63 | 65 | BlobWriteChannelImpl(StorageOptions options, BlobInfo blobInfo, String uploadId) { |
64 | 66 | this.options = options; |
65 | 67 | this.blobInfo = blobInfo; |
66 | 68 | this.uploadId = uploadId; |
67 | | - initTransients(); |
| 69 | + storageRpc = options.storageRpc(); |
| 70 | + storageObject = blobInfo.toPb(); |
68 | 71 | } |
69 | 72 |
|
70 | 73 | @Override |
71 | | - public State save() { |
| 74 | + public RestorableState<BlobWriteChannel> save() { |
72 | 75 | if (isOpen) { |
73 | 76 | flush(true); |
74 | 77 | } |
@@ -101,11 +104,6 @@ public void run() { |
101 | 104 | } |
102 | 105 | } |
103 | 106 |
|
104 | | - private void initTransients() { |
105 | | - storageRpc = options.storageRpc(); |
106 | | - storageObject = blobInfo.toPb(); |
107 | | - } |
108 | | - |
109 | 107 | private void validateOpen() throws IOException { |
110 | 108 | if (!isOpen) { |
111 | 109 | throw new IOException("stream is closed"); |
@@ -158,7 +156,7 @@ public void chunkSize(int chunkSize) { |
158 | 156 | this.chunkSize = Math.max(MIN_CHUNK_SIZE, chunkSize); |
159 | 157 | } |
160 | 158 |
|
161 | | - static class StateImpl implements State, Serializable { |
| 159 | + static class StateImpl implements RestorableState<BlobWriteChannel>, Serializable { |
162 | 160 |
|
163 | 161 | private static final long serialVersionUID = 8541062465055125619L; |
164 | 162 |
|
@@ -223,7 +221,7 @@ public Builder chunkSize(int chunkSize) { |
223 | 221 | return this; |
224 | 222 | } |
225 | 223 |
|
226 | | - public State build() { |
| 224 | + public RestorableState<BlobWriteChannel> build() { |
227 | 225 | return new StateImpl(this); |
228 | 226 | } |
229 | 227 | } |
|
0 commit comments