question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make global parameters singletons

See original GitHub issue

Prerequisites

Description

Currently, global parameters are being rebuilt inside each plugin which has resulted in discrepancies where the global parameter is not configured the same way within a plugin.

Steps to Reproduce

  1. [First Step]
  2. [Second Step]
  3. [and so on…]

Expected behaviour: global parameters built outside of plugin

Actual behaviour: global parameters built inside each plugin Reproduces how often: 100%

Additional Information

Any additional information, configuration or data that might be necessary to reproduce the issue.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
arcturus2commented, May 18, 2020

Just jumping in here too. For some more background had a look at the following and see how DateTimeRangeParameterType is being built again.

https://github.com/constellation-app/constellation-training/blob/32d97260c4e7b1bfeebe3ed30435fd215ce8b2a5/constellation-training-solutions/TrainingSolutions/src/au/gov/asd/tac/constellation/training/solutions/chapter4/ChainCitiesPlugin.java#L60

To be able to use the date range the user wants to query on the DateTimeRangeParameterType needs to be available to the plugin. you can see how its being used

https://github.com/constellation-app/constellation-training/blob/32d97260c4e7b1bfeebe3ed30435fd215ce8b2a5/constellation-training-solutions/TrainingSolutions/src/au/gov/asd/tac/constellation/training/solutions/chapter4/ChainCitiesPlugin.java#L68

So back on line 60 what we should do rather than newing instances is get the existing instance of DateTimeRangeParameterType - i.e these should be singletons.

I was thinking of using a builder pattern so when say build - it will either built it or give you an instance of it if the builder has previously built it.

Happy for other suggestions to. Note that global parameters are used in other modules (like the Training module suite) so minimal breaking API changes is highly desirable.

0reactions
sol695510commented, Jun 2, 2020

From memory, the crux of the issue was that the current global parameters implementation relies on each plugin developer re-building those parameters using a common parameter id. What we really want is for global parameters to already have been built and for all plugins to have access to them.

I’d imagine this being analogous to how any plugin can access a pre-built version of any SchemaVertexType via its SchemaConcept class. So you might have some generic functions in the GlobalParameters class for things like “lookup by string” if it makes sense, but the standard way of accessing these parameters would be something like:

parameters.addParameter(CoreGlobalParameters.QUERY_NAME_PARAMETER)
parameters.addParameter(CoreGlobalParameters.DATETIME_RANGE_PARAMETER)

I think the implementation here #559 is similar to what you’ve described. Advise if otherwise.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript: global variables vs singletons | by Shruti Kapoor
The Singleton pattern is basically just a lazily initialized global variable. It ensures that the class has one instance and that instance is ......
Read more >
Differences between Singleton and global variable [duplicate]
Singleton is used when we do not want to create more than one object. Singleton class ensures that not more than one object...
Read more >
Global Variables in Java with the Singleton Pattern
The Singleton pattern ensures that only one instance of a class will be created and provides a global point of access to it....
Read more >
How to make GLOBAL VARIABLES | SINGLETONS in Unity
Have you felt it before? Making an object reference for each and every variable ?SOLVE IT BY MAKING A SINGLETON SCRIPTthat can make...
Read more >
Singleton Pattern Deep Dive: Why is it bad? - - Sihui Huang
They both provide a global point of access for an object or a variable · The single pattern guarantees there's only one instance,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found