Skip to content

Commit

Permalink
Rename method.
Browse files Browse the repository at this point in the history
  • Loading branch information
mnlipp committed Oct 22, 2024
1 parent 369ec90 commit f940137
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ public void onUpgraded(Upgraded event, IOSubchannel wsChannel)
@SuppressWarnings({ "resource", "PMD.CloseResource" })
CharBufferWriter out = new CharBufferWriter(wsChannel,
wsChannel.responsePipeline()).suppressClose();
new SimpleConsoleCommand("reload").toJson(out);
new SimpleConsoleCommand("reload").emitJson(out);
out.close();
event.stop();
return;
Expand Down Expand Up @@ -824,7 +824,7 @@ public void onConsoleCommand(
@SuppressWarnings({ "resource", "PMD.CloseResource" })
CharBufferWriter out = new CharBufferWriter(upstream,
upstream.responsePipeline()).suppressClose();
event.toJson(out);
event.emitJson(out);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ public List<PageComponentSpecification> pageContent() {
}

@Override
public void toJson(Writer writer) throws IOException {
toJson(writer, "addConletType", conletType(),
public void emitJson(Writer writer) throws IOException {
emitJson(writer, "addConletType", conletType(),
displayNames().entrySet().stream()
.collect(Collectors.toMap(e -> e.getKey().toLanguageTag(),
Entry::getValue)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ public AddPageResources setCssSource(String cssSource) {
}

@Override
public void toJson(Writer writer) throws IOException {
toJson(writer, "addPageResources", Arrays.stream(cssUris()).map(
public void emitJson(Writer writer) throws IOException {
emitJson(writer, "addPageResources", Arrays.stream(cssUris()).map(
URI::toString).toArray(String[]::new),
cssSource(), scriptResources());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public CloseModalDialog(String conletType, String conletId) {
}

@Override
public void toJson(Writer writer) throws IOException {
toJson(writer, "closeModalDialog", conletType, conletId);
public void emitJson(Writer writer) throws IOException {
emitJson(writer, "closeModalDialog", conletType, conletId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,27 @@ public abstract class ConsoleCommand extends Event<Void> {
protected static final ObjectMapper mapper = new ObjectMapper();

/**
* Writes the event as JSON notification to the given writer.
* Derived classes usually simply call
* {@link #toJson(Writer, String, Object...)} with the method
* Emits the
* [JSON notification](https://www.jsonrpc.org/specification#notification)
* using the given writer. Derived classes usually simply call
* {@link #emitJson(Writer, String, Object...)} with the method
* name and parameters.
*
* @param writer the writer
*/
@SuppressWarnings("PMD.LinguisticNaming")
public abstract void toJson(Writer writer)
public abstract void emitJson(Writer writer)
throws InterruptedException, IOException;

/**
* Creates a JSON notification from the given data.
* Closes the `writer`.
*
*
* @param writer the writer
* @throws IOException
* @param method the method
* @param params the params
* @throws IOException Signals that an I/O exception has occurred.
*/
@SuppressWarnings("PMD.LinguisticNaming")
protected void toJson(Writer writer, String method, Object... params)
protected void emitJson(Writer writer, String method, Object... params)
throws IOException {
JsonRpc rpc = new JsonRpc(method);
if (params.length > 0) {
Expand All @@ -68,4 +69,21 @@ protected void toJson(Writer writer, String method, Object... params)
mapper.writeValue(writer, rpc);
writer.flush();
}

/**
* Calls {@link #emitJson(Writer, String, Object...)} with the
* given method and parameters. Provided for backwards compatibility.
*
* @param writer the writer
* @param method the method
* @param params the params
* @throws IOException Signals that an I/O exception has occurred.
* @deprecated Use {@link #emitJson(Writer, String, Object...)} instead.
*/
@Deprecated
@SuppressWarnings("PMD.LinguisticNaming")
protected void toJson(Writer writer, String method, Object... params)
throws IOException {
emitJson(writer, method, params);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public Set<RenderMode> renderModes() {
}

@Override
public void toJson(Writer writer) throws IOException {
toJson(writer, "deleteConlet", conletId(),
public void emitJson(Writer writer) throws IOException {
emitJson(writer, "deleteConlet", conletId(),
renderModes.stream().map(RenderMode::name)
.toArray(size -> new String[size]));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ public Map<String, Object> options() {
}

@Override
public void toJson(Writer writer) throws IOException {
public void emitJson(Writer writer) throws IOException {
options.put("destroyOnClose", true);
toJson(writer, "displayNotification", content(), options);
emitJson(writer, "displayNotification", content(), options);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public Object xtraInfo() {
}

@Override
public void toJson(Writer writer) throws IOException {
toJson(writer, "lastConsoleLayout", previewLayout(), tabsLayout(),
public void emitJson(Writer writer) throws IOException {
emitJson(writer, "lastConsoleLayout", previewLayout(), tabsLayout(),
xtraInfo());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public Object[] params() {
}

@Override
public void toJson(Writer writer) throws IOException {
toJson(writer, "notifyConletView", conletType(), conletId(),
public void emitJson(Writer writer) throws IOException {
emitJson(writer, "notifyConletView", conletType(), conletId(),
method(), params());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ public Map<String, Object> options() {
}

@Override
public void toJson(Writer writer) throws IOException {
public void emitJson(Writer writer) throws IOException {
Map<String, Object> options = options();
try {
toJson(writer, "openModalDialog", conletType, conletId,
emitJson(writer, "openModalDialog", conletType, conletId,
content().get(), options);
} catch (ExecutionException | InterruptedException e) {
throw new IOException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ public Future<String> content() {
* @throws InterruptedException
*/
@Override
public void toJson(Writer writer)
public void emitJson(Writer writer)
throws InterruptedException, IOException {
try {
toJson(writer, "updateConlet", conletType(), conletId(),
emitJson(writer, "updateConlet", conletType(), conletId(),
renderAs().stream().map(RenderMode::name)
.toArray(size -> new String[size]),
supportedRenderModes().stream().map(RenderMode::name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public void setParameters(Object... parameters) {
}

@Override
public void toJson(Writer writer) throws IOException {
toJson(writer, method, params);
public void emitJson(Writer writer) throws IOException {
emitJson(writer, method, params);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public Set<RenderMode> renderModes() {
}

@Override
public void toJson(Writer writer) throws IOException {
toJson(writer, "updateConletType", conletType(),
public void emitJson(Writer writer) throws IOException {
emitJson(writer, "updateConletType", conletType(),
renderModes().stream().map(RenderMode::name)
.toArray(size -> new String[size]));
}
Expand Down

0 comments on commit f940137

Please sign in to comment.