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

📄 modelserverproxy.java

📁 这是一个以JAVA编写的程序,本人还没有试过,是一个简单的温度控制系统
💻 JAVA
字号:
package net.sf.dz.view.tcp.server;import java.io.PrintWriter;import java.util.Iterator;import java.util.HashMap;import java.util.Map;import java.util.StringTokenizer;import org.freehold.jukebox.logger.LogAware;import org.freehold.jukebox.logger.Logger;import net.sf.dz.Model;import net.sf.dz.device.model.Unit;/** * Server side model proxy. * * <p> * * The whole <code>*Proxy</code> hierarchy is not the most efficient nor * elegant way to do the job, however, since the entry points and interfaces * are well defined, it doesn't really matter as long as it does its job, * which is to enable the remote access to the {@link net.sf.dz.Model model} * without a heavy overhead of things like EJB. The overhead cannot be * tolerated because the model may be run on the hardware platforms with * memory and/or performance limitations, such as <a * href="http://www.ibutton.com/TINI/index.html" target="_top">TINI</a>. For * the same reason, the code better be compliant with the lowest possible * version of JDK - for example, TINI offers JDK 1.1 compliance - no * serialization, no reflection. As soon as first limitation is lifted, it * would be possible to implement the {@link net.sf.dz.view.tcp.Message * Message} using serialization, with the disappearance of the second it may * make sense to use the <code>java.lang.reflect.Proxy</code>, but this is * all in the future. Welcome to the stone age. * * @author Copyright &copy; <a href="mailto:vt@freehold.crocodile.org">Vadim Tkachenko</a> 2001-2002 * @version $Id: ModelServerProxy.java,v 1.4 2002/08/06 04:33:26 vtt Exp $ */public class ModelServerProxy extends AbstractServerProxy implements Model {    private Model model;        /**     * Unit map.     *     * The key is the proxy, the value is the unit object.     */    private Map unitMap = new HashMap();        public ModelServerProxy(Logger logger, Model model) {            super(logger);            // VT: FIXME: Check for the argument sanity                this.model = model;                for ( Iterator i = model.iterator(); i.hasNext(); ) {                    Unit unit = (Unit)i.next();            Unit proxy = new UnitServerProxy(logger, unit);                        unitMap.put(proxy, unit);        }    }        public Iterator iterator() {            return unitMap.keySet().iterator();    }        /**     * Render the model reflection.     *     * The reflection is rendered as XML object. The empty line is a     * terminator.     *     * @param pw The print writer to render the model onto.     */    public synchronized void renderReflection(PrintWriter pw) {            pw.println("<model>");                for ( Iterator i = unitMap.keySet().iterator(); i.hasNext(); ) {                    ((UnitServerProxy)i.next()).renderReflection(pw);        }                pw.println("</model>");        pw.println("");        pw.flush();        }        public void dumpState(PrintWriter pw) {            for ( Iterator i = unitMap.keySet().iterator(); i.hasNext(); ) {                    ((UnitServerProxy)i.next()).dumpState(pw);        }                pw.flush();    }        public void listen(PrintWriter pw) {            super.listen(pw);            for ( Iterator i = unitMap.keySet().iterator(); i.hasNext(); ) {                    ((UnitServerProxy)i.next()).listen(pw);        }    }        public void parse(String command) throws Throwable {            StringTokenizer st = new StringTokenizer(command, ":");        String target = st.nextToken();                if ( "unit".equals(target) ) {                    String unitName = st.nextToken();                    for ( Iterator i = unitMap.keySet().iterator(); i.hasNext(); ) {                            UnitServerProxy unitProxy = (UnitServerProxy)i.next();                                if ( unitProxy.getName().equals(unitName) ) {                                    unitProxy.parse(st);                    return;                }                        }                        throw new IllegalArgumentException("Unknown unit name '" + unitName + "'");                } else {                    throw new IllegalArgumentException("Unknown target: '" + target + "'");        }    }}

⌨️ 快捷键说明

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