@Test @Transactional public void testLockSawCompactionObj() { String correlation = "{\n" + " \"businessObject\": {\n" + " \"late_reporting_for\":\"ABC\"\n" + " }\n" + "}"; assertTrue("First Lock", jp.lockObj(new JobDefinition(1L, "SAW", "ABC", "PRC","BZ", "","","",""),"C111", "1")); assertFalse(jp.lockObj(new JobDefinition(2L, "SAW", "ABC_COMPACTION", "PRC","BZ", "",correlation,"",""),"C222", "1")); assertTrue("First Lock", jp.lockObj(new JobDefinition(3L, "SAW", "ABC_COMPACTION", "PRC-2","BZ","",correlation,"",""),"C111", "1")); assertFalse("First Lock", jp.lockObj(new JobDefinition(4L,"SAW", "ABC_COMPACTION", "PRC-2","BZ", "",correlation,"",""),"C222", "1")); assertFalse(jp.lockObj(new JobDefinition(5L, "SAW", "ABC", "PRC-2","BZ", "",correlation,"",""),"C222", "1")); }
public boolean lockObj( JobDefinition jd, String clusterID, String threadID ) { String objectName = jd.getActualObjectName(); ObjectDefinition od = jd.getObjectDefinition(); if ( template.queryForList( FIND_LOCK, od.getNameSpace(), objectName, od.getUsageCode(), od.getFileType(), clusterID, threadID,jd.getWfType() ).size() > 0 ) { return extendLock( jd, clusterID, threadID ); } else { unlockWorker( clusterID, threadID ); int updated = template.update( LOCK_QUERY, od.getNameSpace(), objectName, od.getUsageCode(), od.getFileType(), clusterID, threadID, jd.getWfType() ); return updated == 1; } }
JobPicker { public boolean lockObj( JobDefinition jd, String clusterID, String threadID ) { String objectName = jd.getActualObjectName(); ObjectDefinition od = jd.getObjectDefinition(); if ( template.queryForList( FIND_LOCK, od.getNameSpace(), objectName, od.getUsageCode(), od.getFileType(), clusterID, threadID,jd.getWfType() ).size() > 0 ) { return extendLock( jd, clusterID, threadID ); } else { unlockWorker( clusterID, threadID ); int updated = template.update( LOCK_QUERY, od.getNameSpace(), objectName, od.getUsageCode(), od.getFileType(), clusterID, threadID, jd.getWfType() ); return updated == 1; } } }
JobPicker { public boolean lockObj( JobDefinition jd, String clusterID, String threadID ) { String objectName = jd.getActualObjectName(); ObjectDefinition od = jd.getObjectDefinition(); if ( template.queryForList( FIND_LOCK, od.getNameSpace(), objectName, od.getUsageCode(), od.getFileType(), clusterID, threadID,jd.getWfType() ).size() > 0 ) { return extendLock( jd, clusterID, threadID ); } else { unlockWorker( clusterID, threadID ); int updated = template.update( LOCK_QUERY, od.getNameSpace(), objectName, od.getUsageCode(), od.getFileType(), clusterID, threadID, jd.getWfType() ); return updated == 1; } }  }
JobPicker { public boolean lockObj( JobDefinition jd, String clusterID, String threadID ) { String objectName = jd.getActualObjectName(); ObjectDefinition od = jd.getObjectDefinition(); if ( template.queryForList( FIND_LOCK, od.getNameSpace(), objectName, od.getUsageCode(), od.getFileType(), clusterID, threadID,jd.getWfType() ).size() > 0 ) { return extendLock( jd, clusterID, threadID ); } else { unlockWorker( clusterID, threadID ); int updated = template.update( LOCK_QUERY, od.getNameSpace(), objectName, od.getUsageCode(), od.getFileType(), clusterID, threadID, jd.getWfType() ); return updated == 1; } }  boolean lockObj( JobDefinition jd, String clusterID, String threadID ); void unlockWorker( String clusterID, String threadID ); boolean extendLock( JobDefinition jd, String clusterID, String workerID ); }
JobPicker { public boolean lockObj( JobDefinition jd, String clusterID, String threadID ) { String objectName = jd.getActualObjectName(); ObjectDefinition od = jd.getObjectDefinition(); if ( template.queryForList( FIND_LOCK, od.getNameSpace(), objectName, od.getUsageCode(), od.getFileType(), clusterID, threadID,jd.getWfType() ).size() > 0 ) { return extendLock( jd, clusterID, threadID ); } else { unlockWorker( clusterID, threadID ); int updated = template.update( LOCK_QUERY, od.getNameSpace(), objectName, od.getUsageCode(), od.getFileType(), clusterID, threadID, jd.getWfType() ); return updated == 1; } }  boolean lockObj( JobDefinition jd, String clusterID, String threadID ); void unlockWorker( String clusterID, String threadID ); boolean extendLock( JobDefinition jd, String clusterID, String workerID ); static final String FIND_UNLOCKED_JOB_QUERY; static final String FIND_UNLOCKED_STATS_JOB_QUERY; }