private JobHolder createNewJobHolderWithDelayUntil(Params params, long delayUntil) { JobHolder jobHolder = createNewJobHolder(params); getDelayUntilNsField(jobHolder).set(delayUntil); return jobHolder; }
public static JobHolder createNewJobHolder(Params params, Timer timer) { long delay = getDelayMsField(params).get(); long deadline = getDeadlineMsField(params).get(); boolean cancelOnDeadline = Boolean.TRUE.equals(getCancelOnDeadlineDeadlineField(params).get()); DummyJob job = new DummyJob(params); //noinspection WrongConstant return new JobHolder.Builder() .priority(params.getPriority()) .groupId(params.getGroupId()) .job(job) .id(job.getId()) .persistent(params.isPersistent()) .tags(job.getTags()) .createdNs(timer.nanoTime()) .deadline(deadline > 0 ? timer.nanoTime() + deadline * JobManager.NS_PER_MS : Params.FOREVER, cancelOnDeadline) .delayUntilNs(delay > 0 ? timer.nanoTime() + delay * JobManager.NS_PER_MS : JobManager.NOT_DELAYED_JOB_DELAY) .requiredNetworkType(getNetworkTypeField(params).get()) .runningSessionId(JobManager.NOT_RUNNING_SESSION_ID).build(); }
/** * Creates a new <code>{@link StaticFieldName}</code>: the starting point of the fluent interface for accessing static fields * using Java Reflection. * @param name the name of the field to access using Java Reflection. * @return the created <code>StaticFieldName</code>. * @throws NullPointerException if the given name is <code>null</code>. * @throws IllegalArgumentException if the given name is empty. */ public static StaticFieldName beginStaticFieldAccess(String name) { validateIsNotNullOrEmpty(name); return new StaticFieldName(name); }
/** * Creates a new <code>{@link FieldName}</code>: the starting point of the fluent interface for accessing fields using Java * Reflection. * @param name the name of the field to access using Java Reflection. * @return the created <code>FieldName</code>. * @throws NullPointerException if the given name is <code>null</code>. * @throws IllegalArgumentException if the given name is empty. */ public static FieldName beginFieldAccess(String name) { validateIsNotNullOrEmpty(name); return new FieldName(name); }
/** * Returns a new field invoker. A field invoker is capable of accessing (read/write) the underlying field. * @param target the type containing the static field of interest. * @return the created field invoker. * @throws NullPointerException if the given target is <code>null</code>. * @throws ReflectionError if a static field with a matching name and type cannot be found. */ public Invoker<T> in(Class<?> target) { return newInvoker(name, type, target); } }
/** * Starting point of the fluent interface for accessing static fields via reflection. * @param name the name of the static field to access. * @return the starting point of the method chain. * @throws NullPointerException if the given name is <code>null</code>. * @throws IllegalArgumentException if the given name is empty. */ public static StaticFieldName staticField(String name) { return beginStaticFieldAccess(name); }
/** * Ignores any {@link RuntimeException} which comes from the preceding decorator. * @return the DecoratedResultInvoker ignoring exceptions. */ public DecoratedInvoker<T> ignoringDecoratorExceptions() { return ignoringDecoratorExceptionsOfType(RuntimeException.class); }
/** * Adds a post-decorator to an already decorated field * <p> * Note that if there are more than one post-decorators assigned to a field they will be executed starting from the first * attached decorator. * @param decorator which methods be called after the same targeted object methods * @return the {@link DecoratedInvoker} post decorating the target field interface with given decorator. */ public DecoratedInvoker<T> postDecorateWith(T decorator) { return invoker.postDecorateWith(decorator); } }
/** * Sets the type of the field to access. * @param <T> the generic type of the field type. * @param type the type of the field to access. * @return a recipient for the field type. * @throws NullPointerException if the given type is <code>null</code>. */ public <T> StaticFieldType<T> ofType(Class<T> type) { return newFieldType(name, type); }
/** * Returns the value of the field managed by this class. * * @return the value of the field managed by this class. * @throws ReflectionError if the value of the field cannot be retrieved. */ public T get() { return Invoker.<T> get(field, accessible, target); }
@Test public void testPriorityWithDelayedJobs() throws Exception { JobQueue jobQueue = createNewJobQueue(); JobHolder delayedPriority_5 = createNewJobHolder(new Params(5)); org.fest.reflect.field.Invoker<Long> delayUntilField = getDelayUntilNsField(delayedPriority_5); delayUntilField.set(mockTimer.nanoTime() - 1000); JobHolder delayedPriority_2 = createNewJobHolder(new Params(2)); delayUntilField = getDelayUntilNsField(delayedPriority_2); delayUntilField.set(mockTimer.nanoTime() - 500); JobHolder nonDelayedPriority_6 = createNewJobHolder(new Params(6)); JobHolder nonDelayedPriority_3 = createNewJobHolder(new Params(3)); JobHolder nonDelayedPriority_2 = createNewJobHolder(new Params(2)); jobQueue.insert(delayedPriority_5); jobQueue.insert(delayedPriority_2); jobQueue.insert(nonDelayedPriority_6); jobQueue.insert(nonDelayedPriority_2); jobQueue.insert(nonDelayedPriority_3); TestConstraint constraint = new TestConstraint(mockTimer); int lastPriority = Integer.MAX_VALUE; for (int i = 0; i < 5; i++) { JobHolder next = jobQueue.nextJobAndIncRunCount(constraint); assertThat("next job should not be null", next, notNullValue()); assertThat("next job's priority should be lower then previous for job " + i, next.getPriority() <= lastPriority, is(true)); lastPriority = next.getPriority(); } }
/** * Returns a new field invoker. A field invoker is capable of accessing (read/write) the underlying field. * @param target the type containing the static field of interest. * @return the created field invoker. * @throws NullPointerException if the given target is <code>null</code>. * @throws ReflectionError if a static field with a matching name and type cannot be found. */ public Invoker<T> in(Class<?> target) { return newInvoker(name, type, target); } }