Use NanoHTTPD instead, more stable.

This commit is contained in:
Steven Lawson 2013-08-26 20:39:30 -04:00
parent 7a6cc55640
commit dfb6df63c8
3 changed files with 1432 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,63 @@
package me.StevenLawson.TotalFreedomMod.HTTPD;
import java.io.IOException;
import java.util.Date;
import java.util.Map;
import me.StevenLawson.TotalFreedomMod.TFM_Log;
public class TFM_HTTPDManager
{
public static final int PORT = 28966;
//
private final TFM_HTTPD httpd = new TFM_HTTPD(PORT);
private TFM_HTTPDManager()
{
}
public void start()
{
try
{
httpd.start();
}
catch (IOException ex)
{
TFM_Log.severe(ex);
}
}
public void stop()
{
httpd.stop();
}
private static class TFM_HTTPD extends NanoHTTPD
{
public TFM_HTTPD(int port)
{
super(port);
}
public TFM_HTTPD(String hostname, int port)
{
super(hostname, port);
}
@Override
public Response serve(String uri, Method method, Map<String, String> headers, Map<String, String> parms, Map<String, String> files)
{
return new Response("<p>OK - " + new Date().toString() + "</p>");
}
}
public static TFM_HTTPDManager getInstance()
{
return TFM_HTTPDManagerHolder.INSTANCE;
}
private static class TFM_HTTPDManagerHolder
{
private static final TFM_HTTPDManager INSTANCE = new TFM_HTTPDManager();
}
}

View File

@ -6,6 +6,7 @@ import java.io.InputStream;
import java.util.*;
import me.StevenLawson.TotalFreedomMod.Commands.TFM_Command;
import me.StevenLawson.TotalFreedomMod.Commands.TFM_CommandLoader;
import me.StevenLawson.TotalFreedomMod.HTTPD.TFM_HTTPDManager;
import me.StevenLawson.TotalFreedomMod.Listener.*;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
@ -172,6 +173,8 @@ public class TotalFreedomMod extends JavaPlugin
}
}.runTaskLater(plugin, 20L);
TFM_HTTPDManager.getInstance().start();
TFM_Log.info("Plugin enabled.");
}
@ -180,6 +183,8 @@ public class TotalFreedomMod extends JavaPlugin
{
server.getScheduler().cancelTasks(plugin);
TFM_HTTPDManager.getInstance().stop();
TFM_Log.info("Plugin disabled.");
}