Skip to content

Commit

Permalink
rename class
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasjackson committed Oct 16, 2023
1 parent d01929f commit a8e5c02
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,27 @@

import net.minecraft.util.math.BlockPos;

public class WebServers {
public class Webservers {

private HashMap<String, WebServerContext> SERVERS = new HashMap<String, WebServerContext>();
private HashMap<String, WebserverContext> SERVERS = new HashMap<String, WebserverContext>();

// map iteration methods
public Set<Entry<BlockPos, WebServerContext>> entrySet() {
Set<Entry<BlockPos, WebServerContext>> entrySet = new HashSet<Entry<BlockPos, WebServerContext>>();
public Set<Entry<BlockPos, WebserverContext>> entrySet() {
Set<Entry<BlockPos, WebserverContext>> entrySet = new HashSet<Entry<BlockPos, WebserverContext>>();

for (Entry<String, WebServerContext> entry : SERVERS.entrySet()) {
for (Entry<String, WebserverContext> entry : SERVERS.entrySet()) {
BlockPos pos = deseriaBlockPos(entry.getKey());
entrySet.add(new AbstractMap.SimpleEntry<BlockPos, WebServerContext>(pos, entry.getValue()));
entrySet.add(new AbstractMap.SimpleEntry<BlockPos, WebserverContext>(pos, entry.getValue()));
}

return entrySet;
}

public void add(BlockPos pos, WebServerContext context) {
public void add(BlockPos pos, WebserverContext context) {
SERVERS.put(serializeBlockPos(pos), context);
}

public WebServerContext get(BlockPos pos) {
public WebserverContext get(BlockPos pos) {
return SERVERS.get(serializeBlockPos(pos));
}

Expand All @@ -55,7 +55,7 @@ public boolean exists(BlockPos pos) {
}

public String toJSON() {
Type typeObject = new TypeToken<HashMap<String, WebServerContext>>() {
Type typeObject = new TypeToken<HashMap<String, WebserverContext>>() {
}.getType();

Gson gson = new GsonBuilder()
Expand All @@ -73,28 +73,28 @@ public void writeToConfig() throws IOException {
myWriter.close();
}

public static WebServers loadFromConfig() {
public static Webservers loadFromConfig() {
Path path = Paths.get("config", "webservers.json");
try (FileReader myReader = new FileReader(path.toString())) {
String json = IOUtils.toString(myReader);
myReader.close();

return fromJSON(json);
} catch (IOException e) {
return new WebServers();
return new Webservers();
}
}

public static WebServers fromJSON(String json) {
Type typeObject = new TypeToken<HashMap<String, WebServerContext>>() {
public static Webservers fromJSON(String json) {
Type typeObject = new TypeToken<HashMap<String, WebserverContext>>() {
}.getType();

Gson gson = new GsonBuilder()
.excludeFieldsWithoutExposeAnnotation()
.create();

HashMap<String, WebServerContext> map = gson.fromJson(json, typeObject);
var ws = new WebServers();
HashMap<String, WebserverContext> map = gson.fromJson(json, typeObject);
var ws = new Webservers();
ws.SERVERS = map;

return ws;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class WebserverBlock extends StatefulBlock {

// keeps a map of registered database blocks so we can check for updates
// on server tick
private static WebServers SERVERS = new WebServers();
private static Webservers SERVERS = new Webservers();
private static boolean initialized = false;

private static ExecutorService service = new ThreadPoolExecutor(4, 1000, 0L, TimeUnit.MILLISECONDS,
Expand Down Expand Up @@ -182,10 +182,10 @@ public static void registerEvents() {
if (!initialized) {
initialized = true;

SERVERS = WebServers.loadFromConfig();
SERVERS = Webservers.loadFromConfig();

// start all the servers
for (Entry<BlockPos, WebServerContext> entry : SERVERS.entrySet()) {
for (Entry<BlockPos, WebserverContext> entry : SERVERS.entrySet()) {
server.execute(() -> {
startServer(entry.getKey(), server.getOverworld(), entry.getValue());
});
Expand Down Expand Up @@ -215,7 +215,7 @@ public static void handleBlockUpdate(BlockPos pos, ServerWorld world) {

// we might not have created the instance yet
if (val == null) {
val = new WebServerContext();
val = new WebserverContext();
}

MicroservicesMod.LOGGER.info("configure server {} port: {} path: {} method: {}", pos, blockEntity.getServerPort(),
Expand All @@ -236,7 +236,7 @@ public static void handleBlockUpdate(BlockPos pos, ServerWorld world) {
}
}

public static void startServer(BlockPos pos, ServerWorld world, WebServerContext wctx) {
public static void startServer(BlockPos pos, ServerWorld world, WebserverContext wctx) {
// read the values from interpolation
String port = Interpolate.getValue(wctx.getServerPort());
String path = Interpolate.getValue(wctx.getServerPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import io.javalin.Javalin;

public class WebServerContext {
public class WebserverContext {
@Expose
private String serverPort;

Expand Down Expand Up @@ -50,6 +50,6 @@ public void setServer(Javalin server) {
this.server = server;
}

public WebServerContext() {
public WebserverContext() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import org.junit.jupiter.api.Test;

import com.github.hashicraft.microservices.blocks.WebServerContext;
import com.github.hashicraft.microservices.blocks.WebServers;
import com.github.hashicraft.microservices.blocks.WebserverContext;
import com.github.hashicraft.microservices.blocks.Webservers;
import com.github.hashicraft.microservices.interpolation.File;

import net.minecraft.util.math.BlockPos;
Expand All @@ -17,9 +17,9 @@ public class WebServersTests {

@Test
public void serializesDataToJSON() throws IOException {
WebServers servers = new WebServers();
Webservers servers = new Webservers();

WebServerContext context = new WebServerContext();
WebserverContext context = new WebserverContext();
context.setServerPort("8080");
context.setServerPath("/test");
context.setServerMethod("GET");
Expand All @@ -43,9 +43,9 @@ public void deserializesDataFromJSON() {
}
}""";

WebServers servers = WebServers.fromJSON(json);
Webservers servers = Webservers.fromJSON(json);

WebServerContext context = servers.get(new BlockPos(1, 2, 3));
WebserverContext context = servers.get(new BlockPos(1, 2, 3));

assertContains(context.getServerPort(), "8080");
}
Expand Down

0 comments on commit a8e5c02

Please sign in to comment.