diff --git a/src/conferencing-module/com/silverwrist/venice/conf/iface/UseCount.java b/src/conferencing-module/com/silverwrist/venice/conf/iface/UseCount.java new file mode 100644 index 0000000..0ce2038 --- /dev/null +++ b/src/conferencing-module/com/silverwrist/venice/conf/iface/UseCount.java @@ -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 . + * + * 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 , + * 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 diff --git a/src/conferencing-module/com/silverwrist/venice/conf/module/Controller.java b/src/conferencing-module/com/silverwrist/venice/conf/module/Controller.java index f95c5a3..0667af6 100644 --- a/src/conferencing-module/com/silverwrist/venice/conf/module/Controller.java +++ b/src/conferencing-module/com/silverwrist/venice/conf/module/Controller.java @@ -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 /*-------------------------------------------------------------------------------- diff --git a/src/conferencing-module/com/silverwrist/venice/conf/module/ModuleMain.java b/src/conferencing-module/com/silverwrist/venice/conf/module/ModuleMain.java index 12c6264..23ab861 100644 --- a/src/conferencing-module/com/silverwrist/venice/conf/module/ModuleMain.java +++ b/src/conferencing-module/com/silverwrist/venice/conf/module/ModuleMain.java @@ -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 diff --git a/src/conferencing-module/com/silverwrist/venice/conf/module/ModuleMessages.properties b/src/conferencing-module/com/silverwrist/venice/conf/module/ModuleMessages.properties index 8cea4a4..b4775ad 100644 --- a/src/conferencing-module/com/silverwrist/venice/conf/module/ModuleMessages.properties +++ b/src/conferencing-module/com/silverwrist/venice/conf/module/ModuleMessages.properties @@ -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} diff --git a/src/dynamo-framework/com/silverwrist/dynamo/iface/Module.java b/src/dynamo-framework/com/silverwrist/dynamo/iface/Module.java index e79cb9a..ba3d812 100644 --- a/src/dynamo-framework/com/silverwrist/dynamo/iface/Module.java +++ b/src/dynamo-framework/com/silverwrist/dynamo/iface/Module.java @@ -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; diff --git a/src/dynamo-framework/com/silverwrist/dynamo/iface/ModuleSite.java b/src/dynamo-framework/com/silverwrist/dynamo/iface/ModuleSite.java index 27696d8..6c39708 100644 --- a/src/dynamo-framework/com/silverwrist/dynamo/iface/ModuleSite.java +++ b/src/dynamo-framework/com/silverwrist/dynamo/iface/ModuleSite.java @@ -19,6 +19,8 @@ package com.silverwrist.dynamo.iface; public interface ModuleSite { + public Module getHandle(); + public String getFilename(); public ResourceProvider getResourceProvider(); diff --git a/src/dynamo-framework/com/silverwrist/dynamo/module/ModuleLoader.java b/src/dynamo-framework/com/silverwrist/dynamo/module/ModuleLoader.java index 6dc7ade..6cd6341 100644 --- a/src/dynamo-framework/com/silverwrist/dynamo/module/ModuleLoader.java +++ b/src/dynamo-framework/com/silverwrist/dynamo/module/ModuleLoader.java @@ -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(); diff --git a/src/venice-base/com/silverwrist/venice/community/CommunityManager.java b/src/venice-base/com/silverwrist/venice/community/CommunityManager.java index 9aca1ac..b4b92a9 100644 --- a/src/venice-base/com/silverwrist/venice/community/CommunityManager.java +++ b/src/venice-base/com/silverwrist/venice/community/CommunityManager.java @@ -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(); diff --git a/src/venice-base/com/silverwrist/venice/community/CommunityManagerOps.java b/src/venice-base/com/silverwrist/venice/community/CommunityManagerOps.java index 19c5029..0f61cc3 100644 --- a/src/venice-base/com/silverwrist/venice/community/CommunityManagerOps.java +++ b/src/venice-base/com/silverwrist/venice/community/CommunityManagerOps.java @@ -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 *-------------------------------------------------------------------------------- diff --git a/src/venice-base/com/silverwrist/venice/community/CommunityManagerOps_mysql.java b/src/venice-base/com/silverwrist/venice/community/CommunityManagerOps_mysql.java index 20ccb21..b636661 100644 --- a/src/venice-base/com/silverwrist/venice/community/CommunityManagerOps_mysql.java +++ b/src/venice-base/com/silverwrist/venice/community/CommunityManagerOps_mysql.java @@ -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 diff --git a/src/venice-base/com/silverwrist/venice/community/CommunityServiceDescriptor.java b/src/venice-base/com/silverwrist/venice/community/CommunityServiceDescriptor.java index fd9b8d8..31246ac 100644 --- a/src/venice-base/com/silverwrist/venice/community/CommunityServiceDescriptor.java +++ b/src/venice-base/com/silverwrist/venice/community/CommunityServiceDescriptor.java @@ -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 *-------------------------------------------------------------------------------- diff --git a/src/venice-base/com/silverwrist/venice/community/CommunityServiceInstall.java b/src/venice-base/com/silverwrist/venice/community/CommunityServiceInstall.java new file mode 100644 index 0000000..da508ef --- /dev/null +++ b/src/venice-base/com/silverwrist/venice/community/CommunityServiceInstall.java @@ -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 . + * + * 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 , + * 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