ReportServer fixes and improvements.
This commit is contained in:
parent
6f82f8349d
commit
cd18d2a94f
@ -4,11 +4,9 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
import com.google.gson.JsonArray;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import redis.clients.jedis.JedisPubSub;
|
import redis.clients.jedis.JedisPubSub;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -18,9 +16,7 @@ public class JedisPubSubHandler extends JedisPubSub
|
|||||||
{
|
{
|
||||||
private File _directory;
|
private File _directory;
|
||||||
|
|
||||||
private Gson _gson = new GsonBuilder()
|
private Gson _gson = new Gson();
|
||||||
.setPrettyPrinting()
|
|
||||||
.create();
|
|
||||||
|
|
||||||
public JedisPubSubHandler(File directory)
|
public JedisPubSubHandler(File directory)
|
||||||
{
|
{
|
||||||
@ -35,33 +31,44 @@ public class JedisPubSubHandler extends JedisPubSub
|
|||||||
@Override
|
@Override
|
||||||
public void onMessage(String channel, String dataString)
|
public void onMessage(String channel, String dataString)
|
||||||
{
|
{
|
||||||
if (channel.equals(ReportServer.CHANNEL_DEPLOY))
|
try
|
||||||
{
|
{
|
||||||
JsonObject data = _gson.fromJson(dataString, JsonObject.class);
|
if (channel.equals(ReportServer.CHANNEL_DEPLOY))
|
||||||
String token = data.get("token").getAsString();
|
|
||||||
JsonArray snapshotArray = data.get("snapshots").getAsJsonArray();
|
|
||||||
|
|
||||||
File target = new File(_directory, token + ".json");
|
|
||||||
String json = _gson.toJson(snapshotArray);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
Files.write(target.toPath(), Arrays.asList(json.split("\n")));
|
Map<String, Object> data = _gson.fromJson(dataString, Map.class);
|
||||||
|
String token = (String) data.get("token");
|
||||||
|
|
||||||
|
File target = new File(_directory, token + ".json");
|
||||||
|
System.out.println("Received ChatSnap, token = " + token + ", writing to file.");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Files.write(target.toPath(), Arrays.asList(dataString.split("\n")));
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
else if (channel.equals(ReportServer.CHANNEL_DESTROY))
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
// dataString = token
|
||||||
|
File target = new File(_directory, dataString + ".json");
|
||||||
|
System.out.println("Removing ChatSnap, token = " + dataString);
|
||||||
|
|
||||||
|
if (target.exists() && !target.delete())
|
||||||
|
{
|
||||||
|
System.out.println("Failed to delete: " + target.getPath());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (channel.equals(ReportServer.CHANNEL_DESTROY))
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
// dataString = token
|
System.out.println("Excepting whilst receiving redis message.");
|
||||||
File target = new File(_directory, dataString + ".json");
|
System.out.println("Channel = " + channel);
|
||||||
|
System.out.println("Data: ");
|
||||||
if (target.exists() && !target.delete())
|
System.out.println(dataString);
|
||||||
{
|
e.printStackTrace();
|
||||||
System.out.println("Failed to delete: " + target.getPath());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,8 +16,8 @@ public class ReportServer
|
|||||||
|
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
{
|
{
|
||||||
new ReportServer(new JedisPool(new JedisPoolConfig(), "10.3.203.80", 6379)); // TODO is this okay?
|
System.out.println("Starting...");
|
||||||
System.out.println("Started.");
|
new ReportServer(new JedisPool(new JedisPoolConfig(), "10.3.203.80", 6379, 10)); // TODO is this okay?
|
||||||
}
|
}
|
||||||
|
|
||||||
private JedisPool _jedisPool;
|
private JedisPool _jedisPool;
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
package mineplex.core.chatsnap.publishing;
|
package mineplex.core.chatsnap.publishing;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -15,8 +11,6 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import com.google.gson.FieldNamingPolicy;
|
|
||||||
import com.google.gson.FieldNamingStrategy;
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
@ -70,12 +64,12 @@ public class SnapshotPublisher
|
|||||||
jsonObject.addProperty("token", token);
|
jsonObject.addProperty("token", token);
|
||||||
String json = GSON.toJson(jsonObject);
|
String json = GSON.toJson(jsonObject);
|
||||||
|
|
||||||
/*try (Jedis jedis = _jedisPool.getResource())
|
try (Jedis jedis = _jedisPool.getResource())
|
||||||
{
|
{
|
||||||
jedis.publish(CHANNEL_DEPLOY, json);
|
jedis.publish(CHANNEL_DEPLOY, json);
|
||||||
}*/
|
}
|
||||||
|
|
||||||
try
|
/*try
|
||||||
{
|
{
|
||||||
File dir = new File("data");
|
File dir = new File("data");
|
||||||
dir.mkdir();
|
dir.mkdir();
|
||||||
@ -88,7 +82,7 @@ public class SnapshotPublisher
|
|||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unpublishChatLog(String token)
|
public void unpublishChatLog(String token)
|
||||||
|
Loading…
Reference in New Issue
Block a user