コード例 #1
0
  /**
   * Tests two consecutive connections to see how it works.
   *
   * @throws Exception
   */
  public void testDoubleUsage() throws Exception {

    while (!server.isRunning()) {
      Thread.sleep(100); // waits until the server finishes the startup
    }

    AsyncTaskService client = createTaskClient();

    client.connect();

    Task task = new Task();
    List<I18NText> names1 = new ArrayList<I18NText>();
    I18NText text1 = new I18NText("en-UK", "tarea1");
    names1.add(text1);
    task.setNames(names1);
    TaskData taskData = new TaskData();
    taskData.setStatus(Status.Created);
    taskData.setCreatedBy(new User("usr0"));
    taskData.setActualOwner(new User("usr0"));
    task.setTaskData(taskData);

    ContentData data = new ContentData();
    BlockingAddTaskResponseHandler addTaskHandler = new BlockingAddTaskResponseHandler();
    client.addTask(task, data, addTaskHandler);

    long taskId = addTaskHandler.getTaskId();

    client.disconnect();

    client.connect();

    assertTrue("taskId debe ser un valor mayor a cero", taskId > 0);

    Task task2 = new Task();
    List<I18NText> names2 = new ArrayList<I18NText>();
    I18NText text2 = new I18NText("en-UK", "tarea1");
    names2.add(text2);
    task2.setNames(names2);
    TaskData taskData2 = new TaskData();
    taskData2.setStatus(Status.Created);
    taskData2.setCreatedBy(new User("usr0"));
    taskData2.setActualOwner(new User("usr0"));
    task2.setTaskData(taskData2);

    ContentData data2 = new ContentData();
    BlockingAddTaskResponseHandler addTaskHandler2 = new BlockingAddTaskResponseHandler();
    client.addTask(task2, data2, addTaskHandler2);

    long taskId2 = addTaskHandler2.getTaskId();

    assertTrue("taskId2 debe ser un valor mayor a cero", taskId2 > 0);
    assertNotSame("taskId y taskId2 deben ser distintos", taskId, taskId2);

    client.disconnect();
  }
コード例 #2
0
 public void connect() {
   if (client == null) {
     throw new IllegalStateException(
         "You must set the Task Service Client to the work item to work");
   }
   if (ipAddress == null || ipAddress.equals("") || port <= 0) {
     throw new IllegalStateException("You must set the IP and Port to the work item to work");
   }
   if (client != null) {
     if (!connected) {
       connected = client.connect(ipAddress, port);
       if (!connected) {
         throw new IllegalArgumentException("Could not connect task client");
       }
       registerTaskEvents();
     }
   }
 }