Advertisement
Guest User

Untitled

a guest
May 26th, 2015
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.94 KB | None | 0 0
  1. package hr.fer.zemris.java.webserver;
  2.  
  3. import hr.fer.zemris.java.webserver.RequestContext.RCCookie;
  4.  
  5. import java.io.OutputStream;
  6. import java.io.PushbackInputStream;
  7. import java.net.Socket;
  8. import java.nio.file.Path;
  9. import java.util.ArrayList;
  10. import java.util.HashMap;
  11. import java.util.List;
  12. import java.util.Map;
  13. import java.util.concurrent.ExecutorService;
  14.  
  15. public class SmartHttpServer {
  16.     private String address;
  17.     private int port;
  18.     private int workerThreads;
  19.     private int sessionTimeout;
  20.     private Map<String, String> mimeTypes = new HashMap<String, String>();
  21.     private ServerThread serverThread;
  22.     private ExecutorService threadPool;
  23.     private Path documentRoot;
  24.  
  25.     public SmartHttpServer(String configFileName) {
  26.         // … do stuff here …
  27.     }
  28.  
  29.     protected synchronized void start() {
  30.         // … start server thread if not already running …
  31.         // … init threadpool by Executors.newFixedThreadPool(...); …
  32.     }
  33.  
  34.     protected synchronized void stop() {
  35.         // … signal server thread to stop running …
  36.         // … shutdown threadpool …
  37.     }
  38.  
  39.     protected class ServerThread extends Thread {
  40.         @Override
  41.         public void run() {
  42.             // given in pesudo-code:
  43.             // open serverSocket on specified port
  44.             // while(true) {
  45.             // Socket client = serverSocket.accept();
  46.             // ClientWorker cw = new ClientWorker(client);
  47.             // submit cw to threadpool for execution
  48.             // }
  49.         }
  50.     }
  51.  
  52.     private class ClientWorker implements Runnable {
  53.         private Socket csocket;
  54.         private PushbackInputStream istream;
  55.         private OutputStream ostream;
  56.         private String version;
  57.         private String method;
  58.         private Map<String, String> params = new HashMap<String, String>();
  59.         private Map<String, String> permPrams = null;
  60.         private List<RCCookie> outputCookies = new ArrayList<RequestContext.RCCookie>();
  61.         private String SID;
  62.  
  63.         public ClientWorker(Socket csocket) {
  64.             super();
  65.             this.csocket = csocket;
  66.         }
  67.  
  68.         @Override
  69.         public void run() {
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement