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

📄 sampleadapter.java

📁 SUnRDIS网络应用平台,可以在该平台上开发RFID应用,系统.
💻 JAVA
字号:
/* * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. *  */package com.mycompany.adapter.sample;import java.util.*;import java.util.logging.*;import java.io.*;import java.text.MessageFormat;import java.net.URI;import com.sun.autoid.identity.*;import com.sun.autoid.adapter.AbstractStateController;import com.sun.autoid.adapter.AbstractReaderAdapter;import com.sun.autoid.adapter.TimeoutException;import com.sun.autoid.adapter.command.ResponseInterpreter;/** * * Sample Reader Adapter to the Sun Java System RFID Event Manager * *<p> * <b>Properties:</b> *<ul> * <li><b>LogLevel</b> set the logging level @see java.util.logging.Level</li> * <li><b>hostname</b> the ip address or host name of the reader </li> * <li><b>port</b> the port to connect to on the reader, default is port 8080/li> * <li><b>readerepc</b> the epc assigned to the reader</li> * <li><b>autoread</b> indicates whether or not the reader should go into autoread mode. If true, the reader *      gathers tag information for <b>scanDuration</b> msecs reports its findings and loops again</li> * <li><b>scanDuration</b> the number of msecs the reader pulses its antennae and scans for tags, default is 500 msecs</li> * <li> <b>communicationTimeout</b> the number of msecs the reader adapter will wait before retransmiting requests, *      default = 10000 msec </li> *</ul> * */public class SampleAdapter extends AbstractReaderAdapter implements SampleAdapterMBean {        public static final String NAME = "SampleAdapter";    private static final int PORT = 9011;        private String hostname = null;    private int port = PORT;    private boolean autoread = false;    /** Creates a new instance of SampleAdapter     *     * @param properties the Properties for this reader     */    public SampleAdapter(Properties properties) throws Exception {        super(properties);        try {            setRuntimeProperties(properties);            logger.log(Level.INFO, "Created {0}", this.getName());        }catch(Exception ex) {            String message = MessageFormat.format(                "Failed to setup {0} Adapter",                new Object[] { this.getName() });            logger.log(Level.SEVERE, message, ex);	    throw ex;        }            }           /**     * processes the properties for this reader     *     * @param properties the Properties     */    private void setRuntimeProperties(Properties properties) throws Exception {                hostname = getHostnameProperty();        if (hostname == null)            throw new Exception("'hostname' must be specified");        port = getPortProperty(PORT);        autoread = getAutoreadProperty();    }            /**     * start the component processing     * It starts the worker thread daemon     */    public void startup() {        try {            super.startup();                        logger.log(Level.FINEST,"Starting reader: {0}", this.getName());            deviceIO = new SampleReaderIO(this, hostname, port, 1, properties);            controller = new SampleStateController(this, (SampleReaderIO)deviceIO, properties);            controller.setAutoRead(autoread);            controller.start();           logger.log(Level.FINEST,"Started reader: {0}", this.getName());        } catch (Exception ex) {            logger.log(Level.SEVERE, "Failed to start Sample Adapter", ex);            return;        }                    }        public void updateReaderProperties(Properties readerProps) {        Iterator iter = readerProps.keySet().iterator();        while(iter.hasNext()) {            String key = (String)iter.next();            if(key.equals("Supported Protocols:") ||            key.equals("Firmware Version:"))                continue;            String val = readerProps.getProperty(key);            String oldValue = properties.getProperty(key);            properties.setProperty(key,  val);            propertyChangeSupport.firePropertyChange(key, oldValue, val);        }    }              }

⌨️ 快捷键说明

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