mirror of
https://bitbucket.org/projectswg/lightspeed.git
synced 2026-07-28 22:15:50 -04:00
Commit before massive changes
This commit is contained in:
@@ -38,15 +38,15 @@ import java.util.Set;
|
||||
|
||||
import com.projectswg.common.info.RelationalDatabase;
|
||||
import com.projectswg.common.info.RelationalServerFactory;
|
||||
import com.projectswg.lightspeed_frontend.data.BuildData;
|
||||
import com.projectswg.lightspeed_frontend.data.DeploymentData;
|
||||
import com.projectswg.lightspeed_frontend.data.ServerData;
|
||||
import com.projectswg.lightspeed_frontend.data.SharedBuildData;
|
||||
import com.projectswg.lightspeed_frontend.data.SharedDeploymentData;
|
||||
import com.projectswg.lightspeed_frontend.data.SharedServerData;
|
||||
|
||||
public class BackendData {
|
||||
|
||||
private final WeakMap<String, ServerData> serverMap;
|
||||
private final WeakMap<Long, BuildData> buildMap;
|
||||
private final WeakMap<Long, DeploymentData> deploymentMap;
|
||||
private final WeakMap<String, SharedServerData> serverMap;
|
||||
private final WeakMap<Long, SharedBuildData> buildMap;
|
||||
private final WeakMap<Long, SharedDeploymentData> deploymentMap;
|
||||
|
||||
public BackendData() {
|
||||
serverMap = new WeakMap<>();
|
||||
@@ -55,33 +55,33 @@ public class BackendData {
|
||||
loadServers();
|
||||
}
|
||||
|
||||
public void insertServer(ServerData server) {
|
||||
public void insertServer(SharedServerData server) {
|
||||
synchronized (serverMap) {
|
||||
if (serverMap.put(server.getName(), server) != null)
|
||||
return;
|
||||
}
|
||||
try (ServerTable serverTable = new ServerTable()) {
|
||||
serverTable.insertServer(new ServerInformation(server.getName(), server.getDirectory(), server.getJvmArguments()));
|
||||
serverTable.insertServer(new SQLServerData(server.getName(), server.getDirectory(), server.getJvmArguments()));
|
||||
}
|
||||
}
|
||||
|
||||
public void insertBuild(BuildData build) {
|
||||
public void insertBuild(SharedBuildData build) {
|
||||
synchronized (buildMap) {
|
||||
if (buildMap.put(build.getId(), build) != null)
|
||||
return;
|
||||
}
|
||||
try (BuildHistoryTable buildTable = new BuildHistoryTable()) {
|
||||
buildTable.insertBuildHistory(new BuildInformation(build));
|
||||
buildTable.insertBuildHistory(new SQLBuildData(build));
|
||||
}
|
||||
}
|
||||
|
||||
public void insertDeployment(DeploymentData deployment) {
|
||||
public void insertDeployment(SharedDeploymentData deployment) {
|
||||
synchronized (deploymentMap) {
|
||||
if (deploymentMap.put(deployment.getId(), deployment) != null)
|
||||
return;
|
||||
}
|
||||
try (DeploymentTable deploymentTable = new DeploymentTable()) {
|
||||
deploymentTable.insertDeployment(new DeploymentInformation(deployment));
|
||||
deploymentTable.insertDeployment(new SQLDeploymentData(deployment));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,19 +94,19 @@ public class BackendData {
|
||||
}
|
||||
}
|
||||
|
||||
public List<ServerData> getServerList() {
|
||||
List<ServerData> servers = new ArrayList<>(serverMap.size());
|
||||
public List<SharedServerData> getServerList() {
|
||||
List<SharedServerData> servers = new ArrayList<>(serverMap.size());
|
||||
synchronized (serverMap) {
|
||||
for (Entry<String, ServerData> e : serverMap.entrySet()) {
|
||||
for (Entry<String, SharedServerData> e : serverMap.entrySet()) {
|
||||
servers.add(e.getValue());
|
||||
}
|
||||
}
|
||||
return servers;
|
||||
}
|
||||
|
||||
public ServerData getServer(String serverId) {
|
||||
public SharedServerData getServer(String serverId) {
|
||||
synchronized (serverMap) {
|
||||
ServerData server = serverMap.get(serverId);
|
||||
SharedServerData server = serverMap.get(serverId);
|
||||
if (server != null)
|
||||
return server;
|
||||
server = fetchServer(serverId);
|
||||
@@ -115,9 +115,9 @@ public class BackendData {
|
||||
}
|
||||
}
|
||||
|
||||
public BuildData getBuild(long buildId) {
|
||||
public SharedBuildData getBuild(long buildId) {
|
||||
synchronized (buildMap) {
|
||||
BuildData build = buildMap.get(buildId);
|
||||
SharedBuildData build = buildMap.get(buildId);
|
||||
if (build != null)
|
||||
return build;
|
||||
build = fetchBuild(buildId);
|
||||
@@ -131,7 +131,7 @@ public class BackendData {
|
||||
try (RelationalDatabase db = RelationalServerFactory.getServerDatabase("lightspeed.db")) {
|
||||
try (ServerTable serverTable = new ServerTable(db)) {
|
||||
for (String serverId : serverTable.getServerStrings()) {
|
||||
ServerData server = fetchServer(serverId);
|
||||
SharedServerData server = fetchServer(serverId);
|
||||
serverMap.put(server.getName(), server);
|
||||
}
|
||||
}
|
||||
@@ -139,20 +139,20 @@ public class BackendData {
|
||||
}
|
||||
}
|
||||
|
||||
private ServerData fetchServer(String serverId) {
|
||||
private SharedServerData fetchServer(String serverId) {
|
||||
try (RelationalDatabase db = RelationalServerFactory.getServerDatabase("lightspeed.db")) {
|
||||
try (ServerTable serverTable = new ServerTable(db)) {
|
||||
ServerData server = createServerFromInfo(serverTable.getServerById(serverId));
|
||||
SharedServerData server = createServerFromInfo(serverTable.getServerById(serverId));
|
||||
fetchBuildHistory(db, server);
|
||||
return server;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void fetchBuildHistory(RelationalDatabase db, ServerData server) {
|
||||
private void fetchBuildHistory(RelationalDatabase db, SharedServerData server) {
|
||||
try (BuildHistoryTable buildTable = new BuildHistoryTable(db)) {
|
||||
for (BuildInformation info : buildTable.getBuildHistory(server.getName())) {
|
||||
BuildData build = createBuildFromInfo(server, info);
|
||||
for (SQLBuildData info : buildTable.getBuildHistory(server.getName())) {
|
||||
SharedBuildData build = createBuildFromInfo(server, info);
|
||||
synchronized (buildMap) {
|
||||
buildMap.put(build.getId(), build);
|
||||
}
|
||||
@@ -162,22 +162,22 @@ public class BackendData {
|
||||
}
|
||||
}
|
||||
|
||||
private BuildData fetchBuild(long buildId) {
|
||||
private SharedBuildData fetchBuild(long buildId) {
|
||||
try (RelationalDatabase db = RelationalServerFactory.getServerDatabase("lightspeed.db")) {
|
||||
try (BuildHistoryTable buildTable = new BuildHistoryTable(db)) {
|
||||
BuildInformation info = buildTable.getBuildById(buildId);
|
||||
ServerData server = getServer(info.getServerId());
|
||||
BuildData build = createBuildFromInfo(server, info);
|
||||
SQLBuildData info = buildTable.getBuildById(buildId);
|
||||
SharedServerData server = getServer(info.getServerId());
|
||||
SharedBuildData build = createBuildFromInfo(server, info);
|
||||
fetchDeploymentHistory(db, build);
|
||||
return build;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void fetchDeploymentHistory(RelationalDatabase db, BuildData build) {
|
||||
private void fetchDeploymentHistory(RelationalDatabase db, SharedBuildData build) {
|
||||
try (DeploymentTable deploymentTable = new DeploymentTable(db)) {
|
||||
for (DeploymentInformation info : deploymentTable.getDeployments(build.getId())) {
|
||||
DeploymentData deployment = createDeploymentFromInfo(build, info);
|
||||
for (SQLDeploymentData info : deploymentTable.getDeployments(build.getId())) {
|
||||
SharedDeploymentData deployment = createDeploymentFromInfo(build, info);
|
||||
build.addDeployment(deployment);
|
||||
synchronized (deploymentMap) {
|
||||
deploymentMap.put(deployment.getId(), deployment);
|
||||
@@ -186,15 +186,15 @@ public class BackendData {
|
||||
}
|
||||
}
|
||||
|
||||
private ServerData createServerFromInfo(ServerInformation info) {
|
||||
ServerData server = new ServerData(info.getId());
|
||||
private SharedServerData createServerFromInfo(SQLServerData info) {
|
||||
SharedServerData server = new SharedServerData(info.getId());
|
||||
server.setDirectory(info.getDir());
|
||||
server.setJvmArguments(info.getJvmArgs());
|
||||
return server;
|
||||
}
|
||||
|
||||
private BuildData createBuildFromInfo(ServerData server, BuildInformation info) {
|
||||
BuildData build = new BuildData(info.getId(), server);
|
||||
private SharedBuildData createBuildFromInfo(SharedServerData server, SQLBuildData info) {
|
||||
SharedBuildData build = new SharedBuildData(info.getId(), server);
|
||||
build.setTime(info.getCompletedTime());
|
||||
build.setBuildString(info.getBuildString());
|
||||
build.setTestString(info.getTestString());
|
||||
@@ -208,8 +208,8 @@ public class BackendData {
|
||||
return build;
|
||||
}
|
||||
|
||||
private DeploymentData createDeploymentFromInfo(BuildData build, DeploymentInformation info) {
|
||||
DeploymentData deployment = new DeploymentData(info.getId(), build);
|
||||
private SharedDeploymentData createDeploymentFromInfo(SharedBuildData build, SQLDeploymentData info) {
|
||||
SharedDeploymentData deployment = new SharedDeploymentData(info.getId(), build);
|
||||
deployment.setStartTime(info.getStartTime());
|
||||
deployment.setEndTime(info.getEndTime());
|
||||
return deployment;
|
||||
|
||||
Reference in New Issue
Block a user