more implementation - got the conference list to the script. Also fixed up

the low-level services a bit...
This commit is contained in:
Eric J. Bowersox 2003-07-19 22:06:54 +00:00
parent 354eeec28e
commit 23a1130891
9 changed files with 223 additions and 39 deletions

View File

@ -27,10 +27,19 @@ rhelp = bsf.lookupBean("request_help"); // get request helper
user = vlib.getUser(req); // get user
comm = vlib.getCommunity(req); // get community
// Get the conference access object.
commsvc = vcast.queryCommunityService(rhelp.getRequestObject(Namespaces.DYNAMO_OBJECT_NAMESPACE,"communities"));
conf_ns = "http://www.silverwrist.com/NS/venice/2003/06/19/conferencing";
conf_tmp = commsvc.getServiceForName(conf_ns,"conferencing.service").getAccessObject();
conf_access = lib_conf.castConferenceAccessObject(conf_tmp);
// Create the view.
rc = new VelocityView("Conference List: " + comm.name,"conf/conferences.vm");
rc.setParameter("community",comm);
// Get the conference list.
rc.setParameter("conferences",conf_access.getConferences(user,comm));
// Can we manage the conference list?
perm_namespace = "http://www.silverwrist.com/NS/venice/2003/06/25/conferencing.permissions";
srm = cast.querySecurityReferenceMonitor(req_help.getRequestObject(Namespaces.DYNAMO_OBJECT_NAMESPACE,"srm"));

View File

@ -17,9 +17,10 @@
*#
#*
Parameters:
community = The community we're getting the conferences of.
can_manage = Set if we can manage the ordering of conferences.
can_create = Set if we can create new conferences.
community = The community we're getting the conferences of.
conferences = The list of conferences for this community.
can_manage = Set if we can manage the ordering of conferences.
can_create = Set if we can create new conferences.
*#
#header2( "Conference List:" $community.Name )
## TEMPORARY

View File

@ -37,13 +37,13 @@ public class ConferenceManager implements ConferenceAccessObject
*--------------------------------------------------------------------------------
*/
private DynamicImplConferenceAccess m_dobj;
private UseCount m_uc;
private ConferenceManagerOps m_ops;
private NamespaceCache m_nscache;
private SecurityReferenceMonitor m_srm;
private UserManagement m_users; // user management object
private ReferenceMap m_confs;
private DynamicImplConferenceAccess m_dobj; // DynamicObject implementation
private UseCount m_uc; // use count interface
private ConferenceManagerOps m_ops; // operations object
private NamespaceCache m_nscache; // namespace cache
private SecurityReferenceMonitor m_srm; // security reference monitor
private UserManagement m_users; // user management object
private ReferenceMap m_confs; // cache for conference objects
/*--------------------------------------------------------------------------------
* Constructor

View File

@ -36,6 +36,7 @@ import com.silverwrist.venice.util.*;
import com.silverwrist.venice.conf.ConfNamespaces;
import com.silverwrist.venice.conf.iface.UseCount;
import com.silverwrist.venice.conf.impl.ConferenceManager;
import com.silverwrist.venice.conf.obj.LibraryConference;
public class ModuleMain implements ModuleFunctions, UseCount
{
@ -72,6 +73,7 @@ public class ModuleMain implements ModuleFunctions, UseCount
private ConferenceManager m_mgr;
private ComponentShutdown m_res1;
private ComponentShutdown m_res2;
private ComponentShutdown m_script;
/*--------------------------------------------------------------------------------
* Constructor
@ -178,6 +180,10 @@ public class ModuleMain implements ModuleFunctions, UseCount
m_res1 = resmgr.mountResourceProvider("/scripts/conf",new PrefixResourceProvider(module_res,"/scripts"));
m_res2 = resmgr.mountResourceProvider("/velocity/conf",new PrefixResourceProvider(module_res,"/velocity"));
// Register the script library.
ScriptEngineConfig seconf = (ScriptEngineConfig)(services.queryService(ScriptEngineConfig.class));
m_script = seconf.addDeclaredObject("lib_conf",new LibraryConference(),LibraryConference.class);
} // end try
catch (ConfigException e)
{ // translate the ConfigException into a ModuleException
@ -189,6 +195,8 @@ public class ModuleMain implements ModuleFunctions, UseCount
public void shutdown()
{
m_script.shutdown();
m_script = null;
m_res1.shutdown();
m_res1 = null;
m_res2.shutdown();

View File

@ -0,0 +1,46 @@
/*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at <http://www.mozilla.org/MPL/>.
*
* Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* The Original Code is the Venice Web Communities System.
*
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
* Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
*
* Contributor(s):
*/
package com.silverwrist.venice.conf.obj;
import com.silverwrist.venice.conf.iface.*;
public class LibraryConference
{
/*--------------------------------------------------------------------------------
* Constructor
*--------------------------------------------------------------------------------
*/
public LibraryConference()
{ // do nothing
} // end constructor
/*--------------------------------------------------------------------------------
* External operations
*--------------------------------------------------------------------------------
*/
public ConferenceAccessObject castConferenceAccessObject(Object o) throws ClassCastException
{
if (o instanceof ConferenceAccessObject)
return (ConferenceAccessObject)o;
throw new ClassCastException("LibraryConference.castConferenceAccessObject: invalid cast");
} // end castConferenceAccessObject
} // end class LibraryConference

View File

@ -217,10 +217,15 @@ public class ModuleManager implements NamedObject, ComponentInitialize, Componen
m_instservice.addService(DatabaseInstaller.class,new InstallerImpl(pool));
m_install_services = m_instservice.getServiceProvider(m_appcon.getInitServices());
// Hook the initialization service provider.
SimpleServiceProvider simplesp = new SimpleServiceProvider("ModuleManager Init");
simplesp.addService(ModuleOperations.class,this);
simplesp.addService(ModuleConfigurationData.class,(ModuleConfigurationData)cfg_data);
HookServiceProviders hooker = (HookServiceProviders)(services.queryService(HookServiceProviders.class));
m_shut1 = hooker.hookInitServiceProvider(simplesp);
// Hook this into the service providers.
SingletonServiceProvider ssp = new SingletonServiceProvider("ModuleManager",ModuleOperations.class,this);
HookServiceProviders hooker = (HookServiceProviders)(services.queryService(HookServiceProviders.class));
m_shut1 = hooker.hookInitServiceProvider(ssp);
m_shut2 = hooker.hookRuntimeServiceProvider(ssp);
m_shut3 = hooker.hookOutputServiceProvider(ssp);

View File

@ -20,6 +20,7 @@ package com.silverwrist.dynamo.script;
import java.io.*;
import java.lang.ref.*;
import java.util.*;
import org.apache.log4j.Logger;
import org.w3c.dom.*;
import com.silverwrist.util.*;
import com.silverwrist.dynamo.Namespaces;
@ -105,8 +106,35 @@ public class ScriptController
{
synchronized (ScriptController.this)
{
// remove this object from the list of declared objects
m_declared_objects.remove(m_name);
// "un-declare" the object in all active engines
if ((m_active_engines.size()>0) && logger.isDebugEnabled())
logger.debug("need to remove object \"" + m_name + "\" from " + m_active_engines.size()
+ " active engine(s)");
Iterator it = m_active_engines.iterator();
while (it.hasNext())
{ // get each engine and undeclare it
ScriptEngine engine = (ScriptEngine)(it.next());
engine.undeclareOld(m_name);
} // end while
// "un-declare" the object in all inactive engines
sweep();
if ((m_engines.size()>0) && logger.isDebugEnabled())
logger.debug("need to remove object \"" + m_name + "\" from " + m_engines.size() + " inactive engine(s)");
it = m_engines.iterator();
while (it.hasNext())
{ // get each engine and undeclare it
Reference r = (Reference)(it.next());
ScriptEngine engine = (ScriptEngine)(r.get());
if (engine!=null)
engine.undeclareOld(m_name);
} // end while
} // end synchronized block
} // end shutdown
@ -160,6 +188,8 @@ public class ScriptController
*--------------------------------------------------------------------------------
*/
private static Logger logger = Logger.getLogger(ScriptController.class);
private static final long SWEEP_TIME = 600000L; // 10 minutes
/*--------------------------------------------------------------------------------
@ -167,13 +197,14 @@ public class ScriptController
*--------------------------------------------------------------------------------
*/
private ScriptExecuteHelper m_helper;
private String m_temp_path;
private LinkedList m_engines = new LinkedList();
private ReferenceQueue m_ref_queue = new ReferenceQueue();
private ComponentShutdown m_sweep_task;
private HashMap m_declared_objects = new HashMap();
private ArrayList m_start_hooks = new ArrayList();
private ScriptExecuteHelper m_helper; // helper objects
private String m_temp_path; // temporary path for files
private LinkedList m_engines = new LinkedList(); // currently inactive engines (SoftReferences)
private HashSet m_active_engines = new HashSet(); // currently active engines
private ReferenceQueue m_ref_queue = new ReferenceQueue(); // reference queue of inactive engines
private ComponentShutdown m_sweep_task; // shutdown for reference queue sweeper
private HashMap m_declared_objects = new HashMap(); // declared objects
private ArrayList m_start_hooks = new ArrayList(); // start hooks list
/*--------------------------------------------------------------------------------
* Constructor
@ -197,14 +228,19 @@ public class ScriptController
private final synchronized void sweep()
{
Reference r = m_ref_queue.poll();
int count = 0;
while (r!=null)
{ // remove the stale references
m_engines.remove(r);
r.clear();
count++;
r = m_ref_queue.poll();
} // end while
if ((count>0) && logger.isDebugEnabled())
logger.debug("sweep(): discarded " + count + " stale engine reference(s)");
} // end sweep
/**
@ -215,24 +251,29 @@ public class ScriptController
* @exception com.silverwrist.dynamo.except.ScriptingException If there was an error in creating a new
* <CODE>ScriptEngine</CODE>.
*/
private final ScriptEngine getEngine() throws ScriptingException
private final synchronized ScriptEngine getEngine() throws ScriptingException
{
ScriptEngine rc = null;
synchronized (this)
{ // fiddling with m_engines here...
sweep();
while ((rc==null) && !(m_engines.isEmpty()))
{ // look for a reference that contains a valid ScriptEngine
SoftReference r = (SoftReference)(m_engines.removeFirst());
rc = (ScriptEngine)(r.get());
r.clear();
sweep();
while ((rc==null) && !(m_engines.isEmpty()))
{ // look for a reference that contains a valid ScriptEngine
SoftReference r = (SoftReference)(m_engines.removeFirst());
rc = (ScriptEngine)(r.get());
if ((rc!=null) && logger.isDebugEnabled())
logger.debug("getEngine() reused existing engine");
r.clear();
} // end while
} // end synchronized block
} // end while
if (rc==null)
{ // need to create a new engine
rc = new ScriptEngine(this);
if (logger.isDebugEnabled())
logger.debug("getEngine() created new engine");
} // end if
m_active_engines.add(rc);
return rc;
} // end getEngine
@ -245,6 +286,7 @@ public class ScriptController
private final synchronized void releaseEngine(ScriptEngine engine)
{
sweep();
m_active_engines.remove(engine);
m_engines.addFirst(new SoftReference(engine,m_ref_queue));
} // end releaseEngine
@ -284,6 +326,7 @@ public class ScriptController
*/
public void initialize(Element config_root, ServiceProvider services) throws ConfigException
{
logger.info("Initializing ScriptController");
try
{ // Start by querying the temp directory.
ObjectProvider op = (ObjectProvider)(services.queryService(ObjectProvider.class));
@ -291,13 +334,16 @@ public class ScriptController
File tester = new File(m_temp_path);
if (!(tester.isDirectory()))
{ // temporary directory is bogus!
ConfigException ce = new ConfigException(ScriptController.class,"ScriptEngineMessages",
"scriptCtrl.badTmpDir");
logger.fatal("ScriptController.initialize: bad temporary directory " + m_temp_path);
ConfigException ce = new ConfigException(ScriptController.class,"ScriptEngineMessages","scriptCtrl.badTmpDir");
ce.setParameter(0,m_temp_path);
throw ce;
} // end if
if (logger.isDebugEnabled())
logger.debug("Script engine temporary files path = " + m_temp_path);
} // end try
catch (NoSuchObjectException e)
{ // translate to ConfigException
@ -322,10 +368,14 @@ public class ScriptController
*/
public void shutdown()
{
logger.info("Shutting down ScriptController");
// Shut down the background task.
m_sweep_task.shutdown();
m_sweep_task = null;
m_active_engines.clear(); // release all active engine references
// Do one more sweep to clear dead references.
sweep();
@ -360,10 +410,11 @@ public class ScriptController
*/
public ComponentShutdown addDeclaredObject(String name, Object obj, Class klass) throws ConfigException
{
logger.info("ScriptController.addDeclaredObject(\"" + name + "\",object,class " + klass.getName() + ")");
if (ScriptEngine.isReservedDeclaration(name))
{ // this name is reserved...throw it
ConfigException ce = new ConfigException(ScriptController.class,"ScriptEngineMessages",
"declObj.reserved");
logger.error("the name \"" + name + "\" is reserved");
ConfigException ce = new ConfigException(ScriptController.class,"ScriptEngineMessages","declObj.reserved");
ce.setParameter(0,name);
throw ce;
@ -373,15 +424,43 @@ public class ScriptController
{ // test and add declared object to map
if (m_declared_objects.containsKey(name))
{ // name has already been used
ConfigException ce = new ConfigException(ScriptController.class,"ScriptEngineMessages",
"declObj.already");
logger.error("the name \"" + name + "\" is already in use");
ConfigException ce = new ConfigException(ScriptController.class,"ScriptEngineMessages","declObj.already");
ce.setParameter(0,name);
throw ce;
} // end if
// declare object in any active script engines that currently exist
if ((m_active_engines.size()>0) && logger.isDebugEnabled())
logger.debug("need to register object \"" + name + "\" in " + m_active_engines.size() + " active engine(s)");
Iterator it = m_active_engines.iterator();
while (it.hasNext())
{ // get each engine and declare it
ScriptEngine engine = (ScriptEngine)(it.next());
engine.declareNew(name,obj,klass);
} // end while
// declare object in any inactive script engines that currently exist
sweep();
if ((m_engines.size()>0) && logger.isDebugEnabled())
logger.debug("need to register object \"" + name + "\" in " + m_engines.size() + " inactive engine(s)");
it = m_engines.iterator();
while (it.hasNext())
{ // get each engine and declare it
Reference r = (Reference)(it.next());
ScriptEngine engine = (ScriptEngine)(r.get());
if (engine!=null)
engine.declareNew(name,obj,klass);
} // end while
// add declared object to map
DeclaredObject dobj = new DeclaredObject(name,obj,klass);
m_declared_objects.put(dobj.getName(),dobj);
// return the shutdown
return new DeclareShutdown(dobj.getName());
} // end synchronized block
@ -391,7 +470,7 @@ public class ScriptController
/**
* Adds a new "hook" to the script engine startup process in the form of an event listener. The
* {@link com.silverwrist.dynamo.event.ScriptEngineStartListener#scriptEngineStarting(com.silverwrist.dynamo.event.ScriptEngineStartEvent) scriptEngineStarting()}
* method of the given object will be called when an instance of a script enine starts up.
* method of the given object will be called when an instance of a script engine starts up.
*
* @param listener The event listener to register for handling startup events.
* @return An instance of {@link com.silverwrist.dynamo.iface.ComponentShutdown ComponentShutdown} which will

View File

@ -386,6 +386,8 @@ class ScriptEngine implements ScriptExecute
void start(Request request, List start_hooks) throws ScriptingException
{
if (logger.isDebugEnabled())
logger.debug("ScriptEngine.start(): " + start_hooks.size() + " start hook(s) to call");
m_register_maps.addFirst(new HashMap()); // push new context
Iterator it = start_hooks.iterator();
ScriptEngineStartEvent evt = null;
@ -506,6 +508,39 @@ class ScriptEngine implements ScriptExecute
} // end getCurrentLogger
void declareNew(String name, Object obj, Class klass) throws ConfigException
{
try
{ // call through to BSF to declare the object
m_bsf.declareBean(name,obj,klass);
} // end try
catch (BSFException e)
{ // unable to declare the new object - throw an exception
ConfigException ce = new ConfigException(ScriptEngine.class,"ScriptEngineMessages","engine.declNewFail",e);
ce.setParameter(0,name);
ce.setParameter(1,e.getMessage());
throw ce;
} // end catch
} // end declareNew
void undeclareOld(String name)
{
try
{ // undeclare a bean
m_bsf.undeclareBean(name);
} // end try
catch (BSFException e)
{ // just log the exception and continue
logger.error("Undeclaring bean \"" + name + "\" in script engine threw exception",e);
} // end catch
} // end undeclareOld
/*--------------------------------------------------------------------------------
* Static initializer
*--------------------------------------------------------------------------------

View File

@ -10,7 +10,7 @@
#
# The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
# for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
# Copyright (C) 2002 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
# Copyright (C) 2002-03 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved.
#
# Contributor(s):
# ---------------------------------------------------------------------------------
@ -27,3 +27,4 @@ script.abortStart=Scripting engine startup aborted.
rhino.runtimeError=JavaScript runtime error: {0}
null.message={0}
exception.unexpected=Unexpected exception: {0}
engine.declNewFail=Unable to declare the new object "{0}" in the script engine: {1}