-
-
Notifications
You must be signed in to change notification settings - Fork 211
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 a method to detect which properties were changed in a reload #47
Comments
👍 I thought about that, to have a listener that receives a PropertyChangeEvent containing { key, newValue, oldValue) (newValue and oldValue may be null to mean that a property has been added or removed) cfg.addPropertyChangeListener(new PropertyChangeListener() {
void propertyChanged(PropertyChangeEvent evt) {
//....
}
} The above will get triggered for every property changed. (when reload happens it will be triggered as many times as the number of the properties loaded that have been changed) Another option would be to register for a specific propertyKeyChange: cfg.addPropertyChangeListener(new PropertyKeyChangeListener("foobar") {
void propertyKeyChanged(PropertyChangeEvent evt) {
//....
}
} The above will only be triggered when a specific property is changed. I think I'll implement both. It should not be difficult. Would this cover your use case? |
On master branch, owner should be able to hot-reload properties also when they are loaded from the classpath. I need to test this more, and update the documentation (that states the opposite) |
Also, it would be nice to allow the listener to rollback the property change (or the entire reload), for instance, throwing a PropertyChangeRollbackException, or ReloadRollbackException, what do you think? This can work as a programmable 'validation' mechanism. |
Yes, it would be cool :) but you will also need to implement some sort of |
That's not the hard part, I think. And that was exactly what I had in mind. But there are some cases to take in mind. Suppose property X is changed, and the value passes from A to B. There are two listeners registered for changes on property X. 1st listener gets notified, and for him X := B. So... we have this situation. So... troubles :) One could send another event to 1st listener to say that X gets assigned back to A... but... what if then the 1st listener throws an exception? .... it's a matter to save "capra e cavoli" ;) |
Yeah, and that's exactly the reason why I was suggesting a two-phase commit
|
So it can be something like: cfg.addPropertyChangeListener(new PropertyChangeListener() {
void beforePropertyChange(PropertyChangeEvent evt) throws Whatever... {
//....
}
void afterPropertyChange(PropertyChangeEvent evt) { // throws nothing
}
} In this way one received the event before the change and have the chance to rollback throwing an exception, but he can only assume that the property is actually changed on the method afterPropertyChange(). Sounds good? |
I would probably use a different naming, such as: cfg.addPropertyChangeListener(new PropertyChangeListener() { void commitPropertyChange(PropertyChangeEvent evt) { // throws nothing It looks more clear to me as it sounds much more like a 2 phase commit:
The system will first ask to all participant (listeners) to be prepared for
On Wed, Jul 31, 2013 at 1:16 PM, Luigi R. Viggiano <notifications@github.com
|
@lviggiano - Can I use master build to detect property change? I just need to know which property was changed in my application. |
@lviggiano - When I build from master, 12 tests are failing. Can I skip the tests and build it? |
The feature is still a work in progress, so, it's not completed yet (mostly unimplemented). I'll work on this asap to complete the feature. BTW tests on master branch should not be failing. Can you post your build log or send it to me by email? As far as I know all tests should be green. See: There is one multi-thread test that sometimes fails due to the fact that the test is not perfect synchronizing delays before to check results. Afaik this is the only test that produces build failures, and I need to look into it. |
I just emailed you the logs. |
I'll do. Thanks for the logs. I'm planning next week to start again coding
|
@vaibhavk81 I'm actively working to this feature those days. It should not take long time. |
Thanks! ~Vaibhav On Wed, Sep 11, 2013 at 1:53 PM, Luigi R. Viggiano <notifications@github.com
|
I think the implementation is almost ready, I need to write some more tests and the documentation to close this issue. It's early to say "done", but you can start testing in non-critic environments, if you like. See Mutable: /**
* Adds a {@link PropertyChangeListener} to the Mutable interface.
*
* @param listener the listener to be added.
* @since 1.0.5
*/
void addPropertyChangeListener(PropertyChangeListener listener); PropertyChangeListener comes from the JRE libraries. I will later add a method to register on a single propertyName: void addPropertyChangeListener(String propertyName, PropertyChangeListener listener); I also extended the PropertyChangeListener with TransactionalPropertyChangeListener that exposes an additional method: /**
* A Listener that is aware of properties changes.
*
* @author Luigi R. Viggiano
*/
public interface TransactionalPropertyChangeListener extends PropertyChangeListener {
/**
* This method is invoked before the property is changed. When this method is invoked we cannot assume that the
* change is effective, since some listener can ask to roll back the change operation.
*
* @param evt the {@link PropertyChangeEvent event} of property change.
* @throws RollbackOperationException when the listener wants to rollback the change on the property intercepted
* @throws RollbackBatchException when the listener wants to rollback the entire set of changes if executed in the
* batch.
*/
void beforePropertyChange(PropertyChangeEvent evt) throws RollbackOperationException, RollbackBatchException;
} Test cases are here: In particular I need to test more the reload(). |
Testing is complete. Things to do:
@vaibhavk81 if you want to start using the feature, you can now. |
Thanks a lot! ~Vaibhav On Fri, Sep 13, 2013 at 11:57 PM, Luigi R. Viggiano <
|
I completed a draft implementation for PropertyChangeListeners, @bbossola and @vaibhavk81, if you want to have a look at the code or the unit tests regarding the programming interfaces (internals may still change before the 1.0.5 release) you can refer to the unit tests and javadocs. |
@vaibhavk81 I found out that some tests were failing on Windows boxes, since I am testing only on Linux and Mac OS X I didn't notice the problem before. Current master should build fine on Windows too. I'm very close to 1.0.5 release which will contain this feature. |
Added documentation page: http://owner.aeonbits.org/docs/event-support/ Tomorrow I will release 1.0.5 |
Thanks a lot! ~Vaibhav On Mon, Oct 7, 2013 at 7:05 AM, Luigi R. Viggiano
|
@bbossola tomorrow I'll probably release 1.0.5 with this feature implemented. Can you please have a look and review the interfaces for any design suggestion? http://owner.newinstance.it/1.0.5-SNAPSHOT/xref/index.html the package is org.aeonbits.owner.event. The PropertyChangeEvent and PropertyChangeListener comes from java.beans. |
1.0.5 released. @bbossola @vaibhavk81 you can update your app with the latest version. |
Will do. Thanks! Regards, Sent from my iPhone
|
Thx looks cool!
|
The HotReload is super cool :) however I think that generally it would be nice to know which properties has changed so that you can re-configure only the affected services, It can be embedded into the ReloadEvent, or it could be possible have a helper method (like I have in my code now) that is able to do a "diff" in the properties for me.
The text was updated successfully, but these errors were encountered: