Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorg and refactor repo - continued #1684

Merged
merged 48 commits into from
May 17, 2019
Merged

Reorg and refactor repo - continued #1684

merged 48 commits into from
May 17, 2019

Conversation

chanseokoh
Copy link
Member

@chanseokoh chanseokoh commented May 1, 2019

For Blob changes, following the same spirit in #1647 and #1678.

Other changes involve removing various classes around progress reporting, decoupling functionalities to have small, fine-grained general components, etc.

@@ -27,10 +29,37 @@
*/
public class Authorization {

/**
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to reviewers: these are just moved from Authorizations.

@chanseokoh chanseokoh marked this pull request as ready for review May 7, 2019 15:41
@chanseokoh chanseokoh changed the title Draft - reorg and refactor part 2 Reorg and refactor repo - continued May 7, 2019
@chanseokoh
Copy link
Member Author

Ready for review.

* @param blobProgressListener listener for progress of the pull
* @param blobSizeListener callback to receive the total size of the BLOb to pull
* @param writtenByteCountListener listens on byte count written to an output stream during the
* pull
* @return a {@link Blob}
*/
public Blob pullBlob(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it could be simpler if these blob pull/push clsases took a single ProgressEventDispatcherWrapper with the set/dispatch methods instead of two consumers? I'm not sure how it fits into the class hierarchy though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true it will look simpler technically. But my intent is actually decouple ProgressEventDispatcherWrapper from RegistryClient, which I think makes sense from the API perspective because this ProgressEventDispatcherWrapper is too specific in that it is an unfortunate wrapper required to lazily instantiate ProgressEventDispatcher. I think this class can remain general and free of progress event dispatcher stuff, especially the wrapper. That way I specifically named them writtenByCountListener instead of, say, progressEventDispatcher.

@@ -65,8 +57,9 @@ public void close() {
progressEventDispatcher.close();
}

void initializeWithBlobSize(long blobSize) {
void setProgressTarget(long allocationUnits) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a bit weird to have to call the constructor and this method to fully initialize a ProgressEventDispatcherWrapper, maybe we can consolidate this by changing the signature of RegistryClient#pullBlob?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I did not like this wrapper either. The problem Q originally faced was the progress reporting design that

  1. You have to know and set in advance how much progress units you will allocate when creating a progress event dispatcher.
  2. But you cannot know how much bytes (allocation units) you will download until you read Content-Length.
  3. So the wrapper that will create and hold a progress event dispatcher when this method is called. Other than that, this class is just a thin wrapper that delegates dispatchProgress().

For this reason, obviously it's best to get rid of this unfortunate wrapper if possible. As an attempt to work around the issue, Q probably also felt it doesn't make much sense to have this wrapper in the signature and make it a hard dependency from the API standpoint, also given that there are only just a couple places this wrapper is required. And as I said in the earlier comment, my intention is to actually decouple progress dispatcher stuff from RegistryClient.

@chanseokoh chanseokoh requested a review from a team May 10, 2019 17:54
Copy link
Member

@briandealwis briandealwis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments from the half-way mark.

* resets after this method is called, so this method should only be called once per computation.
* Computes the hash and returns it along with the size of the bytes written to compute the hash.
* The buffer resets after this method is called, so this method should only be called once per
* computation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder how many places do we call this method multiple times?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing none, because the last time I touched this class, it was reporting wrong bytes when called more than once. (Basically, bytesSoFar was not reset.)

@chanseokoh
Copy link
Member Author

I've addressed the comments. This should be good now.

Copy link
Member

@loosebazooka loosebazooka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me, unless @briandealwis has any further questions?

this(blob, contentType, ignored -> {});
}

public BlobHttpContent(Blob blob, String contentType, Consumer<Long> writtenByteCountListener) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems weird that a content object carries a listener — it's entirely possible this content object could be written out multiple times.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Not immediately clear how I can change this though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it not contain a writeTo? Or should writeTo take the listener?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class is implementing HttpContent::writeTo, so it's not like we can simply change the signature at this level. Perhaps next time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah interesting, didn't know HttpContent was something outside of our codebase.

@chanseokoh chanseokoh merged commit ccfa35e into master May 17, 2019
@chanseokoh chanseokoh deleted the cleanup-4 branch May 17, 2019 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants