Implemented the build related packet responses

This commit is contained in:
Josh Larson
2017-03-01 06:47:56 -06:00
parent 398f237fa0
commit 4ebeee9b17
3 changed files with 43 additions and 4 deletions

View File

@@ -145,6 +145,7 @@ public class DeploymentService extends Service {
for (ServerDeploymentData d : deploymentHistory) {
if (d.getId() == p.getDeploymentId()) {
new OutboundPacketIntent(address, new ResponseDeploymentDetailedPacket(d.getShared())).broadcast();
break;
}
}
}

View File

@@ -29,12 +29,17 @@ package com.projectswg.lightspeed.build;
import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import com.projectswg.common.control.Assert;
@@ -47,23 +52,31 @@ import com.projectswg.common.info.RelationalDatabase;
import com.projectswg.common.info.RelationalServerFactory;
import com.projectswg.common.intents.InboundPacketIntent;
import com.projectswg.common.intents.LaunchStarshipIntent;
import com.projectswg.common.intents.OutboundPacketIntent;
import com.projectswg.common.intents.PrepareStarshipIntent;
import com.projectswg.common.network.packets.Packet;
import com.projectswg.common.network.packets.post.PostBuildPacket;
import com.projectswg.common.network.packets.post.PostStopBuildPacket;
import com.projectswg.common.network.packets.request.RequestBuildDetailedPacket;
import com.projectswg.common.network.packets.request.RequestBuildListPacket;
import com.projectswg.common.network.packets.response.ResponseBuildDetailedPacket;
import com.projectswg.common.network.packets.response.ResponseBuildListPacket;
import com.projectswg.lightspeed.build.ServerBuildData.InstallationCallback;
import com.projectswg.lightspeed.server.ServerServerData;
import com.projectswg.lightspeed_frontend.data.SharedBuildData;
public class BuildService extends Service {
private final JavaBuildMethod buildMethod;
private final AtomicLong buildId;
private final Map <String, ServerBuildData> inprogress;
private final Set<ServerBuildData> buildHistory;
public BuildService() {
buildMethod = new JavaBuildMethod(getJdk());
buildId = new AtomicLong(0);
inprogress = new HashMap<>();
buildHistory = new HashSet<>();
registerForIntent(PrepareStarshipIntent.TYPE);
registerForIntent(InboundPacketIntent.TYPE);
@@ -117,6 +130,9 @@ public class BuildService extends Service {
if (old != null)
old.setState(InstallationState.CANCELLED);
}
synchronized (buildHistory) {
buildHistory.add(installation);
}
}
private void onInboundPacketIntent(InboundPacketIntent ipi) {
@@ -124,6 +140,8 @@ public class BuildService extends Service {
switch (p.getType()) {
case POST_BUILD: processBuild((PostBuildPacket) p); break;
case POST_STOP_BUILD: processPostStopBuild((PostStopBuildPacket) p); break;
case REQUEST_BUILD_LIST: processBuildList(ipi.getAddress(), (RequestBuildListPacket) p); break;
case REQUEST_BUILD_DETAILED:processBuildDetailed(ipi.getAddress(), (RequestBuildDetailedPacket) p); break;
default: break;
}
}
@@ -142,6 +160,30 @@ public class BuildService extends Service {
}
}
private void processBuildList(InetSocketAddress address, RequestBuildListPacket p) {
synchronized (buildHistory) {
List<SharedBuildData> buildList = new ArrayList<>();
for (ServerBuildData build : buildHistory) {
if (p.getServerId().equals(build.getServer().getName())) {
buildList.add(build.getShared());
}
}
new OutboundPacketIntent(address, new ResponseBuildListPacket(p.getServerId(), buildList)).broadcast();
}
}
private void processBuildDetailed(InetSocketAddress address, RequestBuildDetailedPacket p) {
synchronized (buildHistory) {
for (ServerBuildData build : buildHistory) {
if (p.getBuildId() == build.getId()) {
new OutboundPacketIntent(address, new ResponseBuildDetailedPacket(build.getShared())).broadcast();
break;
}
}
}
}
private void onCompleted(String serverId, ServerBuildData build) {
synchronized (inprogress) {
Assert.notNull(inprogress.remove(serverId));

View File

@@ -33,11 +33,8 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.projectswg.common.info.Log;
public class CustomJavaCommon {
protected static final String OUT_JAR = "bin/ProjectSWG.jar";
@@ -57,7 +54,6 @@ public class CustomJavaCommon {
public static int execute(String [] command, File dir, StringBuilder out, boolean output) {
try {
Log.i("Executing %s", Arrays.toString(command));
Process process = new ProcessBuilder(command).directory(dir).redirectErrorStream(true).start();
if (out == null)
ingestOutput(process.getInputStream(), output);