Exemplo n.º 1
0
  public NetworkGuard(
      InetAddress[] inetAddress,
      int port,
      IConcurrentFactory concurrentFactory,
      IMessageParser parser,
      IMetaData data)
      throws Exception {
    this.port = port;
    this.parser = parser;
    this.concurrentFactory =
        concurrentFactory == null ? new DummyConcurrentFactory() : concurrentFactory;
    // this.thread = this.concurrentFactory.getThread("NetworkGuard", this);
    this.bindDelay =
        data.getConfiguration().getLongValue(BindDelay.ordinal(), (Long) BindDelay.defValue());

    try {
      for (int addrIdx = 0; addrIdx < inetAddress.length; addrIdx++) {
        GuardTask guardTask = new GuardTask(new InetSocketAddress(inetAddress[addrIdx], port));
        Thread t = this.concurrentFactory.getThread(guardTask);
        guardTask.thread = t;
        tasks.add(guardTask);
      }
      isWork = true;
      for (GuardTask gt : this.tasks) {
        gt.start();
      }
      // thread.start();
    } catch (Exception exc) {
      destroy();
      throw new Exception(exc);
    }
  }
Exemplo n.º 2
0
 @Override
 public void destroy() {
   isWork = false;
   Iterator<GuardTask> it = this.tasks.iterator();
   while (it.hasNext()) {
     GuardTask gt = it.next();
     it.remove();
     gt.cleanTask();
   }
 }