@Test @Transactional public void testLockObjNewLock() { String workerID = String.valueOf(Thread.currentThread().getId()); assertTrue(jp.lockObj(new JobDefinition(1L,"A","B","C","D", "","","",""), "C111", workerID)); assertTrue(jp.lockObj(new JobDefinition(2L,"A","B","C","D", "","","",""), "C111", workerID)); assertFalse(jp.lockObj(new JobDefinition(3L,"A","B","C","D", "","","",""), "C222", workerID)); assertTrue(jp.lockObj(new JobDefinition(4L,"A2","B2","C2","D2", "","","",""), "C111", workerID)); assertFalse(jp.lockObj(new JobDefinition(5L,"A2","B2","C2","D2", "","","",""), "C111","2")); }
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; }