Source Code Cross Referenced for ExecutionAdmin.java in  » Workflow-Engines » shark » org » enhydra » shark » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Workflow Engines » shark » org.enhydra.shark 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        package org.enhydra.shark;
0002:
0003:        import java.util.ArrayList;
0004:        import java.util.HashMap;
0005:        import java.util.List;
0006:        import java.util.Map;
0007:
0008:        import org.enhydra.shark.api.client.wfmc.wapi.WMActivityInstance;
0009:        import org.enhydra.shark.api.client.wfmc.wapi.WMActivityInstanceIterator;
0010:        import org.enhydra.shark.api.client.wfmc.wapi.WMFilter;
0011:        import org.enhydra.shark.api.client.wfmc.wapi.WMProcessInstance;
0012:        import org.enhydra.shark.api.client.wfmc.wapi.WMProcessInstanceIterator;
0013:        import org.enhydra.shark.api.client.wfmc.wapi.WMSessionHandle;
0014:        import org.enhydra.shark.api.client.wfservice.ExecutionAdministration;
0015:        import org.enhydra.shark.api.client.wfservice.NotConnected;
0016:        import org.enhydra.shark.api.client.wfservice.WMEntity;
0017:        import org.enhydra.shark.api.common.ActivityFilterBuilder;
0018:        import org.enhydra.shark.api.common.FilterBuilder;
0019:        import org.enhydra.shark.api.common.ProcessFilterBuilder;
0020:        import org.enhydra.shark.api.common.SharkConstants;
0021:        import org.enhydra.shark.api.internal.caching.CacheMgr;
0022:        import org.enhydra.shark.api.internal.caching.ProcessCache;
0023:        import org.enhydra.shark.api.internal.caching.ResourceCache;
0024:        import org.enhydra.shark.api.internal.instancepersistence.ActivityPersistenceObject;
0025:        import org.enhydra.shark.api.internal.instancepersistence.PersistentManagerInterface;
0026:        import org.enhydra.shark.api.internal.instancepersistence.ProcessPersistenceObject;
0027:        import org.enhydra.shark.api.internal.security.SecurityManager;
0028:        import org.enhydra.shark.api.internal.working.WfActivityInternal;
0029:        import org.enhydra.shark.api.internal.working.WfProcessInternal;
0030:
0031:        /**
0032:         * The client interface through which client accesses the engine objects, and performs the
0033:         * various actions on engine.
0034:         * 
0035:         * @author Sasa Bojanic
0036:         * @version 1.11
0037:         */
0038:        public class ExecutionAdmin implements  ExecutionAdministration {
0039:
0040:            // TODO: we need synchronization on activity table during re-evaluation of activity's
0041:            // assignments
0042:            private static ExecutionAdministration anInstance;
0043:
0044:            private ExecutionAdmin() {
0045:            }
0046:
0047:            public static ExecutionAdministration getInstance() {
0048:                if (null == anInstance) {
0049:                    synchronized (ExecutionAdmin.class) {
0050:                        if (null == anInstance) {
0051:                            anInstance = new ExecutionAdmin();
0052:                        }
0053:                    }
0054:                }
0055:                return anInstance;
0056:            }
0057:
0058:            public void startActivity(WMSessionHandle shandle, String procId,
0059:                    String blockActId, WMEntity actDef) throws Exception {
0060:
0061:                long tStamp = SharkEngineManager.getInstance()
0062:                        .getCallbackUtilities().methodStart(shandle,
0063:                                "ExecutionAdmin.startActivity");
0064:
0065:                try {
0066:                    if (!SharkUtilities.checkSession(shandle)) {
0067:                        throw new NotConnected(
0068:                                "The session handle is not valid!");
0069:                    }
0070:                    checkSecurity(shandle, "startActivity", null);
0071:
0072:                    WfProcessInternal proc = getProcessImpl(shandle, procId,
0073:                            SharkUtilities.WRITE_MODE);
0074:                    proc.start_activity(shandle, actDef.getId(), blockActId);
0075:                } finally {
0076:                    SharkEngineManager.getInstance().getCallbackUtilities()
0077:                            .methodEnd(
0078:                                    shandle,
0079:                                    tStamp,
0080:                                    "ExecutionAdmin.startActivity",
0081:                                    "proc=" + procId + ",blockActId="
0082:                                            + blockActId + ",actDef=" + actDef);
0083:                }
0084:            }
0085:
0086:            public WMActivityInstanceIterator reevaluateAssignmentsWithFiltering(
0087:                    WMSessionHandle shandle, WMFilter procOrActFilter,
0088:                    boolean returnChangedOnly) throws Exception {
0089:                long tStamp = SharkEngineManager
0090:                        .getInstance()
0091:                        .getCallbackUtilities()
0092:                        .methodStart(shandle,
0093:                                "ExecutionAdmin.reevaluateAssignmentsWithFiltering");
0094:
0095:                try {
0096:                    if (!SharkUtilities.checkSession(shandle)) {
0097:                        throw new NotConnected(
0098:                                "The session handle is not valid!");
0099:                    }
0100:                    checkSecurity(shandle,
0101:                            "reevaluateAssignmentsWithFiltering", null);
0102:
0103:                    List acts = new ArrayList();
0104:
0105:                    if (procOrActFilter == null) {
0106:                        ActivityFilterBuilder aieb = SharkEngineManager
0107:                                .getInstance().getActivityFilterBuilder();
0108:                        procOrActFilter = aieb
0109:                                .addStateEquals(
0110:                                        shandle,
0111:                                        SharkConstants.STATE_OPEN_NOT_RUNNING_NOT_STARTED);
0112:                    }
0113:                    if (procOrActFilter.getFilterType() != FilterBuilder.SQL_TYPE_ACTIVITY
0114:                            && procOrActFilter.getFilterType() != FilterBuilder.SQL_TYPE_PROCESS) {
0115:                        throw new Exception(
0116:                                "Invalid filter type! It must be either activity or process filter.");
0117:                    }
0118:                    if (procOrActFilter.getSQLWhereExpression() == null) {
0119:                        throw new Exception(
0120:                                "Invalid filter expression - expression must be defined!");
0121:                    }
0122:                    String sqlExpr = procOrActFilter.getSQLWhereExpression()
0123:                            + procOrActFilter.getOrderBy();
0124:                    int startAt = procOrActFilter.getStartPosition();
0125:                    int limit = procOrActFilter.getLimit();
0126:
0127:                    if (procOrActFilter.getFilterType() == FilterBuilder.SQL_TYPE_ACTIVITY) {
0128:                        acts.addAll(SharkEngineManager.getInstance()
0129:                                .getInstancePersistenceManager()
0130:                                .getActivitiesWhere(shandle, sqlExpr, startAt,
0131:                                        limit));
0132:
0133:                    } else {
0134:                        List procs = SharkEngineManager.getInstance()
0135:                                .getInstancePersistenceManager()
0136:                                .getProcessesWhere(shandle, sqlExpr, startAt,
0137:                                        limit);
0138:
0139:                        for (int i = 0; i < procs.size(); i++) {
0140:                            acts.addAll(SharkEngineManager.getInstance()
0141:                                    .getInstancePersistenceManager()
0142:                                    .getAllActiveActivitiesForProcess(
0143:                                            shandle,
0144:                                            ((ProcessPersistenceObject) procs
0145:                                                    .get(i)).getId()));
0146:                        }
0147:
0148:                    }
0149:
0150:                    List l = new ArrayList();
0151:                    for (int i = 0; i < acts.size(); i++) {
0152:                        ActivityPersistenceObject apo = (ActivityPersistenceObject) acts
0153:                                .get(i);
0154:                        WfActivityInternal aInt = getActivityImpl(shandle, apo
0155:                                .getProcessId(), apo.getId(),
0156:                                SharkUtilities.WRITE_MODE);
0157:                        int r = aInt.reevaluateAssignments(shandle);
0158:                        if (r >= 0) {
0159:                            if (r == 1 || (r == 0 && !returnChangedOnly)) {
0160:                                l
0161:                                        .add(SharkUtilities.getInstance(
0162:                                                shandle, aInt));
0163:                            }
0164:                            SharkEngineManager.getInstance()
0165:                                    .getCallbackUtilities().info(
0166:                                            shandle,
0167:                                            "Assignments for activity " + aInt
0168:                                                    + " are re-evaluated.");
0169:                        }
0170:                    }
0171:                    WMActivityInstance[] ret = new WMActivityInstance[l.size()];
0172:                    l.toArray(ret);
0173:
0174:                    WMActivityInstanceIterator wmai = new WMActivityInstanceIterator();
0175:                    wmai.setArray(ret);
0176:                    wmai.setCount(ret.length);
0177:                    return wmai;
0178:                } finally {
0179:                    SharkEngineManager
0180:                            .getInstance()
0181:                            .getCallbackUtilities()
0182:                            .methodEnd(
0183:                                    shandle,
0184:                                    tStamp,
0185:                                    "ExecutionAdmin.reevaluateAssignmentsWithFiltering",
0186:                                    "filter=" + procOrActFilter
0187:                                            + ",returnChangedOnly="
0188:                                            + returnChangedOnly);
0189:                }
0190:            }
0191:
0192:            public WMActivityInstanceIterator reevaluateAssignmentsForProcesses(
0193:                    WMSessionHandle shandle, String[] procIds,
0194:                    boolean returnChangedOnly) throws Exception {
0195:                long tStamp = SharkEngineManager
0196:                        .getInstance()
0197:                        .getCallbackUtilities()
0198:                        .methodStart(shandle,
0199:                                "ExecutionAdmin.reevaluateAssignmentsForProcesses");
0200:
0201:                try {
0202:                    if (!SharkUtilities.checkSession(shandle)) {
0203:                        throw new NotConnected(
0204:                                "The session handle is not valid!");
0205:                    }
0206:                    checkSecurity(shandle, "reevaluateAssignmentsForProcesses",
0207:                            null);
0208:
0209:                    List l = new ArrayList();
0210:                    for (int i = 0; i < procIds.length; i++) {
0211:
0212:                        WfProcessInternal proc = getProcessImpl(shandle,
0213:                                procIds[i], SharkUtilities.WRITE_MODE);
0214:                        List acts = proc.getActiveActivities(shandle);
0215:                        for (int j = 0; j < acts.size(); j++) {
0216:                            WfActivityInternal aInt = (WfActivityInternal) acts
0217:                                    .get(j);
0218:                            int r = aInt.reevaluateAssignments(shandle);
0219:                            if (r >= 0) {
0220:                                if (r == 1 || (r == 0 && !returnChangedOnly)) {
0221:                                    l.add(SharkUtilities.getInstance(shandle,
0222:                                            aInt));
0223:                                }
0224:                                SharkEngineManager.getInstance()
0225:                                        .getCallbackUtilities().info(
0226:                                                shandle,
0227:                                                "Assignments for activity "
0228:                                                        + aInt
0229:                                                        + " are re-evaluated.");
0230:                            }
0231:                        }
0232:                    }
0233:
0234:                    WMActivityInstance[] ret = new WMActivityInstance[l.size()];
0235:                    l.toArray(ret);
0236:
0237:                    WMActivityInstanceIterator wmai = new WMActivityInstanceIterator();
0238:                    wmai.setArray(ret);
0239:                    wmai.setCount(ret.length);
0240:                    return wmai;
0241:                } finally {
0242:                    SharkEngineManager
0243:                            .getInstance()
0244:                            .getCallbackUtilities()
0245:                            .methodEnd(
0246:                                    shandle,
0247:                                    tStamp,
0248:                                    "ExecutionAdmin.reevaluateAssignmentsForProcesses",
0249:                                    "returnChangedOnly=" + returnChangedOnly);
0250:
0251:                }
0252:            }
0253:
0254:            public WMActivityInstanceIterator reevaluateAssignmentsForActivities(
0255:                    WMSessionHandle shandle, WMActivityInstance[] acts,
0256:                    boolean returnChangedOnly) throws Exception {
0257:                long tStamp = SharkEngineManager
0258:                        .getInstance()
0259:                        .getCallbackUtilities()
0260:                        .methodStart(shandle,
0261:                                "ExecutionAdmin.reevaluateAssignmentsForActivities");
0262:
0263:                try {
0264:                    if (!SharkUtilities.checkSession(shandle)) {
0265:                        throw new NotConnected(
0266:                                "The session handle is not valid!");
0267:                    }
0268:                    checkSecurity(shandle, "reevaluateAssignments", null);
0269:
0270:                    List l = new ArrayList();
0271:                    for (int i = 0; i < acts.length; i++) {
0272:                        WfActivityInternal aInt = getActivityImpl(shandle,
0273:                                acts[i].getProcessInstanceId(),
0274:                                acts[i].getId(), SharkUtilities.WRITE_MODE);
0275:                        int r = aInt.reevaluateAssignments(shandle);
0276:                        if (r >= 0) {
0277:                            if (r == 1 || (r == 0 && !returnChangedOnly)) {
0278:                                l
0279:                                        .add(SharkUtilities.getInstance(
0280:                                                shandle, aInt));
0281:                            }
0282:                            SharkEngineManager.getInstance()
0283:                                    .getCallbackUtilities().info(
0284:                                            shandle,
0285:                                            "Assignments for activity " + aInt
0286:                                                    + " are re-evaluated.");
0287:                        }
0288:                    }
0289:
0290:                    WMActivityInstance[] ret = new WMActivityInstance[l.size()];
0291:                    l.toArray(ret);
0292:
0293:                    WMActivityInstanceIterator wmai = new WMActivityInstanceIterator();
0294:                    wmai.setArray(ret);
0295:                    wmai.setCount(ret.length);
0296:                    return wmai;
0297:                } finally {
0298:                    SharkEngineManager
0299:                            .getInstance()
0300:                            .getCallbackUtilities()
0301:                            .methodEnd(
0302:                                    shandle,
0303:                                    tStamp,
0304:                                    "ExecutionAdmin.reevaluateAssignmentsForActivities",
0305:                                    "returnChangedOnly=" + returnChangedOnly);
0306:
0307:                }
0308:
0309:            }
0310:
0311:            public WMProcessInstanceIterator deleteProcessesWithFiltering(
0312:                    WMSessionHandle shandle, WMFilter procFilter)
0313:                    throws Exception {
0314:                long tStamp = SharkEngineManager.getInstance()
0315:                        .getCallbackUtilities().methodStart(shandle,
0316:                                "ExecutionAdmin.deleteProcessesWithFiltering");
0317:
0318:                try {
0319:                    if (!SharkUtilities.checkSession(shandle)) {
0320:                        throw new NotConnected(
0321:                                "The session handle is not valid!");
0322:                    }
0323:                    checkSecurity(shandle, "deleteProcessesWithFiltering", null);
0324:
0325:                    if (procFilter == null) {
0326:                        ProcessFilterBuilder pieb = SharkEngineManager
0327:                                .getInstance().getProcessFilterBuilder();
0328:                        procFilter = pieb.addStateStartsWith(shandle,
0329:                                SharkConstants.STATEPREFIX_CLOSED);
0330:                    }
0331:                    if (procFilter.getSQLWhereExpression() == null) {
0332:                        throw new Exception(
0333:                                "Invalid filter expression - expression must be defined!");
0334:                    }
0335:                    if (procFilter.getFilterType() != FilterBuilder.SQL_TYPE_PROCESS) {
0336:                        throw new Exception(
0337:                                "Invalid filter type! It must be process filter.");
0338:                    }
0339:                    String sqlExpr = procFilter.getSQLWhereExpression()
0340:                            + procFilter.getOrderBy();
0341:                    int startAt = procFilter.getStartPosition();
0342:                    int limit = procFilter.getLimit();
0343:
0344:                    List procs = SharkEngineManager.getInstance()
0345:                            .getInstancePersistenceManager().getProcessesWhere(
0346:                                    shandle, sqlExpr, startAt, limit);
0347:
0348:                    List l = new ArrayList();
0349:                    for (int i = 0; i < procs.size(); i++) {
0350:                        ProcessPersistenceObject ppo = (ProcessPersistenceObject) procs
0351:                                .get(i);
0352:                        l.addAll(_deleteProcessInstance(shandle, ppo));
0353:                    }
0354:                    WMProcessInstance[] ret = new WMProcessInstance[l.size()];
0355:                    l.toArray(ret);
0356:
0357:                    WMProcessInstanceIterator wmpi = new WMProcessInstanceIterator();
0358:                    wmpi.setArray(ret);
0359:                    wmpi.setCount(ret.length);
0360:                    return wmpi;
0361:                } finally {
0362:                    SharkEngineManager
0363:                            .getInstance()
0364:                            .getCallbackUtilities()
0365:                            .methodEnd(
0366:                                    shandle,
0367:                                    tStamp,
0368:                                    "ExecutionAdmin.deleteProcessesWithFiltering",
0369:                                    "filter=" + procFilter);
0370:                }
0371:            }
0372:
0373:            public WMProcessInstanceIterator deleteProcesses(
0374:                    WMSessionHandle shandle, String[] procIds) throws Exception {
0375:                long tStamp = SharkEngineManager.getInstance()
0376:                        .getCallbackUtilities().methodStart(shandle,
0377:                                "ExecutionAdmin.deleteProcesses");
0378:
0379:                try {
0380:                    if (!SharkUtilities.checkSession(shandle)) {
0381:                        throw new NotConnected(
0382:                                "The session handle is not valid!");
0383:                    }
0384:                    checkSecurity(shandle, "deleteProcesses", null);
0385:
0386:                    PersistentManagerInterface ipm = SharkEngineManager
0387:                            .getInstance().getInstancePersistenceManager();
0388:
0389:                    List l = new ArrayList();
0390:                    for (int i = 0; i < procIds.length; i++) {
0391:                        ProcessPersistenceObject ppo = ipm.restoreProcess(
0392:                                shandle, procIds[i]);
0393:                        l.addAll(_deleteProcessInstance(shandle, ppo));
0394:                    }
0395:                    WMProcessInstance[] ret = new WMProcessInstance[l.size()];
0396:                    l.toArray(ret);
0397:
0398:                    WMProcessInstanceIterator wmpi = new WMProcessInstanceIterator();
0399:                    wmpi.setArray(ret);
0400:                    wmpi.setCount(ret.length);
0401:                    return wmpi;
0402:                } finally {
0403:                    SharkEngineManager.getInstance().getCallbackUtilities()
0404:                            .methodEnd(shandle, tStamp,
0405:                                    "ExecutionAdmin.deleteProcesses", "");
0406:                }
0407:            }
0408:
0409:            protected List _deleteProcessInstance(WMSessionHandle shandle,
0410:                    ProcessPersistenceObject po) throws Exception {
0411:                PersistentManagerInterface ipm = SharkEngineManager
0412:                        .getInstance().getInstancePersistenceManager();
0413:                List deleted = new ArrayList();
0414:                if (po.getState().startsWith(SharkConstants.STATEPREFIX_OPEN)) {
0415:                    throw new Exception(
0416:                            "Can't delete processes which are not closed!");
0417:                }
0418:
0419:                if (po.getActivityRequesterId() != null) {
0420:                    ActivityPersistenceObject apo = ipm.restoreActivity(
0421:                            shandle, po.getActivityRequestersProcessId(), po
0422:                                    .getActivityRequesterId());
0423:                    if (apo != null
0424:                            && apo.getState().startsWith(
0425:                                    SharkConstants.STATEPREFIX_OPEN)) {
0426:                        SharkEngineManager
0427:                                .getInstance()
0428:                                .getCallbackUtilities()
0429:                                .warn(
0430:                                        shandle,
0431:                                        "... Process "
0432:                                                + po.getId()
0433:                                                + " can't be deleted yet because it has active activity requester!");
0434:                        return deleted;
0435:                    }
0436:                }
0437:
0438:                SharkEngineManager.getInstance().getCallbackUtilities().info(
0439:                        shandle, "... Deleting process " + po.getId());
0440:
0441:                CacheMgr cm = SharkEngineManager.getInstance()
0442:                        .getCacheManager();
0443:                List delPos = ipm.deleteProcess(shandle, po.getId(), true);
0444:                for (int i = 0; i < delPos.size(); i++) {
0445:                    ProcessPersistenceObject delpo = (ProcessPersistenceObject) delPos
0446:                            .get(i);
0447:                    deleted.add(SharkUtilities.getInstance(delpo));
0448:                    if (cm != null) {
0449:                        cm.getProcessCache().remove(delpo.getId());
0450:                    }
0451:                }
0452:
0453:                return deleted;
0454:            }
0455:
0456:            // /////////////////////// CACHEADMIN
0457:
0458:            public void setProcessCacheSize(WMSessionHandle shandle, int size)
0459:                    throws Exception {
0460:                long tStamp = SharkEngineManager.getInstance()
0461:                        .getCallbackUtilities().methodStart(shandle,
0462:                                "ExecutionAdmin.setProcessCache");
0463:
0464:                try {
0465:                    if (!SharkUtilities.checkSession(shandle)) {
0466:                        throw new NotConnected(
0467:                                "The session handle is not valid!");
0468:                    }
0469:                    checkSecurity(shandle, "setProcessCacheSize", null);
0470:
0471:                    CacheMgr mgr = SharkEngineManager.getInstance()
0472:                            .getCacheManager();
0473:                    if (mgr == null) {
0474:                        throw new Exception(
0475:                                "Working without internal cache API implementation!");
0476:                    }
0477:                    mgr.getProcessCache().setSize(size);
0478:                } finally {
0479:                    SharkEngineManager.getInstance().getCallbackUtilities()
0480:                            .methodEnd(shandle, tStamp,
0481:                                    "ExecutionAdmin.setProcessCache",
0482:                                    "size=" + size);
0483:                }
0484:            }
0485:
0486:            public void clearProcessCache(WMSessionHandle shandle)
0487:                    throws Exception {
0488:                long tStamp = SharkEngineManager.getInstance()
0489:                        .getCallbackUtilities().methodStart(shandle,
0490:                                "ExecutionAdmin.clearProcessCache");
0491:
0492:                try {
0493:                    if (!SharkUtilities.checkSession(shandle)) {
0494:                        throw new NotConnected(
0495:                                "The session handle is not valid!");
0496:                    }
0497:                    checkSecurity(shandle, "clearProcessCache", null);
0498:
0499:                    CacheMgr mgr = SharkEngineManager.getInstance()
0500:                            .getCacheManager();
0501:                    if (mgr == null) {
0502:                        throw new Exception(
0503:                                "Working without internal cache API implementation!");
0504:                    }
0505:                    ProcessCache pc = mgr.getProcessCache();
0506:                    int size = pc.getSize();
0507:                    pc.setSize(0);
0508:                    pc.setSize(size);
0509:                } finally {
0510:                    SharkEngineManager.getInstance().getCallbackUtilities()
0511:                            .methodEnd(shandle, tStamp,
0512:                                    "ExecutionAdmin.clearProcessCache", "");
0513:                }
0514:            }
0515:
0516:            public void setResourceCacheSize(WMSessionHandle shandle, int size)
0517:                    throws Exception {
0518:                long tStamp = SharkEngineManager.getInstance()
0519:                        .getCallbackUtilities().methodStart(shandle,
0520:                                "ExecutionAdmin.setResourceCache");
0521:
0522:                try {
0523:                    if (!SharkUtilities.checkSession(shandle)) {
0524:                        throw new NotConnected(
0525:                                "The session handle is not valid!");
0526:                    }
0527:                    checkSecurity(shandle, "setResourceCacheSize", null);
0528:
0529:                    CacheMgr mgr = SharkEngineManager.getInstance()
0530:                            .getCacheManager();
0531:                    if (mgr == null) {
0532:                        throw new Exception(
0533:                                "Working without internal cache API implementation!");
0534:                    }
0535:                    mgr.getResourceCache().setSize(size);
0536:                } finally {
0537:                    SharkEngineManager.getInstance().getCallbackUtilities()
0538:                            .methodEnd(shandle, tStamp,
0539:                                    "ExecutionAdmin.setResourceCache",
0540:                                    "size=" + size);
0541:                }
0542:            }
0543:
0544:            public void clearResourceCache(WMSessionHandle shandle)
0545:                    throws Exception {
0546:                long tStamp = SharkEngineManager.getInstance()
0547:                        .getCallbackUtilities().methodStart(shandle,
0548:                                "ExecutionAdmin.clearResourceCache");
0549:
0550:                try {
0551:                    if (!SharkUtilities.checkSession(shandle)) {
0552:                        throw new NotConnected(
0553:                                "The session handle is not valid!");
0554:                    }
0555:                    checkSecurity(shandle, "clearResourceCache", null);
0556:
0557:                    CacheMgr mgr = SharkEngineManager.getInstance()
0558:                            .getCacheManager();
0559:                    if (mgr == null) {
0560:                        throw new Exception(
0561:                                "Working without internal cache API implementation!");
0562:                    }
0563:                    ResourceCache rc = mgr.getResourceCache();
0564:                    int size = rc.getSize();
0565:                    rc.setSize(0);
0566:                    rc.setSize(size);
0567:                } finally {
0568:                    SharkEngineManager.getInstance().getCallbackUtilities()
0569:                            .methodEnd(shandle, tStamp,
0570:                                    "ExecutionAdmin.clearResourceCache", "");
0571:                }
0572:            }
0573:
0574:            public void injectException(WMSessionHandle shandle, String procId,
0575:                    String actId, Exception ex) throws Exception {
0576:                long tStamp = SharkEngineManager.getInstance()
0577:                        .getCallbackUtilities().methodStart(shandle,
0578:                                "ExecutionAdmin.injectException");
0579:                try {
0580:                    WfActivityInternal act = getActivityImpl(shandle, procId,
0581:                            actId, SharkUtilities.WRITE_MODE);
0582:                    act.setException(shandle, ex);
0583:                    act.setExceptionName(shandle, SharkUtilities
0584:                            .extractExceptionName(ex));
0585:                } finally {
0586:                    SharkEngineManager.getInstance().getCallbackUtilities()
0587:                            .methodEnd(
0588:                                    shandle,
0589:                                    tStamp,
0590:                                    "ExecutionAdmin.injectException",
0591:                                    "proc=" + procId + ",act=" + actId
0592:                                            + ",exception=" + ex);
0593:                }
0594:            }
0595:
0596:            public void assignProcessInstanceProperty(WMSessionHandle shandle,
0597:                    String procInstId, String propName, Object propValue)
0598:                    throws Exception {
0599:                long tStamp = SharkEngineManager.getInstance()
0600:                        .getCallbackUtilities().methodStart(shandle,
0601:                                "ExecutionAdmin.assignProcessInstanceProperty");
0602:                try {
0603:                    if (!SharkUtilities.checkSession(shandle)) {
0604:                        throw new NotConnected(
0605:                                "The session handle is not valid!");
0606:                    }
0607:                    checkSecurity(shandle, "assignProcessInstanceProperty",
0608:                            null);
0609:
0610:                    if (!SharkConstants.possibleProcessPropertyNames
0611:                            .contains(propName)) {
0612:                        throw new Exception("Can't assign property " + propName
0613:                                + " to process " + procInstId
0614:                                + "! Possible properties to assign are: "
0615:                                + SharkConstants.possibleProcessPropertyNames);
0616:                    }
0617:                    WfProcessInternal pi = getProcessImpl(shandle, procInstId,
0618:                            SharkUtilities.WRITE_MODE);
0619:                    if (propName.equals(SharkConstants.PROPERTY_NAME_NAME)) {
0620:                        pi.set_name(shandle, (String) propValue);
0621:                    } else if (propName
0622:                            .equals(SharkConstants.PROPERTY_NAME_DESCRIPTION)) {
0623:                        pi.set_description(shandle, (String) propValue);
0624:                    } else if (propName
0625:                            .equals(SharkConstants.PROPERTY_NAME_PRIORITY)) {
0626:                        pi.set_priority(shandle, ((Short) propValue)
0627:                                .shortValue());
0628:                    }
0629:                } finally {
0630:                    SharkEngineManager
0631:                            .getInstance()
0632:                            .getCallbackUtilities()
0633:                            .methodEnd(
0634:                                    shandle,
0635:                                    tStamp,
0636:                                    "ExecutionAdmin.assignProcessInstanceProperty",
0637:                                    "proc=" + procInstId + ",attrName="
0638:                                            + propName + ",attrVal="
0639:                                            + propValue);
0640:                }
0641:
0642:            }
0643:
0644:            public void assignActivityInstanceProperty(WMSessionHandle shandle,
0645:                    String procInstId, String actInstId, String propName,
0646:                    Object propValue) throws Exception {
0647:                long tStamp = SharkEngineManager
0648:                        .getInstance()
0649:                        .getCallbackUtilities()
0650:                        .methodStart(shandle,
0651:                                "ExecutionAdmin.assignActivityInstanceProperty");
0652:                try {
0653:                    if (!SharkUtilities.checkSession(shandle)) {
0654:                        throw new NotConnected(
0655:                                "The session handle is not valid!");
0656:                    }
0657:                    checkSecurity(shandle, "assignActivityInstanceProperty",
0658:                            null);
0659:
0660:                    if (!SharkConstants.possibleActivityPropertyNames
0661:                            .contains(propName)) {
0662:                        throw new Exception("Can't assign property " + propName
0663:                                + " to activity " + actInstId
0664:                                + "! Possible properties to assign are: "
0665:                                + SharkConstants.possibleActivityPropertyNames);
0666:                    }
0667:                    WfActivityInternal ai = getActivityImpl(shandle,
0668:                            procInstId, actInstId, SharkUtilities.WRITE_MODE);
0669:                    if (propName.equals(SharkConstants.PROPERTY_NAME_NAME)) {
0670:                        ai.set_name(shandle, (String) propValue);
0671:                    } else if (propName
0672:                            .equals(SharkConstants.PROPERTY_NAME_DESCRIPTION)) {
0673:                        ai.set_description(shandle, (String) propValue);
0674:                    } else if (propName
0675:                            .equals(SharkConstants.PROPERTY_NAME_PRIORITY)) {
0676:                        ai.set_priority(shandle, ((Short) propValue)
0677:                                .shortValue());
0678:                    }
0679:                } finally {
0680:                    SharkEngineManager
0681:                            .getInstance()
0682:                            .getCallbackUtilities()
0683:                            .methodEnd(
0684:                                    shandle,
0685:                                    tStamp,
0686:                                    "ExecutionAdmin.assignActivityInstanceProperty",
0687:                                    "proc=" + procInstId + ",act=" + actInstId
0688:                                            + ",attrName=" + propName
0689:                                            + ",attrValue=" + propValue);
0690:                }
0691:            }
0692:
0693:            public void assignActivityInstanceAttributeForLocalContext(
0694:                    WMSessionHandle shandle, String procInstId,
0695:                    String actInstId, String attrName, Object attrValue)
0696:                    throws Exception {
0697:                long tStamp = SharkEngineManager
0698:                        .getInstance()
0699:                        .getCallbackUtilities()
0700:                        .methodStart(shandle,
0701:                                "ExecutionAdmin.assignActivityInstanceAttributeForLocalContext");
0702:                try {
0703:                    if (!SharkUtilities.checkSession(shandle)) {
0704:                        throw new NotConnected(
0705:                                "The session handle is not valid!");
0706:                    }
0707:                    checkSecurity(shandle,
0708:                            "assignActivityInstanceAttributeForLocalContext",
0709:                            null);
0710:
0711:                    WfActivityInternal ai = getActivityImpl(shandle,
0712:                            procInstId, actInstId, SharkUtilities.WRITE_MODE);
0713:                    Map pc = new HashMap(1);
0714:                    pc.put(attrName, attrValue);
0715:                    ai.set_process_context(shandle, pc);
0716:                } finally {
0717:                    SharkEngineManager
0718:                            .getInstance()
0719:                            .getCallbackUtilities()
0720:                            .methodEnd(
0721:                                    shandle,
0722:                                    tStamp,
0723:                                    "ExecutionAdmin.assignActivityInstanceAttributeForLocalContext",
0724:                                    "proc=" + procInstId + ",act=" + actInstId
0725:                                            + ",attrName=" + attrName
0726:                                            + ",attrValue=" + attrValue);
0727:                }
0728:            }
0729:
0730:            // ///////////////////////
0731:
0732:            // /////////////////////// DEADLINE
0733:
0734:            public String[] getDeadlineRichedProcessIds(WMSessionHandle shandle)
0735:                    throws Exception {
0736:                long tStamp = SharkEngineManager.getInstance()
0737:                        .getCallbackUtilities().methodStart(shandle,
0738:                                "ExecutionAdmin.getDeadlineRichedProcessIds");
0739:                try {
0740:                    List procs = SharkEngineManager.getInstance()
0741:                            .getInstancePersistenceManager()
0742:                            .getAllIdsForProcessesWithExpiriedDeadlines(
0743:                                    shandle, System.currentTimeMillis());
0744:                    String[] ret = new String[procs.size()];
0745:                    procs.toArray(ret);
0746:                    return ret;
0747:                } finally {
0748:                    SharkEngineManager
0749:                            .getInstance()
0750:                            .getCallbackUtilities()
0751:                            .methodEnd(
0752:                                    shandle,
0753:                                    tStamp,
0754:                                    "ExecutionAdmin.getDeadlineRichedProcessIds",
0755:                                    "");
0756:                }
0757:            }
0758:
0759:            public WMActivityInstanceIterator checkDeadlinesWithFiltering(
0760:                    WMSessionHandle shandle, WMFilter procOrActFilter)
0761:                    throws Exception {
0762:
0763:                long tStamp = SharkEngineManager.getInstance()
0764:                        .getCallbackUtilities().methodStart(shandle,
0765:                                "ExecutionAdmin.checkDeadlinesWithFiltering");
0766:
0767:                try {
0768:                    if (!SharkUtilities.checkSession(shandle)) {
0769:                        throw new NotConnected(
0770:                                "The session handle is not valid!");
0771:                    }
0772:                    checkSecurity(shandle, "checkDeadlinesWithFiltering", null);
0773:
0774:                    List acts = new ArrayList();
0775:                    List procs = new ArrayList();
0776:                    boolean checkOnActs = false;
0777:                    if (procOrActFilter != null) {
0778:                        if (procOrActFilter.getFilterType() != FilterBuilder.SQL_TYPE_ACTIVITY
0779:                                && procOrActFilter.getFilterType() != FilterBuilder.SQL_TYPE_PROCESS) {
0780:                            throw new Exception(
0781:                                    "Invalid filter type! It must be either activity or process filter.");
0782:                        }
0783:                        if (procOrActFilter.getSQLWhereExpression() == null) {
0784:                            throw new Exception(
0785:                                    "Invalid filter expression - expression must be defined!");
0786:                        }
0787:                        String sqlExpr = procOrActFilter
0788:                                .getSQLWhereExpression()
0789:                                + procOrActFilter.getOrderBy();
0790:                        int startAt = procOrActFilter.getStartPosition();
0791:                        int limit = procOrActFilter.getLimit();
0792:
0793:                        if (procOrActFilter.getFilterType() == FilterBuilder.SQL_TYPE_ACTIVITY) {
0794:                            acts.addAll(SharkEngineManager.getInstance()
0795:                                    .getInstancePersistenceManager()
0796:                                    .getActivitiesWhere(shandle, sqlExpr,
0797:                                            startAt, limit));
0798:                            checkOnActs = true;
0799:
0800:                        } else {
0801:                            procs = SharkEngineManager.getInstance()
0802:                                    .getInstancePersistenceManager()
0803:                                    .getProcessesWhere(shandle, sqlExpr,
0804:                                            startAt, limit);
0805:                        }
0806:                    } else {
0807:                        String reevalStr = SharkEngineManager.getInstance()
0808:                                .getCallbackUtilities()
0809:                                .getProperty("Deadlines.reevaluateDeadlines",
0810:                                        "true");
0811:                        boolean dreeval = Boolean.valueOf(reevalStr)
0812:                                .booleanValue();
0813:                        if (dreeval) {
0814:                            procs = SharkEngineManager.getInstance()
0815:                                    .getInstancePersistenceManager()
0816:                                    .getAllRunningProcesses(shandle);
0817:                        } else {
0818:                            procs = SharkEngineManager
0819:                                    .getInstance()
0820:                                    .getInstancePersistenceManager()
0821:                                    .getAllIdsForProcessesWithExpiriedDeadlines(
0822:                                            shandle, System.currentTimeMillis());
0823:                        }
0824:                    }
0825:
0826:                    List l = new ArrayList();
0827:                    if (checkOnActs) {
0828:                        for (int i = 0; i < acts.size(); i++) {
0829:                            ActivityPersistenceObject apo = (ActivityPersistenceObject) acts
0830:                                    .get(i);
0831:                            WfProcessInternal pInt = getProcessImpl(shandle,
0832:                                    apo.getProcessId(),
0833:                                    SharkUtilities.WRITE_MODE);
0834:
0835:                            if (pInt.checkDeadline(shandle, apo.getId())) {
0836:                                l.add(SharkUtilities.getInstance(apo));
0837:                                SharkEngineManager.getInstance()
0838:                                        .getCallbackUtilities().info(
0839:                                                shandle,
0840:                                                "Activity " + apo.getId()
0841:                                                        + " riched deadline.");
0842:                            }
0843:                        }
0844:
0845:                    } else {
0846:                        for (int i = 0; i < procs.size(); i++) {
0847:                            Object pId = procs.get(i);
0848:                            if (pId instanceof  ProcessPersistenceObject) {
0849:                                ProcessPersistenceObject ppo = (ProcessPersistenceObject) pId;
0850:                                pId = ppo.getId();
0851:                            }
0852:                            WfProcessInternal pInt = getProcessImpl(shandle,
0853:                                    (String) pId, SharkUtilities.WRITE_MODE);
0854:                            if (pInt.state(shandle).startsWith(
0855:                                    SharkConstants.STATEPREFIX_CLOSED)) {
0856:                                SharkEngineManager
0857:                                        .getInstance()
0858:                                        .getCallbackUtilities()
0859:                                        .warn(
0860:                                                shandle,
0861:                                                "ExecutionAdmin->checkDeadlinesWithFiltering: The process with Id="
0862:                                                        + pId
0863:                                                        + " is closed, and can't be checked for deadlines!");
0864:                                continue;
0865:                            }
0866:                            WfActivityInternal[] aints = pInt
0867:                                    .checkDeadlines(shandle);
0868:                            for (int j = 0; j < aints.length; j++) {
0869:                                l.add(SharkUtilities.getInstance(shandle,
0870:                                        aints[j]));
0871:                                SharkEngineManager.getInstance()
0872:                                        .getCallbackUtilities().info(
0873:                                                shandle,
0874:                                                "Activity "
0875:                                                        + aints[j].key(shandle)
0876:                                                        + " riched deadline.");
0877:                            }
0878:                        }
0879:                    }
0880:
0881:                    WMActivityInstance[] ret = new WMActivityInstance[l.size()];
0882:                    l.toArray(ret);
0883:
0884:                    WMActivityInstanceIterator wmai = new WMActivityInstanceIterator();
0885:                    wmai.setArray(ret);
0886:                    wmai.setCount(ret.length);
0887:                    return wmai;
0888:                } finally {
0889:                    SharkEngineManager
0890:                            .getInstance()
0891:                            .getCallbackUtilities()
0892:                            .methodEnd(
0893:                                    shandle,
0894:                                    tStamp,
0895:                                    "ExecutionAdmin.checkDeadlinesWithFiltering",
0896:                                    procOrActFilter);
0897:                }
0898:            }
0899:
0900:            public WMActivityInstanceIterator checkDeadlinesForProcesses(
0901:                    WMSessionHandle shandle, String[] procIds) throws Exception {
0902:                long tStamp = SharkEngineManager.getInstance()
0903:                        .getCallbackUtilities().methodStart(shandle,
0904:                                "ExecutionAdmin.checkDeadlinesForProcesses");
0905:
0906:                try {
0907:                    if (!SharkUtilities.checkSession(shandle)) {
0908:                        throw new NotConnected(
0909:                                "The session handle is not valid!");
0910:                    }
0911:                    checkSecurity(shandle, "checkDeadlinesForProcesses", null);
0912:
0913:                    List l = new ArrayList();
0914:                    for (int i = 0; i < procIds.length; i++) {
0915:                        WfProcessInternal pInt = getProcessImpl(shandle,
0916:                                procIds[i], SharkUtilities.WRITE_MODE);
0917:
0918:                        if (pInt.state(shandle).startsWith(
0919:                                SharkConstants.STATEPREFIX_CLOSED)) {
0920:                            throw new Exception(
0921:                                    "ExecutionAdmin->checkDeadlinesForProcesses: The process with Id="
0922:                                            + procIds[i]
0923:                                            + " is closed, and can't be checked for deadlines!");
0924:                        }
0925:                        WfActivityInternal[] aints = pInt
0926:                                .checkDeadlines(shandle);
0927:                        for (int j = 0; j < aints.length; j++) {
0928:                            l
0929:                                    .add(SharkUtilities.getInstance(shandle,
0930:                                            aints[j]));
0931:                            SharkEngineManager.getInstance()
0932:                                    .getCallbackUtilities().info(
0933:                                            shandle,
0934:                                            "Activity " + aints[j].key(shandle)
0935:                                                    + " riched deadline.");
0936:                        }
0937:                    }
0938:
0939:                    WMActivityInstance[] ret = new WMActivityInstance[l.size()];
0940:                    l.toArray(ret);
0941:
0942:                    WMActivityInstanceIterator wmai = new WMActivityInstanceIterator();
0943:                    wmai.setArray(ret);
0944:                    wmai.setCount(ret.length);
0945:                    return wmai;
0946:                } finally {
0947:                    SharkEngineManager
0948:                            .getInstance()
0949:                            .getCallbackUtilities()
0950:                            .methodEnd(
0951:                                    shandle,
0952:                                    tStamp,
0953:                                    "ExecutionAdmin.checkDeadlinesForProcesses",
0954:                                    "");
0955:
0956:                }
0957:
0958:            }
0959:
0960:            public WMActivityInstanceIterator checkDeadlinesForActivities(
0961:                    WMSessionHandle shandle, WMActivityInstance[] acts)
0962:                    throws Exception {
0963:                long tStamp = SharkEngineManager.getInstance()
0964:                        .getCallbackUtilities().methodStart(shandle,
0965:                                "ExecutionAdmin.checkDeadlinesForActivities");
0966:
0967:                try {
0968:                    if (!SharkUtilities.checkSession(shandle)) {
0969:                        throw new NotConnected(
0970:                                "The session handle is not valid!");
0971:                    }
0972:                    checkSecurity(shandle, "checkDeadlinesForActivities", null);
0973:
0974:                    List l = new ArrayList();
0975:                    for (int i = 0; i < acts.length; i++) {
0976:                        WfProcessInternal pInt = getProcessImpl(shandle,
0977:                                acts[i].getProcessInstanceId(),
0978:                                SharkUtilities.WRITE_MODE);
0979:
0980:                        if (pInt.checkDeadline(shandle, acts[i].getId())) {
0981:                            l.add(acts[i]);
0982:                            SharkEngineManager.getInstance()
0983:                                    .getCallbackUtilities().info(
0984:                                            shandle,
0985:                                            "Activity " + acts[i].getId()
0986:                                                    + " riched deadline.");
0987:                        }
0988:                    }
0989:
0990:                    WMActivityInstance[] ret = new WMActivityInstance[l.size()];
0991:                    l.toArray(ret);
0992:
0993:                    WMActivityInstanceIterator wmai = new WMActivityInstanceIterator();
0994:                    wmai.setArray(ret);
0995:                    wmai.setCount(ret.length);
0996:                    return wmai;
0997:                } finally {
0998:                    SharkEngineManager
0999:                            .getInstance()
1000:                            .getCallbackUtilities()
1001:                            .methodEnd(
1002:                                    shandle,
1003:                                    tStamp,
1004:                                    "ExecutionAdmin.checkDeadlinesForActivities",
1005:                                    "");
1006:
1007:                }
1008:            }
1009:
1010:            // /////////////////////// LIMIT
1011:
1012:            public WMProcessInstanceIterator checkLimitsWithProcessFiltering(
1013:                    WMSessionHandle shandle, WMFilter procFilter,
1014:                    boolean checkActivities) throws Exception {
1015:                long tStamp = SharkEngineManager
1016:                        .getInstance()
1017:                        .getCallbackUtilities()
1018:                        .methodStart(shandle,
1019:                                "ExecutionAdmin.checkLimitsWithProcessFiltering");
1020:
1021:                try {
1022:                    if (!SharkUtilities.checkSession(shandle)) {
1023:                        throw new NotConnected(
1024:                                "The session handle is not valid!");
1025:                    }
1026:                    checkSecurity(shandle, "checkLimitsWithProcessFiltering",
1027:                            null);
1028:
1029:                    if (procFilter == null) {
1030:                        ProcessFilterBuilder pieb = SharkEngineManager
1031:                                .getInstance().getProcessFilterBuilder();
1032:                        procFilter = pieb.addStateStartsWith(shandle,
1033:                                SharkConstants.STATEPREFIX_OPEN);
1034:                    }
1035:                    if (procFilter.getSQLWhereExpression() == null) {
1036:                        throw new Exception(
1037:                                "Invalid filter expression - expression must be defined!");
1038:                    }
1039:                    if (procFilter.getFilterType() != FilterBuilder.SQL_TYPE_PROCESS) {
1040:                        throw new Exception(
1041:                                "Invalid filter type! It must be process filter.");
1042:                    }
1043:                    String sqlExpr = procFilter.getSQLWhereExpression()
1044:                            + procFilter.getOrderBy();
1045:                    int startAt = procFilter.getStartPosition();
1046:                    int limit = procFilter.getLimit();
1047:
1048:                    List procs = SharkEngineManager.getInstance()
1049:                            .getInstancePersistenceManager().getProcessesWhere(
1050:                                    shandle, sqlExpr, startAt, limit);
1051:
1052:                    List l = new ArrayList();
1053:                    for (int i = 0; i < procs.size(); i++) {
1054:                        ProcessPersistenceObject ppo = (ProcessPersistenceObject) procs
1055:                                .get(i);
1056:                        WMProcessInstance pi = _checkProcessLimits(shandle,
1057:                                ppo, checkActivities, tStamp);
1058:                        if (pi != null) {
1059:                            l.add(pi);
1060:                        }
1061:                    }
1062:                    WMProcessInstance[] ret = new WMProcessInstance[l.size()];
1063:                    l.toArray(ret);
1064:
1065:                    WMProcessInstanceIterator wmpi = new WMProcessInstanceIterator();
1066:                    wmpi.setArray(ret);
1067:                    wmpi.setCount(ret.length);
1068:                    return wmpi;
1069:                } finally {
1070:                    SharkEngineManager
1071:                            .getInstance()
1072:                            .getCallbackUtilities()
1073:                            .methodEnd(
1074:                                    shandle,
1075:                                    tStamp,
1076:                                    "ExecutionAdmin.checkLimitsWithProcessFiltering",
1077:                                    procFilter + ",checkActivities="
1078:                                            + checkActivities);
1079:                }
1080:
1081:            }
1082:
1083:            public WMProcessInstanceIterator checkLimitsForProcesses(
1084:                    WMSessionHandle shandle, String[] procIds,
1085:                    boolean checkActivities) throws Exception {
1086:
1087:                long tStamp = SharkEngineManager.getInstance()
1088:                        .getCallbackUtilities().methodStart(shandle,
1089:                                "ExecutionAdmin.checkLimitsForProcesses");
1090:
1091:                try {
1092:                    if (!SharkUtilities.checkSession(shandle)) {
1093:                        throw new NotConnected(
1094:                                "The session handle is not valid!");
1095:                    }
1096:                    checkSecurity(shandle, "checkLimitsForProcesses", null);
1097:
1098:                    List l = new ArrayList();
1099:                    for (int i = 0; i < procIds.length; i++) {
1100:                        ProcessPersistenceObject ppo = SharkEngineManager
1101:                                .getInstance().getInstancePersistenceManager()
1102:                                .restoreProcess(shandle, procIds[i]);
1103:                        WMProcessInstance pi = _checkProcessLimits(shandle,
1104:                                ppo, checkActivities, System
1105:                                        .currentTimeMillis());
1106:                        if (pi != null) {
1107:                            l.add(pi);
1108:                        }
1109:                    }
1110:                    WMProcessInstance[] ret = new WMProcessInstance[l.size()];
1111:                    l.toArray(ret);
1112:
1113:                    WMProcessInstanceIterator wmpi = new WMProcessInstanceIterator();
1114:                    wmpi.setArray(ret);
1115:                    wmpi.setCount(ret.length);
1116:                    return wmpi;
1117:                } finally {
1118:                    SharkEngineManager.getInstance().getCallbackUtilities()
1119:                            .methodEnd(shandle, tStamp,
1120:                                    "ExecutionAdmin.checkLimitsForProcesses",
1121:                                    "checkActivities=" + checkActivities);
1122:                }
1123:
1124:            }
1125:
1126:            public WMActivityInstanceIterator checkLimitsWithActivityFiltering(
1127:                    WMSessionHandle shandle, WMFilter actFilter)
1128:                    throws Exception {
1129:                long tStamp = SharkEngineManager
1130:                        .getInstance()
1131:                        .getCallbackUtilities()
1132:                        .methodStart(shandle,
1133:                                "ExecutionAdmin.checkLimitsWithActivityFiltering");
1134:
1135:                try {
1136:                    if (!SharkUtilities.checkSession(shandle)) {
1137:                        throw new NotConnected(
1138:                                "The session handle is not valid!");
1139:                    }
1140:                    checkSecurity(shandle, "checkLimitsWithActivityFiltering",
1141:                            null);
1142:
1143:                    List acts = new ArrayList();
1144:                    if (actFilter == null) {
1145:                        ActivityFilterBuilder aieb = SharkEngineManager
1146:                                .getInstance().getActivityFilterBuilder();
1147:                        actFilter = aieb.addStateStartsWith(shandle,
1148:                                SharkConstants.STATEPREFIX_OPEN);
1149:                        WMFilter filt = aieb
1150:                                .addLimitTimeBefore(shandle, tStamp);
1151:                        actFilter = aieb.and(shandle, actFilter, filt);
1152:                    }
1153:                    if (actFilter.getFilterType() != FilterBuilder.SQL_TYPE_ACTIVITY) {
1154:                        throw new Exception(
1155:                                "Invalid filter type! It must be either activity filter.");
1156:                    }
1157:                    if (actFilter.getSQLWhereExpression() == null) {
1158:                        throw new Exception(
1159:                                "Invalid filter expression - expression must be defined!");
1160:                    }
1161:                    String sqlExpr = actFilter.getSQLWhereExpression()
1162:                            + actFilter.getOrderBy();
1163:                    int startAt = actFilter.getStartPosition();
1164:                    int limit = actFilter.getLimit();
1165:
1166:                    acts.addAll(SharkEngineManager.getInstance()
1167:                            .getInstancePersistenceManager()
1168:                            .getActivitiesWhere(shandle, sqlExpr, startAt,
1169:                                    limit));
1170:
1171:                    List l = new ArrayList();
1172:                    for (int i = 0; i < acts.size(); i++) {
1173:                        ActivityPersistenceObject apo = (ActivityPersistenceObject) acts
1174:                                .get(i);
1175:                        WMActivityInstance ai = _checkActivityLimit(shandle,
1176:                                apo, tStamp);
1177:                        if (ai != null) {
1178:                            l.add(SharkUtilities.getInstance(apo));
1179:                        }
1180:                    }
1181:
1182:                    WMActivityInstance[] ret = new WMActivityInstance[l.size()];
1183:                    l.toArray(ret);
1184:
1185:                    WMActivityInstanceIterator wmai = new WMActivityInstanceIterator();
1186:                    wmai.setArray(ret);
1187:                    wmai.setCount(ret.length);
1188:                    return wmai;
1189:                } finally {
1190:                    SharkEngineManager
1191:                            .getInstance()
1192:                            .getCallbackUtilities()
1193:                            .methodEnd(
1194:                                    shandle,
1195:                                    tStamp,
1196:                                    "ExecutionAdmin.checkLimitsWithActivityFiltering",
1197:                                    actFilter);
1198:                }
1199:
1200:            }
1201:
1202:            public WMActivityInstanceIterator checkLimitsForActivities(
1203:                    WMSessionHandle shandle, WMActivityInstance[] acts)
1204:                    throws Exception {
1205:
1206:                long tStamp = SharkEngineManager.getInstance()
1207:                        .getCallbackUtilities().methodStart(shandle,
1208:                                "ExecutionAdmin.checkLimitsForActivities");
1209:
1210:                try {
1211:                    if (!SharkUtilities.checkSession(shandle)) {
1212:                        throw new NotConnected(
1213:                                "The session handle is not valid!");
1214:                    }
1215:                    checkSecurity(shandle, "checkLimitsForActivities", null);
1216:
1217:                    List l = new ArrayList();
1218:
1219:                    for (int i = 0; i < acts.length; i++) {
1220:                        ActivityPersistenceObject apo = SharkEngineManager
1221:                                .getInstance().getInstancePersistenceManager()
1222:                                .restoreActivity(shandle,
1223:                                        acts[i].getProcessInstanceId(),
1224:                                        acts[i].getId());
1225:                        WMActivityInstance ai = _checkActivityLimit(shandle,
1226:                                apo, tStamp);
1227:                        if (ai != null) {
1228:                            l.add(SharkUtilities.getInstance(apo));
1229:                        }
1230:                    }
1231:
1232:                    WMActivityInstance[] ret = new WMActivityInstance[l.size()];
1233:                    l.toArray(ret);
1234:
1235:                    WMActivityInstanceIterator wmai = new WMActivityInstanceIterator();
1236:                    wmai.setArray(ret);
1237:                    wmai.setCount(ret.length);
1238:                    return wmai;
1239:                } finally {
1240:                    SharkEngineManager.getInstance().getCallbackUtilities()
1241:                            .methodEnd(shandle, tStamp,
1242:                                    "ExecutionAdmin.checkLimitsForActivities",
1243:                                    "");
1244:                }
1245:            }
1246:
1247:            protected WMProcessInstance _checkProcessLimits(
1248:                    WMSessionHandle shandle, ProcessPersistenceObject po,
1249:                    boolean checkActs, long currentTime) throws Exception {
1250:                if (po.getState().startsWith(SharkConstants.STATEPREFIX_CLOSED)) {
1251:                    return null;
1252:                }
1253:                boolean limitReached = false;
1254:
1255:                long procLimitTime = po.getLimitTime();
1256:                if (procLimitTime < currentTime) {
1257:                    SharkEngineManager.getInstance().getCallbackUtilities()
1258:                            .info(
1259:                                    shandle,
1260:                                    "-----> Process : " + po.getId()
1261:                                            + " has reached its limit");
1262:                    limitReached = true;
1263:                }
1264:                if (checkActs) {
1265:                    List apos = SharkEngineManager.getInstance()
1266:                            .getInstancePersistenceManager()
1267:                            .getAllActiveActivitiesForProcess(shandle,
1268:                                    po.getId());
1269:                    for (int i = 0; i < apos.size(); i++) {
1270:                        ActivityPersistenceObject apo = (ActivityPersistenceObject) apos
1271:                                .get(i);
1272:                        long actLimitTime = apo.getLimitTime();
1273:                        if (actLimitTime < currentTime) {
1274:                            SharkEngineManager.getInstance()
1275:                                    .getCallbackUtilities().info(
1276:                                            shandle,
1277:                                            "-----> Activity : " + apo.getId()
1278:                                                    + " has reached its limit");
1279:                            limitReached = true;
1280:                        }
1281:
1282:                    }
1283:                }
1284:
1285:                if (limitReached) {
1286:                    return SharkUtilities.getInstance(po);
1287:                }
1288:                return null;
1289:            }
1290:
1291:            protected WMActivityInstance _checkActivityLimit(
1292:                    WMSessionHandle shandle, ActivityPersistenceObject po,
1293:                    long currentTime) throws Exception {
1294:                if (po.getState().startsWith(SharkConstants.STATEPREFIX_CLOSED)) {
1295:                    return null;
1296:                }
1297:                long actLimitTime = po.getLimitTime();
1298:                if (actLimitTime < currentTime) {
1299:                    SharkEngineManager.getInstance().getCallbackUtilities()
1300:                            .info(
1301:                                    shandle,
1302:                                    "-----> Activity : " + po.getId()
1303:                                            + " has reached its limit");
1304:                    return SharkUtilities.getInstance(po);
1305:                }
1306:
1307:                return null;
1308:            }
1309:
1310:            protected WfProcessInternal getProcessImpl(WMSessionHandle shandle,
1311:                    String procId, int mode) throws Exception {
1312:                WfProcessInternal proc = SharkUtilities.getProcess(shandle,
1313:                        procId, mode);
1314:                if (proc == null)
1315:                    throw new Exception("Process " + procId + " does not exist");
1316:                return proc;
1317:            }
1318:
1319:            protected WfActivityInternal getActivityImpl(
1320:                    WMSessionHandle shandle, String processId, String actId,
1321:                    int mode) throws Exception {
1322:                WfActivityInternal actImpl = SharkUtilities.getActivity(
1323:                        shandle, processId, actId, mode);
1324:                if (actImpl == null)
1325:                    throw new Exception("Activity " + actId + " does not exist");
1326:                return actImpl;
1327:            }
1328:
1329:            protected void checkSecurity(WMSessionHandle shandle,
1330:                    String methodName, Map d) throws Exception {
1331:                SecurityManager sm = SharkEngineManager.getInstance()
1332:                        .getSecurityManager();
1333:                if (sm != null) {
1334:                    sm.check_security(shandle, this.getClass(), methodName, d);
1335:                }
1336:            }
1337:
1338:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.