qsp.java

来自「pos机交易实现源代码 含金融卡交易8583协议实现 开发环境:linux 」· Java 代码 · 共 499 行 · 第 1/2 页

JAVA
499
字号
	Logger.log (new LogEvent (this, "fatalError", e));	throw e;    }    public void setLogger (Logger logger, String realm) {	this.logger = logger;	this.realm  = realm;    }    public String getRealm () {	return realm;    }    public Logger getLogger () {	return logger;    }    public void configure (String tagname) throws ConfigurationException {	QSPConfigurator configurator = QSPConfiguratorFactory.create (tagname);	NodeList nodes = config.getElementsByTagName (tagname);	if (configurator instanceof QSPReConfigurator && nodes.getLength()>0)	    reconfigurables.add (tagname);	for (int i=0; i<nodes.getLength(); i++) {	    configurator.config (this, nodes.item(i));	}    }    public void reconfigure (String tagname) throws ConfigurationException {	QSPConfigurator configurator = QSPConfiguratorFactory.create (tagname);	if (configurator instanceof QSPReConfigurator) {	    NodeList nodes = config.getElementsByTagName (tagname);	    for (int i=0; i<nodes.getLength(); i++) 		((QSPReConfigurator)configurator).reconfig 		    (this, nodes.item(i));	}    }    protected void configure () throws ConfigurationException {        LogEvent evt = new LogEvent (this, "configure");        String[] st = getSupportedTags ();        for (int i=0; i<st.length; i++) {            evt.addMessage (st [i]);            configure (st [i]);        }        evt.addMessage ("-extended tags-");        st = getExtendedTags ();        for (int i=0; i<st.length; i++) {            evt.addMessage (st [i]);            configure (st [i]);        }        Logger.log (evt);    }    private boolean monitorConfigFile () {	long l;        while (lastModified == (l=configFile.lastModified())) {            if (newConfigFile) {                Logger.log (new LogEvent (this, "new-config-detected"));                return true;            }            try {                Thread.interrupted ();  // clear interrupt flag                Thread.sleep (monitorConfigInterval);            } catch (InterruptedException e) {                 Logger.log (                    new LogEvent (this, "sleep-interrupted",                         Long.toString (monitorConfigInterval) + "/" +                        Long.toString (l) + "/" +                         Long.toString (lastModified)                    )                );                return true;            }        }	return (lastModified = l) != 0;    }    public void shutdown () {        Logger.log (new LogEvent (this, "shutdown"));        new Thread() {            public void run() {                try {                    Thread.sleep (1000);                } catch (InterruptedException e) { }                System.exit (0);            }        }.start ();    }    public static void shutdownMuxes() {        Iterator iter = NameRegistrar.getMap().values().iterator();        while (iter.hasNext()) {            Object obj = iter.next();            if (obj instanceof ISOMUX) {                ((ISOMUX)obj).terminate (60000);            }        }    }    public void setConfiguration (Configuration cfg) {        this.cfg = cfg;    }    public Configuration getConfiguration () {        return cfg;    }    public String get (String propName) {        return            (cfg != null) ? cfg.get (propName) : null;    }    public void run () {        while (newConfigFile || monitorConfigFile ()) {            try {                parser.parse (configFile.getPath());                setConfig (parser.getDocument());                if (newConfigFile) {                    Logger.log (                        new LogEvent (this, "new-config-file", configFile)                    );                    configure();                    newConfigFile = false;                } else {                    Iterator iter = getReConfigurables().iterator();                    while (iter.hasNext())                        reconfigure ((String) iter.next());                }            } catch (Exception e) {                Logger.log (new LogEvent (this, "QSP", e));                try {                    Thread.sleep (1000);                } catch (InterruptedException ie) { }            }        }        Logger.log (new LogEvent (this, "shutdown-start"));        shutdownMuxes ();        Logger.log (new LogEvent (this, "shutdown"));        System.exit (0);    }    public static QSP getInstance (String name)         throws NameRegistrar.NotFoundException    {        return (QSP) NameRegistrar.get (NAMEREGISTRAR_PREFIX + name);    }    public static QSP getInstance ()         throws NameRegistrar.NotFoundException    {        return getInstance (DEFAULT_NAME);    }    /**     * @return QSP's config instance (global properties)     */    public static Configuration getGlobalConfiguration () {        Configuration cfg;        try {            cfg = getInstance().getConfiguration();        } catch (NameRegistrar.NotFoundException e) {            cfg = new SimpleConfiguration();        }        return cfg;    }    /**     * Launches QSP     * @param configFile XML based QSP config file     * @param supportedTags array of supported tags     * @param extendedTags array of extended tags     * @param validation true to validate XML file     */    public static void launch (        String configFile,         String[] supportedTags,         String[] extendedTags, boolean validation)    {	DOMParser parser = new DOMParser();        QSP qsp = new QSP (supportedTags, extendedTags, validation);	try {            qsp.setParser (parser);	    qsp.setConfigFile (configFile);	    parser.setFeature(                "http://xml.org/sax/features/validation",                 qsp.getValidation()            );	    parser.setErrorHandler (qsp);	    parser.parse (qsp.configFile.getPath());	    qsp.setConfig (parser.getDocument());            qsp.configure ();                qsp.registerMBean (                TransientSpace.getSpace (), "type=space,name=default"            );	    if (controlPanel != null)		controlPanel.showUp();	    if (qsp.getLogger() != null) 		new SystemMonitor (3600000, qsp.getLogger(), "monitor");            ThreadGroup group = new ThreadGroup("QSP");            new Thread (group, qsp).start();	} catch (Exception e) {	    Logger.log (new LogEvent (qsp, "error", e));            e.printStackTrace ();	}    }    /**     * @return task instance with given name.     * @throws NameRegistrar.NotFoundException;     * @see NameRegistrar     */    public static Object getTask (String name)	throws NameRegistrar.NotFoundException    {	return NameRegistrar.get (            ConfigTask.NAMEREGISTRAR_PREFIX+name        );    }    protected void createMBeanServer ()         throws IOException, MalformedObjectNameException,        InstanceAlreadyExistsException,         MBeanRegistrationException,        MalformedObjectNameException,        NotCompliantMBeanException    {        Trace.parseTraceProperties ();        String domain = cfg.get ("jmx.domain", "QSP");        server = MBeanServerFactory.createMBeanServer(domain);        ObjectName mbeanObjectName = new ObjectName(domain + ":type=QSP");        server.registerMBean (this, mbeanObjectName);    }    public void registerMBean (Object bean, String type)         throws IOException, NotCompliantMBeanException,               InstanceAlreadyExistsException,               InstanceAlreadyExistsException,                MalformedObjectNameException,               MBeanRegistrationException    {        MBeanServer server = getMBeanServer();        ObjectName name = new ObjectName (            server.getDefaultDomain() + ":" + type         );        server.registerMBean (bean, name);    }    /**     * Launches QSP with default values for supportedTags and validation     * @param configFile XML based QSP config file     */    public static void launch (String configFile) {        launch (configFile, SUPPORTED_TAGS, new String[0], true);    }    public static void main (String args[]) {	if (args.length != 1) {	    System.out.println ("Usage: org.jpos.apps.qsp.QSP <configfile>");	    System.exit (1);	}        launch (args[0]);    }}

⌨️ 快捷键说明

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