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

Minimize reflection into Configuration #3127

Merged
merged 2 commits into from
May 27, 2020

Conversation

idodeclare
Copy link
Contributor

Hello,

Please consider for integration this patch to minimize reflection into Configuration and shift that logic to ConfigurationController where it's more difficult to avoid given the REST-exposure of all configuration through a single web method.

RuntimeEnvironment can use functional interfaces to achieve the equivalent of the former reflection without having to identify methods by String; thereby we get compile-time checks.

I also imported an auto-disposable wrapper around Lock so that try-with-resources can be used instead of try-finally.

Thank you.

@coveralls
Copy link

coveralls commented Apr 23, 2020

Pull Request Test Coverage Report for Build 5138

  • 173 of 213 (81.22%) changed or added relevant lines in 3 files are covered.
  • 23 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.02%) to 73.364%

Changes Missing Coverage Covered Lines Changed/Added Lines %
opengrok-indexer/src/main/java/org/opengrok/indexer/util/CloseableReentrantReadWriteLock.java 13 17 76.47%
opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/RuntimeEnvironment.java 137 173 79.19%
Files with Coverage Reduction New Missed Lines %
opengrok-indexer/src/main/java/org/opengrok/indexer/analysis/Ctags.java 1 78.37%
opengrok-indexer/src/main/java/org/opengrok/indexer/util/ClassUtil.java 10 46.39%
opengrok-indexer/src/main/java/org/opengrok/indexer/configuration/RuntimeEnvironment.java 12 70.46%
Totals Coverage Status
Change from base Build 5135: 0.02%
Covered Lines: 37795
Relevant Lines: 51517

💛 - Coveralls

* @param v the input argument
* @param <V> the type of the input to the operation
*/
public <V> void syncWriteConfiguration(ConfigurationValueConsumer<V> consumer, V v) {

Choose a reason for hiding this comment

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

I'd swap the parameter order cause at it seems more natural to me like this

syncWriteConfiguration(groups, (c, g) -> {
      populateGroups(g, new TreeSet<>(getProjects().values()));
      c.setGroups(g);
});

as its "value -> consume" that value, rather then "consumer of a value -> value"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would mean a line like the following:

syncWriteConfiguration(flag, Configuration::setListDirsFirst);

which seems to invert the important part.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll rename the vague arguments and transpose it as you suggest

Copy link
Contributor

Choose a reason for hiding this comment

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

thank you

}

private ResourceLock newWriteUnlocker() {
return () -> CloseableReentrantReadWriteLock.this.writeLock().unlock();

Choose a reason for hiding this comment

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

why this.writeLock().unlock() is not enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh that was from the imported implementation. Yes it seems superfluous

public <V> void syncWriteConfiguration(ConfigurationValueConsumer<V> consumer, V v) {
try (ResourceLock resourceLock = configLock.writeLockAsResource()) {
//noinspection ConstantConditions to silence unreference auto-closeable
assert resourceLock != null;

Choose a reason for hiding this comment

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

why do you assert this when you're explicitely checking this in write|readLockAsResource?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's to silent an annoying Java warning of the auto-closeable not being referenced in the block which was a blocker in IDEA when it runs tests with warnings-as-errors

Choose a reason for hiding this comment

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

what about @SuppressWarnings("unused") ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it’s a very focused warning for auto-closeable

}

/**
* @return a defined {@link ResourceLock} once the {@link #writeLock()} ()}

Choose a reason for hiding this comment

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

there are some extra brackets

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it

}
});
if (capture[EXCEPTION_INDEX] != null) {
throw capture[EXCEPTION_INDEX];

Choose a reason for hiding this comment

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

the exception here is only translated to throw new WebApplicationException(e, Response.Status.BAD_REQUEST)

can you thro that one here and remove the try block in the caller?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

}
return result;
}

Choose a reason for hiding this comment

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

extra line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand

Choose a reason for hiding this comment

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

I don't know :-D I somehow saw two lines. Nevermind.

@ktulinger
Copy link

This is a very good idea with the configuration consumer!

@idodeclare
Copy link
Contributor Author

Thank you for taking a look, @tulinkry

@idodeclare
Copy link
Contributor Author

@ktulinger, were the changes satisfactory?

Copy link
Contributor

@tulinkry tulinkry left a comment

Choose a reason for hiding this comment

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

Sorry, I didn't submit approve! Here we go

@idodeclare
Copy link
Contributor Author

Thank you, @tulinkry

@idodeclare idodeclare force-pushed the feature/minimize_conf_reflection branch from 4e2b0c1 to 754ebdf Compare May 5, 2020 17:30
@idodeclare
Copy link
Contributor Author

Just rebasing to ensure it still builds OK, since any new Configuration properties might be Git-conflict free but still need to be updated for this PR's Configuration API changes.

@tarzanek
Copy link
Contributor

tarzanek commented May 6, 2020

can Creative Commons Attribution-ShareAlike be merged to CDDL project?
if the answer is yes, I'll merge
@vladak FYI

@idodeclare
Copy link
Contributor Author

@tarzanek , yes I believe so. It's the license which Stack Overflow uses

@idodeclare
Copy link
Contributor Author

can Creative Commons Attribution-ShareAlike be merged to CDDL project?
if the answer is yes, I'll merge

@tarzanek, see e.g. OGKTextField.java.

@tarzanek
Copy link
Contributor

in such case this can be merged,
thank you Chris, you rock! :-)

@tarzanek tarzanek merged commit 31c97f2 into oracle:master May 27, 2020
@idodeclare idodeclare deleted the feature/minimize_conf_reflection branch May 27, 2020 18:55
@idodeclare
Copy link
Contributor Author

Thank you, Lubos! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants