-
Notifications
You must be signed in to change notification settings - Fork 150
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
Allow for custom dispatcher #1001
Conversation
* which should not be started on construction. | ||
* @param id the assigned id of the dispatcher | ||
*/ | ||
void start(String id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed to add this so impl could override it. The connection sometimes creates a dispatcher and does not start it - it's created lazy - and wanted to ensure the slim edge that 2 threads try to create at the same time.
@@ -46,7 +54,7 @@ public interface Dispatcher extends Consumer { | |||
* @return The Dispatcher, so calls can be chained. | |||
* @throws IllegalStateException if the dispatcher was previously closed | |||
*/ | |||
public Dispatcher subscribe(String subject); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public is redundant in interfaces
* Property used to set class name for the Dispatcher Factory | ||
* {@link Builder#dispatcherFactory(DispatcherFactory) dispatcherFactory}. | ||
*/ | ||
public static final String PROP_DISPATCHER_FACTORY_CLASS = "dispatcher.factory.class"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for options, there is a build, but you can also set factory class names via property
NatsDispatcher createDispatcher(NatsConnection conn, MessageHandler handler) { | ||
return new NatsDispatcher(conn, handler); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was made a class, not an interface. I'm trying to limit exposure of public things, note the warning, and a public interface required making NatsDispatcher and NatsConnection public
|
||
// Poison pill is a graphic, but common term for an item that breaks loops or stop something. | ||
// In this class the poisonPill is used to break out of timed waits on the blocking queue. | ||
// A simple == is used to check if any message in the queue is this message. | ||
private final NatsMessage poisonPill; | ||
protected final NatsMessage poisonPill; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intentionally did not make this public or an interface. The dev will have to extend this class in code in a matching package.
@@ -165,7 +167,7 @@ class NatsConnection implements Connection { | |||
|
|||
// Connect is only called after creation | |||
void connect(boolean reconnectOnConnect) throws InterruptedException, IOException { | |||
if (options.getServers().size() == 0) { | |||
if (options.getServers().isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Intellij incessantly annoys me about these so I fix them when I'm in a source file.
@@ -1136,8 +1138,11 @@ CompletableFuture<Message> requestFutureInternal(String subject, Headers headers | |||
} | |||
|
|||
if (inboxDispatcher.get() == null) { | |||
NatsDispatcher d = new NatsDispatcher(this, this::deliverReply); | |||
NatsDispatcher d = dispatcherFactory.createDispatcher(this, this::deliverReply); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the factory instead of just newing
private MessageQueue incoming; | ||
private MessageHandler defaultHandler; | ||
protected final MessageQueue incoming; | ||
protected final MessageHandler defaultHandler; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protected since this will be subclasses. final because Intellij says so, probably a good practice
Provide for the developer to provide a custom dispatcher. This is generally discouraged, but there was a specific use case for the thin vertx wrapper to which needed this.