From 58a50508676500a29b29075f66e454b113a08791 Mon Sep 17 00:00:00 2001
From: jdemendi <jdemendi@localhost>
Date: Wed, 08 Aug 2007 09:57:42 +0000
Subject: [PATCH] This set of changes add ID to identify network groups, workflows and workflow elements. These identifiers pave the way for the network group and workflow configuration.
---
opends/src/server/org/opends/server/core/WorkflowImpl.java | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 106 insertions(+), 0 deletions(-)
diff --git a/opends/src/server/org/opends/server/core/WorkflowImpl.java b/opends/src/server/org/opends/server/core/WorkflowImpl.java
index e811757..f28841d 100644
--- a/opends/src/server/org/opends/server/core/WorkflowImpl.java
+++ b/opends/src/server/org/opends/server/core/WorkflowImpl.java
@@ -27,8 +27,16 @@
package org.opends.server.core;
+import static org.opends.server.messages.CoreMessages.*;
+import static org.opends.server.messages.MessageHandler.getMessage;
+import static org.opends.server.util.Validator.ensureNotNull;
+
+import java.util.TreeMap;
+
import org.opends.server.types.DN;
+import org.opends.server.types.DirectoryException;
import org.opends.server.types.Operation;
+import org.opends.server.types.ResultCode;
import org.opends.server.workflowelement.WorkflowElement;
@@ -43,6 +51,8 @@
*/
public class WorkflowImpl implements Workflow
{
+ // The workflow identifier used by the configuration.
+ private String workflowID = null;
// The root of the workflow task tree.
private WorkflowElement rootWorkflowElement = null;
@@ -63,6 +73,13 @@
// flag will always return false.
private boolean isPrivate = false;
+ // The set of workflows registered with the server.
+ private static TreeMap<String, Workflow> registeredWorkflows =
+ new TreeMap<String, Workflow>();
+
+ // A lock to protect concurrent access to the registeredWorkflows.
+ private static Object registeredWorkflowsLock = new Object();
+
/**
* Creates a new instance of a workflow implementation. To define a worfklow
@@ -71,14 +88,17 @@
*
* The rootWorkflowElement must not be null.
*
+ * @param workflowId workflow internal identifier
* @param baseDN identifies the data handled by the workflow
* @param rootWorkflowElement the root node of the workflow task tree
*/
public WorkflowImpl(
+ String workflowId,
DN baseDN,
WorkflowElement rootWorkflowElement
)
{
+ this.workflowID = workflowId;
this.baseDN = baseDN;
this.rootWorkflowElement = rootWorkflowElement;
if (this.rootWorkflowElement != null)
@@ -100,6 +120,17 @@
/**
+ * Gets the workflow internal identifier.
+ *
+ * @return the workflow internal indentifier
+ */
+ public String getWorkflowId()
+ {
+ return workflowID;
+ }
+
+
+ /**
* Indicates whether the root node of the workflow task tree is
* handling a private local backend.
*
@@ -124,4 +155,79 @@
{
rootWorkflowElement.execute(operation);
}
+
+
+ /**
+ * Registers the current worklow (this) with the server.
+ *
+ * @throws DirectoryException If the workflow ID for the provided workflow
+ * conflicts with the workflow ID of an existing
+ * workflow.
+ */
+ public void register()
+ throws DirectoryException
+ {
+ ensureNotNull(workflowID);
+
+ synchronized (registeredWorkflowsLock)
+ {
+ // The workflow must not be already registered
+ if (registeredWorkflows.containsKey(workflowID))
+ {
+ int msgID = MSGID_REGISTER_WORKFLOW_ALREADY_EXISTS;
+ String message = getMessage(msgID, workflowID);
+ throw new DirectoryException(
+ ResultCode.UNWILLING_TO_PERFORM, message, msgID);
+ }
+
+ TreeMap<String, Workflow> newRegisteredWorkflows =
+ new TreeMap<String, Workflow>(registeredWorkflows);
+ newRegisteredWorkflows.put(workflowID, this);
+ registeredWorkflows = newRegisteredWorkflows;
+ }
+ }
+
+
+ /**
+ * Deregisters the current worklow (this) with the server.
+ */
+ public void deregister()
+ {
+ ensureNotNull(workflowID);
+
+ synchronized (registeredWorkflowsLock)
+ {
+ TreeMap<String, Workflow> newWorkflows =
+ new TreeMap<String, Workflow>(registeredWorkflows);
+ newWorkflows.remove(workflowID);
+ registeredWorkflows = newWorkflows;
+ }
+ }
+
+
+ /**
+ * Deregisters a worklow with the server. The workflow to deregister
+ * is identified with its identifier.
+ *
+ * @param workflowID the identifier of the workflow to deregister
+ *
+ * @return the workflow that has been deregistered,
+ * <code>null</code> if no workflow has been found.
+ */
+ public WorkflowImpl deregister(String workflowID)
+ {
+ WorkflowImpl workflowToDeregister = null;
+
+ synchronized (registeredWorkflowsLock)
+ {
+ if (registeredWorkflows.containsKey(workflowID))
+ {
+ workflowToDeregister =
+ (WorkflowImpl) registeredWorkflows.get(workflowID);
+ workflowToDeregister.deregister();
+ }
+ }
+
+ return workflowToDeregister;
+ }
}
--
Gitblit v1.10.0