Skip to content

Commit 491e950

Browse files
authored
Close Activiti ProcessEngine when server shuts down (#70)
1 parent 10c83c0 commit 491e950

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

src/org/labkey/workflow/WorkflowManager.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@
8383
import org.labkey.api.security.UserManager;
8484
import org.labkey.api.security.permissions.AdminPermission;
8585
import org.labkey.api.test.TestWhen;
86+
import org.labkey.api.util.ContextListener;
8687
import org.labkey.api.util.Path;
88+
import org.labkey.api.util.ShutdownListener;
8789
import org.labkey.api.util.TestContext;
8890
import org.labkey.api.view.UnauthorizedException;
8991
import org.labkey.api.view.ViewContext;
@@ -130,6 +132,35 @@ public class WorkflowManager implements WorkflowService
130132
private WorkflowManager()
131133
{
132134
// prevent external construction with a private default constructor
135+
136+
// Don't leave activiti ProcessEngine running with an invalid data source
137+
ContextListener.addShutdownListener(new ShutdownListener()
138+
{
139+
@Override
140+
public String getName()
141+
{
142+
return "WorkflowManager process engine";
143+
}
144+
145+
@Override
146+
public void shutdownPre()
147+
{
148+
if (_processEngine != null)
149+
{
150+
try
151+
{
152+
_processEngine.close();
153+
}
154+
finally
155+
{
156+
_processEngine = null;
157+
}
158+
}
159+
}
160+
161+
@Override
162+
public void shutdownStarted() { /* Nothing to do */ }
163+
});
133164
}
134165

135166
public static WorkflowManager get()
@@ -283,7 +314,7 @@ public ColumnInfo getTaskTypeColumn(TableInfo tableInfo, final String colLabel,
283314
* finds the workflow process with that process variable value that was started last.
284315
* @param key the name of the process variable
285316
* @param valueField the field in the act_hi_varinst table in which the value is stored
286-
* @param sqlValue the string representation of the comparison value to be used in the SQL statement (e.g., for a string
317+
* @param value the string representation of the comparison value to be used in the SQL statement (e.g., for a string
287318
* value, this should contain the single quotes ('string'), but for an integer value it should not (123))
288319
* @param container the container context
289320
* @return the lates workflow instance with a variable with the given name and value
@@ -1132,7 +1163,7 @@ protected FormService getFormService()
11321163
return getProcessEngine().getFormService();
11331164
}
11341165

1135-
private ProcessEngine getProcessEngine()
1166+
private synchronized ProcessEngine getProcessEngine()
11361167
{
11371168
if (_processEngine == null)
11381169
{

0 commit comments

Comments
 (0)