networkservercontrolimpl.java

来自「derby database source code.good for you.」· Java 代码 · 共 2,300 行 · 第 1/5 页

JAVA
2,300
字号
	 *	 * @return  stored application requester	 */	protected AppRequester getAppRequester(AppRequester appRequester)	{		AppRequester s = null;		if (SanityManager.DEBUG) {			if (appRequester == null)				SanityManager.THROWASSERT("null appRequester in getAppRequester");		}		if (!appRequesterTable.isEmpty())			s = (AppRequester)appRequesterTable.get(appRequester.prdid);		if (s == null)		{			appRequesterTable.put(appRequester.prdid, appRequester);			return appRequester;		}		else		{			//compare just in case there are some differences			//if they are different use the one we just read in			if (s.equals(appRequester))				return s;			else				return appRequester;		}	}	/**	 * Get the server manager level for a given manager	 *	 * @param manager codepoint for manager	 * @return manager level	 */	protected int getManagerLevel(int manager)	{		int mindex = CodePoint.getManagerIndex(manager);		if (SanityManager.DEBUG) {			if (mindex == CodePoint.UNKNOWN_MANAGER)			SanityManager.THROWASSERT("manager out of bounds");		}		return MGR_LEVELS[mindex];	}	/**	 * Check whether a CCSID code page is supported	 *	 * @param ccsid	CCSID to check	 * @return true if supported; false otherwise	 */	protected boolean supportsCCSID(int ccsid)	{		try {			CharacterEncodings.getJavaEncoding(ccsid);			}		catch (Exception e) {			return false;		}		return true;	}	/**	 * Put property message on console	 *	 * @param msgProp		message property key	 *	 * @exception throws an Exception if an error occurs	 */	protected void consolePropertyMessage(String msgProp)		throws Exception	{		consolePropertyMessageWork(msgProp, null);	}	/**	 * Put property message on console	 *	 * @param msgProp		message property key	 * @param arg			argument for message	 *	 * @exception throws an Exception if an error occurs	 */	protected void consolePropertyMessage(String msgProp, String arg)		throws Exception	{		consolePropertyMessageWork(msgProp, new String [] {arg});	}	/**	 * Put property message on console	 *	 * @param msgProp		message property key	 * @param args			argument array for message	 *	 * @exception throws an Exception if an error occurs	 */	protected void consolePropertyMessage(String msgProp, String [] args)		throws Exception	{		consolePropertyMessageWork(msgProp, args);	}	/**	 * Is this the command protocol	 * 	 * @param  val	 */	protected static boolean isCmd(String val)	{		if (val.equals(COMMAND_HEADER))			return true;		else			return false;	}	/*******************************************************************************/	/*        Private methods                                                      */	/*******************************************************************************/	/**	 * Write Command reply	 *	 * @param writer	writer to use 	 *	 * @exception	throws Exception if a problem occurs sending OK	 */	private void writeCommandReplyHeader(DDMWriter writer) throws Exception	{		writer.setCMDProtocol();		writer.writeString(REPLY_HEADER);	}	 	/**	 * Send OK from server to client after processing a command	 *	 * @param writer	writer to use for sending OK	 *	 * @exception	throws Exception if a problem occurs sending OK	 */	private void sendOK(DDMWriter writer) throws Exception	{		writeCommandReplyHeader(writer);		writer.writeByte(OK);		writer.flush();	}	/**	 * Send OK and int value	 *	 * @param writer writer to use for sending	 * @param val 	int val to send	 * 	 * @exception throws Exception if a problem occurs	 */	private void sendOKInt(DDMWriter writer, int val) throws Exception	{		writeCommandReplyHeader(writer);		writer.writeByte(OK);		writer.writeNetworkInt(val);		writer.flush();	}	/**	 * Send Error or Warning from server to client after processing a command	 *	 * @param writer	writer to use for sending message	 * @param messageType	1 for Warning, 2 for Error 3 for SQLError	 * @param message 	message 	 *	 * @exception	throws Exception if a problem occurs sending message	 */	private void sendMessage(DDMWriter writer, int messageType, String message) 		throws Exception	{		writeCommandReplyHeader(writer);		writer.writeByte(messageType);		writer.writeLDString(message);		writer.flush();	}	/**	 * Send SQL Exception from server to client after processing a command	 *	 * @param writer	writer to use for sending message	 * @param se		Cloudscape exception	 * @param type		type of exception, SQLERROR or SQLWARNING	 *	 * @exception	throws Exception if a problem occurs sending message	 */	private void sendSQLMessage(DDMWriter writer, SQLException se, int type)		throws Exception	{		StringBuffer locMsg = new StringBuffer();		//localize message if necessary		while (se != null)		{			if (currentSession != null && currentSession.langUtil != null)			{				locMsg.append(se.getSQLState()+":"+ 					MessageService.getLocalizedMessage(					currentSession.langUtil.getLocale(), ((EmbedSQLException)se).getMessageId(), 					((EmbedSQLException)se).getArguments()));			}			else				locMsg.append(se.getSQLState()+":"+se.getMessage());			se = se.getNextException();			if (se != null)				locMsg.append("\n");		}		sendMessage(writer, type, locMsg.toString());	}	/**	 * Send SysInfo information from server to client	 *	 * @param writer 	writer to use for sending sysinfo	 *	 * @exception throws Exception if a problem occurs sending value	 */	private void sendSysInfo(DDMWriter writer) throws Exception	{		StringBuffer sysinfo = new StringBuffer();		sysinfo.append(getNetSysInfo());		sysinfo.append(getCLSSysInfo());		try {			writeCommandReplyHeader(writer);			writer.writeByte(0);	//O.K.			writer.writeLDString(sysinfo.toString());		} catch (DRDAProtocolException e) {			consolePropertyMessage("DRDA_SysInfoWriteError.S", e.getMessage());		}		writer.flush();	}		/**	 * Send RuntimeInfo information from server to client	 *	 * @param writer 	writer to use for sending sysinfo	 *	 * @exception throws Exception if a problem occurs sending value	 */	private void sendRuntimeInfo(DDMWriter writer) throws Exception	{		try {			writeCommandReplyHeader(writer);			writer.writeByte(0);	//O.K.			writer.writeLDString(getRuntimeInfo());				} catch (DRDAProtocolException e) {			consolePropertyMessage("DRDA_SysInfoWriteError.S", e.getMessage());		}		writer.flush();	}		/**	 * Send property information from server to client	 *	 * @param writer 	writer to use for sending sysinfo	 *	 * @exception throws Exception if a problem occurs sending value	 */	private void sendPropInfo(DDMWriter writer) throws Exception	{		try {			ByteArrayOutputStream out = new ByteArrayOutputStream();			Properties p = getPropertyValues();			p.store(out, "NetworkServerControl properties");			try {				writeCommandReplyHeader(writer);				writer.writeByte(0);		//O.K.				writer.writeLDBytes(out.toByteArray());			} catch (DRDAProtocolException e) {				consolePropertyMessage("DRDA_PropInfoWriteError.S", e.getMessage());			}			writer.flush();		} 		catch (Exception e) {			consoleExceptionPrintTrace(e);		}	}	/**	 * Get Net Server information	 *	 * @return system information for the Network Server	 */	private String getNetSysInfo() 	{		StringBuffer sysinfo = new StringBuffer();		LocalizedResource localLangUtil = langUtil;		if (currentSession != null && currentSession.langUtil != null)		localLangUtil = currentSession.langUtil;		sysinfo.append(localLangUtil.getTextMessage("DRDA_SysInfoBanner.I")+ "\n");		sysinfo.append(localLangUtil.getTextMessage("DRDA_SysInfoVersion.I")+ " " + att_srvrlslv);		sysinfo.append("  ");		sysinfo.append(localLangUtil.getTextMessage("DRDA_SysInfoBuild.I")+ " " + buildNumber);		sysinfo.append("  ");		sysinfo.append(localLangUtil.getTextMessage("DRDA_SysInfoDrdaPRDID.I")+ " " + prdId);		if (SanityManager.DEBUG)		{			sysinfo.append("  ** SANE BUILD **");		}		sysinfo.append("\n");		// add property information		Properties p = getPropertyValues();		ByteArrayOutputStream bos = new ByteArrayOutputStream();		PrintStream ps =  new PrintStream(bos);		p.list(ps);		sysinfo.append(bos.toString());		return sysinfo.toString();	}	/**	 * @see NetworkServerControl#getRuntimeInfo	 */	private String getRuntimeInfo() 	{		return buildRuntimeInfo(langUtil);	}	/**	 * Get Cloudscape information	 *	 * @return system information for Cloudscape	 *	 * @exception throws IOException if a problem occurs encoding string	 */	private String getCLSSysInfo() throws IOException	{		ByteArrayOutputStream bos = new ByteArrayOutputStream();		LocalizedResource localLangUtil = langUtil;		if (currentSession != null && currentSession.langUtil != null)		localLangUtil = currentSession.langUtil;		LocalizedOutput aw = localLangUtil.getNewOutput(bos);		org.apache.derby.impl.tools.sysinfo.Main.getMainInfo(aw, false);		return bos.toString();	}	/**	 * Execute the command given on the command line	 *	 * @param args	array of arguments indicating command to be executed	 *	 * @exception Exception	throws an exception if an error occurs	 * see class comments for more information	 */	public void executeWork(String args[]) throws Exception	{		// For convenience just use NetworkServerControlImpls log writer for user messages		logWriter = makePrintWriter(System.out);				int command = 0; 		if (args.length > 0)			command = findCommand(args);		else		{			consolePropertyMessage("DRDA_NoArgs.U");		}		// if we didn't have a valid command just return - error already generated		if (command == COMMAND_UNKNOWN)			return;		// check that we have the right number of required arguments		if (commandArgs.size() != COMMAND_ARGS[command])			consolePropertyMessage("DRDA_InvalidNoArgs.U", COMMANDS[command]);		int min;		int max;		switch (command)		{			case COMMAND_START:				blockingStart(makePrintWriter(System.out));				break;			case COMMAND_SHUTDOWN:				shutdown();				consolePropertyMessage("DRDA_ShutdownSuccess.I");				break;			case COMMAND_TRACE:				{					boolean on = isOn((String)commandArgs.elementAt(0));					trace(sessionArg, on);					consoleTraceMessage(sessionArg, on);					break;				}			case COMMAND_TRACEDIRECTORY:				setTraceDirectory((String) commandArgs.elementAt(0));				consolePropertyMessage("DRDA_TraceDirectoryChange.I", traceDirectory);				break;			case COMMAND_TESTCONNECTION:				ping();				consolePropertyMessage("DRDA_ConnectionTested.I", new String [] 					{hostArg, (new Integer(portNumber)).toString()});				break;			case COMMAND_LOGCONNECTIONS:				{					boolean on = isOn((String)commandArgs.elementAt(0));					logConnections(on);					consolePropertyMessage("DRDA_LogConnectionsChange.I", on ? "DRDA_ON.I" : "DRDA_OFF.I");					break;				}			case COMMAND_SYSINFO:				{					String info = sysinfo();					consoleMessage(info);					break;				}			case COMMAND_MAXTHREADS:				max = 0;				try{					max = Integer.parseInt((String)commandArgs.elementAt(0));				}catch(NumberFormatException e){					consolePropertyMessage("DRDA_InvalidValue.U", new String [] 						{(String)commandArgs.elementAt(0), "maxthreads"});				}				if (max < MIN_MAXTHREADS)					consolePropertyMessage("DRDA_InvalidValue.U", new String [] 						{new Integer(max).toString(), "maxthreads"});				netSetMaxThreads(max);				break;			case COMMAND_RUNTIME_INFO:				String reply = runtimeInfo();				consoleMessage(reply);				break;			case COMMAND_TIMESLICE:				int timeslice = 0;				String timeSliceArg = (String)commandArgs.elementAt(0);            	try{                	timeslice = Integer.parseInt(timeSliceArg);            	}catch(NumberFormatException e){					consolePropertyMessage("DRDA_InvalidValue.U", new String [] 						{(String)commandArgs.elementAt(0), "timeslice"});            	}				if (timeslice < MIN_TIMESLICE)					consolePropertyMessage("DRDA_InvalidValue.U", new String [] 						{new Integer(timeslice).toString(), "timeslice"});				netSetTimeSlice(timeslice);								break;			default:				//shouldn't get here				if (SanityManager.DEBUG)					SanityManager.THROWASSERT("Invalid command in switch:"+ command);		}	}  	/**	 * Add session to the run queue	 *	 * @param clientSession	session needing work	 */	protected void runQueueAdd(Session clientSession)	{		synchronized(runQueue)		{			runQueue.addElement(clientSession);			runQueue.notify();		}	}	/**	 * Go through the arguments and find the command and save the dash arguments	 *	and arguments to the command.  Only one command is allowed in the argument	 *	list.

⌨️ 快捷键说明

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