001: /*
002: * $Id: ListenerPreferences.java,v 1.2 2002/09/16 08:05:06 jkl Exp $
003: *
004: * Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
005: *
006: * Use is subject to license terms, as defined in
007: * Anvil Sofware License, Version 1.1. See LICENSE
008: * file, or http://njet.org/license-1.1.txt
009: */
010: package anvil.server;
011:
012: import java.io.IOException;
013: import javax.servlet.http.Cookie;
014: import javax.servlet.http.HttpServletRequest;
015: import javax.servlet.http.HttpServletResponse;
016: import anvil.session.Session;
017: import anvil.server.listener.Listener;
018:
019: /**
020: * class ListenerPreferences
021: *
022: * @author: Jani Lehtimäki
023: */
024: public class ListenerPreferences extends Preferences {
025:
026: public static final String[] PREFERENCES = { "port", "int",
027: "timeout", "int", "maxclients", "int", "maxthreads", "int",
028: "keepalive", "int", "backlog", "int", };
029:
030: private int _port = 8080;
031: private int _timeout = 120;
032: private int _maxclients = 10;
033: private int _maxthreads = 10;
034: private int _keepalive = 10;
035: private int _backlog = 4;
036:
037: public ListenerPreferences(Zone parent) {
038: super (parent);
039: }
040:
041: public void setPort(int port) {
042: _port = port;
043: }
044:
045: public int getPort() {
046: return _port;
047: }
048:
049: public void setTimeout(int timeout) {
050: _timeout = timeout;
051: }
052:
053: public int getTimeout() {
054: return _timeout;
055: }
056:
057: public void setMaxClients(int max) {
058: _maxclients = max;
059: }
060:
061: public int getMaxClients() {
062: return _maxclients;
063: }
064:
065: public void setMaxThreads(int max) {
066: _maxthreads = max;
067: }
068:
069: public int getMaxThreads() {
070: return _maxthreads;
071: }
072:
073: public void setKeepAlive(int seconds) {
074: _keepalive = seconds;
075: }
076:
077: public int getKeepAlive() {
078: return _keepalive;
079: }
080:
081: public void setBackLog(int size) {
082: _backlog = size;
083: }
084:
085: public int getBackLog() {
086: return _backlog;
087: }
088:
089: public int getType() {
090: return LISTENER;
091: }
092:
093: public String[] getPreferences() {
094: return PREFERENCES;
095: }
096:
097: public Object getPreference(String name) {
098: if (name.equalsIgnoreCase("port")) {
099: return new Integer(_port);
100: }
101: if (name.equalsIgnoreCase("timeout")) {
102: return new Integer(_timeout);
103: }
104: if (name.equalsIgnoreCase("maxclients")) {
105: return new Integer(_maxclients);
106: }
107: if (name.equalsIgnoreCase("maxthreads")) {
108: return new Integer(_maxthreads);
109: }
110: if (name.equalsIgnoreCase("keepalive")) {
111: return new Integer(_keepalive);
112: }
113: if (name.equalsIgnoreCase("backlog")) {
114: return new Integer(_backlog);
115: }
116: return null;
117: }
118:
119: public boolean setPreference(String name, String value) {
120: if (name.equalsIgnoreCase("port")) {
121: setPort(ConfigReader.toInt(value));
122: } else if (name.equalsIgnoreCase("timeout")) {
123: setTimeout(ConfigReader.toInt(value));
124: } else if (name.equalsIgnoreCase("maxclients")) {
125: setMaxClients(ConfigReader.toInt(value));
126: } else if (name.equalsIgnoreCase("maxthreads")) {
127: setMaxThreads(ConfigReader.toInt(value));
128: } else if (name.equalsIgnoreCase("keepalive")) {
129: setKeepAlive(ConfigReader.toInt(value));
130: } else if (name.equalsIgnoreCase("backlog")) {
131: setBackLog(ConfigReader.toInt(value));
132: } else {
133: return false;
134: }
135: return true;
136: }
137:
138: public Listener createListener() {
139: Listener listener = new Listener(this);
140: listener.start();
141: return listener;
142: }
143:
144: }
|