Exemplo n.º 1
0
 public void workerSetTest() {
   Set<Worker> workerSet = new HashSet<Worker>();
   Worker worker1 = new Worker("张三", 18);
   worker1.setWorkerId(1);
   workerSet.add(worker1);
   Worker worker2 = new Worker("李四", 8);
   worker2.setWorkerId(2);
   System.out.println(workerSet.contains(worker2));
 }
Exemplo n.º 2
0
  public void validateArrLines() throws Exception {

    String err = "";
    err += Worker.validateAndCreateMMSs(arrMMSLines);
    err += Worker.validateAndCreateBrowsers(arrBrowserLines);
    err += Worker.validateAndCreateJavaApps(arrJavaAppLines);
    err += Worker.validateAndCreateIMs(arrIMLines);

    if (err.length() > 0) {
      throw new Exception(err);
    }
  }
  @Override
  public void registerNode(
      NodeContext nodeContext, Set<Worker> workers, final StatusChangeListener listener)
      throws CoordinatorException {
    log.info("Going to register node {} with {} workers", nodeContext.getId(), workers.size());

    ZNode typeNode = rootNode.child(CoordinationUtil.nodeNameOf(nodeContext.getId().getType()));
    ZNode node = typeNode.createChild(znode().withPath(nodeContext.getId().getIdentifier()));

    Set<CommandExecutor<?, ?>> executors = Sets.newHashSet();
    Set<Qualifier<?>> qualifiers = Sets.newHashSet();

    for (Worker worker : workers) {
      for (CommandExecutor<?, ?> executor : worker.getExecutors()) {
        Qualifier<?> qualifier = executor.getQualifier();
        if (qualifiers.contains(qualifier)) {
          throw new CoordinatorException(
              "Executor for qualifier " + qualifier + " is already registered");
        }

        executors.add(executor);
      }
    }

    for (CommandExecutor<?, ?> executor : executors) {
      registerExecutor(nodeContext, executor, node);
    }

    rootNode.addNodeWatcher(
        new Watcher() {
          @Override
          public void process(WatchedEvent event) {
            if (event.getState() == Event.KeeperState.Disconnected) {
              listener.onCoordinatorDisconnected();
            }

            if (event.getState() == Event.KeeperState.SyncConnected) {
              listener.onCoordinatorConnected();
            }
          }
        });

    ZNode statuses = rootNode.child(CoordinationUtil.STATUSES_NODE_NAME);

    statuses.createChild(znode().ephemeralSequential().withDataObject(nodeContext.getId()));

    Lock lock = new ReentrantLock();

    lock.lock();
    try {
      Collection<NodeId> nodeIds = Sets.newHashSet();
      StatusWatcher statusWatcher = new StatusWatcher(statuses, lock, nodeIds, listener);
      List<ZNode> nodes = statuses.children(statusWatcher);
      for (ZNode zNode : nodes) {
        nodeIds.add(zNode.getObject(NodeId.class));
      }
    } finally {
      lock.unlock();
    }

    node.createChild(znode().withPath(CoordinationUtil.AVAILABLE_NODE_NAME));
  }
Exemplo n.º 4
0
  public void departTest() {
    Department department1 = depDAO.getDepartment(1);
    Department department2 = depDAO.getDepartment(2);
    Department department3 = depDAO.getDepartment(3);
    Worker worker1 = new Worker("jaku", 18);
    worker1.setWorkerPassword("111111");
    worker1.setDepartment(department1);
    worker1.setWorkerLevel(1);

    Worker worker2 = new Worker("balen", 28);
    worker2.setWorkerPassword("111111");
    worker2.setDepartment(department2);
    worker2.setWorkerLevel(2);

    Worker worker3 = new Worker("admin", 38);
    worker3.setWorkerPassword("111111");
    worker3.setDepartment(department3);
    worker3.setWorkerLevel(3);

    department1.addWorker(worker1);
    department2.addWorker(worker2);
    department3.addWorker(worker3);
    depDAO.saveDepart(department1);
    depDAO.saveDepart(department2);
    depDAO.saveDepart(department3);
  }