Skip to content

Leverage the fact that Id could have a reference to the registry #440

@quidryan

Description

@quidryan

As a user, I would like to hold references to just Id's. Currently I have to keep a reference to the registry, in the cases where my Id's are dynamic based on the data, e.g
In my constructor, I would do establish a base Id and have to keep a registry around:

    private final Registry registry;
    private final Id RESPONSE_ANALYZE_ID;

    public ResponseAnalyzeService(Registry registry) {
        this.registry = registry;
        this.RESPONSE_ANALYZE_ID = registry.createId("response.analyze");
    }

Then in the main code path:

        Id id = null;
        try {
            ResponseAnalysis responseAnalysis = analyzeResponseRaw(requestState);
            id = RESPONSE_ANALYZE_ID
                        .withTag("success", "true")
                        .withTag("action", responseAnalysis.getAction().name())
                        .withTag("reason", responseAnalysis.getReason().name());
        } catch(Exception e) {
            id = RESPONSE_ANALYZE_ID
                    .withTag("success", "false")
                    .withTag("exception", e.getClass().getSimpleName());
        } finally {
            if (id != null) {
                registry.counter(id).increment();
            }
        }

There isn't currently a way to establish a counter based on the dynamic Id, without keeping a reference to the registry around. Since the original RESPONSE_ANALYZE_ID Id in this example came from a registry, it doesn't seem far fetched that it could have a reference to the registry, that would allow some call like id.counter().increment().

I get that it's a big ask to be adding memory references to lightweight objects. I guess my big goal to be able to reduce some of the code in the example, since we follow this pattern a lot and it is more verbose than we would hope and more than the legacy Servo wrapper we have used in the past.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions