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

Change number of custom vars and fix concurrent error #90

Merged
merged 4 commits into from
Apr 8, 2016

Conversation

dotsbb
Copy link
Member

@dotsbb dotsbb commented Mar 19, 2016

* @param maxVariables
*/
public void setMaxCustomVariables(int maxVariables){
CustomVariables.MAX_VARIABLES = maxVariables;
Copy link
Member

Choose a reason for hiding this comment

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

I don't like the use of a static variables like this. I'm on mobile ATM so I can't browse code well, can't we pass this as configuration parameter before tracker init? What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

@d4rken I tried to avoid static vars, but my shot wasn't successful and elegant due to this usage of CustomVariables in TrackMe class, it knows nothing about Tracker instance.

Copy link
Member

Choose a reason for hiding this comment

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

What about removing the limit from the custom variables object and when submitting the trackme, the trackers trims the custom variables to the allowed amount before handing it to the dispatcher?

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 think the most elegant way will be to remove limit of custom vars completely.
We just can assume that developers are responsible enough and read the doc strings.

Copy link
Member

Choose a reason for hiding this comment

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

I agree, that sounds like a clean solution with some javadoc explanation.
Am 24.03.2016 00:39 schrieb "Alexey Subbotin" notifications@github.com:

In piwik-sdk/src/main/java/org/piwik/sdk/Piwik.java
#90 (comment):

@@ -68,6 +68,16 @@ public synchronized Tracker newTracker(@nonnull String trackerUrl, int siteId) t
}

 /**
  • \* Configure Piwik to receive more than 5 custom variable
    
  • \* http://piwik.org/faq/how-to/faq_17931/
    
  • \* Changing this limit will affect all Tracker instances
    
  • \* @param maxVariables
    
  • */
    
  • public void setMaxCustomVariables(int maxVariables){
  •    CustomVariables.MAX_VARIABLES = maxVariables;
    

I think the most elegant way will be to remove limit of custom vars
completely.
We just can assume that developers are responsible enough and read the doc
strings.


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/piwik/piwik-sdk-android/pull/90/files/9c1561bcf2ec4d190e9515b9fa198607815d8669#r57255556

@dotsbb dotsbb force-pushed the change-max-custom-vars-and-fix-concurrent-error branch from 9c1561b to 1c3a3da Compare March 23, 2016 23:35
@dotsbb dotsbb force-pushed the change-max-custom-vars-and-fix-concurrent-error branch from 1c3a3da to 01dd79e Compare March 23, 2016 23:40
* @param name of a specific Custom Variable such as "User type".
* @param value of a specific Custom Variable such as "Customer".
* @return super.put result if index in right range and name/value pair aren't null
*/
public JSONArray put(int index, String name, String value) {
if (index > 0 && index <= MAX_VARIABLES && name != null & value != null) {
if (index > 0 && name != null & value != null) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Wrong indexes will be ignored on the server side

@d4rken
Copy link
Member

d4rken commented Mar 24, 2016

What about wrapping an instance of HashMap instead of extending it? Would make it way easier to guard (just synchronization on 3 methods). Other calls like Map.clear() might still cause issues otherwise, I'm still on mobile, can't check the sources well.

We only need a few specific methods anyways and not all HashMap has to offer.

What do you think?

@dotsbb
Copy link
Member Author

dotsbb commented Mar 26, 2016

@d4rken I've got rid of extending HashMap, as always good idea 👍

*/
public class CustomVariables {
private final Object mConcurrentLock = new Object();
private final HashMap<String, JSONArray> mVars = new HashMap<>();
Copy link
Member

Choose a reason for hiding this comment

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

I think we can go with

private final Map<String, JSONArray> mVars = new ConcurrentHashMap<>();

and then skip the manual syncronization.
According to it's documentation the map iterator is safe during multithreading as long as each thread uses it's own iterator.

@d4rken
Copy link
Member

d4rken commented Apr 7, 2016

Sorry took me a bit longer.
Tests look good, but I may have found a sleaker solution.
Let me know what you think regarding my comments.

Should we do another release after this is merged into dev?

On a side note, shouldn't we submit PRs via forks ;)?

@dotsbb
Copy link
Member Author

dotsbb commented Apr 7, 2016

@d4rken all comments addressed/fixed.

Should we do another release after this is merged into dev?

Sure!

On a side note, shouldn't we submit PRs via forks ;)?

Honestly I Didn't think about it before You asked, for me it was easier to maintain only remote.

@d4rken
Copy link
Member

d4rken commented Apr 7, 2016

👍 I think this can be merged into dev now.

Then we could either do a release with that state or see if we want to include something for #92

@dotsbb dotsbb removed the code review label Apr 8, 2016
@dotsbb dotsbb merged commit 8c7ec7a into dev Apr 8, 2016
@dotsbb dotsbb deleted the change-max-custom-vars-and-fix-concurrent-error branch April 8, 2016 19:14
@d4rken d4rken mentioned this pull request May 25, 2016
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

2 participants