Skip to content

Commit

Permalink
Merge pull request #9 from AnetteTaivere/restructure
Browse files Browse the repository at this point in the history
Restructure project: move classes into appropriate packages
  • Loading branch information
karoliineh authored Mar 28, 2024
2 parents 1cd6399 + a87c626 commit 7d583f5
Show file tree
Hide file tree
Showing 9 changed files with 407 additions and 391 deletions.
5 changes: 4 additions & 1 deletion src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import abstractdebugging.AbstractDebuggingServerLauncher;
import abstractdebugging.ResultsService;
import analysis.GoblintAnalysis;
import analysis.ShowCFGCommand;
import magpiebridge.ShowCFGCommand;
import api.GoblintService;
import api.GoblintServiceLauncher;
import api.messages.params.Params;
Expand All @@ -13,6 +13,9 @@
import gobpie.GobPieException;
import magpiebridge.core.MagpieServer;
import magpiebridge.core.ServerAnalysis;
import magpiebridge.GoblintLanguageExtensionHandler;
import magpiebridge.GoblintMagpieServer;
import magpiebridge.GoblintServerConfiguration;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.lsp4j.MessageParams;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/api/GoblintServiceLauncher.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package api;

import api.json.GoblintMessageJsonHandler;
import api.json.GoblintSocketMessageConsumer;
import api.json.GoblintSocketMessageProducer;
import api.jsonrpc.GoblintSocketMessageConsumer;
import api.jsonrpc.GoblintSocketMessageProducer;
import api.jsonrpc.AutoClosingMessageProcessor;
import api.jsonrpc.CloseableEndpoint;
import gobpie.GobPieException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
package api.json;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.lsp4j.jsonrpc.JsonRpcException;
import org.eclipse.lsp4j.jsonrpc.MessageConsumer;
import org.eclipse.lsp4j.jsonrpc.json.MessageConstants;
import org.eclipse.lsp4j.jsonrpc.json.MessageJsonHandler;
import org.eclipse.lsp4j.jsonrpc.messages.Message;

import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;


/**
* A message consumer that serializes messages to JSON and sends them to an output stream.
*
* @since 0.0.3
*/

public class GoblintSocketMessageConsumer implements MessageConsumer, MessageConstants {

private final String encoding;
private final MessageJsonHandler jsonHandler;
private final Object outputLock = new Object();
private final OutputStream output;

private final Logger log = LogManager.getLogger(GoblintSocketMessageConsumer.class);

public GoblintSocketMessageConsumer(OutputStream output, MessageJsonHandler jsonHandler) {
this(output, StandardCharsets.UTF_8.name(), jsonHandler);
}

public GoblintSocketMessageConsumer(OutputStream output, String encoding, MessageJsonHandler jsonHandler) {
this.output = output;
this.encoding = encoding;
this.jsonHandler = jsonHandler;
}

@Override
public void consume(Message message) {
try {
String content = jsonHandler.serialize(message) + "\n";
byte[] contentBytes = content.getBytes(encoding);
synchronized (outputLock) {
output.write(contentBytes);
output.flush();
}
log.debug("WRITTEN: {}", content);
} catch (IOException exception) {
throw new JsonRpcException(exception);
}
}

}
package api.jsonrpc;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.eclipse.lsp4j.jsonrpc.JsonRpcException;
import org.eclipse.lsp4j.jsonrpc.MessageConsumer;
import org.eclipse.lsp4j.jsonrpc.json.MessageConstants;
import org.eclipse.lsp4j.jsonrpc.json.MessageJsonHandler;
import org.eclipse.lsp4j.jsonrpc.messages.Message;

import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;


/**
* A message consumer that serializes messages to JSON and sends them to an output stream.
*
* @since 0.0.3
*/

public class GoblintSocketMessageConsumer implements MessageConsumer, MessageConstants {

private final String encoding;
private final MessageJsonHandler jsonHandler;
private final Object outputLock = new Object();
private final OutputStream output;

private final Logger log = LogManager.getLogger(GoblintSocketMessageConsumer.class);

public GoblintSocketMessageConsumer(OutputStream output, MessageJsonHandler jsonHandler) {
this(output, StandardCharsets.UTF_8.name(), jsonHandler);
}

public GoblintSocketMessageConsumer(OutputStream output, String encoding, MessageJsonHandler jsonHandler) {
this.output = output;
this.encoding = encoding;
this.jsonHandler = jsonHandler;
}

@Override
public void consume(Message message) {
try {
String content = jsonHandler.serialize(message) + "\n";
byte[] contentBytes = content.getBytes(encoding);
synchronized (outputLock) {
output.write(contentBytes);
output.flush();
}
log.debug("WRITTEN: {}", content);
} catch (IOException exception) {
throw new JsonRpcException(exception);
}
}

}
Loading

0 comments on commit 7d583f5

Please sign in to comment.