Пример #1
0
 private void innerRegister(RoutingModel model) {
   boolean exists = false;
   do {
     try {
       _zk.createTempSeq(model.getKey(), model2Bytes(model));
       _tracer.info("RouteModel has been registered.\r\n" + model.toString());
       exists = false;
     } catch (KeeperException.NodeExistsException ex) {
       if (ex.code() == Code.NODEEXISTS) {
         exists = true;
         _tracer.error("Node is exist.", ex);
         try {
           Thread.sleep(2000);
         } catch (InterruptedException e) {
           e.printStackTrace();
         }
       } else {
         exists = false;
       }
     } catch (Throwable t) {
       _tracer.error("DynamicRouting.onConnected error.", t);
       exists = false;
     }
   } while (exists);
 }
Пример #2
0
 private DynamicRouting(String conn, String userName, String password) {
   _isConnected = false;
   _gson = new Gson();
   _myModels = new ArrayList<RoutingModel>();
   _models = new HashMap<>();
   _zk = new ZKConnection(conn, userName, password);
   _zk.register(this);
 }
Пример #3
0
  @Override
  public synchronized void onConnected(boolean newSession) {
    _isConnected = true;

    if (!newSession) {
      _tracer.info(getRoutingList());
      return;
    }

    for (RoutingModel model : _myModels) innerRegister(model);
    if (_myModels.size() == 0) {
      try {
        _zk.fireDataChanged();
      } catch (Throwable t) {
        _tracer.error("DynamicRouting.onConnected error.", t);
      }
    }
  }