@Test public void testGetZookeeperBasedJobLock() throws Exception { Closer closer = Closer.create(); try { TestingServer testingServer = closer.register(new TestingServer(-1)); Properties properties = new Properties(); properties.setProperty(ConfigurationKeys.JOB_NAME_KEY, "JobLockFactoryTest-" + System.currentTimeMillis()); properties.setProperty(ConfigurationKeys.JOB_LOCK_TYPE, ZookeeperBasedJobLock.class.getName()); properties.setProperty(ZookeeperBasedJobLock.CONNECTION_STRING, testingServer.getConnectString()); properties.setProperty(ZookeeperBasedJobLock.MAX_RETRY_COUNT, "1"); properties.setProperty(ZookeeperBasedJobLock.LOCKS_ACQUIRE_TIMEOUT_MILLISECONDS, "1000"); properties.setProperty(ZookeeperBasedJobLock.RETRY_BACKOFF_SECONDS, "1"); properties.setProperty(ZookeeperBasedJobLock.SESSION_TIMEOUT_SECONDS, "180"); properties.setProperty(ZookeeperBasedJobLock.CONNECTION_TIMEOUT_SECONDS, "30"); JobLock jobLock = closer.register(LegacyJobLockFactoryManager.getJobLock(properties, new JobLockEventListener())); MatcherAssert.assertThat(jobLock, Matchers.instanceOf(ZookeeperBasedJobLock.class)); } finally { closer.close(); } }
public static JobLock getJobLock(Properties properties, JobLockEventListener jobLockEventListener) throws JobLockException { Preconditions.checkNotNull(properties); Preconditions.checkNotNull(jobLockEventListener); JobLock jobLock; if (properties.containsKey(ConfigurationKeys.JOB_LOCK_TYPE)) { try { Class<?> jobLockClass = Class.forName( properties.getProperty(ConfigurationKeys.JOB_LOCK_TYPE, FileBasedJobLock.class.getName())); jobLock = (JobLock) ConstructorUtils.invokeConstructor(jobLockClass, properties); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { throw new JobLockException(e); } } else { jobLock = new FileBasedJobLock(properties); } if (jobLock instanceof ListenableJobLock) { ((ListenableJobLock)jobLock).setEventListener(jobLockEventListener); } return jobLock; }
LegacyJobLockFactoryManager { public static JobLock getJobLock(Properties properties, JobLockEventListener jobLockEventListener) throws JobLockException { Preconditions.checkNotNull(properties); Preconditions.checkNotNull(jobLockEventListener); JobLock jobLock; if (properties.containsKey(ConfigurationKeys.JOB_LOCK_TYPE)) { try { Class<?> jobLockClass = Class.forName( properties.getProperty(ConfigurationKeys.JOB_LOCK_TYPE, FileBasedJobLock.class.getName())); jobLock = (JobLock) ConstructorUtils.invokeConstructor(jobLockClass, properties); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { throw new JobLockException(e); } } else { jobLock = new FileBasedJobLock(properties); } if (jobLock instanceof ListenableJobLock) { ((ListenableJobLock)jobLock).setEventListener(jobLockEventListener); } return jobLock; } }
LegacyJobLockFactoryManager { public static JobLock getJobLock(Properties properties, JobLockEventListener jobLockEventListener) throws JobLockException { Preconditions.checkNotNull(properties); Preconditions.checkNotNull(jobLockEventListener); JobLock jobLock; if (properties.containsKey(ConfigurationKeys.JOB_LOCK_TYPE)) { try { Class<?> jobLockClass = Class.forName( properties.getProperty(ConfigurationKeys.JOB_LOCK_TYPE, FileBasedJobLock.class.getName())); jobLock = (JobLock) ConstructorUtils.invokeConstructor(jobLockClass, properties); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { throw new JobLockException(e); } } else { jobLock = new FileBasedJobLock(properties); } if (jobLock instanceof ListenableJobLock) { ((ListenableJobLock)jobLock).setEventListener(jobLockEventListener); } return jobLock; }  }
LegacyJobLockFactoryManager { public static JobLock getJobLock(Properties properties, JobLockEventListener jobLockEventListener) throws JobLockException { Preconditions.checkNotNull(properties); Preconditions.checkNotNull(jobLockEventListener); JobLock jobLock; if (properties.containsKey(ConfigurationKeys.JOB_LOCK_TYPE)) { try { Class<?> jobLockClass = Class.forName( properties.getProperty(ConfigurationKeys.JOB_LOCK_TYPE, FileBasedJobLock.class.getName())); jobLock = (JobLock) ConstructorUtils.invokeConstructor(jobLockClass, properties); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { throw new JobLockException(e); } } else { jobLock = new FileBasedJobLock(properties); } if (jobLock instanceof ListenableJobLock) { ((ListenableJobLock)jobLock).setEventListener(jobLockEventListener); } return jobLock; }  static JobLock getJobLock(Properties properties, JobLockEventListener jobLockEventListener); }
LegacyJobLockFactoryManager { public static JobLock getJobLock(Properties properties, JobLockEventListener jobLockEventListener) throws JobLockException { Preconditions.checkNotNull(properties); Preconditions.checkNotNull(jobLockEventListener); JobLock jobLock; if (properties.containsKey(ConfigurationKeys.JOB_LOCK_TYPE)) { try { Class<?> jobLockClass = Class.forName( properties.getProperty(ConfigurationKeys.JOB_LOCK_TYPE, FileBasedJobLock.class.getName())); jobLock = (JobLock) ConstructorUtils.invokeConstructor(jobLockClass, properties); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { throw new JobLockException(e); } } else { jobLock = new FileBasedJobLock(properties); } if (jobLock instanceof ListenableJobLock) { ((ListenableJobLock)jobLock).setEventListener(jobLockEventListener); } return jobLock; }  static JobLock getJobLock(Properties properties, JobLockEventListener jobLockEventListener);  }