added installer for community services, and set up conferencing module to
use it, along with some random module manager tweaks to make everything work
This commit is contained in:
parent
3932d55b2a
commit
6269e1c3e8
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* 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.iface;
|
||||
|
||||
public interface UseCount
|
||||
{
|
||||
public void incrementUseCount();
|
||||
|
||||
public void decrementUseCount();
|
||||
|
||||
} // end interface UseCount
|
|
@ -23,6 +23,7 @@ import com.silverwrist.dynamo.iface.*;
|
|||
import com.silverwrist.venice.except.*;
|
||||
import com.silverwrist.venice.iface.*;
|
||||
import com.silverwrist.venice.obj.*;
|
||||
import com.silverwrist.venice.conf.iface.UseCount;
|
||||
|
||||
class Controller implements CommunityServiceController
|
||||
{
|
||||
|
@ -32,15 +33,18 @@ class Controller implements CommunityServiceController
|
|||
*/
|
||||
|
||||
private DynamicImplCommunityServiceController m_dobj;
|
||||
private UseCount m_uc;
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructor
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
Controller()
|
||||
Controller(UseCount uc)
|
||||
{
|
||||
m_dobj = new DynamicImplCommunityServiceController(this);
|
||||
m_uc = uc;
|
||||
uc.incrementUseCount();
|
||||
|
||||
} // end constructor
|
||||
|
||||
|
@ -86,6 +90,9 @@ class Controller implements CommunityServiceController
|
|||
|
||||
public void shutdown()
|
||||
{
|
||||
m_uc.decrementUseCount();
|
||||
m_uc = null;
|
||||
|
||||
} // end shutdown
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
|
|
|
@ -22,16 +22,20 @@ import java.util.*;
|
|||
import com.silverwrist.dynamo.except.*;
|
||||
import com.silverwrist.dynamo.iface.*;
|
||||
import com.silverwrist.dynamo.util.*;
|
||||
import com.silverwrist.venice.community.CommunityServiceInstall;
|
||||
import com.silverwrist.venice.conf.ConfNamespaces;
|
||||
import com.silverwrist.venice.conf.iface.UseCount;
|
||||
|
||||
public class ModuleMain implements ModuleFunctions
|
||||
public class ModuleMain implements ModuleFunctions, UseCount
|
||||
{
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Static data members
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public static final String SERVICE_NAME = "conferencing.service";
|
||||
public static final String CONTROLLER_OBJNAME = "controller";
|
||||
public static final String SHORTVAR = "CONFERENCING";
|
||||
|
||||
private static final QualifiedNameKey NAME =
|
||||
new QualifiedNameKey(ConfNamespaces.CONFERENCING_NAMESPACE,"Venice.conferencing");
|
||||
|
@ -100,12 +104,52 @@ public class ModuleMain implements ModuleFunctions
|
|||
public void install(ModuleSite site, ServiceProvider services, Principal installer, DynamoLog log)
|
||||
throws ModuleException
|
||||
{
|
||||
}
|
||||
synchronized (this)
|
||||
{ // create Controller object if necessary
|
||||
if (m_controller==null)
|
||||
m_controller = new Controller(this);
|
||||
|
||||
} // end synchronized block
|
||||
|
||||
try
|
||||
{ // Install our community service.
|
||||
CommunityServiceInstall csi = (CommunityServiceInstall)(services.queryService(CommunityServiceInstall.class));
|
||||
csi.installService(ConfNamespaces.CONFERENCING_NAMESPACE,SERVICE_NAME,site.getHandle(),
|
||||
ConfNamespaces.CONFERENCING_NAMESPACE,CONTROLLER_OBJNAME,m_controller,SHORTVAR);
|
||||
log.info("Installed service " + ConfNamespaces.CONFERENCING_NAMESPACE + "::" + SERVICE_NAME);
|
||||
|
||||
} // end try
|
||||
catch (DatabaseException de)
|
||||
{ // whoops! that didn't work!
|
||||
log.error("Caught database error while installing service",de);
|
||||
ModuleException me = new ModuleException(ModuleMain.class,"ModuleMessages","install.service.fail",de);
|
||||
me.setParameter(0,de.getMessage());
|
||||
throw me;
|
||||
|
||||
} // end catch
|
||||
|
||||
} // end install
|
||||
|
||||
public void uninstall(ModuleSite site, ServiceProvider services, Principal uninstaller, DynamoLog log)
|
||||
throws ModuleException
|
||||
{
|
||||
}
|
||||
try
|
||||
{ // uninstall the community service
|
||||
CommunityServiceInstall csi = (CommunityServiceInstall)(services.queryService(CommunityServiceInstall.class));
|
||||
csi.removeService(ConfNamespaces.CONFERENCING_NAMESPACE,SERVICE_NAME);
|
||||
log.info("Removed service " + ConfNamespaces.CONFERENCING_NAMESPACE + "::" + SERVICE_NAME);
|
||||
|
||||
} // end try
|
||||
catch (DatabaseException de)
|
||||
{ // whoops! that didn't work!
|
||||
log.error("Caught database error while uninstalling service",de);
|
||||
ModuleException me = new ModuleException(ModuleMain.class,"ModuleMessages","uninstall.service.fail",de);
|
||||
me.setParameter(0,de.getMessage());
|
||||
throw me;
|
||||
|
||||
} // end catch
|
||||
|
||||
} // end uninstall
|
||||
|
||||
public DynamicObject getProvidedObject(String namespace, String name) throws ModuleException
|
||||
{
|
||||
|
@ -114,7 +158,7 @@ public class ModuleMain implements ModuleFunctions
|
|||
synchronized (this)
|
||||
{ // create it if necessary
|
||||
if (m_controller==null)
|
||||
m_controller = new Controller();
|
||||
m_controller = new Controller(this);
|
||||
return m_controller;
|
||||
|
||||
} // end synchronized block
|
||||
|
@ -125,4 +169,21 @@ public class ModuleMain implements ModuleFunctions
|
|||
|
||||
} // end getProvidedObject
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface UseCount
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public synchronized void incrementUseCount()
|
||||
{
|
||||
m_usecount++;
|
||||
|
||||
} // end incrementUseCount
|
||||
|
||||
public synchronized void decrementUseCount()
|
||||
{
|
||||
m_usecount--;
|
||||
|
||||
} // end decrementUseCount
|
||||
|
||||
} // end class ModuleMain
|
||||
|
|
|
@ -16,3 +16,5 @@
|
|||
# ---------------------------------------------------------------------------------
|
||||
# This file has been localized for the en_US locale
|
||||
description=Venice Conferencing System
|
||||
install.service.fail=Failed to install community service object: {0}
|
||||
uninstall.service.fail=Failed to uninstall community service object: {0}
|
||||
|
|
|
@ -26,6 +26,8 @@ public interface Module
|
|||
{
|
||||
public QualifiedNameKey getModuleID();
|
||||
|
||||
public String getFilename();
|
||||
|
||||
public String getDescription();
|
||||
|
||||
public void install(Principal installer, DynamoLog log) throws DatabaseException, ModuleException;
|
||||
|
|
|
@ -19,6 +19,8 @@ package com.silverwrist.dynamo.iface;
|
|||
|
||||
public interface ModuleSite
|
||||
{
|
||||
public Module getHandle();
|
||||
|
||||
public String getFilename();
|
||||
|
||||
public ResourceProvider getResourceProvider();
|
||||
|
|
|
@ -50,6 +50,12 @@ class ModuleLoader extends URLClassLoader implements Module
|
|||
*====================================================================
|
||||
*/
|
||||
|
||||
public Module getHandle()
|
||||
{
|
||||
return (Module)(ModuleLoader.this);
|
||||
|
||||
} // end getHandle
|
||||
|
||||
public String getFilename()
|
||||
{
|
||||
return m_filename;
|
||||
|
@ -284,6 +290,12 @@ class ModuleLoader extends URLClassLoader implements Module
|
|||
|
||||
} // end getModuleID
|
||||
|
||||
public String getFilename()
|
||||
{
|
||||
return m_filename;
|
||||
|
||||
} // end getFilename
|
||||
|
||||
public String getDescription()
|
||||
{
|
||||
return m_modfuncs.getDescription();
|
||||
|
|
|
@ -265,6 +265,68 @@ public class CommunityManager
|
|||
|
||||
} // end class ServiceShutdown
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Internal class implementing the installer
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private class MyInstaller implements CommunityServiceInstall
|
||||
{
|
||||
/*====================================================================
|
||||
* Constructor
|
||||
*====================================================================
|
||||
*/
|
||||
|
||||
MyInstaller()
|
||||
{ // do nothing
|
||||
} // end constructor
|
||||
|
||||
/*====================================================================
|
||||
* Implementations from interface CommunityServiceInstall
|
||||
*====================================================================
|
||||
*/
|
||||
|
||||
public void installService(String service_namespace, String service_name, Module module, String object_namespace,
|
||||
String object_name, CommunityServiceController controller, String shortvar)
|
||||
throws DatabaseException
|
||||
{
|
||||
// first, add the service to the database
|
||||
QualifiedNameKey id = module.getModuleID();
|
||||
int ndx = m_ops.addServiceEntry(m_ns_cache.namespaceNameToId(service_namespace),service_name,
|
||||
m_ns_cache.namespaceNameToId(id.getNamespace()),id.getName(),
|
||||
module.getFilename(),m_ns_cache.namespaceNameToId(object_namespace),
|
||||
object_name,shortvar);
|
||||
|
||||
// now create a descriptor and add it to the list of service descriptors
|
||||
CommunityServiceDescriptor csd =
|
||||
new CommunityServiceDescriptor(ndx,new QualifiedNameKey(service_namespace,service_name),shortvar,controller);
|
||||
m_qname_to_service.put(csd.getName(),csd);
|
||||
m_index_to_service.put(new Integer(ndx),csd);
|
||||
|
||||
} // end installService
|
||||
|
||||
public void removeService(String service_namespace, String service_name) throws DatabaseException
|
||||
{
|
||||
// seek out the CommunityServiceDescriptor by name
|
||||
QualifiedNameKey key = new QualifiedNameKey(service_namespace,service_name);
|
||||
CommunityServiceDescriptor csd = (CommunityServiceDescriptor)(m_qname_to_service.get(key));
|
||||
if (csd==null)
|
||||
return;
|
||||
|
||||
// remove the CSD from the internal tables
|
||||
m_qname_to_service.remove(key);
|
||||
m_index_to_service.remove(new Integer(csd.getIndex()));
|
||||
|
||||
// shut it down
|
||||
csd.getController().shutdown();
|
||||
|
||||
// lastly, remove it from the database
|
||||
m_ops.removeServiceEntry(m_ns_cache.namespaceNameToId(service_namespace),service_name);
|
||||
|
||||
} // end removeService
|
||||
|
||||
} // end class MyInstaller
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Static data members
|
||||
*--------------------------------------------------------------------------------
|
||||
|
@ -290,6 +352,7 @@ public class CommunityManager
|
|||
private Hashtable m_qname_to_service; // maps service QualifiedNameKeys to descriptord
|
||||
private Hashtable m_index_to_service; // maps service index numbers to descriptors
|
||||
private ComponentShutdown m_pszreg; // property serializer registration
|
||||
private ComponentShutdown m_installreg; // installer interface registration
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructor
|
||||
|
@ -436,6 +499,12 @@ public class CommunityManager
|
|||
(PropertySerializerRegistration)(services.queryService(PropertySerializerRegistration.class));
|
||||
m_pszreg = psreg.registerPropertySerializer(new CommunitySerializer());
|
||||
|
||||
// Register our install service to let modules install community services.
|
||||
ModuleOperations module_ops = (ModuleOperations)(services.queryService(ModuleOperations.class));
|
||||
SingletonServiceProvider ssp = new SingletonServiceProvider("Community install services",
|
||||
CommunityServiceInstall.class,new MyInstaller());
|
||||
m_installreg = module_ops.hookInstallServices(ssp);
|
||||
|
||||
// Register our ServiceInit class as a pre-stage init hook.
|
||||
FinalStageRegistration fsreg = (FinalStageRegistration)(services.queryService(FinalStageRegistration.class));
|
||||
fsreg.registerFinalStageInitHook(new ServiceInit());
|
||||
|
@ -449,6 +518,8 @@ public class CommunityManager
|
|||
|
||||
public void shutdown()
|
||||
{
|
||||
m_installreg.shutdown();
|
||||
m_installreg = null;
|
||||
m_pszreg.shutdown();
|
||||
m_pszreg = null;
|
||||
m_id_to_comm.clear();
|
||||
|
|
|
@ -92,6 +92,12 @@ abstract class CommunityManagerOps extends OpsBase
|
|||
|
||||
abstract List getMasterServiceList() throws DatabaseException;
|
||||
|
||||
abstract int addServiceEntry(int service_nsid, String service_name, int module_nsid, String module_name,
|
||||
String module_filename, int object_nsid, String object_name, String shortvar)
|
||||
throws DatabaseException;
|
||||
|
||||
abstract void removeServiceEntry(int service_nsid, String service_name) throws DatabaseException;
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External static operations
|
||||
*--------------------------------------------------------------------------------
|
||||
|
|
|
@ -592,4 +592,107 @@ public class CommunityManagerOps_mysql extends CommunityManagerOps
|
|||
|
||||
} // end getMasterServiceList
|
||||
|
||||
int addServiceEntry(int service_nsid, String service_name, int module_nsid, String module_name,
|
||||
String module_filename, int object_nsid, String object_name, String shortvar)
|
||||
throws DatabaseException
|
||||
{
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
Statement stmt2 = null;
|
||||
try
|
||||
{ // get a connection
|
||||
conn = getConnection();
|
||||
|
||||
// lock the commsvc_master table
|
||||
stmt2 = conn.createStatement();
|
||||
stmt2.executeUpdate("LOCK TABLES commsvc_master WRITE;");
|
||||
|
||||
// create and execute the insert
|
||||
stmt = conn.prepareStatement("INSERT INTO commsvc_master (svc_nsid, svc_name, mod_nsid, mod_name, mod_filename, "
|
||||
+ "obj_nsid, obj_name, shortvar) VALUES (?, ?, ?, ?, ?, ?, ?, ?);");
|
||||
stmt.setInt(1,service_nsid);
|
||||
stmt.setString(2,service_name);
|
||||
stmt.setInt(3,module_nsid);
|
||||
stmt.setString(4,module_name);
|
||||
stmt.setString(5,module_filename);
|
||||
stmt.setInt(6,object_nsid);
|
||||
stmt.setString(7,object_name);
|
||||
stmt.setString(8,shortvar);
|
||||
stmt.executeUpdate();
|
||||
return MySQLUtils.getLastInsertInt(conn);
|
||||
|
||||
} // end try
|
||||
catch (SQLException e)
|
||||
{ // translate to a general DatabaseException
|
||||
throw generalException(e);
|
||||
|
||||
} // end catch
|
||||
finally
|
||||
{ // shut everything down
|
||||
MySQLUtils.unlockTables(conn);
|
||||
SQLUtils.shutdown(stmt);
|
||||
SQLUtils.shutdown(stmt2);
|
||||
SQLUtils.shutdown(conn);
|
||||
|
||||
} // end finally
|
||||
|
||||
} // end addServiceEntry
|
||||
|
||||
void removeServiceEntry(int service_nsid, String service_name) throws DatabaseException
|
||||
{
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
Statement stmt2 = null;
|
||||
ResultSet rs = null;
|
||||
try
|
||||
{ // get a connection
|
||||
conn = getConnection();
|
||||
|
||||
// lock the commsvc_master and commsvc tables
|
||||
stmt2 = conn.createStatement();
|
||||
stmt2.executeUpdate("LOCK TABLES commsvc_master WRITE, commsvc WRITE;");
|
||||
|
||||
// get the index number of the service
|
||||
stmt = conn.prepareStatement("SELECT svcid FROM commsvc_master WHERE svc_nsid = ? AND svc_name = ?;");
|
||||
stmt.setInt(1,service_nsid);
|
||||
stmt.setString(2,service_name);
|
||||
rs = stmt.executeQuery();
|
||||
int ndx = -1;
|
||||
if (rs.next())
|
||||
ndx = rs.getInt(1);
|
||||
else
|
||||
return;
|
||||
rs.close();
|
||||
rs = null;
|
||||
stmt.close();
|
||||
|
||||
// delete all matching entries from commsvc
|
||||
stmt = conn.prepareStatement("DELETE FROM commsvc WHERE svcid = ?;");
|
||||
stmt.setInt(1,ndx);
|
||||
stmt.executeUpdate();
|
||||
stmt.close();
|
||||
|
||||
// delete the service entry itself
|
||||
stmt = conn.prepareStatement("DELETE FROM commsvc_master WHERE svcid = ?;");
|
||||
stmt.setInt(1,ndx);
|
||||
stmt.executeUpdate();
|
||||
|
||||
} // end try
|
||||
catch (SQLException e)
|
||||
{ // translate to a general DatabaseException
|
||||
throw generalException(e);
|
||||
|
||||
} // end catch
|
||||
finally
|
||||
{ // shut everything down
|
||||
MySQLUtils.unlockTables(conn);
|
||||
SQLUtils.shutdown(rs);
|
||||
SQLUtils.shutdown(stmt);
|
||||
SQLUtils.shutdown(stmt2);
|
||||
SQLUtils.shutdown(conn);
|
||||
|
||||
} // end finally
|
||||
|
||||
} // end removeServiceEntry
|
||||
|
||||
} // end class CommunityManagerOps_mysql
|
||||
|
|
|
@ -33,7 +33,7 @@ public final class CommunityServiceDescriptor
|
|||
private CommunityServiceController m_csc;
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructor
|
||||
* Constructors
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
@ -46,6 +46,15 @@ public final class CommunityServiceDescriptor
|
|||
|
||||
} // end constructor
|
||||
|
||||
CommunityServiceDescriptor(int index, QualifiedNameKey qname, String shortvar, CommunityServiceController csc)
|
||||
{
|
||||
m_index = index;
|
||||
m_qname = qname;
|
||||
m_shortvar = shortvar;
|
||||
m_csc = csc;
|
||||
|
||||
} // end constructor
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Package-internal operations
|
||||
*--------------------------------------------------------------------------------
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* 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.community;
|
||||
|
||||
import com.silverwrist.dynamo.except.DatabaseException;
|
||||
import com.silverwrist.dynamo.iface.Module;
|
||||
import com.silverwrist.venice.iface.CommunityServiceController;
|
||||
|
||||
public interface CommunityServiceInstall
|
||||
{
|
||||
public void installService(String service_namespace, String service_name, Module module, String object_namespace,
|
||||
String object_name, CommunityServiceController controller, String shortvar)
|
||||
throws DatabaseException;
|
||||
|
||||
public void removeService(String service_namespace, String service_name) throws DatabaseException;
|
||||
|
||||
} // end interface CommunityServiceInstall
|
Loading…
Reference in New Issue
Block a user