Author: thomas.heute(a)jboss.com
Date: 2007-09-18 06:25:44 -0400 (Tue, 18 Sep 2007)
New Revision: 8310
Added:
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/WorkflowSoftDependency.java
Modified:
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/metadata/IdentityUIConfigurationService.java
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/metadata/IdentityUIConfigurationServiceImpl.java
branches/JBoss_Portal_Branch_2_6/core-identity/src/resources/portal-identity-sar/META-INF/jboss-service.xml
Log:
Add a soft dependency on the Workflow service.
Added:
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/WorkflowSoftDependency.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/WorkflowSoftDependency.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/WorkflowSoftDependency.java 2007-09-18
10:25:44 UTC (rev 8310)
@@ -0,0 +1,173 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software 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. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.identity.services;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.MBeanServerNotification;
+import javax.management.Notification;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+
+import org.jboss.logging.Logger;
+import org.jboss.mx.util.MBeanProxy;
+import org.jboss.mx.util.MBeanProxyCreationException;
+import org.jboss.portal.core.identity.services.metadata.IdentityUIConfigurationService;
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+import org.jboss.portal.workflow.service.WorkflowService;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class WorkflowSoftDependency extends AbstractJBossService
+{
+
+ private Logger log = Logger.getLogger(WorkflowSoftDependency.class);
+
+ private MBeanServer server;
+
+ private IdentityUIConfigurationService identityUIConfigurationService;
+
+ private NotificationListener notificationListener;
+
+ private ObjectName mbeanServerDelegate;
+
+ private ObjectName workflowServiceObjectName;
+
+ public WorkflowSoftDependency()
+ {
+ server = (MBeanServer)MBeanServerFactory.findMBeanServer(null).get(0);
+ try
+ {
+ mbeanServerDelegate = new
ObjectName("JMImplementation:type=MBeanServerDelegate");
+ workflowServiceObjectName = new
ObjectName("portal:service=Workflow,type=WorkflowService");
+ notificationListener = new
WorkflowServiceNotificationListener(workflowServiceObjectName);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void startService()
+ {
+ // Check if the workflow service is already registered
+ if (server.isRegistered(workflowServiceObjectName))
+ {
+ try
+ {
+ WorkflowService workflowService =
(WorkflowService)MBeanProxy.get(WorkflowService.class, workflowServiceObjectName,
server);
+ identityUIConfigurationService.setWorkflowService(workflowService);
+ log.debug("Starting identityUIConfigurationService workflow
part");
+ identityUIConfigurationService.startWorkflow();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ // Add the listener for registration/unregistration if the workflow service
+ try
+ {
+ server.addNotificationListener(mbeanServerDelegate, notificationListener, null,
identityUIConfigurationService);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void stopService()
+ {
+ try
+ {
+ server.removeNotificationListener(mbeanServerDelegate, notificationListener);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void setIdentityUIConfigurationService(IdentityUIConfigurationService
identityUIConfigurationService)
+ {
+ this.identityUIConfigurationService = identityUIConfigurationService;
+ }
+
+ private class WorkflowServiceNotificationListener implements NotificationListener
+ {
+
+ ObjectName objectName = null;
+
+ public WorkflowServiceNotificationListener(ObjectName objectName)
+ {
+ this.objectName = objectName;
+ }
+
+ public void handleNotification(Notification notification, Object object)
+ {
+ if (notification instanceof MBeanServerNotification)
+ {
+ MBeanServerNotification notif = (MBeanServerNotification)notification;
+ try
+ {
+ if (notif.getMBeanName().equals(objectName))
+ {
+ IdentityUIConfigurationService identityUIConfigurationService =
(IdentityUIConfigurationService)object;
+ if
(notif.getType().equals(MBeanServerNotification.REGISTRATION_NOTIFICATION))
+ {
+ try
+ {
+ WorkflowService workflowService =
(WorkflowService)MBeanProxy.get(WorkflowService.class, new
ObjectName("portal:service=Workflow,type=WorkflowService"), server);
+
identityUIConfigurationService.setWorkflowService(workflowService);
+ log.debug("Starting identityUIConfigurationService workflow
part");
+ identityUIConfigurationService.startWorkflow();
+
+ }
+ catch (MBeanProxyCreationException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ else
+ {
+ // Unregistration
+ log.debug("Stopping identityUIConfigurationService workflow
part");
+ identityUIConfigurationService.stopWorkflow();
+ identityUIConfigurationService.setWorkflowService(null);
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ }
+
+}
+
Modified:
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/metadata/IdentityUIConfigurationService.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/metadata/IdentityUIConfigurationService.java 2007-09-18
01:55:41 UTC (rev 8309)
+++
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/metadata/IdentityUIConfigurationService.java 2007-09-18
10:25:44 UTC (rev 8310)
@@ -49,5 +49,11 @@
* @throws NamingException
*/
WorkflowService getWorkflowService();
+
+ void setWorkflowService(WorkflowService workflowService);
+
+ void startWorkflow() throws Exception;
+
+ void stopWorkflow() throws Exception;
}
Modified:
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/metadata/IdentityUIConfigurationServiceImpl.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/metadata/IdentityUIConfigurationServiceImpl.java 2007-09-18
01:55:41 UTC (rev 8309)
+++
branches/JBoss_Portal_Branch_2_6/core-identity/src/main/org/jboss/portal/core/identity/services/metadata/IdentityUIConfigurationServiceImpl.java 2007-09-18
10:25:44 UTC (rev 8310)
@@ -27,8 +27,6 @@
import java.net.URL;
import java.util.Map;
-import javax.naming.InitialContext;
-
import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.core.identity.services.IdentityConstants;
import org.jboss.portal.identity.IdentityContext;
@@ -82,15 +80,10 @@
/** The jndi name */
private String jndiName = null;
- public void startService() throws Exception
+ public void startWorkflow() throws Exception
{
- super.startService();
-
try
{
- // Creating IdentityUIConfiguration
- this.configuration = this.createConfiguration();
-
// Loading workflow if subscriptionmodes != automatic
if (this.configuration.enableWorkflow())
{
@@ -127,6 +120,19 @@
super.stopService();
throw new CoreIdentityConfigurationException(e);
}
+ }
+
+ public void stopWorkflow()
+ {
+
+ }
+
+
+ public void startService() throws Exception
+ {
+ super.startService();
+ // Creating IdentityUIConfiguration
+ this.configuration = this.createConfiguration();
if (this.jndiName != null)
{
@@ -161,11 +167,6 @@
return this.configuration;
}
- public void setWorkflowService(WorkflowService workflowService)
- {
- this.workflowService = workflowService;
- }
-
public IdentityServiceController getIdentityServiceController()
{
return identityServiceController;
@@ -200,20 +201,14 @@
public WorkflowService getWorkflowService()
{
- if ( workflowService == null)
- {
- try
- {
- this.workflowService = (WorkflowService) new
InitialContext().lookup("java:/portal/WorkflowService");
- }
- catch (Exception e)
- {
- log.error("", e);
- }
- }
return workflowService;
}
+ public void setWorkflowService(WorkflowService workflowService)
+ {
+ this.workflowService = workflowService;
+ }
+
private void createJBPMContext(String processName) throws
CoreIdentityConfigurationException
{
if (!IdentityConstants.SUBSCRIPTION_MODE_AUTOMATIC.equals(processName))
Modified:
branches/JBoss_Portal_Branch_2_6/core-identity/src/resources/portal-identity-sar/META-INF/jboss-service.xml
===================================================================
---
branches/JBoss_Portal_Branch_2_6/core-identity/src/resources/portal-identity-sar/META-INF/jboss-service.xml 2007-09-18
01:55:41 UTC (rev 8309)
+++
branches/JBoss_Portal_Branch_2_6/core-identity/src/resources/portal-identity-sar/META-INF/jboss-service.xml 2007-09-18
10:25:44 UTC (rev 8310)
@@ -58,7 +58,6 @@
<depends optional-attribute-name="IdentityServiceController"
proxy-type="attribute">
portal:service=Module,type=IdentityServiceController
</depends>
- <depends>portal:service=Workflow,type=WorkflowService</depends>
<attribute
name="JNDIName">java:portal/IdentityUIConfigurationService</attribute>
</mbean>
@@ -130,4 +129,14 @@
proxy-type="attribute">portal:commandFactory=IdentityUI</depends>
</mbean>
+ <mbean
+ code="org.jboss.portal.core.identity.services.WorkflowSoftDependency"
+ name="portal:service=WorkflowSoftDependency"
+ xmbean-dd=""
+ xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
+ <depends
+ optional-attribute-name="IdentityUIConfigurationService"
+
proxy-type="attribute">portal:service=IdentityUIConfigurationService,type=IdentityUI</depends>
+ <xmbean/>
+ </mbean>
</server>
\ No newline at end of file