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

Add SubjectDataUpdateEvent for permission changes #1627

Merged
merged 1 commit into from Jan 27, 2018

Conversation

lucko
Copy link
Contributor

@lucko lucko commented Aug 11, 2017

Continues on from #1524 (and #1411)

Why only an update event?

More specific update events are hard to (accurately) implement, and I personally don't think they'll get used. The PermissionService API is already pretty confusing to understand (especially to implement) and I think adding events into the mix will make things significantly more difficult.

Adding more specific stuff like PermissionSetEvent raises questions about what to do for bulk changes, changes which are made offline, etc.

In my opinion, a simple update event is all that is needed. It allows plugins which use permissions for data storage to update any caches they may have when data is updated.

Should the event be called async?

The API was recently updated to use CompletableFutures for SubjectData changes, so imo, it makes sense for the event to always be called async.

Consistency is obviously important, it can't be sometimes async and sometimes not. I'm not sure if async events would be a new addition for Sponge, but I assume they're supported? (in other words, is the EventManager thread safe?)

I think that's about it.

@ST-DDT
Copy link
Member

ST-DDT commented Aug 12, 2017

I agree with Zidane here. Even if the perm plugin is used acros multiple servers as long as the change is syned to all servers (to update their perm cache) they should also give the oportunity to other plugins to update their caches.

As for changes made offline. The perm plugin could post the event when the entry is loaded or just rely on the other plugin to update its cache on join. If this is done during a perm plugin reload the plugin should throw this event for all online users/loaded subjects because things could have changed.

protected void onUpdate() {
if (this.updateListener != null) {
this.updateListener.accept(this);
}
Copy link
Member

Choose a reason for hiding this comment

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

IMO this should just post the change event. Otherwise this might be forgotten.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It gives the implementing plugin a chance to add any causes etc.

Also, since it is a requirement that the event is called async, a plugin instance is needed to schedule the event.

@lucko
Copy link
Contributor Author

lucko commented Aug 12, 2017

I've removed the clause about the event being optional.


@Override
public Subject getSubject() {
return subject;
Copy link
Contributor

Choose a reason for hiding this comment

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

this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@lucko
Copy link
Contributor Author

lucko commented Oct 2, 2017

Umm, I've kinda forgotten where this got to exactly, so err...

I think the issues remaining are:

  • Is it ok to call events async?
  • Should this event, in particular be called async? (I personally think yes)
  • Is my kinda weird implementation in MemorySubjectData ok?

I think it might make more sense to either:

  • Make MemorySubjectData abstract, and require that all uses of that class implement the `#onUpdate# method
  • Define #onUpdate as a protected method, so implementations using the class can choose to implement it if they wish.

I'm not sure if this be preferred over the current Consumer (defined listener) implementation.

¯\_(ツ)_/¯

(tagging @Zidane because I think it was you who asked me to PR this, maybe)

@bloodmc
Copy link
Contributor

bloodmc commented Jan 26, 2018

@lucko can you please fix conflicts?

@lucko
Copy link
Contributor Author

lucko commented Jan 26, 2018

@bloodmc Done

I've swapped out the Consumer in favour of a protected update method.

@parlough parlough modified the milestones: Release 7.1, Revision 8.0 Jan 26, 2018
@bloodmc
Copy link
Contributor

bloodmc commented Jan 27, 2018

@zml2008 @Zidane This PR look good to pull?

@Zidane Zidane merged commit 893c7ab into SpongePowered:bleeding Jan 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants