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

📄 remotemanager.java

📁 主要是对串口驱动的的一些控制源码!!! 在下载javacomm20-win32.zip后就可以使用。
💻 JAVA
字号:
/**
 * $Log: RemoteManager.java,v $
 * Revision 1.3  2003/02/01 13:23:35  mwulff
 * no message
 *
 * Revision 1.2  2003/01/17 16:01:25  mwulff
 * added support for remote message handling
 *
 * Revision 1.1  2003/01/16 13:08:09  mwulff
 * initial version
 *
 * Revision 1.2  2002/12/31 12:19:39  mwulff
 * no message
 *
 * Revision 1.1  2002/12/20 18:49:02  mwulff
 * no message
 *
 */
package de.fhm.jkf.resource.sv;

import java.sql.Timestamp;
import java.util.Date;

import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import de.fhm.jkf.comm.clsv.ResponseCommands;

/**
 * @author	marten wulff
 * 
 * * <br><br><center><table border="1" width="80%"><hr>
 * <strong><a href="http://jkf.sourceforge.net">The JKF Project</a></strong>
 * <p>
 * Copyright (C) 2002 by Marten Wulff
 * <p>
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * <p>
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * <p>
 * You should have received a copy of the <a href="http://www.gnu.org/copyleft/lesser.html">
 * GNU Lesser General Public License</a> along with this library; if not, write to
 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA  02111-1307  USA
 * <hr></table></center>
 */
public class RemoteManager {

	// Logging
	private static Logger logger = Logger.getLogger(RemoteManager.class);

	private static RemoteManager instance = null;
	private static Object semaphore = new Object();

	private ResponseCommands responseCommands = null;
	private Level defaultRemoteLogLevel = Level.DEBUG;

	// last changes made to the responseCommands
	private Timestamp lastChanges = null;

	/**
	 * Constructor for RemoteManager.
	 */
	private RemoteManager() {
		super();

		responseCommands = new ResponseCommands();
		responseCommands.setLogLevel(defaultRemoteLogLevel.toInt());
		lastChanges = new Timestamp(new Date().getTime());
	}

	/**
	 * Method for getting a reference to the singleton RemoteManager.
	 * 
	 * @return RemoteManager the reference
	 */
	public static RemoteManager instance() {
		if (instance == null) {
			synchronized (semaphore) {
				if (instance == null) {
					instance = new RemoteManager();
				}
			}
		}

		return instance;
	}

	/**
	 * Method for getting the latest ResponseCommands. If the timestamp
	 * of last changes to the ResponseCommands if after the last client
	 * connection to the server, the container holding the ResponseCommands
	 * is returned. Otherwise the client is up to date and null is returned.
	 * 
	 * @param lastClientConnection the TimeStamp of the last connection from 
	 * 			client to the server
	 * 
	 * @return ResponseCommands if the last client has been before last changes
	 * 			to the response commands or null if not
	 */
	public ResponseCommands getResponseCommands(Timestamp lastClientConnection) {

		if (lastClientConnection == null) {
			return responseCommands;
		}

		synchronized (semaphore) {
			if (lastChanges.after(lastClientConnection)) {
				return responseCommands;
			} else {
				return null;
			}
		}
	}

	/**
	 * Method for setting the Level of remote client log messages.
	 * 
	 * @param newLevel the new Level
	 */
	public void setClientLogLevel(Level newLevel) {
		synchronized(semaphore) {
			responseCommands.setLogLevel(newLevel.toInt());
			updateTimeStamp();
		}
		if(logger.isDebugEnabled()) {
			logger.debug("Setting Client LogLevel to: " + newLevel.toString());
		}
	}

	/**
	 * Method for getting the current client remote log Level. Only
	 * LoggingEvents with a Level greater or equal the this Level
	 * are transfered to the server and also only LoggingEvents, 
	 * retrieved from the client, are logged if their Level is 
	 * greater or equal to this Level.
	 * 
	 * @return Level the current remote log Level of the clients
	 */
	public Level getClientLogLevel() {
		return Level.toLevel(
			responseCommands.getLogLevel(),
			defaultRemoteLogLevel);
	}
	
	public void setClientResponseMessage(String message) {
		synchronized(semaphore) {
			responseCommands.setResponseMessage(message);
			updateTimeStamp();	
		}
		if(logger.isDebugEnabled()) {
			logger.debug("Sending message to client: " + message);
		}
	}

	/**
	 * Method for updating the timestamp at which the last
	 * changes for the response commands occured.
	 */
	private void updateTimeStamp() {
		lastChanges.setTime(new Date().getTime());

		if (logger.isDebugEnabled()) {
			logger.debug(
				"updating TimeStamp for last changes made to the ResponseCommands");
		}
	}
}

⌨️ 快捷键说明

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