⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basicserverconfig.java

📁 一个用java编写的服务器,对于学习网络编程的人来说是个很好的例子
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * This file is part of the QuickServer library 
 * Copyright (C) 2003-2005 QuickServer.org
 *
 * Use, modification, copying and distribution of this software is subject to
 * the terms and conditions of the GNU Lesser General Public License. 
 * You should have received a copy of the GNU LGP License along with this 
 * library; if not, you can download a copy from <http://www.quickserver.org/>.
 *
 * For questions, suggestions, bug-reports, enhancement-requests etc.
 * visit http://www.quickserver.org
 *
 */

package org.quickserver.util.xmlreader;

import org.quickserver.net.server.*;

/**
 * This class encapsulate the basic configuration of QuickServer.
 * @author Akshathkumar Shetty
 * @since 1.2
 * @see org.quickserver.util.xmlreader.QuickServerConfig
 * @see org.quickserver.util.xmlreader.QSAdminServerConfig
 */
public class BasicServerConfig implements java.io.Serializable {
	
	private String clientAuthenticationHandler; //v1.4.6
	private String clientEventHandler; //v1.4.6
	private String clientExtendedEventHandler; //v1.4.6
	private String clientCommandHandler;
	private String clientObjectHandler;
	private String clientBinaryHandler;
	private String clientData;
	private String clientWriteHandler; //v1.4.5
	
	private String serverBanner;
	private String name = null;
	private String maxConnectionMsg = "-ERR Server Busy. Max Connection Reached";	
	private String timeoutMsg = "-ERR Timeout";
	private int maxAuthTry = 5;
	private String maxAuthTryMsg = "-ERR Max Auth Try Reached";
	private int port = 9876;	
	private String bindAddr;
	private long maxConnection = -1;
	private int timeout = 1 * 60 * 1000; //1 min. socket timeout	
	
	private String consoleLoggingLevel = "INFO";
	private String consoleLoggingFormatter;

	//for object pool
	private ObjectPoolConfig objectPoolConfig = new ObjectPoolConfig();
	private boolean communicationLogging = false;

	//v1.3.3
	private AccessConstraintConfig accessConstraintConfig;
	private ServerHooks serverHooks;

	//v1.4.0
	private Secure secure = new Secure();
	private ServerMode serverMode = new ServerMode();

	//v1.4.5
	private AdvancedSettings advancedSettings = new AdvancedSettings();

	//v1.4.6
	private DefaultDataMode defaultDataMode = new DefaultDataMode();

	/**
     * Returns the name of the QuickServer
     * @see #setName
     */
	public String getName() {
		return name;
	}
    /**
     * Sets the name for the QuickServer. 
	 * XML Tag: &lt;name&gt;&lt;/name&gt;
     * @param name for the QuickServer
     * @see #getName
     */
	public void setName(String name) {
		if(name!=null && name.equals("")==false) 
			this.name = name;
	}

	/**
     * Returns the Server Banner of the QuickServer
     * @see #setServerBanner
     */
	public String getServerBanner() {
		return serverBanner;
	}
    /**
     * Sets the serverBanner for the QuickServer
	 * that will be displayed on the standard output [console]
	 * when server starts. &lt;br&gt;&nbsp;&lt;br&gt;
	 * To set welcome message to your client
	 * {@link org.quickserver.net.server.ClientEventHandler#gotConnected} 
	 * XML Tag: &lt;server-banner&gt;&lt;/server-banner&gt;
	 * @param banner for the QuickServer
     * @see #getServerBanner
     */
	public void setServerBanner(String banner) {
		if(banner!=null && banner.equals("")==false) 
			serverBanner = banner;
	}

	/**
     * Sets the port for the QuickServer to listen on.
	 * If not set, it will run on Port 9876<br/>
	 * XML Tag: &lt;port&gt;&lt;/port&gt;
	 * @param port to listen on.
     * @see #getPort
     */
	public void setPort(int port) {
		if(port>=0)
			this.port = port;
	}
	/**
     * Returns the port for the QuickServer
     * @see #setPort
     */
	public int getPort() {
		return port;
	}

	/**
     * Sets the ClientCommandHandler class that interacts with 
	 * client sockets.
	 * XML Tag: &lt;client-command-handler&gt;&lt;/client-command-handler&gt;
	 * @param handler the fully qualified name of the class that 
	 *  implements {@link org.quickserver.net.server.ClientCommandHandler}
	 * @see #getClientCommandHandler
     */
	public void setClientCommandHandler(String handler) {
		if(handler!=null && handler.equals("")==false) 
			clientCommandHandler = handler;
	}
	/**
     * Sets the ClientCommandHandler class that interacts with 
	 * client sockets.
	 * @since 1.4.6
     */
	public void setClientCommandHandler(ClientCommandHandler handler) {
		if(handler!=null) 
			clientCommandHandler = handler.getClass().getName();
	}
	/**
     * Returns the ClientCommandHandler class that interacts with 
	 * client sockets.
	 * @see #setClientCommandHandler
     */
	public String getClientCommandHandler() {
		return clientCommandHandler;
	}

	/**
     * Sets the ClientEventHandler class that gets notified of
	 * client events.
	 * XML Tag: &lt;client-event-handler&gt;&lt;/client-event-handler&gt;
	 * @param handler the fully qualified name of the class that 
	 *  implements {@link org.quickserver.net.server.ClientEventHandler}
	 * @see #getClientEventHandler
	 * @since 1.4.6
     */
	public void setClientEventHandler(String handler) {
		if(handler!=null && handler.equals("")==false) 
			clientEventHandler = handler;
	}
	/**
     * Sets the ClientEventHandler class that gets notified of
	 * client events.
	 * @since 1.4.6
     */
	public void setClientEventHandler(ClientEventHandler handler) {
		if(handler!=null) 
			clientEventHandler = handler.getClass().getName();
	}
	/**
     * Returns the ClientEventHandler class that gets notified of
	 * client events.
	 * @see #setClientEventHandler
	 * @since 1.4.6
     */
	public String getClientEventHandler() {
		return clientEventHandler;
	}

	/**
     * Sets the ClientExtendedEventHandler class that gets notified of
	 * client's extended events.
	 * XML Tag: &lt;client-extended-event-handler&gt;&lt;/client-extended-event-handler&gt;
	 * @param handler the fully qualified name of the class that 
	 *  implements {@link org.quickserver.net.server.ClientExtendedEventHandler}
	 * @see #getClientExtendedEventHandler
	 * @since 1.4.6
     */
	public void setClientExtendedEventHandler(String handler) {
		if(handler!=null && handler.equals("")==false) 
			clientExtendedEventHandler = handler;
	}
	/**
     * Sets the ClientExtendedEventHandler class that gets notified of
	 * client's extended events.
	 * @since 1.4.6
     */
	public void setClientExtendedEventHandler(ClientExtendedEventHandler handler) {
		if(handler!=null) 
			clientExtendedEventHandler = handler.getClass().getName();
	}
	/**
     * Returns the ClientExtendedEventHandler class that gets notified of
	 * client's extended events.
	 * @see #setClientExtendedEventHandler
	 * @since 1.4.6
     */
	public String getClientExtendedEventHandler() {
		return clientExtendedEventHandler;
	}

	/**
     * Sets the Authenticator class that handles the 
	 * authentication of the client.
	 * XML Tag: &lt;authenticator&gt;&lt;/authenticator&gt;
	 * @param authenticator the fully qualified name of the class 
	 * that implements {@link org.quickserver.net.server.Authenticator}.
	 * @see #getAuthenticator
	 * @since 1.3
     */
	public void setAuthenticator(String authenticator) {
		if(authenticator!=null && authenticator.equals("")==false) 
			this.clientAuthenticationHandler = authenticator;
	}
	/**
     * Sets the Authenticator class that handles the 
	 * authentication of the client.
	 * @since 1.4.6
     */
	public void setAuthenticator(Authenticator authenticator) {
		if(authenticator!=null) 
			this.clientAuthenticationHandler = authenticator.getClass().getName();
	}
	/**
     * Returns the Authenticator class that handles the 
	 * authentication of the client.
	 * @see #setAuthenticator
	 * @since 1.3
     */
	public String getAuthenticator() {
		return clientAuthenticationHandler;
	}

	/**
     * Sets the ClientAuthenticationHandler class that handles the 
	 * authentication of the client.
	 * XML Tag: &lt;client-authentication-handler&gt;&lt;/client-authentication-handler&gt;
	 * @param clientAuthenticationHandler the fully qualified name of the class 
	 * that implements {@link org.quickserver.net.server.ClientAuthenticationHandler}.
	 * @see #getClientAuthenticationHandler
	 * @since 1.4.6
     */
	public void setClientAuthenticationHandler(String clientAuthenticationHandler) {
		if(clientAuthenticationHandler!=null && clientAuthenticationHandler.equals("")==false) 
			this.clientAuthenticationHandler = clientAuthenticationHandler;
	}
	/**
     * Sets the ClientAuthenticationHandler class that handles the 
	 * authentication of the client.
	 * @since 1.4.6
     */
	public void setClientAuthenticationHandler(ClientAuthenticationHandler clientAuthenticationHandler) {
		if(clientAuthenticationHandler!=null) 
			this.clientAuthenticationHandler = clientAuthenticationHandler.getClass().getName();
	}
	/**
     * Returns the ClientAuthenticationHandler class that handles the 
	 * authentication of the client.
	 * @see #setClientAuthenticationHandler
	 * @since 1.4.6
     */
	public String getClientAuthenticationHandler() {
		return clientAuthenticationHandler;
	}

	/**
     * Sets the ClientData class that carries client data. 
	 * XML Tag: &lt;client-data&gt;&lt;/client-data&gt;
	 * @param data the fully qualified name of the class that 
	 * extends {@link org.quickserver.net.server.ClientData}.
	 * @see #getClientData
     */
	public void setClientData(String data) {
		if(data!=null && data.equals("")==false)
			this.clientData = data;
	}
	/**
     * Sets the ClientData class that carries client data. 
	 * @since 1.4.6
     */
	public void setClientData(ClientData data) {
		if(data!=null)
			this.clientData = data.getClass().getName();
	}
	/**
     * Returns the ClientData class string that carries client data  
	 * @return the fully qualified name of the class that 
	 * implements {@link org.quickserver.net.server.ClientData}.
	 * @see #setClientData
     */
	public String getClientData() {
		return clientData;
	}

	/**
     * Sets the Client Socket timeout in milliseconds.
	 * XML Tag: &lt;timeout&gt;&lt;/timeout&gt;
	 * @param time client socket timeout in milliseconds.
	 * @see #getTimeout
     */
	public void setTimeout(int time) {
		timeout = time;
	}
	/**
     * Returns the Client Socket timeout in milliseconds.
	 * @see #setTimeout
     */
	public int getTimeout() {
		return timeout;
	}

	/** 
	 * Sets maximum allowed login attempts.
	 * XML Tag: &lt;max-auth-try&gt;&lt;/max-auth-try&gt;
	 */
	public void setMaxAuthTry(int authTry) {
		maxAuthTry = authTry;
	}
	/** 
	 * Returns maximum allowed login attempts.
	 * Default is : 5
	 */
	public int getMaxAuthTry() {
		return maxAuthTry;
	}

	/** 
	 * Sets message to be displayed when maximum allowed login 
	 * attempts has reached.
	 * Default is : -ERR Max Auth Try Reached<br/>
	 * XML Tag: &lt;max-auth-try-msg&gt;&lt;/max-auth-try-msg&gt;
	 * @see #getMaxAuthTryMsg

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -