Ejemplo n.º 1
0
  /**
   * Executes the Task. If the Task contains sub tasks, it will call exeute() on those as well. If
   * the Task is unsucessful (which sometimes is important to see) the method returns false, else it
   * will return true.
   *
   * @return a boolean stating if the Task was sucessful.
   */
  public boolean execute() throws GeneralTaskException {
    // Is never done, therefore no check for exception

    // Creates the move task and executes it

    /*
    TODO There is a problem here for low FPS. This code beneath is corrected
    	 so that the program will not hang up, but it also makes it possible
    	 for the turtle to, quite often, walk outside the radius and then walk
    	 back the next cycle. When FPS are very low the turtle would go very far
    	 from the center object and then back again, like a jojo.
    	 A possible other solution would be to check if the movement would be
    	 outside the radius, and then in some way shorten or replace the turtle
    	 so that it stays at the maximum radius, alternatively even bounces on the
    	 edge of the circle that is defined by the radius. A low FPS would still
    	 make strange results, though.

    	 Another problem is that if the could should be rewritten to test the
    	 the position before setting it, it would force the relative speed to
    	 to be calculated with the old speed twice, once here to check the
    	 position and once in the MoveTask.
    */

    Vector vector = velocity.getVector();
    Point point = position.getPoint();
    float direction = vector.getDirection();

    // Checks if the individual has wobbled outside the radius
    if (centerObject.getPoint().distanceTo(point) > radius) {
      // Corrects the angle to point directly to the centerObject
      direction = point.angleTo(centerObject.getPoint());
    }
    vector = new Vector(randomizeDirection(direction), vector.getMagnitude());

    MoveTask moveTask = new MoveTask(vector, relativeSpeed);
    moveTask.setPrivateInformation(position, velocity, characteristics, resources);
    moveTask.execute();

    return true;
  }
Ejemplo n.º 2
0
  @Test
  public void testMoveTaskSerde() throws Exception {
    final MoveTask task =
        new MoveTask(
            null,
            "foo",
            new Interval("2010-01-01/P1D"),
            ImmutableMap.<String, Object>of("bucket", "hey", "baseKey", "what"),
            null,
            null);

    final String json = jsonMapper.writeValueAsString(task);

    Thread.sleep(100); // Just want to run the clock a bit to make sure the task id doesn't change
    final MoveTask task2 = (MoveTask) jsonMapper.readValue(json, Task.class);

    Assert.assertEquals("foo", task.getDataSource());
    Assert.assertEquals(new Interval("2010-01-01/P1D"), task.getInterval());
    Assert.assertEquals(
        ImmutableMap.<String, Object>of("bucket", "hey", "baseKey", "what"),
        task.getTargetLoadSpec());

    Assert.assertEquals(task.getId(), task2.getId());
    Assert.assertEquals(task.getGroupId(), task2.getGroupId());
    Assert.assertEquals(task.getDataSource(), task2.getDataSource());
    Assert.assertEquals(task.getInterval(), task2.getInterval());
    Assert.assertEquals(task.getTargetLoadSpec(), task2.getTargetLoadSpec());
  }