bamphpservicemanager.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 211 行
JAVA
211 行
/* * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved * * This file is part of Resin(R) Open Source * * Each copy or derived work must preserve the copyright notice and this * notice unmodified. * * Resin Open Source is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Resin Open Source 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, or any warranty * of NON-INFRINGEMENT. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License * along with Resin Open Source; if not, write to the * * Free Software Foundation, Inc. * 59 Temple Place, Suite 330 * Boston, MA 02111-1307 USA * * @author Emil Ong */package com.caucho.quercus.lib.bam;import java.io.IOException;import java.io.Serializable;import java.util.ArrayList;import java.util.HashMap;import java.util.logging.Level;import java.util.logging.Logger;import com.caucho.bam.BamBroker;import com.caucho.bam.BamError;import com.caucho.bam.BamServiceManager;import com.caucho.bam.BamStream;import com.caucho.config.ConfigException;import com.caucho.hemp.broker.GenericService;import com.caucho.quercus.Quercus;import com.caucho.quercus.env.Env;import com.caucho.quercus.env.JavaValue;import com.caucho.quercus.env.BooleanValue;import com.caucho.quercus.env.NullValue;import com.caucho.quercus.env.StringValue;import com.caucho.quercus.env.Value;import com.caucho.quercus.page.QuercusPage;import com.caucho.quercus.page.InterpretedPage;import com.caucho.quercus.parser.QuercusParser;import com.caucho.quercus.program.JavaClassDef;import com.caucho.quercus.program.QuercusProgram;import com.caucho.util.L10N;import com.caucho.vfs.NullWriteStream;import com.caucho.vfs.Path;import com.caucho.vfs.WriteStream;import com.caucho.xmpp.disco.DiscoInfoQuery;import javax.annotation.PostConstruct;import javax.sql.DataSource;import javax.webbeans.In;/** * BAM agent that calls into a PHP script to handle messages/queries. **/public class BamPhpServiceManager implements BamServiceManager { private static final L10N L = new L10N(BamPhpServiceManager.class); private static final Logger log = Logger.getLogger(BamPhpServiceManager.class.getName()); private final Quercus _quercus = new Quercus(); private final HashMap<String,BamPhpAgent> _children = new HashMap<String,BamPhpAgent>(); private ArrayList<String> _featureNames = new ArrayList<String>(); private QuercusProgram _program; private Path _script; private String _encoding = "ISO-8859-1"; @In BamBroker _broker; public BamPhpServiceManager() { } public BamPhpServiceManager(Path script, String encoding) { _script = script; _encoding = encoding; } public Path getScript() { return _script; } public void setScript(Path script) { _script = script; } public String getEncoding() { return _encoding; } public void setEncoding(String encoding) { _encoding = encoding; } BamBroker getBroker() { return _broker; } @PostConstruct public void init() throws ConfigException { if (_script == null) throw new ConfigException(L.l("script path not specified")); _broker.addServiceManager(this); } public boolean startService(String jid) { Env env = null; boolean started = false; try { QuercusPage page = _quercus.parse(_script); env = createEnv(page, "_quercus_bam_start_service", jid); page.executeTop(env); started = env.getGlobalValue("_quercus_bam_function_return").toBoolean(); } finally { if (env != null) env.close(); return started; } } public boolean stopService(String jid) { Env env = null; boolean stoped = false; try { QuercusPage page = _quercus.parse(_script); env = createEnv(page, "_quercus_bam_stop_service", jid); page.executeTop(env); stoped = env.getGlobalValue("_quercus_bam_function_return").toBoolean(); } finally { if (env != null) env.close(); return stoped; } } boolean hasChild(String jid) { return _children.containsKey(jid); } BamPhpAgent removeChild(String jid) { return _children.remove(jid); } void addChild(String jid, BamPhpAgent child) { _children.put(jid, child); } private Env createEnv(QuercusPage page, String type, String jid) { WriteStream out = new NullWriteStream(); Env env = new Env(_quercus, page, out, null, null); env.start(); JavaClassDef agentClassDef = env.getJavaClassDefinition(BamPhpServiceManager.class); env.setGlobalValue("_quercus_bam_service_manager", agentClassDef.wrap(env, this)); env.setGlobalValue(type, BooleanValue.TRUE); env.setGlobalValue("_quercus_bam_service_jid", StringValue.create(jid)); return env; } public String toString() { return "BamPhpServiceManager[script=" + _script + "]"; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?