From ad3e2db5eefd3093a066e7b61df0653abc9b6f2e Mon Sep 17 00:00:00 2001 From: ulrich Date: Fri, 07 May 2021 14:05:08 +0000 Subject: [PATCH] Nicht erforderliche globale Variablen entfernt --- src/de/uhilger/tango/Server.java | 43 ++++++++++++++++++++++++------------------- 1 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/de/uhilger/tango/Server.java b/src/de/uhilger/tango/Server.java index 7c47baf..d356c0f 100644 --- a/src/de/uhilger/tango/Server.java +++ b/src/de/uhilger/tango/Server.java @@ -36,6 +36,7 @@ import de.uhilger.tango.entity.Entity; import java.util.Iterator; import java.util.List; +import java.util.ResourceBundle; /** * Die Klasse Server stellt Methoden zur Ausführung eines HTTP-Servers @@ -64,7 +65,7 @@ private String ctx; - private HttpServer server; + //private HttpServer server; /** * Ein neues Objekt der Kalsse Server erzeugen @@ -73,7 +74,7 @@ */ public Server(int port) { this.port = port; - } + } /** * Den Port angeben, unter dem der Server erreichbar sein soll @@ -106,37 +107,41 @@ * Objekt * @throws java.lang.ClassNotFoundException */ - public void start() throws IOException, ClassNotFoundException { - logger.log(Level.INFO, App.getRs(RB_SERVER_START_MSG), Integer.toString(port)); + public void start(String wwwData, String conf) throws IOException, ClassNotFoundException { + ResourceBundle rb = ResourceBundle.getBundle(App.RB_NAME); + logger.log(Level.INFO, rb.getString(RB_SERVER_START_MSG), Integer.toString(port)); - String wwwData = App.getInitParameter(App.getRs(App.RB_AP_WWW_DATA)); + //String wwwData = App.getInitParameter(rb.getString(App.RB_AP_WWW_DATA)); File wwwDir = new File(wwwData); - server = HttpServer.create(new InetSocketAddress(port), 0); - server.createContext(ctx + App.getRs(RB_WEBROOT), new FileHandler(wwwDir.getAbsolutePath())); - ablageorteEinklinken(server); - server.createContext(ctx + App.getRs(RB_STORE), new StorageHandler()); - server.createContext(ctx + App.getRs(RB_STRG), new MediaSteuerung()); - server.createContext(ctx + App.getRs(RB_GSTRG), new GeraetSteuerung()); - server.createContext(ctx + App.getRs(RB_ALIST), new ListHandler()); - server.createContext(ctx + App.getRs(RB_STOP_SERVER), new StopServerHandler()); - server.setExecutor(Executors.newFixedThreadPool(20)); + HttpServer server = HttpServer.create(new InetSocketAddress(port), 0); + server.createContext(ctx + rb.getString(RB_WEBROOT), new FileHandler(wwwDir.getAbsolutePath())); + ablageorteEinklinken(server, rb, conf); + server.createContext(ctx + rb.getString(RB_STORE), new StorageHandler(conf)); + server.createContext(ctx + rb.getString(RB_STRG), new MediaSteuerung(conf)); + server.createContext(ctx + rb.getString(RB_GSTRG), new GeraetSteuerung(conf)); + server.createContext(ctx + rb.getString(RB_ALIST), new ListHandler(conf)); + server.createContext(ctx + rb.getString(RB_STOP_SERVER), new StopServerHandler()); + //server.setExecutor(Executors.newFixedThreadPool(20)); + server.setExecutor(Executors.newCachedThreadPool()); server.start(); } + /* public void ablageortEntfernen(String url) { server.removeContext(ctx + url); } - public void ablageortHinzufuegen(Ablageort ort) { + public void ablageortHinzufuegen(Ablageort ort, String conf) { server.createContext(ctx + ort.getUrl(), - new ListFileHandler(new File(ort.getOrt()).getAbsolutePath())); + new ListFileHandler(new File(ort.getOrt()).getAbsolutePath(), conf)); } + */ - private void ablageorteEinklinken(HttpServer server) + private void ablageorteEinklinken(HttpServer server, ResourceBundle rb, String conf) throws ClassNotFoundException, IOException { String typ = Ablageort.class.getSimpleName(); - FileStorage store = new FileStorage(App.getInitParameter(App.getRs(App.RB_AP_CONF))); + FileStorage store = new FileStorage(conf); List<String> orte = store.list(typ); Iterator<String> i = orte.iterator(); while(i.hasNext()) { @@ -147,7 +152,7 @@ logger.log(Level.FINE, "{0}{1}", new Object[]{ctx, ablageort.getUrl()}); logger.fine(ablageort.getOrt()); server.createContext(ctx + ablageort.getUrl(), - new ListFileHandler(new File(ablageort.getOrt()).getAbsolutePath())); + new ListFileHandler(new File(ablageort.getOrt()).getAbsolutePath(), conf)); } } } -- Gitblit v1.9.3