A javitasok elesitve
authorelgekko <vasary@elgekko.net>
Mon, 23 May 2022 09:14:36 +0000 (11:14 +0200)
committerelgekko <vasary@elgekko.net>
Mon, 23 May 2022 09:14:36 +0000 (11:14 +0200)
22 files changed:
server/hu.user.mediacube.executors.tests/jobs/executors.xml [new file with mode: 0644]
server/hu.user.mediacube.executors.tests/jobs/executors.yaml [deleted file]
server/hu.user.mediacube.executors.tests/jobs/steps [new symlink]
server/hu.user.mediacube.executors.tests/jobs/templates/create-content-list.xml [new file with mode: 0644]
server/hu.user.mediacube.executors.tests/settings/application.yaml
server/hu.user.mediacube.executors.tests/src/hu/user/mediacube/executors/tests/CreateContentListTest.java [new file with mode: 0644]
server/hu.user.mediacube.executors.tests/src/hu/user/mediacube/executors/tests/GGGClassLoader.java [deleted file]
server/hu.user.mediacube.executors.tests/src/hu/user/mediacube/executors/tests/SmallTests.java
server/hu.user.mediacube.executors.tests/src/hu/user/mediacube/executors/tests/Test1.java [deleted file]
server/user.jobengine.executors/.settings/org.eclipse.core.resources.prefs
server/user.jobengine.executors/src/user/jobengine/server/steps/ArchiveRecursive.java
server/user.jobengine.executors/src/user/jobengine/server/steps/HLSProxyStep.java
server/user.jobengine.executors/src/user/jobengine/server/steps/MetadataTransformStep.java
server/user.jobengine.executors/src/user/jobengine/server/steps/shared/EscortFiles.java
server/user.jobengine.osgi.commons/src/user/commons/configuration/SystemConfiguration.java
server/user.jobengine.osgi.db/generated/user/jobengine/db/EntityBaseDAO.java
server/user.jobengine.osgi.db/src/user/jobengine/db/ItemManager.java
server/user.jobengine.osgi.db/src/user/jobengine/db/SqlIntegrityErrorParser.java [new file with mode: 0644]
server/user.jobengine.osgi.server/src/user/jobengine/server/DynamicStepsLoader.java
server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngine.java
server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngineConfiguration.java
server/user.mediacube.gui/bin/user/jobengine/zk/util/SessionListener.class [deleted file]

diff --git a/server/hu.user.mediacube.executors.tests/jobs/executors.xml b/server/hu.user.mediacube.executors.tests/jobs/executors.xml
new file mode 100644 (file)
index 0000000..c48ea25
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<!DOCTYPE xml>\r
+\r
+<executors>\r
+       <executor className="CreateContentListStep.java" maxConcurrent="1" isRemote="false" />\r
+</executors>
\ No newline at end of file
diff --git a/server/hu.user.mediacube.executors.tests/jobs/executors.yaml b/server/hu.user.mediacube.executors.tests/jobs/executors.yaml
deleted file mode 100644 (file)
index 8cba80b..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-executors:\r
- - className: user.jobengine.server.steps.ArchiveListBuilderStep\r
-   maxConcurrent: 1\r
- - className: user.jobengine.server.steps.ArchiveMaterialSubmitStep\r
-   maxConcurrent: 2\r
diff --git a/server/hu.user.mediacube.executors.tests/jobs/steps b/server/hu.user.mediacube.executors.tests/jobs/steps
new file mode 120000 (symlink)
index 0000000..486f105
--- /dev/null
@@ -0,0 +1 @@
+c:/work/user/mediacube/server/user.jobengine.executors/src/user/jobengine/server/steps
\ No newline at end of file
diff --git a/server/hu.user.mediacube.executors.tests/jobs/templates/create-content-list.xml b/server/hu.user.mediacube.executors.tests/jobs/templates/create-content-list.xml
new file mode 100644 (file)
index 0000000..ff82745
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<jobtemplate multiInstance="true" useSessionLog="true">\r
+       <declarations>\r
+               <parameters>\r
+                       <parameter name="sourcePath" type="java.lang.String" />\r
+                       <parameter name="targetFile" type="java.lang.String" />\r
+               </parameters>\r
+       </declarations>\r
+       <commands>\r
+               <calljobstep type="CreateContentListStep.java" weight="1" >\r
+                       <inputs>\r
+                               <input>\r
+                                       <parameter name="sourcePath" />\r
+                               </input>\r
+                               <input>\r
+                                       <parameter name="targetFile" />\r
+                               </input>\r
+                       </inputs>\r
+               </calljobstep>\r
+       </commands>\r
+</jobtemplate>
\ No newline at end of file
index 020389ea86dbbe3aa94ff7f869ce67d17496aa13..5149acf753db2fa13ad1f3eb15d3406a3285dcc0 100644 (file)
@@ -1,6 +1,6 @@
 datasource:\r
    mediacube:\r
-      url: jdbc:db2://192.168.224.128:50000/mc\r
+      url: jdbc:db2://localvm:50000/mc\r
       user: db2admin\r
       password: password\r
       external-indexer: false\r
@@ -8,7 +8,7 @@ datasource:
       login-timeout: 3\r
       pool-size: 10\r
    mediacube-nosql:\r
-      url: jdbc:db2://192.168.224.128:50000/mc\r
+      url: jdbc:db2://localvm:50000/mc\r
       user: db2admin\r
       password: password\r
       schema: test\r
diff --git a/server/hu.user.mediacube.executors.tests/src/hu/user/mediacube/executors/tests/CreateContentListTest.java b/server/hu.user.mediacube.executors.tests/src/hu/user/mediacube/executors/tests/CreateContentListTest.java
new file mode 100644 (file)
index 0000000..79533ca
--- /dev/null
@@ -0,0 +1,87 @@
+package hu.user.mediacube.executors.tests;\r
+\r
+import java.io.IOException;\r
+import java.nio.file.Files;\r
+import java.nio.file.Path;\r
+import java.nio.file.Paths;\r
+import java.util.LinkedHashSet;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Set;\r
+import java.util.concurrent.Semaphore;\r
+\r
+import org.apache.commons.io.FileUtils;\r
+import org.junit.AfterClass;\r
+import org.junit.BeforeClass;\r
+import org.junit.Test;\r
+\r
+import user.commons.JobStatus;\r
+import user.commons.ListUtils;\r
+import user.commons.configuration.IConfiguration;\r
+import user.commons.configuration.SystemConfiguration;\r
+import user.jobengine.db.ItemManager;\r
+import user.jobengine.server.IJobRuntime;\r
+import user.jobengine.server.JobEngine;\r
+import user.jobengine.server.JobEngineConfiguration;\r
+import user.tsm.client.TSMException;\r
+\r
+public class CreateContentListTest {\r
+\r
+       private static final Path targetFilePath = Paths.get("/work/test.txt");\r
+       protected static ItemManager manager = null;\r
+       protected static JobEngine engine = null;\r
+\r
+       @BeforeClass\r
+       static public void setUpConnection() throws TSMException {\r
+\r
+               IConfiguration configuration = SystemConfiguration.getInstance();\r
+               JobEngineConfiguration jobengineConfig = JobEngineConfiguration.getInstance();\r
+               jobengineConfig.bindSystemConfiguration(configuration);\r
+\r
+               manager = ItemManager.getInstance();\r
+               manager.bindSystemConfiguration(jobengineConfig);\r
+               manager.connect();\r
+               engine = JobEngine.getInstance();\r
+               engine.setItemManager(manager);\r
+               engine.bindJobEngineConfiguration(jobengineConfig);\r
+               engine.startup();\r
+\r
+       }\r
+\r
+       @AfterClass\r
+       static public void tearDownConnection() throws IOException {\r
+               engine.shutdown();\r
+               manager.disconnect();\r
+               Files.delete(targetFilePath);\r
+       }\r
+\r
+       @Test\r
+       public void execute() throws Exception {\r
+               Semaphore lock = new Semaphore(1);\r
+               lock.acquire();\r
+               Map<String, Object> params = ListUtils.asMap("sourcePath", "/data/video", "targetFile", targetFilePath.toString());\r
+               IJobRuntime runtime = engine.submit("create-content-list.xml", "create-content-list.xml", params);\r
+               runtime.addEventListener(e -> {\r
+                       if (JobStatus.FINISHED.equals(e.getStatus()) || JobStatus.SUSPENDED.equals(e.getStatus()))\r
+                               lock.release();\r
+               });\r
+               lock.acquire();\r
+\r
+               printWhiteList();\r
+       }\r
+\r
+       void printWhiteList() throws IOException {\r
+               Set<String> result = new LinkedHashSet<>();\r
+               List<String> lines = FileUtils.readLines(targetFilePath.toFile());\r
+\r
+               for (String line : lines) {\r
+                       String[] tokens = line.trim().split("\t");\r
+                       if (tokens.length == 0)\r
+                               continue;\r
+                       result.add(tokens[0]);\r
+               }\r
+\r
+               result.forEach(l -> System.out.println(l));\r
+       }\r
+\r
+}\r
diff --git a/server/hu.user.mediacube.executors.tests/src/hu/user/mediacube/executors/tests/GGGClassLoader.java b/server/hu.user.mediacube.executors.tests/src/hu/user/mediacube/executors/tests/GGGClassLoader.java
deleted file mode 100644 (file)
index 1c9109f..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-package hu.user.mediacube.executors.tests;\r
-\r
-import groovy.lang.GroovyClassLoader;\r
-\r
-public class GGGClassLoader extends GroovyClassLoader {\r
-\r
-}\r
index 07d9501dcd258d35b49dfb862891f96c39de4da5..9e5bb23df9d0b7463dd5d2c17848f551d81f5d0a 100644 (file)
@@ -1573,4 +1573,11 @@ public class SmallTests {
                System.out.println(octopusAddress);\r
        }\r
 \r
+       @Test\r
+       public void test9999993() throws Exception {\r
+               Path sut = Paths.get("/opt/test/media.mxf");\r
+               System.out.println(EscortFiles.constructMetadataPath(sut));\r
+\r
+       }\r
+\r
 }\r
diff --git a/server/hu.user.mediacube.executors.tests/src/hu/user/mediacube/executors/tests/Test1.java b/server/hu.user.mediacube.executors.tests/src/hu/user/mediacube/executors/tests/Test1.java
deleted file mode 100644 (file)
index 15b8de2..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-package hu.user.mediacube.executors.tests;\r
-\r
-public class Test1 {\r
-\r
-       public void execute() {\r
-               System.out.println("Execute...");\r
-       }\r
-}\r
index fd375d990b44b82d324e1378d19d74791ed39f08..b446aa4493f6800f24f0b56a44ee51cca328a229 100644 (file)
@@ -2,6 +2,7 @@ eclipse.preferences.version=1
 encoding//src/user/jobengine/server/steps/ArchiveMaterialSubmitStep.java=UTF-8\r
 encoding//src/user/jobengine/server/steps/ArchiveRecursive.java=UTF-8\r
 encoding//src/user/jobengine/server/steps/CalculateMD5Step.java=UTF-8\r
+encoding//src/user/jobengine/server/steps/CreateContentListStep.java=UTF-8\r
 encoding//src/user/jobengine/server/steps/DummyTestStep1.java=UTF-8\r
 encoding//src/user/jobengine/server/steps/ForkDownloadStep.java=UTF-8\r
 encoding/<project>=UTF-8\r
index cb4db0c231835af341f9f13985c10fb685e34efb..3b1bdd00dd272925d1e2d5b5b1d1c27705cb1332 100644 (file)
@@ -38,19 +38,11 @@ import user.mediacube.metadata.interfaces.PlanAirMetadataListOptions;
 public class ArchiveRecursive extends JobStep implements FileVisitor<Path> {\r
        private static final Logger logger = LogManager.getLogger();\r
        private static final String JOBTEMPLATE = "archive-material.xml";\r
-       private static final String ITEM_TITLE = "itemTitle";\r
-       private static final String ITEM_HOUSEID = "itemHouseId";\r
-       private static final String MEDIA_HOUSEID = "mediaHouseId";\r
-       private static final String MEDIA_TITLE = "mediaTitle";\r
-       private static final String MEDIA_DESCRIPTION = "mediaDescription";\r
-       private static final String MEDIA_TYPE = "mediaType";\r
        private static final String ARCHIVE = "Archiválás";\r
        private static final String ARCHIVE_ITEM = "archiveItem";\r
        private static final String KILL_DATE_DAYS = "killDateDays";\r
-//     private SimpleDateFormat df = new SimpleDateFormat("yyyy.MM.dd");\r
+       private List<String> skipPathNames = Arrays.asList("!ARCHIVALAS_ALATT", "EBREDJ_VELUNK_ARCHIV", EscortFiles.STATUSFOLDER, EscortFiles.CONFLICTFOLDER);\r
 \r
-       private List<String> skipPathNames = Arrays.asList("!ARCHIVALAS_ALATT", EscortFiles.STATUSFOLDER,\r
-                       EscortFiles.CONFLICTFOLDER);\r
        private int limit;\r
        private int submitted;\r
        private int killDateDays;\r
@@ -127,15 +119,14 @@ public class ArchiveRecursive extends JobStep implements FileVisitor<Path> {
                this.disableProxy = disableProxy;\r
                logger.info(getSessionMarker(), "Starting in {}", sourcePath);\r
                try {\r
-                       String location = "/opt/test-mediacube/file_list_original.txt";\r
-                       includeList = loadIncludeList(location);\r
+                       String location = "/opt/test-mediacube/archive-recursive-files.txt";\r
+                       includeList = loadWhiteList(location);\r
 \r
                        if (getJobRuntime().forkPrepare()) {\r
                                Files.walkFileTree(Paths.get(sourcePath), this);\r
                        }\r
                } catch (Exception e) {\r
-                       logger.error(getSessionMarker(), "A(z) '{}' mappa elérése sikertelen. A rendszer hibaüzenete: {}",\r
-                                       sourcePath, e.getMessage());\r
+                       logger.error(getSessionMarker(), "A(z) '{}' mappa elérése sikertelen. A rendszer hibaüzenete: {}", sourcePath, e.getMessage());\r
                } finally {\r
                        if (submitted > 0)\r
                                getJobRuntime().forkWaitComplete();\r
@@ -192,8 +183,7 @@ public class ArchiveRecursive extends JobStep implements FileVisitor<Path> {
                                if (metadata == null)\r
                                        logger.info(getSessionMarker(), "Metadata not available for {}", mediaHouseId);\r
                                else {\r
-                                       logger.info(getSessionMarker(), "Metadata is available for {}: {}", mediaHouseId,\r
-                                                       metadata.getMediaTitle());\r
+                                       logger.info(getSessionMarker(), "Metadata is available for {}: {}", mediaHouseId, metadata.getMediaTitle());\r
 \r
                                        if (mediaHouseId.equals(metadata.getForeignMediaId()))\r
                                                result = metadata;\r
@@ -229,15 +219,13 @@ public class ArchiveRecursive extends JobStep implements FileVisitor<Path> {
                                result = file.delete();\r
                        }\r
                } catch (Exception e) {\r
-                       logger.error(getSessionMarker(), "A {} fájl nem törölhető. A rendszer hibaüzenete: {}", filePath,\r
-                                       e.getMessage());\r
+                       logger.error(getSessionMarker(), "A {} fájl nem törölhető. A rendszer hibaüzenete: {}", filePath, e.getMessage());\r
                }\r
                return result;\r
        }\r
 \r
        @Override\r
-       public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes paramBasicFileAttributes)\r
-                       throws IOException {\r
+       public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes paramBasicFileAttributes) throws IOException {\r
                Path dirName = dir.getFileName();\r
 \r
                if (skipPathNames.contains(dirName.toString())) {\r
@@ -257,38 +245,35 @@ public class ArchiveRecursive extends JobStep implements FileVisitor<Path> {
                        return false;\r
                }\r
 \r
-               if (limit != 0 && submitted == limit) {\r
-                       logger.info(getSessionMarker(), "Limit reached {}, canceling", limit);\r
-                       return false;\r
-               }\r
-\r
                String fileName = mediaPath.getFileName().toString();\r
                if (fileName.startsWith(".") || fileName.endsWith(".nomd"))\r
                        return false;\r
 \r
-               logger.info(getSessionMarker(), "Processing {}", mediaPath);\r
+               if (limit != 0 && submitted == limit) {\r
+                       logger.info(getSessionMarker(), "Limit reached {}, canceling", limit);\r
+                       return false;\r
+               }\r
 \r
                File mediaFile = mediaPath.toFile();\r
                if (mediaFile.isDirectory()) {\r
                        return false;\r
                }\r
 \r
-               Path nomdFile = Paths.get(mediaPath.toString() + ".nomd");\r
-\r
-               if (nomdFile.toFile().exists()) {\r
-                       // toroljuk es ujbol letrehozzuk ha kell\r
-                       if (!removeFile(nomdFile)) {\r
-                               logger.info(getSessionMarker(), "Can't delete nomd file for {}, skipping", nomdFile);\r
-                               return false;\r
-                       }\r
-                       if (EscortFiles.isMediaCatched(mediaPath)) {\r
-                               Path catchedFile = EscortFiles.createMediaCatchFilePath(mediaPath);\r
-                               if (!removeFile(catchedFile)) {\r
-                                       logger.info(getSessionMarker(), "Can't delete catched file for {}, skipping", nomdFile);\r
-                                       return false;\r
-                               }\r
-                       }\r
-               }\r
+//\r
+//             if (nomdFile.toFile().exists()) {\r
+//                     // toroljuk es ujbol letrehozzuk ha kell\r
+//                     if (!removeFile(nomdFile)) {\r
+//                             logger.info(getSessionMarker(), "Can't delete nomd file for {}, skipping", nomdFile);\r
+//                             return false;\r
+//                     }\r
+//                     if (EscortFiles.isMediaCatched(mediaPath)) {\r
+//                             Path catchedFile = EscortFiles.createMediaCatchFilePath(mediaPath);\r
+//                             if (!removeFile(catchedFile)) {\r
+//                                     logger.info(getSessionMarker(), "Can't delete catched file for {}, skipping", nomdFile);\r
+//                                     return false;\r
+//                             }\r
+//                     }\r
+//             }\r
 \r
                if (EscortFiles.isMediaCatched(mediaPath)) {\r
                        // logger.info(getSessionMarker(), "Skipping already catched {}", mediaPath);\r
@@ -311,13 +296,20 @@ public class ArchiveRecursive extends JobStep implements FileVisitor<Path> {
 //                     Message msg = new ParameterizedMessage("Nincs metaadat!");\r
 //                     logger.info(new MediaCubeMarker("vasary@elgekko.net,muszak@mediavivantis.hu",\r
 //                                     "Értesítés problémás " + mediaPath.getFileName().toString() + " archiválásról"), msg);\r
+                       Path nomdFile = Paths.get(mediaPath.toString() + ".nomd");\r
                        Files.createFile(nomdFile);\r
                        return false;\r
                }\r
 \r
+               logger.info(getSessionMarker(), "Archiving {}", mediaPath);\r
+\r
                try {\r
                        checkArchiveItem(archiveItem);\r
 \r
+                       EscortFiles.createMediaCatch(mediaPath);\r
+                       String metadata = archiveItemJSON(archiveItem);\r
+                       EscortFiles.createMetadata(mediaPath.getParent().toString(), mediaPath.getFileName().toString(), metadata);\r
+\r
                        Map<String, Object> parameters = ListUtils.asMap(ARCHIVE_ITEM, archiveItem, KILL_DATE_DAYS, killDateDays);\r
                        IJobRuntime runtime = getEngine().submit(getJobRuntime(), e -> {\r
                                if (e.getStatus().equals(JobStatus.CANCELED) || e.getStatus().equals(JobStatus.SUSPENDED))\r
@@ -326,14 +318,11 @@ public class ArchiveRecursive extends JobStep implements FileVisitor<Path> {
                        if (runtime == null)\r
                                throw new Exception("Submit returned null runtime");\r
                        runtime.setRelated(mediaPath.toString());\r
-                       EscortFiles.createMediaCatch(mediaPath);\r
-                       String metadata = archiveItemJSON(archiveItem);\r
-                       EscortFiles.createMetadata(mediaPath.getParent().toString(), mediaPath.getFileName().toString(), metadata);\r
+\r
                        submitted++;\r
                } catch (Exception e) {\r
-                       logger.error(getSessionMarker(),\r
-                                       "A(z) '{}' állomány archiválási kísérlete sikertelen. A rendszer üzenete: {}", mediaPath,\r
-                                       e.getMessage());\r
+                       logger.catching(e);\r
+                       logger.error(getSessionMarker(), "A(z) '{}' állomány archiválási kísérlete sikertelen. A rendszer üzenete: {}", mediaPath, e.getMessage());\r
                        return false;\r
                }\r
 \r
@@ -344,7 +333,8 @@ public class ArchiveRecursive extends JobStep implements FileVisitor<Path> {
        public FileVisitResult visitFile(Path filePath, BasicFileAttributes paramBasicFileAttributes) throws IOException {\r
                // logger.info(getSessionMarker(), "Will checked {}", filePath);\r
                try {\r
-                       processPathItem(filePath);\r
+                       if (!processPathItem(filePath))\r
+                               return FileVisitResult.TERMINATE;\r
                } catch (Exception e) {\r
                        logger.catching(e);\r
                }\r
@@ -399,4 +389,18 @@ public class ArchiveRecursive extends JobStep implements FileVisitor<Path> {
                return result;\r
        }\r
 \r
+       private Set<String> loadWhiteList(String location) throws IOException {\r
+               Set<String> result = new LinkedHashSet<>();\r
+               Path path = Paths.get(location);\r
+               List<String> lines = FileUtils.readLines(path.toFile());\r
+\r
+               for (String line : lines) {\r
+                       String[] tokens = line.trim().split("\t");\r
+                       if (tokens.length == 0)\r
+                               continue;\r
+                       result.add(tokens[0]);\r
+               }\r
+               return result;\r
+       }\r
+\r
 }\r
index e54a5a8691374a00ba86a2dd5132b44a558dca80..7d2704c44e5515d84e9acdc43eac80a1e442ae9a 100644 (file)
@@ -27,12 +27,12 @@ public class HLSProxyStep extends JobStep {
                Path sourceFilePath = Paths.get(archiveItem.getMediaFile());\r
                try {\r
                        String fileName = sourceFilePath.getFileName().toString();\r
-                       String proxyName = fileName.substring(0, fileName.lastIndexOf(".")) + "S01"\r
-                                       + fileName.substring(fileName.lastIndexOf("."));\r
-                       Path lowresSourcePath = Paths.get(sourceFilePath.getParent().toString(), EscortFiles.STATUSFOLDER,\r
-                                       proxyName);\r
-                       if (!lowresSourcePath.toFile().exists())\r
-                               throw new Exception("File does not exist: " + lowresSourcePath);\r
+                       String proxyName = fileName.substring(0, fileName.lastIndexOf(".")) + "S01" + fileName.substring(fileName.lastIndexOf("."));\r
+                       Path lowresSourcePath = Paths.get(sourceFilePath.getParent().toString(), EscortFiles.STATUSFOLDER, proxyName);\r
+                       if (!lowresSourcePath.toFile().exists()) {\r
+                               logger.info(marker, "HLS proxy not found for {}", archiveItem.getMediaFile());\r
+                               return null;\r
+                       }\r
 \r
                        Store lowresStore = getManager().getCurrentLowresStore();\r
                        StoreUri lowresStoreUri = lowresStore.getTargetStoreUri(RemoteStoreProtocol.LOCAL);\r
@@ -40,8 +40,7 @@ public class HLSProxyStep extends JobStep {
 \r
                        Path subdirPath = null;\r
                        if (proxyName.indexOf(".") > 2) {\r
-                               subdirPath = Paths.get(proxyName.substring(0, 1), proxyName.substring(1, 2), proxyName.substring(2, 3),\r
-                                               proxyName);\r
+                               subdirPath = Paths.get(proxyName.substring(0, 1), proxyName.substring(1, 2), proxyName.substring(2, 3), proxyName);\r
                        } else {\r
                                subdirPath = Paths.get(proxyName);\r
                        }\r
@@ -60,20 +59,17 @@ public class HLSProxyStep extends JobStep {
                        lowresTargetPath = Paths.get(webPath, subDir);\r
                        // Files.move(lowresSourcePath, lowresTargetPath);\r
 \r
-                       FFMpeg.hls_audio4ch(lowresSourcePath.toAbsolutePath().toString(),\r
-                                       lowresTargetPath.toAbsolutePath().toString(), p -> {\r
-                                               setProgress((int) p);\r
-                                       });\r
+                       FFMpeg.hls_audio4ch(lowresSourcePath.toAbsolutePath().toString(), lowresTargetPath.toAbsolutePath().toString(), p -> {\r
+                               setProgress((int) p);\r
+                       });\r
 \r
                        Path lowresHTTPPath = Paths.get(subDir, "index.m3u8");\r
-                       MediaFile mediaFile = getManager().createMediaFile(lowresHTTPPath.toString(), LOWRES_FILETYPE,\r
-                                       lowresStore.getName());\r
+                       MediaFile mediaFile = getManager().createMediaFile(lowresHTTPPath.toString(), LOWRES_FILETYPE, lowresStore.getName());\r
                        mediaFile.setMediaId(mediaCubeMedia.getId());\r
                        getManager().add(mediaFile);\r
                } catch (Exception e) {\r
                        logger.catching(e);\r
-                       logger.error(marker, "A HLS proxy létrehozása sikertelen a '{}' fájlból. A rendszer üzenete: {}",\r
-                                       sourceFilePath, e.getMessage());\r
+                       logger.error(marker, "A HLS proxy létrehozása sikertelen a '{}' fájlból. A rendszer üzenete: {}", sourceFilePath, e.getMessage());\r
                }\r
                return null;\r
        }\r
index d19382037bfb7a731bae89825c2dc055aac67953..4bd544153fde38aa394218872554a764d10b7560 100644 (file)
@@ -4,12 +4,9 @@ import java.io.File;
 import java.nio.file.Files;\r
 import java.nio.file.Path;\r
 import java.nio.file.Paths;\r
-import java.nio.file.attribute.FileAttribute;\r
-import java.nio.file.attribute.PosixFilePermission;\r
-import java.nio.file.attribute.PosixFilePermissions;\r
-import java.util.Date;\r
-import java.util.Set;\r
+import java.util.List;\r
 \r
+import org.apache.commons.io.FilenameUtils;\r
 import org.apache.logging.log4j.LogManager;\r
 import org.apache.logging.log4j.Logger;\r
 import org.apache.logging.log4j.Marker;\r
@@ -17,11 +14,9 @@ import org.apache.logging.log4j.Marker;
 import com.ibm.nosql.json.api.BasicDBList;\r
 \r
 import user.jobengine.db.Item;\r
-import user.jobengine.db.ItemManager;\r
 import user.jobengine.db.ItemType;\r
 import user.jobengine.db.Media;\r
-import user.jobengine.server.IJobEngine;\r
-import user.jobengine.server.IJobRuntime;\r
+import user.jobengine.server.steps.shared.EscortFiles;\r
 \r
 /**\r
  * Itemek es mediak krealasa a ArchiveItem objektum alapjan.\r
@@ -31,10 +26,7 @@ import user.jobengine.server.IJobRuntime;
 public class MetadataTransformStep extends JobStep {\r
        private static final String CONFLICT = ".CONFLICT";\r
        private static final Logger logger = LogManager.getLogger();\r
-       private static final String ITEM_MANAGER_IS_NULL = "ItemManager is null";\r
        public static final String DEFAULT_MEDIATYPE = "Generic";\r
-       private ItemManager itemManager;\r
-\r
        private Marker marker;;\r
 \r
        private void addTags(ArchiveItem archiveItem, Media mediaCubeMedia) {\r
@@ -44,7 +36,7 @@ public class MetadataTransformStep extends JobStep {
 \r
                                try {\r
                                        String tagText = String.valueOf(tag);\r
-                                       itemManager.addMediaTag(tagText, mediaCubeMedia.getId());\r
+                                       getManager().addMediaTag(tagText, mediaCubeMedia.getId());\r
                                        System.out.println();\r
 \r
                                } catch (Exception e) {\r
@@ -54,48 +46,32 @@ public class MetadataTransformStep extends JobStep {
                }\r
        }\r
 \r
-       private void checkDuplicates(ArchiveItem archiveItem, String sourceFileName) throws Exception {\r
-               if (itemManager.isMediaFileExists(sourceFileName)) {\r
-                       try {\r
-                               Path sourcePath = Paths.get(archiveItem.getMediaFile());\r
-                               Path parent = sourcePath.getParent();\r
-                               Path conflictPath = Paths.get(parent.toString(), CONFLICT);\r
-                               File folder = conflictPath.toFile();\r
-                               if (!folder.exists() || !folder.isDirectory()) {\r
-                                       Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwxrwxrwx");\r
-                                       FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions.asFileAttribute(perms);\r
-                                       try {\r
-                                               Files.createDirectories(conflictPath, attr);\r
-                                       } catch (Exception e) {\r
-                                               try {\r
-                                                       Files.createDirectory(conflictPath);\r
-                                               } catch (Exception e1) {\r
-                                                       logger.catching(e);\r
-                                                       throw e;\r
-                                               }\r
-                                       }\r
-                               }\r
-\r
-                               Files.move(sourcePath, Paths.get(conflictPath.toString(), sourceFileName + (new Date()).getTime()));\r
-                       } catch (Exception e1) {\r
-                               logger.catching(e1);\r
-                               logger.error(marker, "Hiba az '{}' állomány mappába másolásakor. A rendszer üzenete: {}", CONFLICT, e1.getMessage());\r
-                       }\r
-                       throw new Exception("Az '" + sourceFileName + "' állomány már megtalálható az archívumban, archiválása nem lehetséges.");\r
+       private void moveToDuplicates(ArchiveItem archiveItem, String sourceFileName) {\r
+               try {\r
+                       Path sourcePath = Paths.get(archiveItem.getMediaFile());\r
+                       Path conflictPath = Paths.get(sourcePath.getParent().toString(), CONFLICT);\r
+                       EscortFiles.ensureUNCFolder(conflictPath);\r
+                       Files.move(sourcePath, Paths.get(conflictPath.toString(), sourceFileName));\r
+                       Path metadataPath = EscortFiles.constructMetadataPath(sourcePath);\r
+                       if (metadataPath.toFile().exists())\r
+                               Files.move(metadataPath, Paths.get(conflictPath.toString(), metadataPath.getFileName().toString()));\r
+               } catch (Exception e1) {\r
+                       logger.catching(e1);\r
+                       logger.error(marker, "Hiba az '{}' állomány mappába mozgatásakor. A rendszer üzenete: {}", CONFLICT, e1.getMessage());\r
                }\r
        }\r
 \r
        private Item createItem(ArchiveItem archiveItem) {\r
                Item mediaCubeItem = getExistingItem(archiveItem.getItemHouseId(), archiveItem.getItemTitle());\r
                if (mediaCubeItem == null)\r
-                       mediaCubeItem = itemManager.createItem(DEFAULT_MEDIATYPE, archiveItem.getItemTitle(), archiveItem.getItemDescription(),\r
+                       mediaCubeItem = getManager().createItem(DEFAULT_MEDIATYPE, archiveItem.getItemTitle(), archiveItem.getItemDescription(),\r
                                        archiveItem.getItemHouseId());\r
                return mediaCubeItem;\r
        }\r
 \r
        private Media createMedia(ArchiveItem archiveItem, Item mediaCubeItem, String mediaType) {\r
                Media mediaCubeMedia;\r
-               mediaCubeMedia = itemManager.createMedia(mediaType, archiveItem.getMediaTitle(), archiveItem.getMediaDescription(), archiveItem.getMediaHouseId());\r
+               mediaCubeMedia = getManager().createMedia(mediaType, archiveItem.getMediaTitle(), archiveItem.getMediaDescription(), archiveItem.getMediaHouseId());\r
                mediaCubeMedia.setLength(archiveItem.getDuration());\r
                mediaCubeItem.appendMedia(mediaCubeMedia);\r
 \r
@@ -103,24 +79,30 @@ public class MetadataTransformStep extends JobStep {
        }\r
 \r
        @StepEntry\r
-       public Object[] execute(ArchiveItem archiveItem, IJobEngine jobEngine, IJobRuntime jobRuntime) throws Exception {\r
-               marker = jobRuntime.getSessionMarker();\r
+       public Object[] execute(ArchiveItem archiveItem) throws Exception {\r
+               marker = getSessionMarker();\r
                Media mediaCubeMedia = null;\r
-               itemManager = (ItemManager) jobEngine.getItemManager();\r
-               if (itemManager == null)\r
-                       throw new NullPointerException(ITEM_MANAGER_IS_NULL);\r
                try {\r
                        File sourceMediaFile = new File(archiveItem.getMediaFile());\r
                        String sourceFileName = sourceMediaFile.getName();\r
-                       checkDuplicates(archiveItem, sourceFileName);\r
+\r
+                       getJobRuntime().setRelated(FilenameUtils.removeExtension(sourceFileName));\r
+\r
+                       if (getManager().isMediaFileExists(sourceFileName)) {\r
+                               cleanUpOnDuplicate(archiveItem, sourceFileName);\r
+                               logger.warn(marker, "Az '" + sourceFileName + "' állomány már megtalálható az archívumban, archiválása nem lehetséges.");\r
+                               cancel();\r
+                               return null;\r
+                       }\r
+\r
                        Item mediaCubeItem = createItem(archiveItem);\r
-                       jobRuntime.incrementProgress(50);\r
+                       setProgress(50);\r
                        String mediaType = getCreateType(archiveItem);\r
                        mediaCubeMedia = createMedia(archiveItem, mediaCubeItem, mediaType);\r
-                       //ha itemid 0 akkor merge, egyebkent media insert\r
+                       // ha itemid 0 akkor merge, egyebkent media insert\r
 \r
                        if (mediaCubeItem.getId() == 0)\r
-                               itemManager.mergeItemStructure(mediaCubeItem);\r
+                               getManager().mergeItemStructure(mediaCubeItem);\r
                        else {\r
                                mediaCubeMedia.setItemId(mediaCubeItem.getId());\r
                                mediaCubeMedia.add();\r
@@ -137,19 +119,26 @@ public class MetadataTransformStep extends JobStep {
                                logger.error(marker, "Az '{}' állomány .catched jelző állománya nem törölhető.", fileName);\r
                        throw e;\r
                } finally {\r
-                       jobRuntime.incrementProgress(100);\r
+                       setProgress(100);\r
                }\r
                return new Object[] { mediaCubeMedia };\r
        }\r
 \r
+       private void cleanUpOnDuplicate(ArchiveItem archiveItem, String sourceFileName) {\r
+               moveToDuplicates(archiveItem, sourceFileName);\r
+               archiveItem.removeCatchedFile();\r
+               List<Path> killDateFiles = EscortFiles.getKillDateFiles(Paths.get(archiveItem.getMediaFile()));\r
+               EscortFiles.remove(killDateFiles);\r
+       }\r
+\r
        private String getCreateType(ArchiveItem archiveItem) {\r
                String mediaType = archiveItem.getMediaType();\r
                if (mediaType == null || mediaType.length() == 0)\r
                        mediaType = DEFAULT_MEDIATYPE;\r
                else {\r
-                       ItemType mediaItemType = itemManager.getItemType(mediaType);\r
+                       ItemType mediaItemType = getManager().getItemType(mediaType);\r
                        if (mediaItemType == null)\r
-                               itemManager.createItemType(mediaType, mediaType).add();\r
+                               getManager().createItemType(mediaType, mediaType).add();\r
                }\r
                return mediaType;\r
        }\r
@@ -157,9 +146,9 @@ public class MetadataTransformStep extends JobStep {
        private Item getExistingItem(String itemHouseId, String itemTitle) {\r
                Item[] result = new Item[] { null };\r
                String sql = String.format("select id from item where houseid='%s' and title='%s'", itemHouseId, itemTitle);\r
-               itemManager.executeQuery(sql, rs -> {\r
+               getManager().executeQuery(sql, rs -> {\r
                        long id = rs.getLong("id");\r
-                       result[0] = itemManager.getItem(id);\r
+                       result[0] = getManager().getItem(id);\r
                        return true;\r
                }, null);\r
                return result[0];\r
index 8e8900316b35b749011bc816dedb4663b3fcb710..673cc5e622d717d21ff4bb3073752b069b7e7bab 100644 (file)
@@ -7,6 +7,7 @@ import java.io.InputStream;
 import java.io.OutputStream;\r
 import java.io.StringWriter;\r
 import java.io.UnsupportedEncodingException;\r
+import java.nio.file.DirectoryStream;\r
 import java.nio.file.Files;\r
 import java.nio.file.Path;\r
 import java.nio.file.Paths;\r
@@ -14,8 +15,11 @@ import java.nio.file.attribute.FileAttribute;
 import java.nio.file.attribute.PosixFilePermission;\r
 import java.nio.file.attribute.PosixFilePermissions;\r
 import java.text.SimpleDateFormat;\r
+import java.util.ArrayList;\r
 import java.util.Calendar;\r
+import java.util.Collections;\r
 import java.util.Date;\r
+import java.util.List;\r
 import java.util.Set;\r
 \r
 import javax.xml.parsers.DocumentBuilder;\r
@@ -60,6 +64,7 @@ public class EscortFiles {
        private static final String EXTENDEDID = "extendedId";\r
        private static final String ID = "ID";\r
        private static final String KILLDATE_FILENAME = "%s.%s.killdate";\r
+       private static final String KILLDATE_EXT = ".killdate";\r
        private static final String FORMAT_KILLDATENAME = "yyyyMMdd";\r
        public static final String STATUSFOLDER = ".STATUS";\r
        public static final String CONFLICTFOLDER = ".CONFLICT";\r
@@ -114,8 +119,12 @@ public class EscortFiles {
                Files.write(metadataPath, metadata.getBytes());\r
        }\r
 \r
-       public static boolean createMetadataIfNotExists(String filePath, String fileName, String metadata)\r
-                       throws IOException {\r
+       public static Path constructMetadataPath(Path filePath) throws IOException {\r
+               String metadataFileName = filePath.getFileName().toString() + DOT_JSON;\r
+               return Paths.get(filePath.getParent().toString(), STATUSFOLDER, metadataFileName);\r
+       }\r
+       \r
+       public static boolean createMetadataIfNotExists(String filePath, String fileName, String metadata) throws IOException {\r
                boolean result = false;\r
                if (!EscortFiles.isMetadataExists(filePath, fileName)) {\r
                        EscortFiles.createMetadata(filePath, fileName, metadata);\r
@@ -143,17 +152,14 @@ public class EscortFiles {
                // <ModifiedTimeStamp>07-13-2020 (19:36:52)</ModifiedTimeStamp>\r
                // <RecordTimeStamp>05-18-2013 (18:52:24)</RecordTimeStamp>\r
                SimpleDateFormat df = new SimpleDateFormat("MM-dd-yyyy (HH:mm:ss)");\r
-               root.appendChild(xmlDocument.createElement(MODIFIEDTIMESTAMP))\r
-                               .appendChild(xmlDocument.createTextNode(df.format(modified)));\r
-               root.appendChild(xmlDocument.createElement(RECORDTIMESTAMP))\r
-                               .appendChild(xmlDocument.createTextNode(df.format(recorded)));\r
+               root.appendChild(xmlDocument.createElement(MODIFIEDTIMESTAMP)).appendChild(xmlDocument.createTextNode(df.format(modified)));\r
+               root.appendChild(xmlDocument.createElement(RECORDTIMESTAMP)).appendChild(xmlDocument.createTextNode(df.format(recorded)));\r
                xmlDocument.appendChild(root);\r
 \r
                return xmDocumentToString(xmlDocument);\r
        }\r
 \r
-       public static byte[] createNEXIOKillDateFile(String fileName, Date killDate, String description, String agency)\r
-                       throws Exception {\r
+       public static byte[] createNEXIOKillDateFile(String fileName, Date killDate, String description, String agency) throws Exception {\r
                DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();\r
                DocumentBuilder db = dbf.newDocumentBuilder();\r
                DOMImplementation impl = db.getDOMImplementation();\r
@@ -167,8 +173,7 @@ public class EscortFiles {
                }\r
 \r
                if (StringUtils.isNotBlank(description))\r
-                       root.appendChild(xmlDocument.createElement(EXTENDEDDESCRIPTION))\r
-                                       .appendChild(xmlDocument.createTextNode(description));\r
+                       root.appendChild(xmlDocument.createElement(EXTENDEDDESCRIPTION)).appendChild(xmlDocument.createTextNode(description));\r
                if (StringUtils.isNotBlank(agency))\r
                        root.appendChild(xmlDocument.createElement(EXTENDEDAGENCY)).appendChild(xmlDocument.createTextNode(agency));\r
                xmlDocument.appendChild(root);\r
@@ -288,10 +293,35 @@ public class EscortFiles {
                }\r
        }\r
 \r
+       public static void remove(List<Path> files) {\r
+               if (files != null)\r
+                       files.forEach(f -> remove(f));\r
+       }\r
+\r
        public static void removeCatchedFile(Path escortFile) {\r
                remove(Paths.get(escortFile.toString() + DOT_CATCHED));\r
        }\r
 \r
+       public static List<Path> getKillDateFiles(Path filePath) {\r
+               String killDateFilePattern = String.format("%s.*%s", filePath.getFileName().toString(), KILLDATE_EXT);\r
+               List<Path> result = new ArrayList<>();\r
+               try {\r
+                       Path statusPath = Paths.get(filePath.getParent().toString(), STATUSFOLDER);\r
+                       File statusPathFile = statusPath.toFile();\r
+                       if (statusPathFile.exists() && statusPathFile.isDirectory()) {\r
+                               try (DirectoryStream<Path> stream = Files.newDirectoryStream(statusPath, killDateFilePattern)) {\r
+                                       stream.forEach(p -> result.add(p));\r
+                               } catch (Exception e) {\r
+                                       logger.catching(e);\r
+                               }\r
+                       }\r
+                       Collections.sort(result);\r
+               } catch (Exception e) {\r
+                       logger.catching(e);\r
+               }\r
+               return result;\r
+       }\r
+\r
        /***\r
         * A media eleresi utjan alapjan a .STATUS almappabol torli a .catch fajlt.\r
         *\r
@@ -303,8 +333,7 @@ public class EscortFiles {
                remove(catchedFile);\r
        }\r
 \r
-       public static void setNEXIOKillDate(int killDateDays, String targetFileName, String nexioAgency, StoreUri targetUri)\r
-                       throws Exception {\r
+       public static void setNEXIOKillDate(int killDateDays, String targetFileName, String nexioAgency, StoreUri targetUri) throws Exception {\r
                OutputStream outStream = null;\r
                try {\r
                        FTPClient targetFTP = ((FtpDirectoryLister) targetUri.getLister()).connect();\r
@@ -312,14 +341,12 @@ public class EscortFiles {
                        killDate.add(Calendar.DAY_OF_YEAR, killDateDays);\r
                        if (targetFileName.toLowerCase().contains(".mxf"))\r
                                targetFileName = targetFileName.substring(0, targetFileName.lastIndexOf('.'));\r
-                       byte[] killDateFile = EscortFiles.createNEXIOKillDateFile(targetFileName, killDate.getTime(), null,\r
-                                       nexioAgency);\r
+                       byte[] killDateFile = EscortFiles.createNEXIOKillDateFile(targetFileName, killDate.getTime(), null, nexioAgency);\r
                        String xml = targetFileName + ".xml";\r
                        outStream = targetFTP.storeFileStream(xml);\r
                        if (outStream == null) {\r
                                throw new NullPointerException(\r
-                                               "Can not open: " + targetFileName.substring(0, targetFileName.lastIndexOf('.')) + ".xml"\r
-                                                               + " Reply:" + targetFTP.getReplyString());\r
+                                               "Can not open: " + targetFileName.substring(0, targetFileName.lastIndexOf('.')) + ".xml" + " Reply:" + targetFTP.getReplyString());\r
                        }\r
                        outStream.write(killDateFile);\r
                        outStream.flush();\r
@@ -332,8 +359,8 @@ public class EscortFiles {
                }\r
        }\r
 \r
-       private static byte[] xmDocumentToString(Document xmlDocument) throws TransformerFactoryConfigurationError,\r
-                       TransformerConfigurationException, TransformerException, IOException, UnsupportedEncodingException {\r
+       private static byte[] xmDocumentToString(Document xmlDocument)\r
+                       throws TransformerFactoryConfigurationError, TransformerConfigurationException, TransformerException, IOException, UnsupportedEncodingException {\r
                DOMSource domSource = new DOMSource(xmlDocument);\r
                TransformerFactory tf = TransformerFactory.newInstance();\r
                Transformer transformer = tf.newTransformer();\r
@@ -347,4 +374,5 @@ public class EscortFiles {
                sw.close();\r
                return result.getBytes("UTF-16");\r
        }\r
+\r
 }\r
index 10111159031c785519e9ab36ba8abe726af4e22a..100f2535671e60384aeb3288a1eb9290aee9ab74 100644 (file)
@@ -46,7 +46,7 @@ public class SystemConfiguration implements IConfiguration {
        @Override\r
        public String getConfig(String relativeConfigName) throws FileNotFoundException {\r
                Path result = Paths.get(System.getProperty("user.dir", ""), relativeConfigName);\r
-               if (Files.exists(result))\r
+               if (Files.exists(result) || Files.isSymbolicLink(result))\r
                        return result.toString();\r
                result = Paths.get(System.getProperty("system.config.root", ""), relativeConfigName);\r
                if (Files.exists(result))\r
index f52862755e0c96ebef93504b09b994be80ea8dbc..1829f5962128dc1d948bfd46b03daf2b1b5f69db 100644 (file)
-/*@lineinfo:filename=EntityBaseDAO*//*@lineinfo:user-code*//*@lineinfo:1^1*/package user.jobengine.db;
-
-import user.commons.IEntityBase;
-import user.commons.logging.LogUtils;
-import java.sql.SQLException;
-import java.sql.ResultSet;
-import java.util.List;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import sqlj.runtime.ref.DefaultContext;
-import sqlj.runtime.ref.ResultSetIterImpl;
-/**
- * Az entitasok alap DAO osztalya.
- */
-@SuppressWarnings("unused")
-public abstract class EntityBaseDAO implements IEntityBaseDAO {
-       protected ItemManager manager;
-       protected static final Logger logger = LogManager.getLogger();
-       
-       public EntityBaseDAO(ItemManager manager) {
-               this.manager = manager;
-       }
-
-       @SuppressWarnings("rawtypes")
-       protected void checkNull(Object obj, Class type) {
-               if (obj == null)
-                       throw new IllegalArgumentException(type.getName() + " can not be null.");
-       }
-       
-       @Override
-       public void add(IEntityBase entity) {
-               DefaultContext context = manager.getDbContext();
-               try {
-                       add(context, entity);
-               } catch (Exception e) {
-                       //TODO reszletezes
-                       throw new ItemManagerException(e);
-               } finally {
-                       manager.putDbContext(context);
-               }
-       }
-
-       public void add(DefaultContext context, IEntityBase entity) {
-               manager.traceIn();
-               try {
-                       checkNull(entity, IEntityBase.class);
-                       beforeAdd(context, entity);
-                       long id = entity.getId();
-
-                       insert(context, entity);        
-                       if (id == 0) {
-                               /*@lineinfo:generated-code*//*@lineinfo:52^4*/
-
-//  ************************************************************
-//  #sql [context] { SELECT IDENTITY_VAL_LOCAL()  INTO :id,  FROM SYSIBM.SYSDUMMY1  };
-//  ************************************************************
-
-{
-  sqlj.runtime.profile.RTResultSet __sJT_rtRs;
-  sqlj.runtime.ConnectionContext __sJT_connCtx = context;
-  if (__sJT_connCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_DEFAULT_CONN_CTX();
-  sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();
-  if (__sJT_execCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();
-  synchronized (__sJT_execCtx) {
-    sqlj.runtime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, EntityBaseDAO_SJProfileKeys.getKey(0), 0);
-    try 
-    {
-      __sJT_rtRs = __sJT_execCtx.executeQuery();
-    }
-    finally 
-    {
-      __sJT_execCtx.releaseStatement();
-    }
-  }
-  try 
-  {
-    sqlj.runtime.ref.ResultSetIterImpl.checkColumns(__sJT_rtRs, 1);
-    if (!__sJT_rtRs.next())
-    {
-      sqlj.runtime.error.RuntimeRefErrors.raise_NO_ROW_SELECT_INTO();
-    }
-    id = __sJT_rtRs.getLongNoNull(1);
-    if (__sJT_rtRs.next())
-    {
-      sqlj.runtime.error.RuntimeRefErrors.raise_MULTI_ROW_SELECT_INTO();
-    }
-  }
-  finally 
-  {
-    __sJT_rtRs.close();
-  }
-}
-
-
-//  ************************************************************
-
-/*@lineinfo:user-code*//*@lineinfo:52^80*/
-                               entity.setId(id);
-                       }
-                       afterAdd(context, entity);
-                       /*@lineinfo:generated-code*//*@lineinfo:56^3*/
-
-//  ************************************************************
-//  #sql [context] { COMMIT  };
-//  ************************************************************
-
-{
-  sqlj.runtime.ConnectionContext __sJT_connCtx = context;
-  if (__sJT_connCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_DEFAULT_CONN_CTX();
-  sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();
-  if (__sJT_execCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();
-  synchronized (__sJT_execCtx) {
-    sqlj.runtime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, EntityBaseDAO_SJProfileKeys.getKey(0), 1);
-    try 
-    {
-      __sJT_execCtx.executeUpdate();
-    }
-    finally 
-    {
-      __sJT_execCtx.releaseStatement();
-    }
-  }
-}
-
-
-//  ************************************************************
-
-/*@lineinfo:user-code*//*@lineinfo:56^27*/
-                       if (useMemoryCache())
-                               manager.storeCached(entity.getId(), entity);
-                       
-               } catch (Exception e) {
-                       try {
-                               /*@lineinfo:generated-code*//*@lineinfo:62^4*/
-
-//  ************************************************************
-//  #sql [context] { ROLLBACK  };
-//  ************************************************************
-
-{
-  sqlj.runtime.ConnectionContext __sJT_connCtx = context;
-  if (__sJT_connCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_DEFAULT_CONN_CTX();
-  sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();
-  if (__sJT_execCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();
-  synchronized (__sJT_execCtx) {
-    sqlj.runtime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, EntityBaseDAO_SJProfileKeys.getKey(0), 2);
-    try 
-    {
-      __sJT_execCtx.executeUpdate();
-    }
-    finally 
-    {
-      __sJT_execCtx.releaseStatement();
-    }
-  }
-}
-
-
-//  ************************************************************
-
-/*@lineinfo:user-code*//*@lineinfo:62^30*/
-                       } catch(Exception e1) {
-                       }
-                       manager.throwError(e);
-               }
-               manager.traceOut();
-       }
-       
-       @Override
-       public IEntityBase get(long id) {
-               IEntityBase entity = null;
-               DefaultContext context = manager.getDbContext();
-               try {
-                       entity = get(context, id);
-               } catch (Exception e) {
-                       throw new ItemManagerException(e);
-               } finally {
-                       manager.putDbContext(context);
-               }
-               return entity;
-       }
-
-       public IEntityBase get(DefaultContext context, long id) {
-               manager.traceIn();
-               IEntityBase entity = null;
-               try {
-                       if (id == 0)
-                               throw new IllegalArgumentException("Cannot get EntityBase with 0 ID.");
-                       if (useMemoryCache())
-                               entity = manager.retrieveCached(getCacheType(), id);
-                       if (entity == null) {
-                               ResultSetIterImpl iter = selectByKey(context, id);
-                               checkNull(iter, ResultSetIterImpl.class);
-                               entity = getEntity(context, iter);
-                               if (useMemoryCache())
-                                       manager.storeCached(id, entity);
-                       }
-                       afterGet(context, entity);
-               } catch (Exception e) {
-                       throw new ItemManagerException(e);
-               }
-               manager.traceOut();
-               return entity;
-       }
-
-       @Override
-       public List<IEntityBase> getAll() {
-               List<IEntityBase> result = null;
-               DefaultContext context = manager.getDbContext();
-               try {
-                       result = getAll(context);
-               } catch (Exception e) {
-                       throw new ItemManagerException(e);
-               } finally {
-                       manager.putDbContext(context);
-               }
-               return result;
-       }
-
-       @Override
-       public List<IEntityBase> getAll(IDAOIterProvider provider) {
-               List<IEntityBase> result = null;
-               DefaultContext context = manager.getDbContext();
-               try {
-                       result = getAll(context, provider);
-               } catch (Exception e) {
-                       throw new ItemManagerException(e);
-               } finally {
-                       manager.putDbContext(context);
-               }
-               return result;
-       }
-       
-       @Override
-       public IEntityBase get(IDAOIterProvider provider) {
-               IEntityBase entity = null;
-               DefaultContext context = manager.getDbContext();
-               try {
-                       entity = get(context, provider);
-               } catch (Exception e) {
-                       throw new ItemManagerException(e);
-               } finally {
-                       manager.putDbContext(context);
-               }
-               return entity;
-       }
-       
-       private IEntityBase get(DefaultContext context, IDAOIterProvider provider) {
-               manager.traceIn();
-               IEntityBase entity = null;
-               try {
-                       ResultSetIterImpl iter = provider.get(context, this);
-                       checkNull(iter, ResultSetIterImpl.class);
-                       entity = getEntity(context, iter);
-                       afterGet(context, entity);
-               } catch (Exception e) {
-                       throw new ItemManagerException(e);
-               }
-               manager.traceOut();
-               return entity;
-       }       
-       
-       public List<IEntityBase> getAll(DefaultContext context, IDAOIterProvider provider) {
-               manager.traceIn();
-               List<IEntityBase> result = null;
-               try {
-                       ResultSetIterImpl iter = provider.get(context, this);
-                       checkNull(iter, ResultSetIterImpl.class);
-                       result = getList(context, iter, false, true);
-               } catch (Exception e) {
-                       throw new ItemManagerException(e);
-               }
-               manager.traceOut();
-               return result;
-       }
-
-       public List<IEntityBase> getAll(DefaultContext context) {
-               manager.traceIn();
-               List<IEntityBase> result = null;
-               try {
-                       ResultSetIterImpl iter = selectAll(context);
-                       checkNull(iter, ResultSetIterImpl.class);
-                       result = getList(context, iter, false, true);
-               } catch (Exception e) {
-                       throw new ItemManagerException(e);
-               }
-               manager.traceOut();
-               return result;
-       }
-       
-       @Override
-       public List<IEntityBase> getAll(long id) {
-               List<IEntityBase> result = null;
-               DefaultContext context = manager.getDbContext();
-               try {
-                       result = getAll(context, id);
-               } catch (Exception e) {
-                       throw new ItemManagerException(e);
-               } finally {
-                       manager.putDbContext(context);
-               }
-               return result;
-       }
-
-       public List<IEntityBase> getAll(DefaultContext context, long id) {
-               manager.traceIn();
-               List<IEntityBase> result = null;
-               try {
-                       ResultSetIterImpl iter = selectByForeignKey(context, id);
-                       checkNull(iter, ResultSetIterImpl.class);
-                       result = getList(context, iter, false, true);
-               } catch (Exception e) {
-                       throw new ItemManagerException(e);
-               }
-               manager.traceOut();
-               return result;
-       }
-
-       protected IEntityBase getEntity(DefaultContext context, ResultSetIterImpl iter) {
-               manager.traceIn();
-               IEntityBase entity = null;
-               try {
-                       List<IEntityBase> result = getList(context, iter, false, false);
-                       if (result != null) {
-                               if (result.size() != 1)
-                                       throw new IllegalStateException("Expected one, found " + result.size() + ".");
-                               entity = result.get(0); 
-                       }
-               } catch (Exception e) {
-                       throw new ItemManagerException(e);
-               }
-               manager.traceOut();
-               return entity;
-       }
-       
-//     protected List<IEntityBase> getList(ResultSetIterImpl iter) {
-//             List<IEntityBase> result = null;
-//             DefaultContext context = manager.getDbContext();
-//             try {
-//                     result = getList(context, iter);
-//             } catch (Exception e) {
-//                     throw new ItemManagerException(e);
-//             } finally {
-//                     manager.putDbContext(context);
-//             }
-//             return result;
-//     }
-       
-       protected List<IEntityBase> getList(ResultSetIterImpl iter, boolean isChunked) {
-               List<IEntityBase> result = null;
-               DefaultContext context = manager.getDbContext();
-               try {
-                       result = getList(context, iter, isChunked, true);                       
-               } catch (Exception e) {
-                       throw new ItemManagerException(e);
-               } finally {
-                       manager.putDbContext(context);
-               }
-               return result;
-       }
-
-       protected List<IEntityBase> getList(DefaultContext context, ResultSetIterImpl iter, boolean isChunked) {
-               return getList(context, iter, isChunked, true);
-       }
-       
-       protected List<IEntityBase> getList(DefaultContext context, ResultSetIterImpl iter, boolean isChunked, boolean enablecache) {
-               manager.traceIn();
-               List<IEntityBase> result = null;
-               try {
-                       if (useMemoryCache() && enablecache)
-                               result = manager.getAllCached(getCacheType());
-                       
-                       if (result == null) {
-                               result = entities(context, iter, isChunked);
-                               if (useMemoryCache() && enablecache)
-                                       manager.setAllCached(getCacheType(), result);
-                       }
-                       
-                       /*@lineinfo:generated-code*//*@lineinfo:280^3*/
-
-//  ************************************************************
-//  #sql [context] { COMMIT  };
-//  ************************************************************
-
-{
-  sqlj.runtime.ConnectionContext __sJT_connCtx = context;
-  if (__sJT_connCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_DEFAULT_CONN_CTX();
-  sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();
-  if (__sJT_execCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();
-  synchronized (__sJT_execCtx) {
-    sqlj.runtime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, EntityBaseDAO_SJProfileKeys.getKey(0), 3);
-    try 
-    {
-      __sJT_execCtx.executeUpdate();
-    }
-    finally 
-    {
-      __sJT_execCtx.releaseStatement();
-    }
-  }
-}
-
-
-//  ************************************************************
-
-/*@lineinfo:user-code*//*@lineinfo:280^27*/
-               } catch (Exception e) {
-                       try {
-                               /*@lineinfo:generated-code*//*@lineinfo:283^4*/
-
-//  ************************************************************
-//  #sql [context] { ROLLBACK  };
-//  ************************************************************
-
-{
-  sqlj.runtime.ConnectionContext __sJT_connCtx = context;
-  if (__sJT_connCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_DEFAULT_CONN_CTX();
-  sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();
-  if (__sJT_execCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();
-  synchronized (__sJT_execCtx) {
-    sqlj.runtime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, EntityBaseDAO_SJProfileKeys.getKey(0), 4);
-    try 
-    {
-      __sJT_execCtx.executeUpdate();
-    }
-    finally 
-    {
-      __sJT_execCtx.releaseStatement();
-    }
-  }
-}
-
-
-//  ************************************************************
-
-/*@lineinfo:user-code*//*@lineinfo:283^30*/
-                       } catch(Exception e1) {
-                       }
-                       manager.throwError(e);
-               }
-               manager.traceOut();
-               return result;
-       }
-       
-       @Override
-       public void modify(IEntityBase entity) {
-               DefaultContext context = manager.getDbContext();
-               try {
-                       modify(context, entity); 
-               } catch (Exception e) {
-                       throw new ItemManagerException(e);
-               } finally {
-                       manager.putDbContext(context);
-               }
-       }
-
-       @Override
-       public void merge(IEntityBase entity) {
-               DefaultContext context = manager.getDbContext();
-               try {
-                       if (entity.getId() == 0)
-                               add(entity);
-                       else
-                               modify(context, entity); 
-               } catch (Exception e) {
-                       throw new ItemManagerException(e);
-               } finally {
-                       manager.putDbContext(context);
-               }
-       }
-
-       public void modify(DefaultContext context, IEntityBase entity) {
-               manager.traceIn();
-               try {
-                       checkNull(entity, IEntityBase.class);
-                       long id = entity.getId();
-                       entity.checkParameter("ID", id, false);
-                       update(context, entity);
-                       afterModify(context, entity);
-                       /*@lineinfo:generated-code*//*@lineinfo:327^3*/
-
-//  ************************************************************
-//  #sql [context] { COMMIT  };
-//  ************************************************************
-
-{
-  sqlj.runtime.ConnectionContext __sJT_connCtx = context;
-  if (__sJT_connCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_DEFAULT_CONN_CTX();
-  sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();
-  if (__sJT_execCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();
-  synchronized (__sJT_execCtx) {
-    sqlj.runtime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, EntityBaseDAO_SJProfileKeys.getKey(0), 5);
-    try 
-    {
-      __sJT_execCtx.executeUpdate();
-    }
-    finally 
-    {
-      __sJT_execCtx.releaseStatement();
-    }
-  }
-}
-
-
-//  ************************************************************
-
-/*@lineinfo:user-code*//*@lineinfo:327^27*/
-                       if (useMemoryCache())
-                               manager.storeCached(entity.getId(), entity);
-               } catch (Exception e) {
-                       try {
-                               /*@lineinfo:generated-code*//*@lineinfo:332^4*/
-
-//  ************************************************************
-//  #sql [context] { ROLLBACK  };
-//  ************************************************************
-
-{
-  sqlj.runtime.ConnectionContext __sJT_connCtx = context;
-  if (__sJT_connCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_DEFAULT_CONN_CTX();
-  sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();
-  if (__sJT_execCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();
-  synchronized (__sJT_execCtx) {
-    sqlj.runtime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, EntityBaseDAO_SJProfileKeys.getKey(0), 6);
-    try 
-    {
-      __sJT_execCtx.executeUpdate();
-    }
-    finally 
-    {
-      __sJT_execCtx.releaseStatement();
-    }
-  }
-}
-
-
-//  ************************************************************
-
-/*@lineinfo:user-code*//*@lineinfo:332^30*/
-                       } catch(Exception e1) {
-                       }
-                       manager.throwError(e);
-               }
-               manager.traceOut();
-       }
-       
-       @Override
-       public void remove(IEntityBase entity) {
-               DefaultContext context = manager.getDbContext();
-               try {
-                       remove(context, entity);
-               } catch (Exception e) {
-                       throw new ItemManagerException(e);
-               } finally {
-                       manager.putDbContext(context);
-               }
-       }
-
-       public void remove(DefaultContext context, IEntityBase entity) {
-               manager.traceIn();
-               try {
-                       checkNull(entity, IEntityBase.class);
-                       long id = entity.getId();
-                       entity.checkParameter("ID", id, false);
-                       beforeDelete(context, entity);
-                       delete(context, id);
-                       afterDelete(context, entity);
-                       /*@lineinfo:generated-code*//*@lineinfo:361^3*/
-
-//  ************************************************************
-//  #sql [context] { COMMIT  };
-//  ************************************************************
-
-{
-  sqlj.runtime.ConnectionContext __sJT_connCtx = context;
-  if (__sJT_connCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_DEFAULT_CONN_CTX();
-  sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();
-  if (__sJT_execCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();
-  synchronized (__sJT_execCtx) {
-    sqlj.runtime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, EntityBaseDAO_SJProfileKeys.getKey(0), 7);
-    try 
-    {
-      __sJT_execCtx.executeUpdate();
-    }
-    finally 
-    {
-      __sJT_execCtx.releaseStatement();
-    }
-  }
-}
-
-
-//  ************************************************************
-
-/*@lineinfo:user-code*//*@lineinfo:361^27*/
-                       if (useMemoryCache())
-                               manager.removeCached(getCacheType(), entity.getId());
-               } catch (Exception e) {
-                       try {
-                               /*@lineinfo:generated-code*//*@lineinfo:366^4*/
-
-//  ************************************************************
-//  #sql [context] { ROLLBACK  };
-//  ************************************************************
-
-{
-  sqlj.runtime.ConnectionContext __sJT_connCtx = context;
-  if (__sJT_connCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_DEFAULT_CONN_CTX();
-  sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();
-  if (__sJT_execCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();
-  synchronized (__sJT_execCtx) {
-    sqlj.runtime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, EntityBaseDAO_SJProfileKeys.getKey(0), 8);
-    try 
-    {
-      __sJT_execCtx.executeUpdate();
-    }
-    finally 
-    {
-      __sJT_execCtx.releaseStatement();
-    }
-  }
-}
-
-
-//  ************************************************************
-
-/*@lineinfo:user-code*//*@lineinfo:366^30*/
-                       } catch(Exception e1) {
-                       }
-                       manager.throwError(e);
-               }
-               manager.traceOut();
-       }
-
-       public void remove(List<Long> ids) {
-               DefaultContext context = manager.getDbContext();
-               try {
-                       remove(context, ids);
-               } catch (Exception e) {
-                       throw new ItemManagerException(e);
-               } finally {
-                       manager.putDbContext(context);
-               }
-       }
-       
-       protected void remove(DefaultContext context, List<Long> ids) {
-               manager.traceIn();
-               try {
-                       for (long id : ids)
-                               delete(context, id);
-                       /*@lineinfo:generated-code*//*@lineinfo:390^3*/
-
-//  ************************************************************
-//  #sql [context] { COMMIT  };
-//  ************************************************************
-
-{
-  sqlj.runtime.ConnectionContext __sJT_connCtx = context;
-  if (__sJT_connCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_DEFAULT_CONN_CTX();
-  sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();
-  if (__sJT_execCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();
-  synchronized (__sJT_execCtx) {
-    sqlj.runtime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, EntityBaseDAO_SJProfileKeys.getKey(0), 9);
-    try 
-    {
-      __sJT_execCtx.executeUpdate();
-    }
-    finally 
-    {
-      __sJT_execCtx.releaseStatement();
-    }
-  }
-}
-
-
-//  ************************************************************
-
-/*@lineinfo:user-code*//*@lineinfo:390^27*/
-                       if (useMemoryCache()) {
-                               for (long id : ids)
-                                       manager.removeCached(getCacheType(), id);
-                       }
-               } catch (Exception e) {
-                       try {
-                               /*@lineinfo:generated-code*//*@lineinfo:397^4*/
-
-//  ************************************************************
-//  #sql [context] { ROLLBACK  };
-//  ************************************************************
-
-{
-  sqlj.runtime.ConnectionContext __sJT_connCtx = context;
-  if (__sJT_connCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_DEFAULT_CONN_CTX();
-  sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();
-  if (__sJT_execCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();
-  synchronized (__sJT_execCtx) {
-    sqlj.runtime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, EntityBaseDAO_SJProfileKeys.getKey(0), 10);
-    try 
-    {
-      __sJT_execCtx.executeUpdate();
-    }
-    finally 
-    {
-      __sJT_execCtx.releaseStatement();
-    }
-  }
-}
-
-
-//  ************************************************************
-
-/*@lineinfo:user-code*//*@lineinfo:397^30*/
-                       } catch(Exception e1) {
-                       }
-                       manager.throwError(e);
-               }
-               manager.traceOut();
-       }
-       
-       @Override
-       public void truncate() {
-               manager.traceIn();
-               DefaultContext context = manager.getDbContext();
-               try {
-                       truncateTable(context);
-                       /*@lineinfo:generated-code*//*@lineinfo:411^3*/
-
-//  ************************************************************
-//  #sql [context] { COMMIT  };
-//  ************************************************************
-
-{
-  sqlj.runtime.ConnectionContext __sJT_connCtx = context;
-  if (__sJT_connCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_DEFAULT_CONN_CTX();
-  sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();
-  if (__sJT_execCtx == null) sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();
-  synchronized (__sJT_execCtx) {
-    sqlj.runtime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, EntityBaseDAO_SJProfileKeys.getKey(0), 11);
-    try 
-    {
-      __sJT_execCtx.executeUpdate();
-    }
-    finally 
-    {
-      __sJT_execCtx.releaseStatement();
-    }
-  }
-}
-
-
-//  ************************************************************
-
-/*@lineinfo:user-code*//*@lineinfo:411^27*/
-               } catch (Exception e) {
-                       throw new ItemManagerException(e);
-               } finally {
-                       manager.putDbContext(context);
-               }
-               manager.traceOut();
-       }
-
-       protected void afterGet(DefaultContext context, IEntityBase entity) throws SQLException { }
-       protected void beforeAdd(DefaultContext context, IEntityBase entity) throws SQLException { }
-       protected void afterAdd(DefaultContext context, IEntityBase entity) throws SQLException { }
-       protected void afterModify(DefaultContext context, IEntityBase entity) throws SQLException { }
-       protected void beforeDelete(DefaultContext context, IEntityBase entity) throws SQLException { }
-       protected void afterDelete(DefaultContext context, IEntityBase entity) throws SQLException { }
-       
-       protected List<IEntityBase> entities(DefaultContext context, ResultSetIterImpl iter, boolean isChunked) throws SQLException {
-               return null;    
-       }
-
-       public List<IEntityBase> entities(DefaultContext context, ResultSet rs) throws SQLException {
-               return null;    
-       }
-       
-       protected ResultSetIterImpl selectByKey(DefaultContext context, long id) throws SQLException {
-               return null;    
-       }
-       
-       protected ResultSetIterImpl selectByForeignKey(DefaultContext context, long id) throws SQLException {
-               return null;    
-       }
-       
-       protected ResultSetIterImpl selectAll(DefaultContext context) throws SQLException {
-               return null;    
-       }
-       
-       protected void delete(DefaultContext context, long id) throws SQLException { }
-       
-       protected void truncateTable(DefaultContext context) throws SQLException { }
-       
-       protected void insert(DefaultContext context, IEntityBase entity) throws SQLException { }
-       
-       protected void update(DefaultContext context, IEntityBase entity) throws SQLException  { }
-       
-       protected boolean useMemoryCache() { return false; }
-       
-       protected Class<? extends IEntityBase> getCacheType() { return null; }
-}/*@lineinfo:generated-code*/class EntityBaseDAO_SJProfileKeys 
-{
-  private java.lang.Object[] keys;
-  private final sqlj.runtime.profile.Loader loader = sqlj.runtime.RuntimeContext.getRuntime().getLoaderForClass(getClass());
-  private static EntityBaseDAO_SJProfileKeys inst = null;
-  public static java.lang.Object getKey(int keyNum) 
-    throws java.sql.SQLException 
-  {
-    synchronized(user.jobengine.db.EntityBaseDAO_SJProfileKeys.class) {
-      if (inst == null)
-      {
-        inst = new EntityBaseDAO_SJProfileKeys();
-      }
-    }
-    return inst.keys[keyNum];
-  }
-  private EntityBaseDAO_SJProfileKeys() 
-    throws java.sql.SQLException 
-  {
-    keys = new java.lang.Object[1];
-    keys[0] = DefaultContext.getProfileKey(loader, "user.jobengine.db.EntityBaseDAO_SJProfile0");
-  }
-}
+/*@lineinfo:filename=EntityBaseDAO*//*@lineinfo:user-code*//*@lineinfo:1^1*/\r
+package user.jobengine.db;\r
+\r
+import java.sql.ResultSet;\r
+import java.sql.SQLException;\r
+import java.util.List;\r
+\r
+import org.apache.logging.log4j.LogManager;\r
+import org.apache.logging.log4j.Logger;\r
+\r
+import sqlj.runtime.ref.DefaultContext;\r
+import sqlj.runtime.ref.ResultSetIterImpl;\r
+import user.commons.IEntityBase;\r
+\r
+/**\r
+ * Az entitasok alap DAO osztalya.\r
+ */\r
+@SuppressWarnings("unused")\r
+public abstract class EntityBaseDAO implements IEntityBaseDAO {\r
+       protected ItemManager manager;\r
+       protected static final Logger logger = LogManager.getLogger();\r
+\r
+       public EntityBaseDAO(ItemManager manager) {\r
+               this.manager = manager;\r
+       }\r
+\r
+       @SuppressWarnings("rawtypes")\r
+       protected void checkNull(Object obj, Class type) {\r
+               if (obj == null)\r
+                       throw new IllegalArgumentException(type.getName() + " can not be null.");\r
+       }\r
+\r
+       @Override\r
+       public void add(IEntityBase entity) {\r
+               DefaultContext context = manager.getDbContext();\r
+               try {\r
+                       add(context, entity);\r
+               } catch (Exception e) {\r
+\r
+                       // TODO reszletezes\r
+                       throw new ItemManagerException(e);\r
+               } finally {\r
+                       manager.putDbContext(context);\r
+               }\r
+       }\r
+\r
+       public void add(DefaultContext context, IEntityBase entity) {\r
+               manager.traceIn();\r
+               try {\r
+                       checkNull(entity, IEntityBase.class);\r
+                       beforeAdd(context, entity);\r
+                       long id = entity.getId();\r
+\r
+                       insert(context, entity);\r
+                       if (id == 0) {\r
+                               /* @lineinfo:generated-code */\r
+                               /* @lineinfo:52^4 */\r
+\r
+//  ************************************************************\r
+//  #sql [context] { SELECT IDENTITY_VAL_LOCAL()  INTO :id,  FROM SYSIBM.SYSDUMMY1  };\r
+//  ************************************************************\r
+\r
+                               {\r
+                                       sqlj.runtime.profile.RTResultSet __sJT_rtRs;\r
+                                       sqlj.runtime.ConnectionContext __sJT_connCtx = context;\r
+                                       if (__sJT_connCtx == null)\r
+                                               sqlj.runtime.error.RuntimeRefErrors.raise_NULL_DEFAULT_CONN_CTX();\r
+                                       sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();\r
+                                       if (__sJT_execCtx == null)\r
+                                               sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();\r
+                                       synchronized (__sJT_execCtx) {\r
+                                               sqlj.runtime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, EntityBaseDAO_SJProfileKeys.getKey(0), 0);\r
+                                               try {\r
+                                                       __sJT_rtRs = __sJT_execCtx.executeQuery();\r
+                                               } finally {\r
+                                                       __sJT_execCtx.releaseStatement();\r
+                                               }\r
+                                       }\r
+                                       try {\r
+                                               sqlj.runtime.ref.ResultSetIterImpl.checkColumns(__sJT_rtRs, 1);\r
+                                               if (!__sJT_rtRs.next()) {\r
+                                                       sqlj.runtime.error.RuntimeRefErrors.raise_NO_ROW_SELECT_INTO();\r
+                                               }\r
+                                               id = __sJT_rtRs.getLongNoNull(1);\r
+                                               if (__sJT_rtRs.next()) {\r
+                                                       sqlj.runtime.error.RuntimeRefErrors.raise_MULTI_ROW_SELECT_INTO();\r
+                                               }\r
+                                       } finally {\r
+                                               __sJT_rtRs.close();\r
+                                       }\r
+                               }\r
+\r
+//  ************************************************************\r
+\r
+                               /* @lineinfo:user-code *//* @lineinfo:52^80 */\r
+                               entity.setId(id);\r
+                       }\r
+                       afterAdd(context, entity);\r
+                       /* @lineinfo:generated-code *//* @lineinfo:56^3 */\r
+\r
+//  ************************************************************\r
+//  #sql [context] { COMMIT  };\r
+//  ************************************************************\r
+\r
+                       {\r
+                               sqlj.runtime.ConnectionContext __sJT_connCtx = context;\r
+                               if (__sJT_connCtx == null)\r
+                                       sqlj.runtime.error.RuntimeRefErrors.raise_NULL_DEFAULT_CONN_CTX();\r
+                               sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();\r
+                               if (__sJT_execCtx == null)\r
+                                       sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();\r
+                               synchronized (__sJT_execCtx) {\r
+                                       sqlj.runtime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, EntityBaseDAO_SJProfileKeys.getKey(0), 1);\r
+                                       try {\r
+                                               __sJT_execCtx.executeUpdate();\r
+                                       } finally {\r
+                                               __sJT_execCtx.releaseStatement();\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+//  ************************************************************\r
+\r
+                       /* @lineinfo:user-code *//* @lineinfo:56^27 */\r
+                       if (useMemoryCache())\r
+                               manager.storeCached(entity.getId(), entity);\r
+\r
+               } catch (Exception e) {\r
+                       try {\r
+                               /* @lineinfo:generated-code */\r
+                               /* @lineinfo:62^4 */\r
+\r
+//  ************************************************************\r
+//  #sql [context] { ROLLBACK  };\r
+//  ************************************************************\r
+\r
+                               {\r
+                                       sqlj.runtime.ConnectionContext __sJT_connCtx = context;\r
+                                       if (__sJT_connCtx == null)\r
+                                               sqlj.runtime.error.RuntimeRefErrors.raise_NULL_DEFAULT_CONN_CTX();\r
+                                       sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();\r
+                                       if (__sJT_execCtx == null)\r
+                                               sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();\r
+                                       synchronized (__sJT_execCtx) {\r
+                                               sqlj.runtime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, EntityBaseDAO_SJProfileKeys.getKey(0), 2);\r
+                                               try {\r
+                                                       __sJT_execCtx.executeUpdate();\r
+                                               } finally {\r
+                                                       __sJT_execCtx.releaseStatement();\r
+                                               }\r
+                                       }\r
+                               }\r
+\r
+//  ************************************************************\r
+\r
+                               /* @lineinfo:user-code *//* @lineinfo:62^30 */\r
+                       } catch (Exception e1) {\r
+                       }\r
+                       manager.throwError(e);\r
+               }\r
+               manager.traceOut();\r
+       }\r
+\r
+       @Override\r
+       public IEntityBase get(long id) {\r
+               IEntityBase entity = null;\r
+               DefaultContext context = manager.getDbContext();\r
+               try {\r
+                       entity = get(context, id);\r
+               } catch (Exception e) {\r
+                       throw new ItemManagerException(e);\r
+               } finally {\r
+                       manager.putDbContext(context);\r
+               }\r
+               return entity;\r
+       }\r
+\r
+       public IEntityBase get(DefaultContext context, long id) {\r
+               manager.traceIn();\r
+               IEntityBase entity = null;\r
+               try {\r
+                       if (id == 0)\r
+                               throw new IllegalArgumentException("Cannot get EntityBase with 0 ID.");\r
+                       if (useMemoryCache())\r
+                               entity = manager.retrieveCached(getCacheType(), id);\r
+                       if (entity == null) {\r
+                               ResultSetIterImpl iter = selectByKey(context, id);\r
+                               checkNull(iter, ResultSetIterImpl.class);\r
+                               entity = getEntity(context, iter);\r
+                               if (useMemoryCache())\r
+                                       manager.storeCached(id, entity);\r
+                       }\r
+                       afterGet(context, entity);\r
+               } catch (Exception e) {\r
+                       throw new ItemManagerException(e);\r
+               }\r
+               manager.traceOut();\r
+               return entity;\r
+       }\r
+\r
+       @Override\r
+       public List<IEntityBase> getAll() {\r
+               List<IEntityBase> result = null;\r
+               DefaultContext context = manager.getDbContext();\r
+               try {\r
+                       result = getAll(context);\r
+               } catch (Exception e) {\r
+                       throw new ItemManagerException(e);\r
+               } finally {\r
+                       manager.putDbContext(context);\r
+               }\r
+               return result;\r
+       }\r
+\r
+       @Override\r
+       public List<IEntityBase> getAll(IDAOIterProvider provider) {\r
+               List<IEntityBase> result = null;\r
+               DefaultContext context = manager.getDbContext();\r
+               try {\r
+                       result = getAll(context, provider);\r
+               } catch (Exception e) {\r
+                       throw new ItemManagerException(e);\r
+               } finally {\r
+                       manager.putDbContext(context);\r
+               }\r
+               return result;\r
+       }\r
+\r
+       @Override\r
+       public IEntityBase get(IDAOIterProvider provider) {\r
+               IEntityBase entity = null;\r
+               DefaultContext context = manager.getDbContext();\r
+               try {\r
+                       entity = get(context, provider);\r
+               } catch (Exception e) {\r
+                       throw new ItemManagerException(e);\r
+               } finally {\r
+                       manager.putDbContext(context);\r
+               }\r
+               return entity;\r
+       }\r
+\r
+       private IEntityBase get(DefaultContext context, IDAOIterProvider provider) {\r
+               manager.traceIn();\r
+               IEntityBase entity = null;\r
+               try {\r
+                       ResultSetIterImpl iter = provider.get(context, this);\r
+                       checkNull(iter, ResultSetIterImpl.class);\r
+                       entity = getEntity(context, iter);\r
+                       afterGet(context, entity);\r
+               } catch (Exception e) {\r
+                       throw new ItemManagerException(e);\r
+               }\r
+               manager.traceOut();\r
+               return entity;\r
+       }\r
+\r
+       public List<IEntityBase> getAll(DefaultContext context, IDAOIterProvider provider) {\r
+               manager.traceIn();\r
+               List<IEntityBase> result = null;\r
+               try {\r
+                       ResultSetIterImpl iter = provider.get(context, this);\r
+                       checkNull(iter, ResultSetIterImpl.class);\r
+                       result = getList(context, iter, false, true);\r
+               } catch (Exception e) {\r
+                       throw new ItemManagerException(e);\r
+               }\r
+               manager.traceOut();\r
+               return result;\r
+       }\r
+\r
+       public List<IEntityBase> getAll(DefaultContext context) {\r
+               manager.traceIn();\r
+               List<IEntityBase> result = null;\r
+               try {\r
+                       ResultSetIterImpl iter = selectAll(context);\r
+                       checkNull(iter, ResultSetIterImpl.class);\r
+                       result = getList(context, iter, false, true);\r
+               } catch (Exception e) {\r
+                       throw new ItemManagerException(e);\r
+               }\r
+               manager.traceOut();\r
+               return result;\r
+       }\r
+\r
+       @Override\r
+       public List<IEntityBase> getAll(long id) {\r
+               List<IEntityBase> result = null;\r
+               DefaultContext context = manager.getDbContext();\r
+               try {\r
+                       result = getAll(context, id);\r
+               } catch (Exception e) {\r
+                       throw new ItemManagerException(e);\r
+               } finally {\r
+                       manager.putDbContext(context);\r
+               }\r
+               return result;\r
+       }\r
+\r
+       public List<IEntityBase> getAll(DefaultContext context, long id) {\r
+               manager.traceIn();\r
+               List<IEntityBase> result = null;\r
+               try {\r
+                       ResultSetIterImpl iter = selectByForeignKey(context, id);\r
+                       checkNull(iter, ResultSetIterImpl.class);\r
+                       result = getList(context, iter, false, true);\r
+               } catch (Exception e) {\r
+                       throw new ItemManagerException(e);\r
+               }\r
+               manager.traceOut();\r
+               return result;\r
+       }\r
+\r
+       protected IEntityBase getEntity(DefaultContext context, ResultSetIterImpl iter) {\r
+               manager.traceIn();\r
+               IEntityBase entity = null;\r
+               try {\r
+                       List<IEntityBase> result = getList(context, iter, false, false);\r
+                       if (result != null) {\r
+                               if (result.size() != 1)\r
+                                       throw new IllegalStateException("Expected one, found " + result.size() + ".");\r
+                               entity = result.get(0);\r
+                       }\r
+               } catch (Exception e) {\r
+                       throw new ItemManagerException(e);\r
+               }\r
+               manager.traceOut();\r
+               return entity;\r
+       }\r
+\r
+//     protected List<IEntityBase> getList(ResultSetIterImpl iter) {\r
+//             List<IEntityBase> result = null;\r
+//             DefaultContext context = manager.getDbContext();\r
+//             try {\r
+//                     result = getList(context, iter);\r
+//             } catch (Exception e) {\r
+//                     throw new ItemManagerException(e);\r
+//             } finally {\r
+//                     manager.putDbContext(context);\r
+//             }\r
+//             return result;\r
+//     }\r
+\r
+       protected List<IEntityBase> getList(ResultSetIterImpl iter, boolean isChunked) {\r
+               List<IEntityBase> result = null;\r
+               DefaultContext context = manager.getDbContext();\r
+               try {\r
+                       result = getList(context, iter, isChunked, true);\r
+               } catch (Exception e) {\r
+                       throw new ItemManagerException(e);\r
+               } finally {\r
+                       manager.putDbContext(context);\r
+               }\r
+               return result;\r
+       }\r
+\r
+       protected List<IEntityBase> getList(DefaultContext context, ResultSetIterImpl iter, boolean isChunked) {\r
+               return getList(context, iter, isChunked, true);\r
+       }\r
+\r
+       protected List<IEntityBase> getList(DefaultContext context, ResultSetIterImpl iter, boolean isChunked, boolean enablecache) {\r
+               manager.traceIn();\r
+               List<IEntityBase> result = null;\r
+               try {\r
+                       if (useMemoryCache() && enablecache)\r
+                               result = manager.getAllCached(getCacheType());\r
+\r
+                       if (result == null) {\r
+                               result = entities(context, iter, isChunked);\r
+                               if (useMemoryCache() && enablecache)\r
+                                       manager.setAllCached(getCacheType(), result);\r
+                       }\r
+\r
+                       /* @lineinfo:generated-code *//* @lineinfo:280^3 */\r
+\r
+//  ************************************************************\r
+//  #sql [context] { COMMIT  };\r
+//  ************************************************************\r
+\r
+                       {\r
+                               sqlj.runtime.ConnectionContext __sJT_connCtx = context;\r
+                               if (__sJT_connCtx == null)\r
+                                       sqlj.runtime.error.RuntimeRefErrors.raise_NULL_DEFAULT_CONN_CTX();\r
+                               sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();\r
+                               if (__sJT_execCtx == null)\r
+                                       sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();\r
+                               synchronized (__sJT_execCtx) {\r
+                                       sqlj.runtime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, EntityBaseDAO_SJProfileKeys.getKey(0), 3);\r
+                                       try {\r
+                                               __sJT_execCtx.executeUpdate();\r
+                                       } finally {\r
+                                               __sJT_execCtx.releaseStatement();\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+//  ************************************************************\r
+\r
+                       /* @lineinfo:user-code *//* @lineinfo:280^27 */\r
+               } catch (Exception e) {\r
+                       try {\r
+                               /* @lineinfo:generated-code */\r
+                               /* @lineinfo:283^4 */\r
+\r
+//  ************************************************************\r
+//  #sql [context] { ROLLBACK  };\r
+//  ************************************************************\r
+\r
+                               {\r
+                                       sqlj.runtime.ConnectionContext __sJT_connCtx = context;\r
+                                       if (__sJT_connCtx == null)\r
+                                               sqlj.runtime.error.RuntimeRefErrors.raise_NULL_DEFAULT_CONN_CTX();\r
+                                       sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();\r
+                                       if (__sJT_execCtx == null)\r
+                                               sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();\r
+                                       synchronized (__sJT_execCtx) {\r
+                                               sqlj.runtime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, EntityBaseDAO_SJProfileKeys.getKey(0), 4);\r
+                                               try {\r
+                                                       __sJT_execCtx.executeUpdate();\r
+                                               } finally {\r
+                                                       __sJT_execCtx.releaseStatement();\r
+                                               }\r
+                                       }\r
+                               }\r
+\r
+//  ************************************************************\r
+\r
+                               /* @lineinfo:user-code *//* @lineinfo:283^30 */\r
+                       } catch (Exception e1) {\r
+                       }\r
+                       manager.throwError(e);\r
+               }\r
+               manager.traceOut();\r
+               return result;\r
+       }\r
+\r
+       @Override\r
+       public void modify(IEntityBase entity) {\r
+               DefaultContext context = manager.getDbContext();\r
+               try {\r
+                       modify(context, entity);\r
+               } catch (Exception e) {\r
+                       throw new ItemManagerException(e);\r
+               } finally {\r
+                       manager.putDbContext(context);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void merge(IEntityBase entity) {\r
+               DefaultContext context = manager.getDbContext();\r
+               try {\r
+                       if (entity.getId() == 0)\r
+                               add(entity);\r
+                       else\r
+                               modify(context, entity);\r
+               } catch (Exception e) {\r
+                       throw new ItemManagerException(e);\r
+               } finally {\r
+                       manager.putDbContext(context);\r
+               }\r
+       }\r
+\r
+       public void modify(DefaultContext context, IEntityBase entity) {\r
+               manager.traceIn();\r
+               try {\r
+                       checkNull(entity, IEntityBase.class);\r
+                       long id = entity.getId();\r
+                       entity.checkParameter("ID", id, false);\r
+                       update(context, entity);\r
+                       afterModify(context, entity);\r
+                       /* @lineinfo:generated-code *//* @lineinfo:327^3 */\r
+\r
+//  ************************************************************\r
+//  #sql [context] { COMMIT  };\r
+//  ************************************************************\r
+\r
+                       {\r
+                               sqlj.runtime.ConnectionContext __sJT_connCtx = context;\r
+                               if (__sJT_connCtx == null)\r
+                                       sqlj.runtime.error.RuntimeRefErrors.raise_NULL_DEFAULT_CONN_CTX();\r
+                               sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();\r
+                               if (__sJT_execCtx == null)\r
+                                       sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();\r
+                               synchronized (__sJT_execCtx) {\r
+                                       sqlj.runtime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, EntityBaseDAO_SJProfileKeys.getKey(0), 5);\r
+                                       try {\r
+                                               __sJT_execCtx.executeUpdate();\r
+                                       } finally {\r
+                                               __sJT_execCtx.releaseStatement();\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+//  ************************************************************\r
+\r
+                       /* @lineinfo:user-code *//* @lineinfo:327^27 */\r
+                       if (useMemoryCache())\r
+                               manager.storeCached(entity.getId(), entity);\r
+               } catch (Exception e) {\r
+                       try {\r
+                               /* @lineinfo:generated-code */\r
+                               /* @lineinfo:332^4 */\r
+\r
+//  ************************************************************\r
+//  #sql [context] { ROLLBACK  };\r
+//  ************************************************************\r
+\r
+                               {\r
+                                       sqlj.runtime.ConnectionContext __sJT_connCtx = context;\r
+                                       if (__sJT_connCtx == null)\r
+                                               sqlj.runtime.error.RuntimeRefErrors.raise_NULL_DEFAULT_CONN_CTX();\r
+                                       sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();\r
+                                       if (__sJT_execCtx == null)\r
+                                               sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();\r
+                                       synchronized (__sJT_execCtx) {\r
+                                               sqlj.runtime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, EntityBaseDAO_SJProfileKeys.getKey(0), 6);\r
+                                               try {\r
+                                                       __sJT_execCtx.executeUpdate();\r
+                                               } finally {\r
+                                                       __sJT_execCtx.releaseStatement();\r
+                                               }\r
+                                       }\r
+                               }\r
+\r
+//  ************************************************************\r
+\r
+                               /* @lineinfo:user-code *//* @lineinfo:332^30 */\r
+                       } catch (Exception e1) {\r
+                       }\r
+                       manager.throwError(e);\r
+               }\r
+               manager.traceOut();\r
+       }\r
+\r
+       @Override\r
+       public void remove(IEntityBase entity) {\r
+               DefaultContext context = manager.getDbContext();\r
+               try {\r
+                       remove(context, entity);\r
+               } catch (Exception e) {\r
+                       throw new ItemManagerException(e);\r
+               } finally {\r
+                       manager.putDbContext(context);\r
+               }\r
+       }\r
+\r
+       public void remove(DefaultContext context, IEntityBase entity) {\r
+               manager.traceIn();\r
+               try {\r
+                       checkNull(entity, IEntityBase.class);\r
+                       long id = entity.getId();\r
+                       entity.checkParameter("ID", id, false);\r
+                       beforeDelete(context, entity);\r
+                       delete(context, id);\r
+                       afterDelete(context, entity);\r
+                       /* @lineinfo:generated-code *//* @lineinfo:361^3 */\r
+\r
+//  ************************************************************\r
+//  #sql [context] { COMMIT  };\r
+//  ************************************************************\r
+\r
+                       {\r
+                               sqlj.runtime.ConnectionContext __sJT_connCtx = context;\r
+                               if (__sJT_connCtx == null)\r
+                                       sqlj.runtime.error.RuntimeRefErrors.raise_NULL_DEFAULT_CONN_CTX();\r
+                               sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();\r
+                               if (__sJT_execCtx == null)\r
+                                       sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();\r
+                               synchronized (__sJT_execCtx) {\r
+                                       sqlj.runtime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, EntityBaseDAO_SJProfileKeys.getKey(0), 7);\r
+                                       try {\r
+                                               __sJT_execCtx.executeUpdate();\r
+                                       } finally {\r
+                                               __sJT_execCtx.releaseStatement();\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+//  ************************************************************\r
+\r
+                       /* @lineinfo:user-code *//* @lineinfo:361^27 */\r
+                       if (useMemoryCache())\r
+                               manager.removeCached(getCacheType(), entity.getId());\r
+               } catch (Exception e) {\r
+                       try {\r
+                               /* @lineinfo:generated-code */\r
+                               /* @lineinfo:366^4 */\r
+\r
+//  ************************************************************\r
+//  #sql [context] { ROLLBACK  };\r
+//  ************************************************************\r
+\r
+                               {\r
+                                       sqlj.runtime.ConnectionContext __sJT_connCtx = context;\r
+                                       if (__sJT_connCtx == null)\r
+                                               sqlj.runtime.error.RuntimeRefErrors.raise_NULL_DEFAULT_CONN_CTX();\r
+                                       sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();\r
+                                       if (__sJT_execCtx == null)\r
+                                               sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();\r
+                                       synchronized (__sJT_execCtx) {\r
+                                               sqlj.runtime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, EntityBaseDAO_SJProfileKeys.getKey(0), 8);\r
+                                               try {\r
+                                                       __sJT_execCtx.executeUpdate();\r
+                                               } finally {\r
+                                                       __sJT_execCtx.releaseStatement();\r
+                                               }\r
+                                       }\r
+                               }\r
+\r
+//  ************************************************************\r
+\r
+                               /* @lineinfo:user-code *//* @lineinfo:366^30 */\r
+                       } catch (Exception e1) {\r
+                       }\r
+                       manager.throwError(e);\r
+               }\r
+               manager.traceOut();\r
+       }\r
+\r
+       @Override\r
+       public void remove(List<Long> ids) {\r
+               DefaultContext context = manager.getDbContext();\r
+               try {\r
+                       remove(context, ids);\r
+               } catch (Exception e) {\r
+                       throw new ItemManagerException(e);\r
+               } finally {\r
+                       manager.putDbContext(context);\r
+               }\r
+       }\r
+\r
+       protected void remove(DefaultContext context, List<Long> ids) {\r
+               manager.traceIn();\r
+               try {\r
+                       for (long id : ids)\r
+                               delete(context, id);\r
+                       /* @lineinfo:generated-code *//* @lineinfo:390^3 */\r
+\r
+//  ************************************************************\r
+//  #sql [context] { COMMIT  };\r
+//  ************************************************************\r
+\r
+                       {\r
+                               sqlj.runtime.ConnectionContext __sJT_connCtx = context;\r
+                               if (__sJT_connCtx == null)\r
+                                       sqlj.runtime.error.RuntimeRefErrors.raise_NULL_DEFAULT_CONN_CTX();\r
+                               sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();\r
+                               if (__sJT_execCtx == null)\r
+                                       sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();\r
+                               synchronized (__sJT_execCtx) {\r
+                                       sqlj.runtime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, EntityBaseDAO_SJProfileKeys.getKey(0), 9);\r
+                                       try {\r
+                                               __sJT_execCtx.executeUpdate();\r
+                                       } finally {\r
+                                               __sJT_execCtx.releaseStatement();\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+//  ************************************************************\r
+\r
+                       /* @lineinfo:user-code *//* @lineinfo:390^27 */\r
+                       if (useMemoryCache()) {\r
+                               for (long id : ids)\r
+                                       manager.removeCached(getCacheType(), id);\r
+                       }\r
+               } catch (Exception e) {\r
+                       try {\r
+                               /* @lineinfo:generated-code */\r
+                               /* @lineinfo:397^4 */\r
+\r
+//  ************************************************************\r
+//  #sql [context] { ROLLBACK  };\r
+//  ************************************************************\r
+\r
+                               {\r
+                                       sqlj.runtime.ConnectionContext __sJT_connCtx = context;\r
+                                       if (__sJT_connCtx == null)\r
+                                               sqlj.runtime.error.RuntimeRefErrors.raise_NULL_DEFAULT_CONN_CTX();\r
+                                       sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();\r
+                                       if (__sJT_execCtx == null)\r
+                                               sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();\r
+                                       synchronized (__sJT_execCtx) {\r
+                                               sqlj.runtime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, EntityBaseDAO_SJProfileKeys.getKey(0), 10);\r
+                                               try {\r
+                                                       __sJT_execCtx.executeUpdate();\r
+                                               } finally {\r
+                                                       __sJT_execCtx.releaseStatement();\r
+                                               }\r
+                                       }\r
+                               }\r
+\r
+//  ************************************************************\r
+\r
+                               /* @lineinfo:user-code *//* @lineinfo:397^30 */\r
+                       } catch (Exception e1) {\r
+                       }\r
+                       manager.throwError(e);\r
+               }\r
+               manager.traceOut();\r
+       }\r
+\r
+       @Override\r
+       public void truncate() {\r
+               manager.traceIn();\r
+               DefaultContext context = manager.getDbContext();\r
+               try {\r
+                       truncateTable(context);\r
+                       /* @lineinfo:generated-code *//* @lineinfo:411^3 */\r
+\r
+//  ************************************************************\r
+//  #sql [context] { COMMIT  };\r
+//  ************************************************************\r
+\r
+                       {\r
+                               sqlj.runtime.ConnectionContext __sJT_connCtx = context;\r
+                               if (__sJT_connCtx == null)\r
+                                       sqlj.runtime.error.RuntimeRefErrors.raise_NULL_DEFAULT_CONN_CTX();\r
+                               sqlj.runtime.ExecutionContext __sJT_execCtx = __sJT_connCtx.getExecutionContext();\r
+                               if (__sJT_execCtx == null)\r
+                                       sqlj.runtime.error.RuntimeRefErrors.raise_NULL_EXEC_CTX();\r
+                               synchronized (__sJT_execCtx) {\r
+                                       sqlj.runtime.profile.RTStatement __sJT_stmt = __sJT_execCtx.registerStatement(__sJT_connCtx, EntityBaseDAO_SJProfileKeys.getKey(0), 11);\r
+                                       try {\r
+                                               __sJT_execCtx.executeUpdate();\r
+                                       } finally {\r
+                                               __sJT_execCtx.releaseStatement();\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+//  ************************************************************\r
+\r
+                       /* @lineinfo:user-code *//* @lineinfo:411^27 */\r
+               } catch (Exception e) {\r
+                       throw new ItemManagerException(e);\r
+               } finally {\r
+                       manager.putDbContext(context);\r
+               }\r
+               manager.traceOut();\r
+       }\r
+\r
+       protected void afterGet(DefaultContext context, IEntityBase entity) throws SQLException {\r
+       }\r
+\r
+       protected void beforeAdd(DefaultContext context, IEntityBase entity) throws SQLException {\r
+       }\r
+\r
+       protected void afterAdd(DefaultContext context, IEntityBase entity) throws SQLException {\r
+       }\r
+\r
+       protected void afterModify(DefaultContext context, IEntityBase entity) throws SQLException {\r
+       }\r
+\r
+       protected void beforeDelete(DefaultContext context, IEntityBase entity) throws SQLException {\r
+       }\r
+\r
+       protected void afterDelete(DefaultContext context, IEntityBase entity) throws SQLException {\r
+       }\r
+\r
+       protected List<IEntityBase> entities(DefaultContext context, ResultSetIterImpl iter, boolean isChunked) throws SQLException {\r
+               return null;\r
+       }\r
+\r
+       public List<IEntityBase> entities(DefaultContext context, ResultSet rs) throws SQLException {\r
+               return null;\r
+       }\r
+\r
+       protected ResultSetIterImpl selectByKey(DefaultContext context, long id) throws SQLException {\r
+               return null;\r
+       }\r
+\r
+       protected ResultSetIterImpl selectByForeignKey(DefaultContext context, long id) throws SQLException {\r
+               return null;\r
+       }\r
+\r
+       protected ResultSetIterImpl selectAll(DefaultContext context) throws SQLException {\r
+               return null;\r
+       }\r
+\r
+       protected void delete(DefaultContext context, long id) throws SQLException {\r
+       }\r
+\r
+       protected void truncateTable(DefaultContext context) throws SQLException {\r
+       }\r
+\r
+       protected void insert(DefaultContext context, IEntityBase entity) throws SQLException {\r
+       }\r
+\r
+       protected void update(DefaultContext context, IEntityBase entity) throws SQLException {\r
+       }\r
+\r
+       protected boolean useMemoryCache() {\r
+               return false;\r
+       }\r
+\r
+       protected Class<? extends IEntityBase> getCacheType() {\r
+               return null;\r
+       }\r
+}\r
+\r
+/* @lineinfo:generated-code */class EntityBaseDAO_SJProfileKeys {\r
+       private java.lang.Object[] keys;\r
+       private final sqlj.runtime.profile.Loader loader = sqlj.runtime.RuntimeContext.getRuntime().getLoaderForClass(getClass());\r
+       private static EntityBaseDAO_SJProfileKeys inst = null;\r
+\r
+       public static java.lang.Object getKey(int keyNum) throws java.sql.SQLException {\r
+               synchronized (user.jobengine.db.EntityBaseDAO_SJProfileKeys.class) {\r
+                       if (inst == null) {\r
+                               inst = new EntityBaseDAO_SJProfileKeys();\r
+                       }\r
+               }\r
+               return inst.keys[keyNum];\r
+       }\r
+\r
+       private EntityBaseDAO_SJProfileKeys() throws java.sql.SQLException {\r
+               keys = new java.lang.Object[1];\r
+               keys[0] = DefaultContext.getProfileKey(loader, "user.jobengine.db.EntityBaseDAO_SJProfile0");\r
+       }\r
+}\r
index b4c0b443c5c2a41a79e9e728c8f2bd78e65793e0..0641a583673291c54fda116beb5e70243bc0e701 100644 (file)
@@ -60,10 +60,12 @@ public class ItemManager extends MemoryCache implements IItemManager {
 \r
        private static final Logger logger = LogManager.getLogger();\r
 \r
-       static ItemManager currentInstance = null;\r
+       static ItemManager instance = null;\r
 \r
        static public ItemManager getInstance() {\r
-               return currentInstance;\r
+               if (instance == null)\r
+                       instance = new ItemManager();\r
+               return instance;\r
        }\r
 \r
        private IConfiguration systemConfig;\r
@@ -78,6 +80,11 @@ public class ItemManager extends MemoryCache implements IItemManager {
        private Connection connection;\r
 \r
        public ItemManager() {\r
+               if (instance == null)\r
+                       instance = this;\r
+               else\r
+                       throw new RuntimeException("Multiple ItemManager instances are not supported!");\r
+\r
                initializeItemManager(signalServer);\r
        }\r
 \r
@@ -1139,7 +1146,6 @@ public class ItemManager extends MemoryCache implements IItemManager {
        }\r
 \r
        void initialize() {\r
-               currentInstance = this;\r
                super.setItemManager(this);\r
 \r
                baseDAOs.put(MetadataType.class, new MetadataTypeDAO(this));\r
@@ -1379,16 +1385,39 @@ public class ItemManager extends MemoryCache implements IItemManager {
        public void throwError(Exception e) {\r
                if (e != null) {\r
                        String message = e.getMessage();\r
+\r
+                       if ("SqlIntegrityConstraintViolationException".equals(e.getClass().getSimpleName())) {\r
+                               SqlIntegrityErrorParser parser = new SqlIntegrityErrorParser(message);\r
+                               if (parser.isParsed()) {\r
+                                       String name = getDBColumnName(parser.getTbSpaceId(), parser.getTbId(), parser.getColNr());\r
+                                       message += String.format("\r\nInvolved column name is %s.", name);\r
+                               }\r
+                       }\r
+\r
                        if (message == null || message.length() == 0)\r
                                message = e.getClass().getName();\r
                        StackTraceElement element = Thread.currentThread().getStackTrace()[2];\r
                        message += String.format(", source: %1$s.%2$s", element.getClassName(), element.getMethodName());\r
-                       // if (logger != null)\r
-                       // logger.error(message, e);\r
+\r
                        throw new ItemManagerException(message);\r
                }\r
        }\r
 \r
+       private String getDBColumnName(String tbSpaceId, String tbId, String colNr) {\r
+               String sql = "SELECT T.TABNAME || '.' || C.COLNAME FROM SYSCAT.TABLES AS T, SYSCAT.COLUMNS AS C " + "WHERE T.TBSPACEID = ? " + "AND T.TABLEID = ? "\r
+                               + "AND C.COLNO = ? " + "AND C.TABSCHEMA = T.TABSCHEMA " + "AND C.TABNAME = T.TABNAME";\r
+               String[] result = new String[] { null };\r
+               executeQuery(sql, rs -> {\r
+                       result[0] = rs.getString(1);\r
+                       return false;\r
+               }, d -> {\r
+                       d.setString(1, tbSpaceId);\r
+                       d.setString(2, tbId);\r
+                       d.setString(3, colNr);\r
+               });\r
+               return result[0];\r
+       }\r
+\r
        @Override\r
        public void traceIn() {\r
                // StackTraceElement element =\r
diff --git a/server/user.jobengine.osgi.db/src/user/jobengine/db/SqlIntegrityErrorParser.java b/server/user.jobengine.osgi.db/src/user/jobengine/db/SqlIntegrityErrorParser.java
new file mode 100644 (file)
index 0000000..8ddaf0b
--- /dev/null
@@ -0,0 +1,44 @@
+package user.jobengine.db;\r
+\r
+public class SqlIntegrityErrorParser {\r
+       private static final String COLNO = "COLNO=";\r
+       private static final String TABLEID = "TABLEID=";\r
+       private static final String TBSPACEID = "TBSPACEID=";\r
+       private String tbSpaceId;\r
+       private String tbId;\r
+       private String colNr;\r
+       private boolean parsed;\r
+\r
+       public SqlIntegrityErrorParser(String m) {\r
+               try {\r
+                       if (m.contains(TBSPACEID) && m.contains(TABLEID) && m.contains(COLNO)) {\r
+                               tbSpaceId = getValue(TBSPACEID, m);\r
+                               tbId = getValue(TABLEID, m);\r
+                               colNr = getValue(COLNO, m);\r
+                               parsed = true;\r
+                       }\r
+               } catch (Exception e) {\r
+               }\r
+       }\r
+\r
+       private String getValue(String col, String m) {\r
+               int i = m.indexOf(col);\r
+               return m.substring(i + col.length(), m.indexOf(" ", i)).replace(",", "").replace("\"", "");\r
+       }\r
+\r
+       public String getTbSpaceId() {\r
+               return tbSpaceId;\r
+       }\r
+\r
+       public String getTbId() {\r
+               return tbId;\r
+       }\r
+\r
+       public String getColNr() {\r
+               return colNr;\r
+       }\r
+\r
+       public boolean isParsed() {\r
+               return parsed;\r
+       }\r
+}\r
index 5e8a3b409a42cb8f8eec9630c8d351c46644f5b5..87b5327463662a4481659ea35fa64f962b46b6ec 100644 (file)
@@ -29,23 +29,13 @@ public class DynamicStepsLoader {
 \r
        public Class<?> loadClassFromSourceCode(GroovyClassLoader gcl, String fileName) throws IOException {\r
                Class<?> result = null;\r
-\r
-               Path path = Paths.get(stepsDir, fileName);\r
-               File classFile = null;\r
-\r
-               // Windows alatt az eleresi utak irasmodja egyforma kell legyen.\r
-               // A GroovyClassLoader\r
-               // ld. createGroovyClassLoader a new File(path.toFile().getCanonicalPath())-al\r
-               // operal.\r
-               classFile = new File(path.toFile().getCanonicalPath());\r
-               logger.info("Class path is normalized to {}", classFile.getCanonicalPath());\r
-\r
-               if (!classFile.exists())\r
-                       return result;\r
-\r
-               result = gcl.parseClass(classFile);\r
-               if (result != null)\r
-                       logger.info("Class for {} successfully loaded", fileName);\r
+               Path path = Paths.get(stepsDir, fileName).toFile().getCanonicalFile().toPath();\r
+               logger.info("Class path is normalized to {}", path.toString());\r
+               if (Files.exists(path)) {\r
+                       result = gcl.parseClass(path.toFile());\r
+                       if (result != null)\r
+                               logger.info("Class for {} successfully loaded", fileName);\r
+               }\r
                return result;\r
        }\r
 \r
@@ -74,8 +64,7 @@ public class DynamicStepsLoader {
        private Set<File> getJavaFileList(Path path, String excludeFileName) {\r
                Set<File> result = new HashSet<>();\r
                if (path.toFile().isDirectory()) {\r
-                       Predicate<Path> filter = file -> !Files.isDirectory(file)\r
-                                       && file.getFileName().toString().endsWith(".java");\r
+                       Predicate<Path> filter = file -> !Files.isDirectory(file) && file.getFileName().toString().endsWith(".java");\r
                        try (Stream<Path> stream = Files.list(path)) {\r
                                stream.filter(filter).forEach(p -> {\r
 \r
index 85ae209e73c3b4c00beac7e9f2ee74d42b6700c4..9d91156a14b9afdd147382a6dc2b65dd8b1d7510 100644 (file)
-package user.jobengine.server;
-
-import java.sql.Timestamp;
-import java.time.LocalDate;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CyclicBarrier;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.PriorityBlockingQueue;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicLong;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-import com.ibm.nosql.json.api.BasicDBList;
-import com.ibm.nosql.json.api.BasicDBObject;
-
-import user.commons.Job;
-import user.commons.JobStatus;
-import user.commons.cluster.ClusteredJob;
-import user.jobengine.db.IItemManager;
-import user.jobengine.db.ItemManagerData.SignalType;
-import user.jobengine.server.actions.IStatusMachine;
-import user.jobengine.server.actions.JobAction;
-import user.jobengine.server.actions.StatusMachine;
-import user.jobengine.server.ast.JobTemplate;
-import user.jobengine.server.instructions.CallJobStepInstruction;
-import user.jobengine.server.instructions.IInstruction;
-import user.jobengine.server.messagequeue.IUserMessage;
-import user.jobengine.server.messagequeue.IUserMessageQueues;
-import user.jobengine.server.messagequeue.UserMessageQueues;
-import user.jobengine.server.messages.IJobMessage;
-import user.jobengine.server.messages.JobStepCompletedMessage;
-import user.jobengine.server.messages.UserReplyMessage;
-import user.jobengine.server.scheduler.ScheduledJob;
-import user.jobengine.server.scheduler.SchedulerService;
-import user.tsm.client.TSMClient;
-import user.tsm.client.TSMException;
-
-/**
- * MAM motor implementáció.
- */
-public class JobEngine implements IJobEngine {
-
-       private class JobChangedListenerChecker extends Thread {
-               private volatile boolean shutdown = false;
-
-               @Override
-               public void run() {
-                       try {
-                               startUpBarrier.await();
-                       } catch (Exception e) {
-                       }
-
-                       while (!shutdown) {
-                               try {
-                                       Thread.sleep(1000);
-                                       removeJobChangedListenerGarbage();
-                               } catch (InterruptedException e) {
-                                       shutdown = true;
-                               }
-                       }
-               }
-
-               void shutDown() {
-                       shutdown = true;
-                       try {
-                               join();
-                       } catch (InterruptedException e) {
-                       }
-               }
-       }
-
-       private class MessageDispatcher extends Thread {
-               private volatile boolean shutdown = false;
-
-               @Override
-               public void run() {
-                       try {
-                               startUpBarrier.await();
-                       } catch (Exception e) {
-                       }
-
-                       while (!shutdown) {
-                               try {
-                                       IJobMessage message = messageQueue.poll(QUEUE_POLL_INTERVAL_MS, TimeUnit.MILLISECONDS);
-                                       if (message != null)
-                                               message.process(JobEngine.this);
-
-                               } catch (InterruptedException e) {
-                                       shutdown = true;
-                               }
-                       }
-                       // a leallitas utan az osszes fuggo uzenet vegrehajtasa
-                       while (!messageQueue.isEmpty()) {
-                               try {
-                                       IJobMessage message = messageQueue.poll(QUEUE_POLL_INTERVAL_MS, TimeUnit.MILLISECONDS);
-                                       if (message != null)
-                                               message.process(JobEngine.this);
-                               } catch (InterruptedException e) {
-                                       shutdown = true;
-                               }
-                       }
-               }
-
-               void shutDown() {
-                       shutdown = true;
-                       try {
-                               join();
-                       } catch (InterruptedException e) {
-                       }
-               }
-       }
-
-       private class VM extends Thread {
-               private volatile boolean shutdown = false;
-               private IInstruction ir = null;
-
-               @Override
-               public void run() {
-                       try {
-                               startUpBarrier.await();
-                       } catch (Exception e) {
-                       }
-
-                       while (!shutdown) {
-                               try {
-                                       Thread.sleep(QUEUE_POLL_INTERVAL_MS);
-                                       // IJobRuntime jobRuntime = runQueue.poll(QUEUE_POLL_INTERVAL_MS,
-                                       // TimeUnit.MILLISECONDS);
-                                       IJobRuntime jobRuntime = runQueue.poll();
-                                       if (jobRuntime != null) {
-                                               logger.debug("Processing {}", jobRuntime.getId());
-                                               // varakozo esetben vegrehajtjuk a kovetkezo utasitast
-                                               if (jobRuntime.hasNextInstruction() && jobRuntime.isWaitFinish()) {
-                                                       ir = jobRuntime.getNextInstruction();
-                                                       ir.execute(JobEngine.this, jobRuntime);
-                                               } else {
-                                                       // normal esetben elfutunk a kovetkezo job step-ig, vagy vegig
-                                                       while (jobRuntime.hasNextInstruction() && jobRuntime.isRunnable()) {
-                                                               ir = jobRuntime.getNextInstruction();
-                                                               ir.execute(JobEngine.this, jobRuntime);
-                                                       }
-                                               }
-
-                                               if (!jobRuntime.hasNextInstruction() && jobRuntime.isRunnable())
-                                                       jobCleanup(jobRuntime);
-
-                                       }
-                               } catch (Exception e) {
-                                       logger.error("Critical VM error!", e);
-                                       // shutdown = true;
-                               }
-                       }
-               }
-
-               void shutDown() {
-                       shutdown = true;
-                       try {
-                               join();
-                       } catch (InterruptedException e) {
-                       }
-               }
-       }
-
-       private static final Logger logger = LogManager.getLogger();
-       static private IItemManager itemManager;
-       private static IJobEngine instance;
-
-       public static IJobEngine getInstance() {
-               return instance;
-       }
-
-       static public IItemManager getStaticItemManager() {
-               return itemManager;
-       }
-
-       private volatile boolean isRunning;
-
-       private volatile boolean isAllExecutionDisabled;
-       private volatile boolean isScheduledExecutionDisabled;
-       private final BlockingQueue<IJobRuntime> runQueue;
-       private final BlockingQueue<IJobMessage> messageQueue;
-       private final Map<Long, IJobRuntime> submittedJobs;
-       private VM vm;
-       private MessageDispatcher dispatcher;
-       private JobChangedListenerChecker jobChangedListenerChecker;
-
-       private IUserMessageQueues userMessageQueues;
-
-       private final CyclicBarrier startUpBarrier;
-
-       private final IStatusMachine statusMachine;
-
-       private AtomicLong nextJobId;
-       private SchedulerService schedulerService = null;
-       private Set<IJobChangedListener> jobChangedListenerList = ConcurrentHashMap.newKeySet();
-       private Map<String, LocalDate> remoteWorkers;
-       private String masterServerAddress = System.getProperty("jobengine.master.server", "");
-       private final JobEngineRemote remoteEngine;
-
-       private ConcurrentHashMap<IJobChangedListener, Long> keepAliveJobChangedListeners = new ConcurrentHashMap<>();
-
-       private IJobEngineConfiguration jobEngineConfiguration;
-
-       /**
-        * A MAM motor példányosítása. Ennek során létrejönnek a várakozási sorok, az
-        * ütemező szál, az üzenet kezelő szál.
-        */
-       public JobEngine() {
-
-               runQueue = new PriorityBlockingQueue<IJobRuntime>();
-               messageQueue = new LinkedBlockingQueue<IJobMessage>();
-               submittedJobs = createJobs();
-               startUpBarrier = new CyclicBarrier(4);
-               nextJobId = new AtomicLong(0);
-               statusMachine = createStatusMachine();
-               if (instance != null)
-                       throw new RuntimeException("Multiple JobEngine instances are not supported!");
-               instance = this;
-
-               remoteWorkers = new ConcurrentHashMap<>();
-               // logger.info("JobEngine created");
-               if (isWorker())
-                       remoteEngine = createRemoteEngine();
-               else
-                       remoteEngine = null;
-       }
-
-       public void activate() {
-       }
-
-       @Override
-       public boolean addJobChangedEventListener(IJobChangedListener listener) {
-               boolean result = !jobChangedListenerList.contains(listener);
-               if (listener != null && result)
-                       jobChangedListenerList.add(listener);
-
-               return result;
-       }
-
-       @Override
-       public void addToExecutorQueue(IJobRuntime jobRuntime) {
-               try {
-                       Object typeName = jobRuntime.popFromStack();
-                       if (typeName == null)
-                               throw new Exception(
-                                               jobRuntime.toString() + " illegal execution state detected: executor name is null.");
-                       String executorName = String.valueOf(typeName);
-                       if (!jobEngineConfiguration.getExecutors().containsKey(executorName))
-                               throw new Exception(jobRuntime.toString() + " executor is unavailable: " + executorName);
-
-                       // a lista mindig letezik, de sima futtataskor csak 1 elemu, az aktualis van
-                       // benne
-                       // ha van parhuzamos futtatas, akkor letrejonnek benne a step szellemek is, es
-                       // meghivodik a fork
-                       List<IJobRuntime> jobs = spawnJobs(jobRuntime, executorName);
-                       jobEngineConfiguration.getExecutors().get(executorName).submit(jobs.toArray(new IJobRuntime[] {}));
-                       jobs.forEach(r -> fireJobChangedEvent(new JobChangedEvent(r, SignalType.EXECUTE)));
-
-               } catch (Exception e) {
-                       logger.catching(e);
-                       suspendWaitExecutorJob(e, jobRuntime);
-               }
-       }
-
-       @Override
-       public void addToRunQueue(IJobRuntime jobRuntime) {
-               try {
-                       logger.debug("{} adding to run queue", jobRuntime);
-                       if (jobRuntime.getIp() == 0 && !jobRuntime.isService() && jobRuntime.getParentJobId() == 0)
-                               logger.info(jobRuntime.getSessionMarker(), "A '{}' folyamat elindult.", jobRuntime.getName());
-                       runQueue.put(jobRuntime);
-               } catch (Exception e) {
-                       logger.error(e.getMessage(), e);
-               }
-       }
-
-       /**
-        * Job prioritasa megvaltozott. Job main queue-ban es a JobStepExecutorok
-        * soraiban is ujra kell rendezni a jobokat. Az ujrarendezes a put-nal is megy
-        * automatikusan, mivel eltero prioritasu jobot dobhatnak be vagy default
-        * prioritasut a korabban atrendezett listaba.
-        *
-        * @param jobRuntime
-        */
-       @Override
-       public void applyPriorityChange(IJobRuntime jobRuntime) {
-               logger.info("rePrioritization start for {}", jobRuntime.getId());
-               // synchronized(this.runQueue){
-
-               // job main queue reorder
-
-               if (this.runQueue.contains(jobRuntime)) {
-                       logger.info("runQueue");
-                       this.runQueue.remove(jobRuntime);
-                       try {
-                               this.runQueue.put(jobRuntime);
-                       } catch (InterruptedException e) {
-                       }
-               }
-
-               // JobStepExecutor reorder
-               if (jobEngineConfiguration.getExecutors() != null) {
-                       for (IJobStepExecutor exec : jobEngineConfiguration.getExecutors().values()) {
-                               if (exec.containsRuntime(jobRuntime)) {
-                                       logger.info("executor");
-                                       exec.changePriority(jobRuntime);
-                               }
-                       }
-               }
-
-               // } logger.info("rePrioritization end");
-       }
-
-       @Override
-       public synchronized void bindItemManagerService(IItemManager service) {
-               setItemManager(service);
-       }
-
-       public synchronized void bindJobEngineConfiguration(Object service) {
-               if (service instanceof JobEngineConfiguration) {
-                       jobEngineConfiguration = (IJobEngineConfiguration) service;
-                       isScheduledExecutionDisabled = jobEngineConfiguration.isScheduledExecutionDisabled();
-                       logger.info("IJobEngineConfiguration service binded");
-               }
-       }
-
-       private void bootstrap() throws JobEngineException {
-               // submit("fake-noparams.xml", "Bootstrap", null);
-       }
-
-       private void closeSessionLog(IJobRuntime jobRuntime) {
-               if (!jobRuntime.isService() && jobRuntime.getParentJobId() == 0) {
-                       if (JobStatus.FINISHED.equals(jobRuntime.getStatus()))
-                               logger.info(jobRuntime.getFinishMarker(), "A(z) '{}' folyamat futása sikeresen véget ért.",
-                                               jobRuntime.getName());
-                       else
-                               logger.error(jobRuntime.getFinishMarker(), "A(z) '{}' folyamat futása megszakadt.",
-                                               jobRuntime.getName());
-               }
-       }
-
-       protected Map<Long, IJobRuntime> createJobs() {
-               return new ConcurrentHashMap<Long, IJobRuntime>();
-       }
-
-       protected JobEngineRemote createRemoteEngine() {
-               return new JobEngineRemote(masterServerAddress);
-       }
-
-       protected IStatusMachine createStatusMachine() {
-               return new StatusMachine(this);
-       }
-
-       public void deactivate() {
-       }
-
-       @Override
-       public void executeAssignVariableInstruction(IJobRuntime jobRuntime) {
-               Object value = jobRuntime.popFromStack();
-               String name = (String) jobRuntime.popFromStack();
-
-               // a gyerek job-ok visszateresi erteket a spawn sorszammal kiegeszitve mentjuk
-               // TODO el kell tudni erni a kovetkezo lepesekbol ezeket az ertekeket
-               if (jobRuntime.getParentJobId() > 0) {
-                       IJobRuntime parentRuntime = getJobById(jobRuntime.getParentJobId());
-                       parentRuntime.setVariable(name + jobRuntime.getSpawnOrder(), value);
-               }
-
-               jobRuntime.setVariable(name, value);
-       }
-
-       /***
-        * Fuggetlen (beagyazott) alfolyamat letrehozasa
-        */
-       @Override
-       public void executeCallConcurrentJobStepInstruction(IJobRuntime jobRuntime, IProgram subProgram) {
-               JobRuntime c = new JobRuntime(this, jobRuntime, subProgram);
-               jobRuntime.addChild(c);
-               submit(c);
-       }
-
-       @Override
-       public void executeCallJobStepInstruction(IJobRuntime jobRuntime) {
-               statusMachine.processAction(JobAction.EXECUTE, jobRuntime);
-       }
-
-       @Override
-       public void executeCheckParameterInstruction(IJobRuntime jobRuntime) {
-               try {
-                       jobRuntime.checkStackParameter();
-               } catch (Exception e) {
-                       logger.error(e.getMessage());
-               }
-       }
-
-       @Override
-       public void executeDeclareVariableInstruction(IJobRuntime jobRuntime) {
-               Class<?> type = (Class<?>) jobRuntime.popFromStack();
-               String name = (String) jobRuntime.popFromStack();
-               jobRuntime.addVariable(name, type);
-       }
-
-       @Override
-       public void executeGetParameterInstruction(IJobRuntime jobRuntime) {
-               try {
-                       String name = (String) jobRuntime.popFromStack();
-                       Object value = jobRuntime.getParameter(name);
-                       jobRuntime.pushToStack(value);
-               } catch (Exception e) {
-                       logger.error(e.getMessage());
-                       jobRuntime.setDescription(e.getMessage());
-                       suspendWaitExecutorJob(e, jobRuntime);
-               }
-       }
-
-       @Override
-       public void executeGetVariableInstruction(IJobRuntime jobRuntime) {
-               try {
-                       String name = (String) jobRuntime.popFromStack();
-                       Object value = jobRuntime.getVariable(name);
-                       jobRuntime.pushToStack(value);
-               } catch (Exception e) {
-                       logger.error(e.getMessage());
-                       jobRuntime.setDescription(e.getMessage());
-                       suspendWaitExecutorJob(e, jobRuntime);
-               }
-       }
-
-       @Override
-       public void executePushToStackInstruction(IJobRuntime jobRuntime, Object item) {
-               jobRuntime.pushToStack(item);
-       }
-
-       @Override
-       public void executeSendMessageToUserInstruction(IJobRuntime jobRuntime) {
-               statusMachine.processAction(JobAction.MESSAGE, jobRuntime);
-
-               int messageNumber = (Integer) jobRuntime.popFromStack();
-               String catalogName = (String) jobRuntime.popFromStack();
-               Object[] inputs = getInputsFromStack(jobRuntime);
-               getUserMessageQueues().addMessage(jobRuntime, catalogName, messageNumber, true, inputs);
-       }
-
-       @Override
-       public void executeWaitForSpawnJobsInstruction(IJobRuntime jobRuntime) {
-               // logger.info("Processing {} {}", jobRuntime.getId(),
-               // jobRuntime.canContinueExecution());
-
-               if (jobRuntime.canContinueExecution()) {
-                       jobRuntime.setStatus(JobStatus.RUNNABLE);
-               } else {
-                       if (!JobStatus.WAIT_FINISH.equals(jobRuntime.getStatus())) {
-                               jobRuntime.setStatus(JobStatus.WAIT_FINISH);
-                       }
-                       jobRuntime.decrementInstructionPointer();
-               }
-               addToRunQueue(jobRuntime);
-       }
-
-       @Override
-       public void fireJobChangedEvent(JobChangedEvent event) {
-               for (IJobChangedListener listener : jobChangedListenerList) {
-                       listener.jobChanged(event);
-               }
-       }
-
-       @Override
-       public Object[] getInputsFromStack(IJobRuntime jobRuntime) {
-               jobRuntime.swapStack();
-               Integer parameterCount = (Integer) jobRuntime.popFromStack();
-               Object[] result = new Object[parameterCount];
-               for (int index = 0; index < parameterCount; index++) {
-                       result[index] = jobRuntime.popFromStack();
-               }
-               return result;
-       }
-
-       @Override
-       public IItemManager getItemManager() {
-               return itemManager;
-       }
-
-       @Override
-       public Job getJob(long id) {
-               Job result = null;
-               if (submittedJobs.containsKey(id))
-                       result = (Job) submittedJobs.get(id);
-               return result;
-       }
-
-       @Override
-       public IJobRuntime getJobById(long jobId) {
-               if (!submittedJobs.containsKey(jobId)) {
-                       logger.warn("Job does not exist anymore {}. Possibly canceled already.", jobId);
-               }
-               return submittedJobs.get(jobId);
-       }
-
-       @Override
-       public IJobEngineConfiguration getJobEngineConfiguration() {
-               return jobEngineConfiguration;
-       }
-
-       @Override
-       public Map<Long, IJobRuntime> getJobs() {
-               return submittedJobs;
-       }
-
-       protected long getNextJobId() {
-               return nextJobId.incrementAndGet();
-       }
-
-       @Override
-       public IProgram getProgram(String name) {
-               return jobEngineConfiguration.getPrograms().get(name);
-       }
-
-       @Override
-       public JobEngineRemote getRemoteEngine() {
-               return remoteEngine;
-       }
-
-       @Override
-       public ScheduledJob getScheduledJob(String template) throws Exception {
-               ArrayList<Entry<String, BasicDBObject>> schedules = jobEngineConfiguration.getSchedules();
-               BasicDBObject schedule = null;
-               boolean templateFirstOccurence = false;
-
-               for (int index = 0; index < schedules.size(); index++) {
-                       if (schedules.get(index).getKey().equals(template)) {
-                               if (!templateFirstOccurence) {
-                                       templateFirstOccurence = true;
-                                       schedule = schedules.get(index).getValue();
-                               } else {
-                                       throw new Exception("Key " + template + " is already contained in scheduled jobs!");
-                               }
-                       }
-               }
-
-               if (schedule == null)
-                       return null;
-               return jobEngineConfiguration.createScheduledJob(schedule, this);
-       }
-
-       @Override
-       public SchedulerService getScheduler() {
-               return schedulerService;
-       }
-
-       @Override
-       public IUserMessageQueues getUserMessageQueues() {
-               return userMessageQueues;
-       }
-
-       @Override
-       public boolean isAllExecutionDisabled() {
-               return isAllExecutionDisabled;
-       }
-
-       private void isRunnable(IProgram program) throws JobEngineException {
-               JobTemplate template = program.getTemplate();
-               // A JOB xml-ben beállítható, hogy futhatnak-e párhuzamosan.
-               if (template.isMultiInstance())
-                       return;
-
-               // Collection<IJobRuntime> values = getJobs().values();
-
-               // vegigmenni a submittedJobs-on!
-
-               Set<Long> ids = submittedJobs.keySet();
-               for (long id : ids) {
-                       if (!submittedJobs.containsKey(id))
-                               continue;
-
-                       IJobRuntime runtime = submittedJobs.get(id);
-                       if (runtime == null)
-                               continue;
-
-                       if (!template.getFileName().equals(runtime.getTemplate()))
-                               continue;
-
-                       // 'EXECUTING', 'WAIT_EXECUTOR', 'WAIT_SUSPEND', 'RUNNABLE'
-                       if (runtime.isExecuting() || runtime.isRunnable() || runtime.isWaitingSuspend()
-                                       || runtime.isWaitingExecutor())
-                               throw new JobEngineException(String.format("Can not submit job. Job with %s.%s already running",
-                                               template.getFileName(), template.getName()));
-               }
-               /*
-                * List<Job> runningJobs = itemManager.getRunningJobs(template.getFileName());
-                * if (runningJobs != null) { for (Job job : runningJobs) { Job runningJob =
-                * getJob(job.getId());
-                * 
-                * if (runningJob != null && runningJob.getStatus() != JobStatus.SUSPENDED)
-                * throw new JobEngineException(String.
-                * format("Can not submit job. Job with %s.%s already running",
-                * template.getFileName(), template.getName())); } }
-                */
-       }
-
-       @Override
-       public boolean isRunning() {
-               return isRunning;
-       }
-
-       @Override
-       public boolean isScheduledExecutionDisabled() {
-               return isScheduledExecutionDisabled;
-       }
-
-       @Override
-       public boolean isWorker() {
-               return masterServerAddress.length() > 0;
-       }
-
-       @Override
-       public void jobCleanup(IJobRuntime jobRuntime) {
-               logger.info("Cleanup {}", jobRuntime.getId());
-               statusMachine.processAction(JobAction.FINISH, jobRuntime);
-       }
-
-       @Override
-       public boolean keepAliveJobChangedListener(IJobChangedListener listener) {
-               boolean result = false;
-               if (keepAliveJobChangedListeners != null) {
-                       long now = System.currentTimeMillis();
-                       // ha mar hozza van adva, nem adja hozza
-                       result = addJobChangedEventListener(listener);
-                       keepAliveJobChangedListeners.put(listener, now);
-                       logger.debug("Refreshing listener {}, now {} ({})", listener, now, keepAliveJobChangedListeners.size());
-               }
-
-               return result;
-       }
-
-       @Deprecated
-       @Override
-       public void keepAliveWorker(String remoteAddr) {
-               remoteWorkers.put(remoteAddr, LocalDate.now());
-       }
-
-       @Override
-       public void processCancelRequest(IJobMessage message) {
-               IJobRuntime jobRuntime = getJobById(message.getJobId());
-
-               if (jobRuntime == null) {
-                       logger.warn("Job with id {} does not exist!", message.getJobId());
-                       return;
-               }
-
-               // a gyerekek miatt nem az!
-               if (!jobRuntime.isCancelable())
-                       return;
-
-               // Ha a jobs tartalmazta ezt a job-ot, akkor kikerül belőle.
-               // if (jobs.containsKey(message.getJobId()))
-               // jobs.remove(message.getJobId());
-               statusMachine.processAction(JobAction.CANCEL, jobRuntime);
-       }
-
-       @Override
-       public void processJobStepCompletedMessage(IJobMessage message) {
-               IJobRuntime jobRuntime = getJobById(message.getJobId());
-
-               if (jobRuntime == null) {
-                       logger.warn("Job with id {} does not exist!", message.getJobId());
-                       return;
-               }
-
-               // TODO ez hibat okoz az archivalasnal, mert hamarabb eltavolitja a childUd-ket
-
-               // if (jobRuntime.getParentJobId() > 0)
-               // removeSpanwChild(jobRuntime);
-
-               JobStepCompletedMessage m = (JobStepCompletedMessage) message;
-               // kesz vagyunk, jelezni
-               if (isWorker()) {
-                       statusMachine.processAction(JobAction.DONE, jobRuntime);
-                       return;
-               }
-
-               // a cancel hamarabb megjott?
-               // ha remote akkor tuti
-               if (jobRuntime == null) {
-
-               }
-               Object[] outputs = m.getOutputs();
-               putOutputsToStack(jobRuntime, outputs);
-
-               statusMachine.processAction(JobAction.DONE, jobRuntime);
-       }
-
-       @Override
-       public void processJobStepSkippedMessage(IJobMessage message) {
-               IJobRuntime jobRuntime = getJobById(message.getJobId());
-               statusMachine.processAction(JobAction.SKIP, jobRuntime);
-       }
-
-       @Override
-       public void processReplyMessage(IJobMessage message) {
-               IJobRuntime jobRuntime = getJobById(message.getJobId());
-               UserReplyMessage m = (UserReplyMessage) message;
-               IUserMessage userMessage = getUserMessageQueues().getUserMessages().get(m.getMessageId());
-               userMessage.setReply((Integer) m.getReply());
-               userMessage.setMustReply(false);
-               jobRuntime.pushToStack(m.getReply());
-               statusMachine.processAction(JobAction.REPLY, jobRuntime);
-       }
-
-       @Override
-       public void processRestartRequest(IJobMessage message) {
-               Job job = (Job) itemManager.get(Job.class, message.getJobId());
-               if (job != null) {
-                       IProgram program = getProgram(job.getTemplate());
-                       if (program != null) {
-                               IJobRuntime result = new JobRuntime(this, program, job, itemManager);
-                               result.setStatus(JobStatus.CANCELED);
-                               statusMachine.processAction(JobAction.RESTART, result);
-                       }
-               } else {
-                       logger.info("JobEngine processRestartReqest: Job is null");
-               }
-       }
-
-       @Override
-       public void processResumeRequest(IJobMessage message) {
-               IJobRuntime jobRuntime = getJobById(message.getJobId());
-               statusMachine.processAction(JobAction.RESUME, jobRuntime);
-       }
-
-       @Override
-       public void processSuspendRequest(IJobMessage message) {
-               IJobRuntime jobRuntime = getJobById(message.getJobId());
-               statusMachine.processAction(JobAction.SUSPEND, jobRuntime);
-       }
-
-       @Override
-       public void putOutputsToStack(IJobRuntime jobRuntime, Object[] outputs) {
-               if (outputs != null) {
-                       for (Object object : outputs) {
-                               jobRuntime.pushToStack(object);
-                       }
-                       jobRuntime.arrangeStack();
-               }
-       }
-
-       @Override
-       public void reloadGracefully() throws Exception {
-               if (schedulerService != null)
-                       schedulerService.shutdown();
-
-               jobEngineConfiguration.resetStepClassLoader();
-               jobEngineConfiguration.load(this, true);
-
-               schedulerService = new SchedulerService(this);
-               schedulerService.startup();
-               logger.info("JobEngine gracefully reloaded");
-               isRunning = true;
-       }
-
-       @Override
-       public void removeFromExecutorQueue(IJobRuntime jobRuntime) {
-               for (IJobStepExecutor executor : jobEngineConfiguration.getExecutors().values())
-                       executor.revoke(jobRuntime);
-       }
-
-       @Override
-       public void removeFromRunQueue(IJobRuntime jobRuntime) {
-               runQueue.remove(jobRuntime);
-       }
-
-       @Override
-       public void removeGarbage() {
-               List<Long> removeId = new ArrayList<>();
-               for (Long id : submittedJobs.keySet()) {
-                       IJobRuntime runtime = submittedJobs.get(id);
-                       if (runtime != null && (JobStatus.SUSPENDED.equals(runtime.getStatus())
-                                       || JobStatus.CANCELED.equals(runtime.getStatus())))
-                               removeId.add(id);
-               }
-               for (Long id : removeId)
-                       submittedJobs.remove(id);
-       }
-
-       @Override
-       public void removeJob(long id) {
-               if (submittedJobs.containsKey(id)) {
-                       IJobRuntime jobRuntime = submittedJobs.remove(id);
-                       fireJobChangedEvent(new JobChangedEvent(jobRuntime, SignalType.DELETE));
-                       logger.debug("--- {} removed from VM", jobRuntime);
-                       closeSessionLog(jobRuntime);
-               }
-
-       }
-
-       @Override
-       public void removeJobChangedEventListener(IJobChangedListener listener) {
-               if (listener != null) {
-                       jobChangedListenerList.remove(listener);
-               }
-       }
-
-       synchronized protected void removeJobChangedListenerGarbage() {
-               List<IJobChangedListener> toBeRemoved = new ArrayList<>();
-               for (IJobChangedListener listener : keepAliveJobChangedListeners.keySet()) {
-                       long lastMod = keepAliveJobChangedListeners.get(listener);
-                       long now = System.currentTimeMillis();
-                       if ((now - lastMod) > 5 * 1000) {
-
-                               toBeRemoved.add(listener);
-                               logger.debug("{} refreshed {}, now {}", listener, lastMod, now);
-                       }
-               }
-               toBeRemoved.forEach(r -> {
-                       logger.debug("Removing listener {}", r);
-                       removeJobChangedEventListener(r);
-                       keepAliveJobChangedListeners.remove(r);
-               });
-       }
-
-       @Override
-       public void removeSpanwChild(IJobRuntime jobRuntime) {
-               IJobRuntime parent = getJobById(jobRuntime.getParentJobId());
-               if (parent == null)
-                       return;
-
-               parent.removeSpanwChild(jobRuntime.getId());
-
-       }
-
-       @Override
-       public ClusteredJob requestJob(String className) throws Exception {
-               IJobStepExecutor executor = jobEngineConfiguration.getExecutors().get(className);
-               if (executor == null)
-                       throw new Exception("Unregistered executor request: " + className);
-               if (!executor.isRemoteEnabled())
-                       throw new Exception("Job is not registered for remote workers: " + className);
-
-               ClusteredJob job = executor.steelJob();
-               return job;
-       }
-
-       @Override
-       public void restartGracefully() throws Exception {
-               isRunning = false;
-               if (schedulerService != null)
-                       schedulerService.shutdown();
-
-               vm.shutDown();
-               shutdownExecutors();
-
-               startUpBarrier.reset();
-               logger.info("JobEngine gracefully stopped");
-
-               jobEngineConfiguration.resetStepClassLoader();
-               jobEngineConfiguration.load(this, false);
-
-               vm.start();
-
-               startupExecutors();
-               startUpBarrier.await();
-
-               schedulerService = new SchedulerService(this);
-               schedulerService.startup();
-               logger.info("JobEngine gracefully started");
-               isRunning = true;
-       }
-
-       @Override
-       public void sendMessage(IJobMessage jobMessage) {
-               messageQueue.add(jobMessage);
-       }
-
-       @Override
-       public void setAllExecutionDisabled(boolean isDisabled) {
-               this.isAllExecutionDisabled = isDisabled;
-       }
-
-       @Override
-       public void setItemManager(IItemManager _itemManager) {
-               itemManager = _itemManager;
-       }
-
-       @Override
-       public void setScheduledExecutionDisabled(boolean isDisabled) {
-               this.isScheduledExecutionDisabled = isDisabled;
-       }
-
-       @Override
-       public void shutdown() {
-               isRunning = false;
-               if (schedulerService != null)
-                       schedulerService.shutdown();
-
-               vm.shutDown();
-               shutdownExecutors();
-               dispatcher.shutDown();
-               jobChangedListenerChecker.shutDown();
-
-               try {
-                       TSMClient.CleanUpMultithread();
-               } catch (TSMException e) {
-                       logger.catching(e);
-               }
-               logger.info("JobEngine stopped");
-       }
-
-       private void shutdownExecutors() {
-               Collection<IJobStepExecutor> executors = jobEngineConfiguration.getExecutors().values();
-               for (IJobStepExecutor executor : executors) {
-                       logger.trace("Notify executor {}", executor.getStepUnitName());
-                       executor.shutdown();
-               }
-               for (IJobStepExecutor executor : executors) {
-                       logger.info("Stopping executor {}", executor.getStepUnitName());
-                       executor.waitShutdown();
-               }
-
-       }
-
-       private List<IJobRuntime> spawnJobs(IJobRuntime jobRuntime, String executorName) throws InterruptedException {
-               List<IJobRuntime> result = new ArrayList<>();
-
-               CallJobStepInstruction currentInstruction = jobRuntime.getCurrentCallJobStepInstruction();
-               if (currentInstruction != null) {
-                       String forEach = currentInstruction.getForEach();
-                       if (StringUtils.isNotBlank(forEach)) {
-                               Object parameter = jobRuntime.getParameter(forEach);
-                               if (parameter == null)
-                                       parameter = jobRuntime.getVariable(forEach);
-
-                               // a sima array helyett ezt jobb hasznalni
-                               if (parameter != null && parameter instanceof BasicDBList) {
-
-                                       BasicDBList iter = (BasicDBList) parameter;
-                                       for (int i = 1; i < iter.size(); i++) {
-                                               IJobRuntime jobRuntimeCopy = new JobRuntime(jobRuntime);
-                                               jobRuntimeCopy.setSpawnOrder(i);
-                                               jobRuntimeCopy.add();
-
-                                               jobRuntime.addSpawnChild(jobRuntimeCopy);
-
-                                               storeJob(jobRuntimeCopy);
-                                               result.add(jobRuntimeCopy);
-                                       }
-                               }
-                       }
-
-               }
-
-               result.add(jobRuntime);
-               return result;
-       }
-
-       @Override
-       public void startup() {
-               try {
-                       removeGarbage();
-
-                       jobEngineConfiguration.load(this, false);
-
-                       vm = new VM();
-                       dispatcher = new MessageDispatcher();
-                       userMessageQueues = new UserMessageQueues();
-                       jobChangedListenerChecker = new JobChangedListenerChecker();
-
-                       vm.start();
-                       dispatcher.start();
-                       jobChangedListenerChecker.start();
-
-                       startupExecutors();
-                       startUpBarrier.await();
-
-                       schedulerService = new SchedulerService(this);
-                       schedulerService.startup();
-                       bootstrap();
-                       isRunning = true;
-                       TSMClient.SetUpMultithread();
-               } catch (Exception e) {
-                       logger.error(e.getMessage());
-                       logger.error(e);
-               }
-               logger.info("JobEngine started");
-
-       }
-
-       private void startupExecutors() {
-               for (IJobStepExecutor executor : jobEngineConfiguration.getExecutors().values())
-                       executor.startup();
-       }
-
-       @Override
-       public void storeJob(IJobRuntime runtime) {
-               submittedJobs.put(runtime.getId(), runtime);
-               logger.debug("+++ {} stored in VM ", runtime);
-       }
-
-       private void submit(IJobRuntime runtime) {
-               runtime.setSubmitted(new Timestamp(System.currentTimeMillis()));
-               runtime.add();
-               addToRunQueue(runtime);
-               submittedJobs.put(runtime.getId(), runtime);
-               logger.debug("+++ {} added to VM ", runtime);
-       }
-
-       @Override
-       public IJobRuntime submit(IJobRuntime parent, IJobStatusChangedListener statusListener, String template,
-                       String name, int priority, String owner, Map<String, Object> parameters) throws JobEngineException {
-               IJobRuntime result = null;
-               IProgram program = getProgram(template);
-               if (program != null) {
-                       isRunnable(program);
-                       result = new JobRuntime(this, program);
-                       result.setPersister(itemManager);
-                       result.setTemplate(template);
-                       result.setName(name);
-                       result.setParameters(parameters);
-                       result.setPriority(priority);
-                       result.setService(program.getTemplate().isService());
-                       if (parent != null)
-                               result.setParentJobId(parent.getId());
-                       if (statusListener != null)
-                               result.addEventListener(statusListener);
-                       submit(result);
-               } else {
-                       logger.error("Unknown template {}", template);
-                       throw new JobEngineException("Unknown template " + template);
-               }
-               return result;
-       }
-
-       @Override
-       public IJobRuntime submit(IJobRuntime parent, IJobStatusChangedListener statusListener, String template,
-                       String name, Map<String, Object> parameters) throws JobEngineException {
-               IJobRuntime result = null;
-               result = submit(parent, statusListener, template, name, 0, DEFAULT_OWNER, parameters);
-               return result;
-       }
-
-       @Override
-       public IJobRuntime submit(IJobRuntime parent, String template, String name, int priority,
-                       Map<String, Object> parameters) throws JobEngineException {
-               IJobRuntime result = null;
-               result = submit(parent, null, template, name, 0, DEFAULT_OWNER, parameters);
-               return result;
-       }
-
-       IJobRuntime submit(IProgram program, IJobStatusChangedListener listener) {
-               IJobRuntime jobRuntime = new JobRuntime(this, program);
-               jobRuntime.addEventListener(listener);
-               addToRunQueue(jobRuntime);
-               return jobRuntime;
-       }
-
-       @Override
-       public IJobRuntime submit(String template, String name, Map<String, Object> parameters) throws JobEngineException {
-               // Az ütemezett task-okat configból a Quartz futtatja
-               if (isAllExecutionDisabled) {
-                       logger.info("JobEngine is disabled, can not submit job '{}'", name);
-                       return null;
-               }
-               IJobRuntime result = null;
-               IProgram program = getProgram(template);
-               result = submit(null, null, template, name == null ? program.getTemplate().getName() : name, 0, DEFAULT_OWNER,
-                               parameters);
-               return result;
-       }
-
-       @Override
-       public IJobRuntime submit(String template, String name, Map<String, Object> parameters, String owner)
-                       throws JobEngineException {
-               IJobRuntime result = null;
-               result = submit(null, null, template, name, 0, owner, parameters);
-               return result;
-       }
-
-       @Override
-       public void suspendExecutingJob(Throwable t, IJobRuntime jobRuntime) {
-               String description = t.getClass().getSimpleName() + " : " + t.getMessage();
-               jobRuntime.setDescription(description);
-               logger.error(description);
-               // TODO itt miert FINISH a kovetkezo allapot, miert nem SUSPEND
-               statusMachine.processAction(JobAction.FINISH, jobRuntime);
-               closeSessionLog(jobRuntime);
-       }
-
-       @Override
-       public void suspendWaitExecutorJob(Throwable t, IJobRuntime jobRuntime) {
-               String description = t.getMessage();
-               jobRuntime.setDescription(description);
-               logger.error(description);
-               statusMachine.processAction(JobAction.SUSPEND, jobRuntime);
-               closeSessionLog(jobRuntime);
-       }
-
-       public synchronized void unbindItemManagerService(IItemManager service) {
-               try {
-                       shutdown();
-               } catch (Exception e) {
-                       logger.error("Couldn't shutdown jobEngine", e);
-               }
-       }
-
-}
+package user.jobengine.server;\r
+\r
+import java.sql.Timestamp;\r
+import java.time.LocalDate;\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.Map.Entry;\r
+import java.util.Set;\r
+import java.util.concurrent.BlockingQueue;\r
+import java.util.concurrent.ConcurrentHashMap;\r
+import java.util.concurrent.CyclicBarrier;\r
+import java.util.concurrent.LinkedBlockingQueue;\r
+import java.util.concurrent.PriorityBlockingQueue;\r
+import java.util.concurrent.TimeUnit;\r
+import java.util.concurrent.atomic.AtomicLong;\r
+\r
+import org.apache.commons.lang.StringUtils;\r
+import org.apache.logging.log4j.LogManager;\r
+import org.apache.logging.log4j.Logger;\r
+\r
+import com.ibm.nosql.json.api.BasicDBList;\r
+import com.ibm.nosql.json.api.BasicDBObject;\r
+\r
+import user.commons.Job;\r
+import user.commons.JobStatus;\r
+import user.commons.cluster.ClusteredJob;\r
+import user.jobengine.db.IItemManager;\r
+import user.jobengine.db.ItemManagerData.SignalType;\r
+import user.jobengine.server.actions.IStatusMachine;\r
+import user.jobengine.server.actions.JobAction;\r
+import user.jobengine.server.actions.StatusMachine;\r
+import user.jobengine.server.ast.JobTemplate;\r
+import user.jobengine.server.instructions.CallJobStepInstruction;\r
+import user.jobengine.server.instructions.IInstruction;\r
+import user.jobengine.server.messagequeue.IUserMessage;\r
+import user.jobengine.server.messagequeue.IUserMessageQueues;\r
+import user.jobengine.server.messagequeue.UserMessageQueues;\r
+import user.jobengine.server.messages.IJobMessage;\r
+import user.jobengine.server.messages.JobStepCompletedMessage;\r
+import user.jobengine.server.messages.UserReplyMessage;\r
+import user.jobengine.server.scheduler.ScheduledJob;\r
+import user.jobengine.server.scheduler.SchedulerService;\r
+import user.tsm.client.TSMClient;\r
+import user.tsm.client.TSMException;\r
+\r
+/**\r
+ * MAM motor implementáció.\r
+ */\r
+public class JobEngine implements IJobEngine {\r
+\r
+       private class JobChangedListenerChecker extends Thread {\r
+               private volatile boolean shutdown = false;\r
+\r
+               @Override\r
+               public void run() {\r
+                       try {\r
+                               startUpBarrier.await();\r
+                       } catch (Exception e) {\r
+                       }\r
+\r
+                       while (!shutdown) {\r
+                               try {\r
+                                       Thread.sleep(1000);\r
+                                       removeJobChangedListenerGarbage();\r
+                               } catch (InterruptedException e) {\r
+                                       shutdown = true;\r
+                               }\r
+                       }\r
+               }\r
+\r
+               void shutDown() {\r
+                       shutdown = true;\r
+                       try {\r
+                               join();\r
+                       } catch (InterruptedException e) {\r
+                       }\r
+               }\r
+       }\r
+\r
+       private class MessageDispatcher extends Thread {\r
+               private volatile boolean shutdown = false;\r
+\r
+               @Override\r
+               public void run() {\r
+                       try {\r
+                               startUpBarrier.await();\r
+                       } catch (Exception e) {\r
+                       }\r
+\r
+                       while (!shutdown) {\r
+                               try {\r
+                                       IJobMessage message = messageQueue.poll(QUEUE_POLL_INTERVAL_MS, TimeUnit.MILLISECONDS);\r
+                                       if (message != null)\r
+                                               message.process(JobEngine.this);\r
+\r
+                               } catch (InterruptedException e) {\r
+                                       shutdown = true;\r
+                               }\r
+                       }\r
+                       // a leallitas utan az osszes fuggo uzenet vegrehajtasa\r
+                       while (!messageQueue.isEmpty()) {\r
+                               try {\r
+                                       IJobMessage message = messageQueue.poll(QUEUE_POLL_INTERVAL_MS, TimeUnit.MILLISECONDS);\r
+                                       if (message != null)\r
+                                               message.process(JobEngine.this);\r
+                               } catch (InterruptedException e) {\r
+                                       shutdown = true;\r
+                               }\r
+                       }\r
+               }\r
+\r
+               void shutDown() {\r
+                       shutdown = true;\r
+                       try {\r
+                               join();\r
+                       } catch (InterruptedException e) {\r
+                       }\r
+               }\r
+       }\r
+\r
+       private class VM extends Thread {\r
+               private volatile boolean shutdown = false;\r
+               private IInstruction ir = null;\r
+\r
+               @Override\r
+               public void run() {\r
+                       try {\r
+                               startUpBarrier.await();\r
+                       } catch (Exception e) {\r
+                       }\r
+\r
+                       while (!shutdown) {\r
+                               try {\r
+                                       Thread.sleep(QUEUE_POLL_INTERVAL_MS);\r
+                                       // IJobRuntime jobRuntime = runQueue.poll(QUEUE_POLL_INTERVAL_MS,\r
+                                       // TimeUnit.MILLISECONDS);\r
+                                       IJobRuntime jobRuntime = runQueue.poll();\r
+                                       if (jobRuntime != null) {\r
+                                               logger.debug("Processing {}", jobRuntime.getId());\r
+                                               // varakozo esetben vegrehajtjuk a kovetkezo utasitast\r
+                                               if (jobRuntime.hasNextInstruction() && jobRuntime.isWaitFinish()) {\r
+                                                       ir = jobRuntime.getNextInstruction();\r
+                                                       ir.execute(JobEngine.this, jobRuntime);\r
+                                               } else {\r
+                                                       // normal esetben elfutunk a kovetkezo job step-ig, vagy vegig\r
+                                                       while (jobRuntime.hasNextInstruction() && jobRuntime.isRunnable()) {\r
+                                                               ir = jobRuntime.getNextInstruction();\r
+                                                               ir.execute(JobEngine.this, jobRuntime);\r
+                                                       }\r
+                                               }\r
+\r
+                                               if (!jobRuntime.hasNextInstruction() && jobRuntime.isRunnable())\r
+                                                       jobCleanup(jobRuntime);\r
+\r
+                                       }\r
+                               } catch (Exception e) {\r
+                                       logger.error("Critical VM error!", e);\r
+                                       // shutdown = true;\r
+                               }\r
+                       }\r
+               }\r
+\r
+               void shutDown() {\r
+                       shutdown = true;\r
+                       try {\r
+                               join();\r
+                       } catch (InterruptedException e) {\r
+                       }\r
+               }\r
+       }\r
+\r
+       private static final Logger logger = LogManager.getLogger();\r
+       static private IItemManager itemManager;\r
+       private static JobEngine instance;\r
+\r
+       public static JobEngine getInstance() {\r
+               if (instance == null)\r
+                       instance = new JobEngine();\r
+               return instance;\r
+       }\r
+\r
+       static public IItemManager getStaticItemManager() {\r
+               return itemManager;\r
+       }\r
+\r
+       private volatile boolean isRunning;\r
+\r
+       private volatile boolean isAllExecutionDisabled;\r
+       private volatile boolean isScheduledExecutionDisabled;\r
+       private final BlockingQueue<IJobRuntime> runQueue;\r
+       private final BlockingQueue<IJobMessage> messageQueue;\r
+       private final Map<Long, IJobRuntime> submittedJobs;\r
+       private VM vm;\r
+       private MessageDispatcher dispatcher;\r
+       private JobChangedListenerChecker jobChangedListenerChecker;\r
+\r
+       private IUserMessageQueues userMessageQueues;\r
+\r
+       private final CyclicBarrier startUpBarrier;\r
+\r
+       private final IStatusMachine statusMachine;\r
+\r
+       private AtomicLong nextJobId;\r
+       private SchedulerService schedulerService = null;\r
+       private Set<IJobChangedListener> jobChangedListenerList = ConcurrentHashMap.newKeySet();\r
+       private Map<String, LocalDate> remoteWorkers;\r
+       private String masterServerAddress = System.getProperty("jobengine.master.server", "");\r
+       private final JobEngineRemote remoteEngine;\r
+\r
+       private ConcurrentHashMap<IJobChangedListener, Long> keepAliveJobChangedListeners = new ConcurrentHashMap<>();\r
+\r
+       private IJobEngineConfiguration jobEngineConfiguration;\r
+\r
+       /**\r
+        * A MAM motor példányosítása. Ennek során létrejönnek a várakozási sorok, az\r
+        * ütemező szál, az üzenet kezelő szál.\r
+        */\r
+       public JobEngine() {\r
+\r
+               runQueue = new PriorityBlockingQueue<IJobRuntime>();\r
+               messageQueue = new LinkedBlockingQueue<IJobMessage>();\r
+               submittedJobs = createJobs();\r
+               startUpBarrier = new CyclicBarrier(4);\r
+               nextJobId = new AtomicLong(0);\r
+               statusMachine = createStatusMachine();\r
+\r
+               if (instance == null)\r
+                       instance = this;\r
+               else\r
+                       throw new RuntimeException("Multiple JobEngine instances are not supported!");\r
+\r
+               remoteWorkers = new ConcurrentHashMap<>();\r
+               // logger.info("JobEngine created");\r
+               if (isWorker())\r
+                       remoteEngine = createRemoteEngine();\r
+               else\r
+                       remoteEngine = null;\r
+       }\r
+\r
+       public void activate() {\r
+       }\r
+\r
+       @Override\r
+       public boolean addJobChangedEventListener(IJobChangedListener listener) {\r
+               boolean result = !jobChangedListenerList.contains(listener);\r
+               if (listener != null && result)\r
+                       jobChangedListenerList.add(listener);\r
+\r
+               return result;\r
+       }\r
+\r
+       @Override\r
+       public void addToExecutorQueue(IJobRuntime jobRuntime) {\r
+               try {\r
+                       Object typeName = jobRuntime.popFromStack();\r
+                       if (typeName == null)\r
+                               throw new Exception(jobRuntime.toString() + " illegal execution state detected: executor name is null.");\r
+                       String executorName = String.valueOf(typeName);\r
+                       if (!jobEngineConfiguration.getExecutors().containsKey(executorName))\r
+                               throw new Exception(jobRuntime.toString() + " executor is unavailable: " + executorName);\r
+\r
+                       // a lista mindig letezik, de sima futtataskor csak 1 elemu, az aktualis van\r
+                       // benne\r
+                       // ha van parhuzamos futtatas, akkor letrejonnek benne a step szellemek is, es\r
+                       // meghivodik a fork\r
+                       List<IJobRuntime> jobs = spawnJobs(jobRuntime, executorName);\r
+                       jobEngineConfiguration.getExecutors().get(executorName).submit(jobs.toArray(new IJobRuntime[] {}));\r
+                       jobs.forEach(r -> fireJobChangedEvent(new JobChangedEvent(r, SignalType.EXECUTE)));\r
+\r
+               } catch (Exception e) {\r
+                       logger.catching(e);\r
+                       suspendWaitExecutorJob(e, jobRuntime);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void addToRunQueue(IJobRuntime jobRuntime) {\r
+               try {\r
+                       logger.debug("{} adding to run queue", jobRuntime);\r
+                       if (jobRuntime.getIp() == 0 && !jobRuntime.isService() && jobRuntime.getParentJobId() == 0)\r
+                               logger.info(jobRuntime.getSessionMarker(), "A '{}' folyamat elindult.", jobRuntime.getName());\r
+                       runQueue.put(jobRuntime);\r
+               } catch (Exception e) {\r
+                       logger.error(e.getMessage(), e);\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Job prioritasa megvaltozott. Job main queue-ban es a JobStepExecutorok\r
+        * soraiban is ujra kell rendezni a jobokat. Az ujrarendezes a put-nal is megy\r
+        * automatikusan, mivel eltero prioritasu jobot dobhatnak be vagy default\r
+        * prioritasut a korabban atrendezett listaba.\r
+        *\r
+        * @param jobRuntime\r
+        */\r
+       @Override\r
+       public void applyPriorityChange(IJobRuntime jobRuntime) {\r
+               logger.info("rePrioritization start for {}", jobRuntime.getId());\r
+               // synchronized(this.runQueue){\r
+\r
+               // job main queue reorder\r
+\r
+               if (this.runQueue.contains(jobRuntime)) {\r
+                       logger.info("runQueue");\r
+                       this.runQueue.remove(jobRuntime);\r
+                       try {\r
+                               this.runQueue.put(jobRuntime);\r
+                       } catch (InterruptedException e) {\r
+                       }\r
+               }\r
+\r
+               // JobStepExecutor reorder\r
+               if (jobEngineConfiguration.getExecutors() != null) {\r
+                       for (IJobStepExecutor exec : jobEngineConfiguration.getExecutors().values()) {\r
+                               if (exec.containsRuntime(jobRuntime)) {\r
+                                       logger.info("executor");\r
+                                       exec.changePriority(jobRuntime);\r
+                               }\r
+                       }\r
+               }\r
+\r
+               // } logger.info("rePrioritization end");\r
+       }\r
+\r
+       @Override\r
+       public synchronized void bindItemManagerService(IItemManager service) {\r
+               setItemManager(service);\r
+       }\r
+\r
+       public synchronized void bindJobEngineConfiguration(Object service) {\r
+               if (service instanceof JobEngineConfiguration) {\r
+                       jobEngineConfiguration = (IJobEngineConfiguration) service;\r
+                       isScheduledExecutionDisabled = jobEngineConfiguration.isScheduledExecutionDisabled();\r
+                       logger.info("IJobEngineConfiguration service binded");\r
+               }\r
+       }\r
+\r
+       private void bootstrap() throws JobEngineException {\r
+               // submit("fake-noparams.xml", "Bootstrap", null);\r
+       }\r
+\r
+       private void closeSessionLog(IJobRuntime jobRuntime) {\r
+               if (!jobRuntime.isService() && jobRuntime.getParentJobId() == 0) {\r
+                       if (JobStatus.FINISHED.equals(jobRuntime.getStatus()))\r
+                               logger.info(jobRuntime.getFinishMarker(), "A(z) '{}' folyamat futása sikeresen véget ért.", jobRuntime.getName());\r
+                       else\r
+                               logger.error(jobRuntime.getFinishMarker(), "A(z) '{}' folyamat futása megszakadt.", jobRuntime.getName());\r
+               }\r
+       }\r
+\r
+       protected Map<Long, IJobRuntime> createJobs() {\r
+               return new ConcurrentHashMap<Long, IJobRuntime>();\r
+       }\r
+\r
+       protected JobEngineRemote createRemoteEngine() {\r
+               return new JobEngineRemote(masterServerAddress);\r
+       }\r
+\r
+       protected IStatusMachine createStatusMachine() {\r
+               return new StatusMachine(this);\r
+       }\r
+\r
+       public void deactivate() {\r
+       }\r
+\r
+       @Override\r
+       public void executeAssignVariableInstruction(IJobRuntime jobRuntime) {\r
+               Object value = jobRuntime.popFromStack();\r
+               String name = (String) jobRuntime.popFromStack();\r
+\r
+               // a gyerek job-ok visszateresi erteket a spawn sorszammal kiegeszitve mentjuk\r
+               // TODO el kell tudni erni a kovetkezo lepesekbol ezeket az ertekeket\r
+               if (jobRuntime.getParentJobId() > 0) {\r
+                       IJobRuntime parentRuntime = getJobById(jobRuntime.getParentJobId());\r
+                       parentRuntime.setVariable(name + jobRuntime.getSpawnOrder(), value);\r
+               }\r
+\r
+               jobRuntime.setVariable(name, value);\r
+       }\r
+\r
+       /***\r
+        * Fuggetlen (beagyazott) alfolyamat letrehozasa\r
+        */\r
+       @Override\r
+       public void executeCallConcurrentJobStepInstruction(IJobRuntime jobRuntime, IProgram subProgram) {\r
+               JobRuntime c = new JobRuntime(this, jobRuntime, subProgram);\r
+               jobRuntime.addChild(c);\r
+               submit(c);\r
+       }\r
+\r
+       @Override\r
+       public void executeCallJobStepInstruction(IJobRuntime jobRuntime) {\r
+               statusMachine.processAction(JobAction.EXECUTE, jobRuntime);\r
+       }\r
+\r
+       @Override\r
+       public void executeCheckParameterInstruction(IJobRuntime jobRuntime) {\r
+               try {\r
+                       jobRuntime.checkStackParameter();\r
+               } catch (Exception e) {\r
+                       logger.error(e.getMessage());\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void executeDeclareVariableInstruction(IJobRuntime jobRuntime) {\r
+               Class<?> type = (Class<?>) jobRuntime.popFromStack();\r
+               String name = (String) jobRuntime.popFromStack();\r
+               jobRuntime.addVariable(name, type);\r
+       }\r
+\r
+       @Override\r
+       public void executeGetParameterInstruction(IJobRuntime jobRuntime) {\r
+               try {\r
+                       String name = (String) jobRuntime.popFromStack();\r
+                       Object value = jobRuntime.getParameter(name);\r
+                       jobRuntime.pushToStack(value);\r
+               } catch (Exception e) {\r
+                       logger.error(e.getMessage());\r
+                       jobRuntime.setDescription(e.getMessage());\r
+                       suspendWaitExecutorJob(e, jobRuntime);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void executeGetVariableInstruction(IJobRuntime jobRuntime) {\r
+               try {\r
+                       String name = (String) jobRuntime.popFromStack();\r
+                       Object value = jobRuntime.getVariable(name);\r
+                       jobRuntime.pushToStack(value);\r
+               } catch (Exception e) {\r
+                       logger.error(e.getMessage());\r
+                       jobRuntime.setDescription(e.getMessage());\r
+                       suspendWaitExecutorJob(e, jobRuntime);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void executePushToStackInstruction(IJobRuntime jobRuntime, Object item) {\r
+               jobRuntime.pushToStack(item);\r
+       }\r
+\r
+       @Override\r
+       public void executeSendMessageToUserInstruction(IJobRuntime jobRuntime) {\r
+               statusMachine.processAction(JobAction.MESSAGE, jobRuntime);\r
+\r
+               int messageNumber = (Integer) jobRuntime.popFromStack();\r
+               String catalogName = (String) jobRuntime.popFromStack();\r
+               Object[] inputs = getInputsFromStack(jobRuntime);\r
+               getUserMessageQueues().addMessage(jobRuntime, catalogName, messageNumber, true, inputs);\r
+       }\r
+\r
+       @Override\r
+       public void executeWaitForSpawnJobsInstruction(IJobRuntime jobRuntime) {\r
+               // logger.info("Processing {} {}", jobRuntime.getId(),\r
+               // jobRuntime.canContinueExecution());\r
+\r
+               if (jobRuntime.canContinueExecution()) {\r
+                       jobRuntime.setStatus(JobStatus.RUNNABLE);\r
+               } else {\r
+                       if (!JobStatus.WAIT_FINISH.equals(jobRuntime.getStatus())) {\r
+                               jobRuntime.setStatus(JobStatus.WAIT_FINISH);\r
+                       }\r
+                       jobRuntime.decrementInstructionPointer();\r
+               }\r
+               addToRunQueue(jobRuntime);\r
+       }\r
+\r
+       @Override\r
+       public void fireJobChangedEvent(JobChangedEvent event) {\r
+               for (IJobChangedListener listener : jobChangedListenerList) {\r
+                       listener.jobChanged(event);\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public Object[] getInputsFromStack(IJobRuntime jobRuntime) {\r
+               jobRuntime.swapStack();\r
+               Integer parameterCount = (Integer) jobRuntime.popFromStack();\r
+               Object[] result = new Object[parameterCount];\r
+               for (int index = 0; index < parameterCount; index++) {\r
+                       result[index] = jobRuntime.popFromStack();\r
+               }\r
+               return result;\r
+       }\r
+\r
+       @Override\r
+       public IItemManager getItemManager() {\r
+               return itemManager;\r
+       }\r
+\r
+       @Override\r
+       public Job getJob(long id) {\r
+               Job result = null;\r
+               if (submittedJobs.containsKey(id))\r
+                       result = (Job) submittedJobs.get(id);\r
+               return result;\r
+       }\r
+\r
+       @Override\r
+       public IJobRuntime getJobById(long jobId) {\r
+               if (!submittedJobs.containsKey(jobId)) {\r
+                       logger.warn("Job does not exist anymore {}. Possibly canceled already.", jobId);\r
+               }\r
+               return submittedJobs.get(jobId);\r
+       }\r
+\r
+       @Override\r
+       public IJobEngineConfiguration getJobEngineConfiguration() {\r
+               return jobEngineConfiguration;\r
+       }\r
+\r
+       @Override\r
+       public Map<Long, IJobRuntime> getJobs() {\r
+               return submittedJobs;\r
+       }\r
+\r
+       protected long getNextJobId() {\r
+               return nextJobId.incrementAndGet();\r
+       }\r
+\r
+       @Override\r
+       public IProgram getProgram(String name) {\r
+               return jobEngineConfiguration.getPrograms().get(name);\r
+       }\r
+\r
+       @Override\r
+       public JobEngineRemote getRemoteEngine() {\r
+               return remoteEngine;\r
+       }\r
+\r
+       @Override\r
+       public ScheduledJob getScheduledJob(String template) throws Exception {\r
+               ArrayList<Entry<String, BasicDBObject>> schedules = jobEngineConfiguration.getSchedules();\r
+               BasicDBObject schedule = null;\r
+               boolean templateFirstOccurence = false;\r
+\r
+               for (int index = 0; index < schedules.size(); index++) {\r
+                       if (schedules.get(index).getKey().equals(template)) {\r
+                               if (!templateFirstOccurence) {\r
+                                       templateFirstOccurence = true;\r
+                                       schedule = schedules.get(index).getValue();\r
+                               } else {\r
+                                       throw new Exception("Key " + template + " is already contained in scheduled jobs!");\r
+                               }\r
+                       }\r
+               }\r
+\r
+               if (schedule == null)\r
+                       return null;\r
+               return jobEngineConfiguration.createScheduledJob(schedule, this);\r
+       }\r
+\r
+       @Override\r
+       public SchedulerService getScheduler() {\r
+               return schedulerService;\r
+       }\r
+\r
+       @Override\r
+       public IUserMessageQueues getUserMessageQueues() {\r
+               return userMessageQueues;\r
+       }\r
+\r
+       @Override\r
+       public boolean isAllExecutionDisabled() {\r
+               return isAllExecutionDisabled;\r
+       }\r
+\r
+       private void isRunnable(IProgram program) throws JobEngineException {\r
+               JobTemplate template = program.getTemplate();\r
+               // A JOB xml-ben beállítható, hogy futhatnak-e párhuzamosan.\r
+               if (template.isMultiInstance())\r
+                       return;\r
+\r
+               // Collection<IJobRuntime> values = getJobs().values();\r
+\r
+               // vegigmenni a submittedJobs-on!\r
+\r
+               Set<Long> ids = submittedJobs.keySet();\r
+               for (long id : ids) {\r
+                       if (!submittedJobs.containsKey(id))\r
+                               continue;\r
+\r
+                       IJobRuntime runtime = submittedJobs.get(id);\r
+                       if (runtime == null)\r
+                               continue;\r
+\r
+                       if (!template.getFileName().equals(runtime.getTemplate()))\r
+                               continue;\r
+\r
+                       // 'EXECUTING', 'WAIT_EXECUTOR', 'WAIT_SUSPEND', 'RUNNABLE'\r
+                       if (runtime.isExecuting() || runtime.isRunnable() || runtime.isWaitingSuspend() || runtime.isWaitingExecutor())\r
+                               throw new JobEngineException(String.format("Can not submit job. Job with %s.%s already running", template.getFileName(), template.getName()));\r
+               }\r
+               /*\r
+                * List<Job> runningJobs = itemManager.getRunningJobs(template.getFileName());\r
+                * if (runningJobs != null) { for (Job job : runningJobs) { Job runningJob =\r
+                * getJob(job.getId());\r
+                *\r
+                * if (runningJob != null && runningJob.getStatus() != JobStatus.SUSPENDED)\r
+                * throw new JobEngineException(String.\r
+                * format("Can not submit job. Job with %s.%s already running",\r
+                * template.getFileName(), template.getName())); } }\r
+                */\r
+       }\r
+\r
+       @Override\r
+       public boolean isRunning() {\r
+               return isRunning;\r
+       }\r
+\r
+       @Override\r
+       public boolean isScheduledExecutionDisabled() {\r
+               return isScheduledExecutionDisabled;\r
+       }\r
+\r
+       @Override\r
+       public boolean isWorker() {\r
+               return masterServerAddress.length() > 0;\r
+       }\r
+\r
+       @Override\r
+       public void jobCleanup(IJobRuntime jobRuntime) {\r
+               logger.info("Cleanup {}", jobRuntime.getId());\r
+               statusMachine.processAction(JobAction.FINISH, jobRuntime);\r
+       }\r
+\r
+       @Override\r
+       public boolean keepAliveJobChangedListener(IJobChangedListener listener) {\r
+               boolean result = false;\r
+               if (keepAliveJobChangedListeners != null) {\r
+                       long now = System.currentTimeMillis();\r
+                       // ha mar hozza van adva, nem adja hozza\r
+                       result = addJobChangedEventListener(listener);\r
+                       keepAliveJobChangedListeners.put(listener, now);\r
+                       logger.debug("Refreshing listener {}, now {} ({})", listener, now, keepAliveJobChangedListeners.size());\r
+               }\r
+\r
+               return result;\r
+       }\r
+\r
+       @Deprecated\r
+       @Override\r
+       public void keepAliveWorker(String remoteAddr) {\r
+               remoteWorkers.put(remoteAddr, LocalDate.now());\r
+       }\r
+\r
+       @Override\r
+       public void processCancelRequest(IJobMessage message) {\r
+               IJobRuntime jobRuntime = getJobById(message.getJobId());\r
+\r
+               if (jobRuntime == null) {\r
+                       logger.warn("Job with id {} does not exist!", message.getJobId());\r
+                       return;\r
+               }\r
+\r
+               // a gyerekek miatt nem az!\r
+               if (!jobRuntime.isCancelable())\r
+                       return;\r
+\r
+               // Ha a jobs tartalmazta ezt a job-ot, akkor kikerül belőle.\r
+               // if (jobs.containsKey(message.getJobId()))\r
+               // jobs.remove(message.getJobId());\r
+               statusMachine.processAction(JobAction.CANCEL, jobRuntime);\r
+       }\r
+\r
+       @Override\r
+       public void processJobStepCompletedMessage(IJobMessage message) {\r
+               IJobRuntime jobRuntime = getJobById(message.getJobId());\r
+\r
+               if (jobRuntime == null) {\r
+                       logger.warn("Job with id {} does not exist!", message.getJobId());\r
+                       return;\r
+               }\r
+\r
+               // TODO ez hibat okoz az archivalasnal, mert hamarabb eltavolitja a childUd-ket\r
+\r
+               // if (jobRuntime.getParentJobId() > 0)\r
+               // removeSpanwChild(jobRuntime);\r
+\r
+               JobStepCompletedMessage m = (JobStepCompletedMessage) message;\r
+               // kesz vagyunk, jelezni\r
+               if (isWorker()) {\r
+                       statusMachine.processAction(JobAction.DONE, jobRuntime);\r
+                       return;\r
+               }\r
+\r
+               // a cancel hamarabb megjott?\r
+               // ha remote akkor tuti\r
+               if (jobRuntime == null) {\r
+\r
+               }\r
+               Object[] outputs = m.getOutputs();\r
+               putOutputsToStack(jobRuntime, outputs);\r
+\r
+               statusMachine.processAction(JobAction.DONE, jobRuntime);\r
+       }\r
+\r
+       @Override\r
+       public void processJobStepSkippedMessage(IJobMessage message) {\r
+               IJobRuntime jobRuntime = getJobById(message.getJobId());\r
+               statusMachine.processAction(JobAction.SKIP, jobRuntime);\r
+       }\r
+\r
+       @Override\r
+       public void processReplyMessage(IJobMessage message) {\r
+               IJobRuntime jobRuntime = getJobById(message.getJobId());\r
+               UserReplyMessage m = (UserReplyMessage) message;\r
+               IUserMessage userMessage = getUserMessageQueues().getUserMessages().get(m.getMessageId());\r
+               userMessage.setReply((Integer) m.getReply());\r
+               userMessage.setMustReply(false);\r
+               jobRuntime.pushToStack(m.getReply());\r
+               statusMachine.processAction(JobAction.REPLY, jobRuntime);\r
+       }\r
+\r
+       @Override\r
+       public void processRestartRequest(IJobMessage message) {\r
+               Job job = (Job) itemManager.get(Job.class, message.getJobId());\r
+               if (job != null) {\r
+                       IProgram program = getProgram(job.getTemplate());\r
+                       if (program != null) {\r
+                               IJobRuntime result = new JobRuntime(this, program, job, itemManager);\r
+                               result.setStatus(JobStatus.CANCELED);\r
+                               statusMachine.processAction(JobAction.RESTART, result);\r
+                       }\r
+               } else {\r
+                       logger.info("JobEngine processRestartReqest: Job is null");\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void processResumeRequest(IJobMessage message) {\r
+               IJobRuntime jobRuntime = getJobById(message.getJobId());\r
+               statusMachine.processAction(JobAction.RESUME, jobRuntime);\r
+       }\r
+\r
+       @Override\r
+       public void processSuspendRequest(IJobMessage message) {\r
+               IJobRuntime jobRuntime = getJobById(message.getJobId());\r
+               statusMachine.processAction(JobAction.SUSPEND, jobRuntime);\r
+       }\r
+\r
+       @Override\r
+       public void putOutputsToStack(IJobRuntime jobRuntime, Object[] outputs) {\r
+               if (outputs != null) {\r
+                       for (Object object : outputs) {\r
+                               jobRuntime.pushToStack(object);\r
+                       }\r
+                       jobRuntime.arrangeStack();\r
+               }\r
+       }\r
+\r
+       @Override\r
+       public void reloadGracefully() throws Exception {\r
+               if (schedulerService != null)\r
+                       schedulerService.shutdown();\r
+\r
+               jobEngineConfiguration.resetStepClassLoader();\r
+               jobEngineConfiguration.load(this, true);\r
+\r
+               schedulerService = new SchedulerService(this);\r
+               schedulerService.startup();\r
+               logger.info("JobEngine gracefully reloaded");\r
+               isRunning = true;\r
+       }\r
+\r
+       @Override\r
+       public void removeFromExecutorQueue(IJobRuntime jobRuntime) {\r
+               for (IJobStepExecutor executor : jobEngineConfiguration.getExecutors().values())\r
+                       executor.revoke(jobRuntime);\r
+       }\r
+\r
+       @Override\r
+       public void removeFromRunQueue(IJobRuntime jobRuntime) {\r
+               runQueue.remove(jobRuntime);\r
+       }\r
+\r
+       @Override\r
+       public void removeGarbage() {\r
+               List<Long> removeId = new ArrayList<>();\r
+               for (Long id : submittedJobs.keySet()) {\r
+                       IJobRuntime runtime = submittedJobs.get(id);\r
+                       if (runtime != null && (JobStatus.SUSPENDED.equals(runtime.getStatus()) || JobStatus.CANCELED.equals(runtime.getStatus())))\r
+                               removeId.add(id);\r
+               }\r
+               for (Long id : removeId)\r
+                       submittedJobs.remove(id);\r
+       }\r
+\r
+       @Override\r
+       public void removeJob(long id) {\r
+               if (submittedJobs.containsKey(id)) {\r
+                       IJobRuntime jobRuntime = submittedJobs.remove(id);\r
+                       fireJobChangedEvent(new JobChangedEvent(jobRuntime, SignalType.DELETE));\r
+                       logger.debug("--- {} removed from VM", jobRuntime);\r
+                       closeSessionLog(jobRuntime);\r
+               }\r
+\r
+       }\r
+\r
+       @Override\r
+       public void removeJobChangedEventListener(IJobChangedListener listener) {\r
+               if (listener != null) {\r
+                       jobChangedListenerList.remove(listener);\r
+               }\r
+       }\r
+\r
+       synchronized protected void removeJobChangedListenerGarbage() {\r
+               List<IJobChangedListener> toBeRemoved = new ArrayList<>();\r
+               for (IJobChangedListener listener : keepAliveJobChangedListeners.keySet()) {\r
+                       long lastMod = keepAliveJobChangedListeners.get(listener);\r
+                       long now = System.currentTimeMillis();\r
+                       if ((now - lastMod) > 5 * 1000) {\r
+\r
+                               toBeRemoved.add(listener);\r
+                               logger.debug("{} refreshed {}, now {}", listener, lastMod, now);\r
+                       }\r
+               }\r
+               toBeRemoved.forEach(r -> {\r
+                       logger.debug("Removing listener {}", r);\r
+                       removeJobChangedEventListener(r);\r
+                       keepAliveJobChangedListeners.remove(r);\r
+               });\r
+       }\r
+\r
+       @Override\r
+       public void removeSpanwChild(IJobRuntime jobRuntime) {\r
+               IJobRuntime parent = getJobById(jobRuntime.getParentJobId());\r
+               if (parent == null)\r
+                       return;\r
+\r
+               parent.removeSpanwChild(jobRuntime.getId());\r
+\r
+       }\r
+\r
+       @Override\r
+       public ClusteredJob requestJob(String className) throws Exception {\r
+               IJobStepExecutor executor = jobEngineConfiguration.getExecutors().get(className);\r
+               if (executor == null)\r
+                       throw new Exception("Unregistered executor request: " + className);\r
+               if (!executor.isRemoteEnabled())\r
+                       throw new Exception("Job is not registered for remote workers: " + className);\r
+\r
+               ClusteredJob job = executor.steelJob();\r
+               return job;\r
+       }\r
+\r
+       @Override\r
+       public void restartGracefully() throws Exception {\r
+               isRunning = false;\r
+               if (schedulerService != null)\r
+                       schedulerService.shutdown();\r
+\r
+               vm.shutDown();\r
+               shutdownExecutors();\r
+\r
+               startUpBarrier.reset();\r
+               logger.info("JobEngine gracefully stopped");\r
+\r
+               jobEngineConfiguration.resetStepClassLoader();\r
+               jobEngineConfiguration.load(this, false);\r
+\r
+               vm.start();\r
+\r
+               startupExecutors();\r
+               startUpBarrier.await();\r
+\r
+               schedulerService = new SchedulerService(this);\r
+               schedulerService.startup();\r
+               logger.info("JobEngine gracefully started");\r
+               isRunning = true;\r
+       }\r
+\r
+       @Override\r
+       public void sendMessage(IJobMessage jobMessage) {\r
+               messageQueue.add(jobMessage);\r
+       }\r
+\r
+       @Override\r
+       public void setAllExecutionDisabled(boolean isDisabled) {\r
+               this.isAllExecutionDisabled = isDisabled;\r
+       }\r
+\r
+       @Override\r
+       public void setItemManager(IItemManager _itemManager) {\r
+               itemManager = _itemManager;\r
+       }\r
+\r
+       @Override\r
+       public void setScheduledExecutionDisabled(boolean isDisabled) {\r
+               this.isScheduledExecutionDisabled = isDisabled;\r
+       }\r
+\r
+       @Override\r
+       public void shutdown() {\r
+               isRunning = false;\r
+               if (schedulerService != null)\r
+                       schedulerService.shutdown();\r
+\r
+               vm.shutDown();\r
+               shutdownExecutors();\r
+               dispatcher.shutDown();\r
+               jobChangedListenerChecker.shutDown();\r
+\r
+               try {\r
+                       TSMClient.CleanUpMultithread();\r
+               } catch (TSMException e) {\r
+                       logger.catching(e);\r
+               }\r
+               logger.info("JobEngine stopped");\r
+       }\r
+\r
+       private void shutdownExecutors() {\r
+               Collection<IJobStepExecutor> executors = jobEngineConfiguration.getExecutors().values();\r
+               for (IJobStepExecutor executor : executors) {\r
+                       logger.trace("Notify executor {}", executor.getStepUnitName());\r
+                       executor.shutdown();\r
+               }\r
+               for (IJobStepExecutor executor : executors) {\r
+                       logger.info("Stopping executor {}", executor.getStepUnitName());\r
+                       executor.waitShutdown();\r
+               }\r
+\r
+       }\r
+\r
+       private List<IJobRuntime> spawnJobs(IJobRuntime jobRuntime, String executorName) throws InterruptedException {\r
+               List<IJobRuntime> result = new ArrayList<>();\r
+\r
+               CallJobStepInstruction currentInstruction = jobRuntime.getCurrentCallJobStepInstruction();\r
+               if (currentInstruction != null) {\r
+                       String forEach = currentInstruction.getForEach();\r
+                       if (StringUtils.isNotBlank(forEach)) {\r
+                               Object parameter = jobRuntime.getParameter(forEach);\r
+                               if (parameter == null)\r
+                                       parameter = jobRuntime.getVariable(forEach);\r
+\r
+                               // a sima array helyett ezt jobb hasznalni\r
+                               if (parameter != null && parameter instanceof BasicDBList) {\r
+\r
+                                       BasicDBList iter = (BasicDBList) parameter;\r
+                                       for (int i = 1; i < iter.size(); i++) {\r
+                                               IJobRuntime jobRuntimeCopy = new JobRuntime(jobRuntime);\r
+                                               jobRuntimeCopy.setSpawnOrder(i);\r
+                                               jobRuntimeCopy.add();\r
+\r
+                                               jobRuntime.addSpawnChild(jobRuntimeCopy);\r
+\r
+                                               storeJob(jobRuntimeCopy);\r
+                                               result.add(jobRuntimeCopy);\r
+                                       }\r
+                               }\r
+                       }\r
+\r
+               }\r
+\r
+               result.add(jobRuntime);\r
+               return result;\r
+       }\r
+\r
+       @Override\r
+       public void startup() {\r
+               try {\r
+                       removeGarbage();\r
+\r
+                       jobEngineConfiguration.load(this, false);\r
+\r
+                       vm = new VM();\r
+                       dispatcher = new MessageDispatcher();\r
+                       userMessageQueues = new UserMessageQueues();\r
+                       jobChangedListenerChecker = new JobChangedListenerChecker();\r
+\r
+                       vm.start();\r
+                       dispatcher.start();\r
+                       jobChangedListenerChecker.start();\r
+\r
+                       startupExecutors();\r
+                       startUpBarrier.await();\r
+\r
+                       schedulerService = new SchedulerService(this);\r
+                       schedulerService.startup();\r
+                       bootstrap();\r
+                       isRunning = true;\r
+                       TSMClient.SetUpMultithread();\r
+               } catch (Exception e) {\r
+                       logger.error(e.getMessage());\r
+                       logger.error(e);\r
+               }\r
+               logger.info("JobEngine started");\r
+\r
+       }\r
+\r
+       private void startupExecutors() {\r
+               for (IJobStepExecutor executor : jobEngineConfiguration.getExecutors().values())\r
+                       executor.startup();\r
+       }\r
+\r
+       @Override\r
+       public void storeJob(IJobRuntime runtime) {\r
+               submittedJobs.put(runtime.getId(), runtime);\r
+               logger.debug("+++ {} stored in VM ", runtime);\r
+       }\r
+\r
+       private void submit(IJobRuntime runtime) {\r
+               runtime.setSubmitted(new Timestamp(System.currentTimeMillis()));\r
+               runtime.add();\r
+               addToRunQueue(runtime);\r
+               submittedJobs.put(runtime.getId(), runtime);\r
+               logger.debug("+++ {} added to VM ", runtime);\r
+       }\r
+\r
+       @Override\r
+       public IJobRuntime submit(IJobRuntime parent, IJobStatusChangedListener statusListener, String template, String name, int priority, String owner,\r
+                       Map<String, Object> parameters) throws JobEngineException {\r
+               IJobRuntime result = null;\r
+               IProgram program = getProgram(template);\r
+               if (program != null) {\r
+                       isRunnable(program);\r
+                       result = new JobRuntime(this, program);\r
+                       result.setPersister(itemManager);\r
+                       result.setTemplate(template);\r
+                       result.setName(name);\r
+                       result.setParameters(parameters);\r
+                       result.setPriority(priority);\r
+                       result.setService(program.getTemplate().isService());\r
+                       if (parent != null)\r
+                               result.setParentJobId(parent.getId());\r
+                       if (statusListener != null)\r
+                               result.addEventListener(statusListener);\r
+                       submit(result);\r
+               } else {\r
+                       logger.error("Unknown template {}", template);\r
+                       throw new JobEngineException("Unknown template " + template);\r
+               }\r
+               return result;\r
+       }\r
+\r
+       @Override\r
+       public IJobRuntime submit(IJobRuntime parent, IJobStatusChangedListener statusListener, String template, String name, Map<String, Object> parameters)\r
+                       throws JobEngineException {\r
+               IJobRuntime result = null;\r
+               result = submit(parent, statusListener, template, name, 0, DEFAULT_OWNER, parameters);\r
+               return result;\r
+       }\r
+\r
+       @Override\r
+       public IJobRuntime submit(IJobRuntime parent, String template, String name, int priority, Map<String, Object> parameters) throws JobEngineException {\r
+               IJobRuntime result = null;\r
+               result = submit(parent, null, template, name, 0, DEFAULT_OWNER, parameters);\r
+               return result;\r
+       }\r
+\r
+       IJobRuntime submit(IProgram program, IJobStatusChangedListener listener) {\r
+               IJobRuntime jobRuntime = new JobRuntime(this, program);\r
+               jobRuntime.addEventListener(listener);\r
+               addToRunQueue(jobRuntime);\r
+               return jobRuntime;\r
+       }\r
+\r
+       @Override\r
+       public IJobRuntime submit(String template, String name, Map<String, Object> parameters) throws JobEngineException {\r
+               // Az ütemezett task-okat configból a Quartz futtatja\r
+               if (isAllExecutionDisabled) {\r
+                       logger.info("JobEngine is disabled, can not submit job '{}'", name);\r
+                       return null;\r
+               }\r
+               IJobRuntime result = null;\r
+               IProgram program = getProgram(template);\r
+               result = submit(null, null, template, name == null ? program.getTemplate().getName() : name, 0, DEFAULT_OWNER, parameters);\r
+               return result;\r
+       }\r
+\r
+       @Override\r
+       public IJobRuntime submit(String template, String name, Map<String, Object> parameters, String owner) throws JobEngineException {\r
+               IJobRuntime result = null;\r
+               result = submit(null, null, template, name, 0, owner, parameters);\r
+               return result;\r
+       }\r
+\r
+       @Override\r
+       public void suspendExecutingJob(Throwable t, IJobRuntime jobRuntime) {\r
+               String description = t.getClass().getSimpleName() + " : " + t.getMessage();\r
+               jobRuntime.setDescription(description);\r
+               logger.error(description);\r
+               // TODO itt miert FINISH a kovetkezo allapot, miert nem SUSPEND\r
+               statusMachine.processAction(JobAction.FINISH, jobRuntime);\r
+               closeSessionLog(jobRuntime);\r
+       }\r
+\r
+       @Override\r
+       public void suspendWaitExecutorJob(Throwable t, IJobRuntime jobRuntime) {\r
+               String description = t.getMessage();\r
+               jobRuntime.setDescription(description);\r
+               logger.error(description);\r
+               statusMachine.processAction(JobAction.SUSPEND, jobRuntime);\r
+               closeSessionLog(jobRuntime);\r
+       }\r
+\r
+       public synchronized void unbindItemManagerService(IItemManager service) {\r
+               try {\r
+                       shutdown();\r
+               } catch (Exception e) {\r
+                       logger.error("Couldn't shutdown jobEngine", e);\r
+               }\r
+       }\r
+\r
+}\r
index ccae13d47ff24410c35b19244da758951f273d15..7ff3e5d12a6628d443a67c3a482abc2613aabc01 100644 (file)
@@ -73,6 +73,14 @@ public class JobEngineConfiguration implements IJobEngineConfiguration {
        private GroovyClassLoader groovyClassLoader;\r
        private DynamicStepsLoader dynamicStepsLoader;\r
 \r
+       static JobEngineConfiguration currentInstance = null;\r
+\r
+       static public JobEngineConfiguration getInstance() {\r
+               if (currentInstance == null)\r
+                       currentInstance = new JobEngineConfiguration();\r
+               return currentInstance;\r
+       }\r
+\r
        public synchronized void bindSystemConfiguration(Object service) {\r
                if (service instanceof IConfiguration) {\r
                        systemConfig = (IConfiguration) service;\r
@@ -91,8 +99,7 @@ public class JobEngineConfiguration implements IJobEngineConfiguration {
        public IJobStep createJobStep(String stepUnitName) throws Exception {\r
                IJobStep result = null;\r
 \r
-               boolean isGroovyClass = stepUnitName.toLowerCase().endsWith(".java")\r
-                               || stepUnitName.toLowerCase().endsWith(".groovy");\r
+               boolean isGroovyClass = stepUnitName.toLowerCase().endsWith(".java") || stepUnitName.toLowerCase().endsWith(".groovy");\r
                logger.info("Looking for {} step ClassLoader requirement", stepUnitName);\r
 \r
                if (resetStepClassLoader) {\r
@@ -125,8 +132,7 @@ public class JobEngineConfiguration implements IJobEngineConfiguration {
 \r
                if (isGroovyClass) {\r
                        if (dynamicStepsLoader != null)\r
-                               stepClass = (Class<IJobStep>) dynamicStepsLoader.loadClassFromSourceCode(groovyClassLoader,\r
-                                               stepUnitName);\r
+                               stepClass = (Class<IJobStep>) dynamicStepsLoader.loadClassFromSourceCode(groovyClassLoader, stepUnitName);\r
                } else\r
                        stepClass = (Class<IJobStep>) stepsClassLoader.loadClass(stepUnitName);\r
 \r
@@ -278,8 +284,7 @@ public class JobEngineConfiguration implements IJobEngineConfiguration {
                                                int newMaxConcurrent = executor.getMaxConcurrent();\r
                                                if (currentMaxConcurrent != newMaxConcurrent) {\r
                                                        stepExecutor.setMaxConcurrent(newMaxConcurrent);\r
-                                                       logger.info("Executor maxConcurrent changed from {} to {}", currentMaxConcurrent,\r
-                                                                       newMaxConcurrent);\r
+                                                       logger.info("Executor maxConcurrent changed from {} to {}", currentMaxConcurrent, newMaxConcurrent);\r
                                                }\r
                                        }\r
 \r
@@ -301,8 +306,16 @@ public class JobEngineConfiguration implements IJobEngineConfiguration {
 \r
                // a kulcs nem lehet a template, mert kulonbozo parameterekkel is benne lehet!\r
                schedules.clear();\r
-               String configFilePath = systemConfig.getConfig(JobEngineConfiguration.CONF_SCHEDULES);\r
-               logger.info("Loading scheduler configuration file {}", configFilePath);\r
+               String configFilePath = null;\r
+\r
+               try {\r
+                       configFilePath = systemConfig.getConfig(JobEngineConfiguration.CONF_SCHEDULES);\r
+                       logger.info("Loading scheduler configuration file {}", configFilePath);\r
+               } catch (Exception e) {\r
+                       logger.warn(e.getMessage());\r
+                       return;\r
+               }\r
+\r
                String jsonConfig = new String(Files.readAllBytes(Paths.get(configFilePath)));\r
                BasicDBObject dbo = (BasicDBObject) JSONUtil.jsonToDbObject(jsonConfig);\r
                BasicDBList scheduledJobs = NoSQLUtils.asDBList(dbo, "joblist");\r
@@ -413,16 +426,16 @@ public class JobEngineConfiguration implements IJobEngineConfiguration {
                        BasicDBObject temp = schedules.get(i).getValue();\r
                        temp.remove("xml");\r
                        temp.remove("nextTime");\r
-                       if(temp.get("active") == null) {\r
+                       if (temp.get("active") == null) {\r
                                temp.remove("active");\r
                        }\r
-                       if(temp.get("executeimmediate") == null) {\r
+                       if (temp.get("executeimmediate") == null) {\r
                                temp.remove("executeimmediate");\r
                        }\r
                        jobList.add(temp);\r
                }\r
                dbo.put("joblist", jobList);\r
-               \r
+\r
                return dbo;\r
        }\r
 \r
@@ -457,14 +470,12 @@ public class JobEngineConfiguration implements IJobEngineConfiguration {
                        if (!Files.isDirectory(templatesPath))\r
                                throw new FileNotFoundException(templatesPath + " is not a directory!");\r
                        if (templateToSave.getFileName() != null) {\r
-                               filePath = templatesPath.toString() + FileSystems.getDefault().getSeparator()\r
-                                               + templateToSave.getFileName();\r
+                               filePath = templatesPath.toString() + FileSystems.getDefault().getSeparator() + templateToSave.getFileName();\r
                                if (Files.isWritable(Paths.get(filePath))) {\r
                                        logger.info("{} is writable", filePath);\r
                                } else {\r
                                        logger.info("{} is not writable", filePath);\r
-                                       DosFileAttributeView dos = Files.getFileAttributeView(Paths.get(filePath),\r
-                                                       DosFileAttributeView.class);\r
+                                       DosFileAttributeView dos = Files.getFileAttributeView(Paths.get(filePath), DosFileAttributeView.class);\r
                                        if (dos != null) {\r
                                                try {\r
                                                        dos.setReadOnly(false);\r
@@ -520,8 +531,7 @@ public class JobEngineConfiguration implements IJobEngineConfiguration {
                                duplicateFileName = FilenameUtils.getName(duplicateFileName).replace(".xml", "").concat("-copy.xml");\r
                                filePath = templatesPath.toString() + FileSystems.getDefault().getSeparator() + duplicateFileName;\r
                        }\r
-                       InputStream is = new FileInputStream(\r
-                                       templatesPath.toString() + FileSystems.getDefault().getSeparator() + selectedJob.getString("template"));\r
+                       InputStream is = new FileInputStream(templatesPath.toString() + FileSystems.getDefault().getSeparator() + selectedJob.getString("template"));\r
                        Files.copy(is, Paths.get(filePath));\r
                } catch (FileNotFoundException e) {\r
                        logger.error("File not found: {}", filePath);\r
@@ -529,7 +539,7 @@ public class JobEngineConfiguration implements IJobEngineConfiguration {
                        logger.error("IOException: {}", e.getCause());\r
                }\r
                return duplicateFileName;\r
-               \r
+\r
        }\r
 \r
        @Override\r
diff --git a/server/user.mediacube.gui/bin/user/jobengine/zk/util/SessionListener.class b/server/user.mediacube.gui/bin/user/jobengine/zk/util/SessionListener.class
deleted file mode 100644 (file)
index bd5a888..0000000
Binary files a/server/user.mediacube.gui/bin/user/jobengine/zk/util/SessionListener.class and /dev/null differ