| 1: | ||
| 2: | /** | |
| 3: | * class Server. | |
| 4: | * Le "Context" du Strategy Pattern | |
| 5: | * | |
| 6: | * @author Laurent Dehoey I177416 | |
| 7: | * @version 23/01/2003 | |
| 8: | */ | |
| 9: | ||
| 10: | public class Server{ | |
| 11: | ||
| 12: | /** | |
| 13: | * Notre Serveur qui pourra en fonction des besoins | |
| 14: | * etre un "ClassicServer" : creation d'un nouveau thread protocolaire | |
| 15: | * la vole quand un client se prsente (dans la limite de "queue length" = 50 ?) | |
| 16: | * ou un "PoolServer" : creation d'un nombre fixe de threads protocolaires | |
| 17: | * la creation du serveur (prochain TP10) | |
| 18: | */ | |
| 19: | private AbstractServer server; | |
| 20: | ||
| 21: | /** Cration d'un serveur HTTP par dfaut, en stratgie classique | |
| 22: | * @param port le port associ | |
| 23: | */ | |
| 24: | public Server(int port) throws java.io.IOException{ | |
| 25: | final String DOC_ROOT = "."; | |
| 26: | Protocol httpService = new HttpProtocol(DOC_ROOT); | |
| 27: | // this.setVerbose(true); | |
| 28: | server = new ClassicServer(httpService,port); | |
| 29: | setVerbose(true); | |
| 30: | } | |
| 31: | ||
| 32: | /** Cration d'un serveur en stratgie classique, | |
| 33: | * le protocole est transmis par l'utilisateur | |
| 34: | * @param protocol le protocole de communication | |
| 35: | * @param port le port associ | |
| 36: | */ | |
| 37: | public Server(Protocol protocol, int port) throws java.io.IOException{ | |
| 38: | server = new ClassicServer(protocol,port); | |
| 39: | setVerbose(true); | |
| 40: | } | |
| 41: | ||
| 42: | /** Cration d'un serveur l'aide d'une instance | |
| 43: | * d'une classe drive de AbtsractServer | |
| 44: | * @param s le serveur | |
| 45: | */ | |
| 46: | public Server(AbstractServer s){ | |
| 47: | this.server = s; | |
| 48: | setVerbose(true); | |
| 49: | } | |
| 50: | ||
| 51: | /** Affectation du serveur courant l'aide d'une instance | |
| 52: | * d'une classe drive de AbtsractServer | |
| 53: | * @param s le serveur | |
| 54: | */ | |
| 55: | public void setServer(AbstractServer s){ | |
| 56: | this.server = s; | |
| 57: | setVerbose(true); | |
| 58: | } | |
| 59: | ||
| 60: | public void setVerbose(boolean verbose){ | |
| 61: | this.server.setVerbose(verbose); | |
| 62: | } | |
| 63: | ||
| 64: | public void interrupt(){ | |
| 65: | this.server.interrupt(); | |
| 66: | } | |
| 67: | /** | |
| 68: | * le point d'entre pour les tests unitaires | |
| 69: | * | |
| 70: | */ | |
| 71: | public static void main(String[] args) throws java.io.IOException{ | |
| 72: | // un serveur HTTP en 8111 ou en param d'appel | |
| 73: | Server httpServer; | |
| 74: | System.out.println("(java)Server 0.01a is Starting...."); | |
| 75: | ||
| 76: | if (args.length==1) | |
| 77: | httpServer = new Server(Integer.parseInt(args[0])); | |
| 78: | else | |
| 79: | httpServer = new Server(8111); | |
| 80: | System.out.println("\nstatic void main from Server.java has issued all its instructions"); | |
| 81: | System.out.println("\nJVM is waiting for the end of threads\n"); | |
| 82: | ||
| 83: | } | |
| 84: | ||
| 85: | ||
| 86: | } |
This page was automatically generated by SharpDevelop.