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

Extract out IdGeneratorBase and Add NonceGenerator #43

Merged
merged 22 commits into from
Feb 19, 2025

Conversation

CyberDrudge
Copy link

No description provided.

Copy link
Contributor

@santanusinha santanusinha left a comment

Choose a reason for hiding this comment

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

Class designs need to be redone.

@Slf4j
public class IdGeneratorBase {

private final int MINIMUM_ID_LENGTH;
Copy link
Contributor

Choose a reason for hiding this comment

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

static

public class IdGeneratorBase {

private final int MINIMUM_ID_LENGTH;
private final Pattern PATTERN;
Copy link
Contributor

Choose a reason for hiding this comment

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

static

private final Pattern PATTERN;
@Getter
private static int NODE_ID;
protected final DateTimeFormatter DATE_TIME_FORMATTER;
Copy link
Contributor

Choose a reason for hiding this comment

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

don't use this naming pattern for non static

Copy link
Author

Choose a reason for hiding this comment

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

Updated

}

public synchronized void registerGlobalConstraints(final IdValidationConstraint... constraints) {
registerGlobalConstraints(ImmutableList.copyOf(constraints));
Copy link
Contributor

Choose a reason for hiding this comment

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

List.copyOf()


public RandomNonceGenerator(final IdFormatter idFormatter) {
super(idFormatter);
RetryPolicy<GenerationResult> RETRY_POLICY = RetryPolicy.<GenerationResult>builder()
Copy link
Contributor

Choose a reason for hiding this comment

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

These things should all be moved to base. It needs to expose a very limited set of methods (one or two) to generate the id based on logic(random in this case)

}

@Override
public DateTime getDateTimeFromTime(final long time) {
Copy link
Contributor

Choose a reason for hiding this comment

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

what is this method, why is this public and why is it placed below private methods?

import lombok.Getter;

@Getter
@Builder
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove builder here. All members should be populated.


private static final List<IdValidationConstraint> GLOBAL_CONSTRAINTS = new ArrayList<>();
private static int nodeId;
private static final IdGeneratorBase baseGenerator = new IdGeneratorBase(
Copy link
Contributor

Choose a reason for hiding this comment

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

Too many comments already Havent reviewed this or any further file after this,

@CyberDrudge CyberDrudge force-pushed the weighted-id-generation-1 branch from 83841db to 402b171 Compare October 9, 2024 07:44
@CyberDrudge CyberDrudge force-pushed the weighted-id-generation-1 branch from 47ea2e3 to 29cd86a Compare December 10, 2024 09:09
@CyberDrudge CyberDrudge force-pushed the weighted-id-generation-1 branch from 6833733 to b83b806 Compare December 16, 2024 11:36
protected final IdFormatter idFormatter;
protected final NonceGeneratorBase nonceGenerator;

public static void initialize(final int node) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We can get rid of this and let the library initialise per instance of this class

String prefix,
final Domain domain,
boolean skipGlobal) {
private static Optional<Id> generateWithConstraints(String prefix, final Domain domain, boolean skipGlobal) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Revert formatting why has the formatting been changed in multiple places? revert all of these

.skipGlobal(skipGlobal)
.domain(domain.getDomain())
.idFormatter(domain.getIdFormatter())
.build());
Copy link
Contributor

Choose a reason for hiding this comment

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

Revert all formatting changes

Copy link
Author

Choose a reason for hiding this comment

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

Done

* @param idString String idString
* @return ID if it could be generated
*/
public Optional<Id> parse(final String idString) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this

Copy link
Author

@CyberDrudge CyberDrudge Feb 17, 2025

Choose a reason for hiding this comment

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

This will be used for parsing all IDs. This method will determine the formatter used for creation of that ID, then it will delegate the request to that specific formatter. Now that formatter will parse the ID

Copy link
Contributor

Choose a reason for hiding this comment

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

This would be required. So there are two layers to parsing -

  1. To determine which formatter was used to generate this ID (in future plan is to add two digit unique identifier per formatter for this)
  2. Once formatter is defined, individual formatters would be invoked to further parse all related metadata from the ID

This method is only trying to identify the formatter. Rest would be done by individual formatters. We can probably move this method to a new class (say IDParsers)

*/
@SuppressWarnings("unused")
@Slf4j
public abstract class IdGeneratorBase {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this class abstract when there are no abstract functions and the constructor is public as well?

Copy link
Author

Choose a reason for hiding this comment

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

Made the constructor protected

Copy link
Contributor

Choose a reason for hiding this comment

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

@santanusinha Use case of using an abstract class here is to just be able to override constructor and nothing else

.map(generationResult -> this.getIdFromIdInfo(generationResult.getNonceInfo(), request.getPrefix(), request.getIdFormatter()));
}

public void setNodeId(int nodeId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this non-final?

Copy link
Author

Choose a reason for hiding this comment

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

Made it final

@santanusinha santanusinha merged commit 7da19f9 into appform-io:main Feb 19, 2025
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.

3 participants