Skip to content

Commit

Permalink
Added tracking api to multi Application
Browse files Browse the repository at this point in the history
  • Loading branch information
scottf committed Sep 3, 2024
1 parent f6d3d46 commit f413c82
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
52 changes: 29 additions & 23 deletions js-multi-tool/src/main/java/io/nats/jsmulti/settings/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -448,13 +448,6 @@ else if (_readMaxWaitMillis < _readTimeoutMillis) {
customActionRunner = null;
}

if (_customAppClassName == null) {
app = new Application() {};
}
else {
app = (Application)classForName(_customActionClassName, "Custom Application");
}

latencyFlag = _latencyFlag;
servers = _servers;
credsFile = _credsFile;
Expand Down Expand Up @@ -488,19 +481,6 @@ else if (_readMaxWaitMillis < _readTimeoutMillis) {
subNameWhenQueue = _subDurableWhenQueue;
lastServerIndex = servers.length; // will roll to 0 first use, see getNextServer

if (_optionsFactoryClassName == null) {
OptionsFactory appOf = app.getOptionsFactory();
if (appOf == null) {
optionsFactory = new OptionsFactory() {};
}
else {
optionsFactory = appOf;
}
}
else {
optionsFactory = (OptionsFactory)classForName(_optionsFactoryClassName, "Options Factory");
}

payloads = new ArrayList<>();
if (payloadVariants == 1) {
payloads.add(new byte[payloadSize]);
Expand All @@ -520,11 +500,37 @@ else if (_readMaxWaitMillis < _readTimeoutMillis) {
total += perThread[x];
}

int ix = 0;
int ix = -1;
while (total < messageCount) {
perThread[ix++]++;
if (++ix == threads) {
ix = 0;
}
perThread[ix]++;
total++;
}

//
if (_customAppClassName == null) {
app = new Application() {};
}
else {
app = (Application)classForName(_customActionClassName, "Custom Application");
}

if (_optionsFactoryClassName == null) {
OptionsFactory appOf = app.getOptionsFactory();
if (appOf == null) {
optionsFactory = new OptionsFactory() {};
}
else {
optionsFactory = appOf;
}
}
else {
optionsFactory = (OptionsFactory)classForName(_optionsFactoryClassName, "Options Factory");
}

app.init(this);
}

@SuppressWarnings("SameParameterValue")
Expand All @@ -536,8 +542,8 @@ private Object classForName(String className, String label) {
}
catch (Exception e) {
error("Error creating " + label + ": " + e);
throw new RuntimeException();
}
return null;
}

private void error(String errMsg) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
import io.nats.jsmulti.settings.Context;

public interface Application {
default void init(Context ctx) throws Exception {
default void init(Context ctx) {
}

default void track(Stats stats, boolean isFinal) throws Exception {
default void track(Stats stats, boolean isFinal) {
}

default void report(Object o) {
Expand Down

0 comments on commit f413c82

Please sign in to comment.