コード例 #1
0
 private void setMetaServers(List<Pair<String, HostPort>> servers) throws Exception {
   deleteChildren(ZKPathUtils.getMetaServersZkPath(), false);
   for (Pair<String, HostPort> pair : servers) {
     String path = ZKPaths.makePath(ZKPathUtils.getMetaServersZkPath(), pair.getKey());
     ensurePath(path);
     m_curator.setData().forPath(path, ZKSerializeUtils.serialize(pair.getValue()));
   }
 }
コード例 #2
0
  protected void writeProperties(List<Pair<String, String>> properties, ByteBuf buf) {
    HermesPrimitiveCodec codec = new HermesPrimitiveCodec(buf);
    if (properties != null) {
      Map<String, String> map = new HashMap<String, String>();
      for (Pair<String, String> prop : properties) {
        map.put(prop.getKey(), prop.getValue());
      }

      codec.writeStringStringMap(map);
    } else {
      codec.writeNull();
    }
  }
コード例 #3
0
  private Pair<Long, MessageMeta> clearDeliveredMessageMetasBefore(long offset) {
    Pair<Long, MessageMeta> messageMetaOfOffset = null;

    while (!m_deliveredMessageMetas.isEmpty()) {
      Pair<Long, MessageMeta> cur = m_deliveredMessageMetas.peek();
      if (cur != null) {
        if (cur.getKey() < offset) {
          m_deliveredMessageMetas.poll();
          continue;
        } else if (cur.getKey() == offset) {
          messageMetaOfOffset = m_deliveredMessageMetas.poll();
          break;
        } else {
          // cur.getId() > offset
          break;
        }
      } else {
        break;
      }
    }

    return messageMetaOfOffset;
  }
コード例 #4
0
 @Override
 protected String[] getZkPersistTouchPaths(Pair<String, Integer> topicPartition) {
   return new String[] {ZKPathUtils.getBrokerLeaseTopicParentZkPath(topicPartition.getKey())};
 }
コード例 #5
0
 @Override
 protected String convertKeyToZkPath(Pair<String, Integer> topicPartition) {
   return ZKPathUtils.getBrokerLeaseZkPath(topicPartition.getKey(), topicPartition.getValue());
 }
コード例 #6
0
  public void process(Action action, Payload payload, Model model) {
    switch (action) {
      case TOPOLOGY_GRAPH_NODE_CONFIG_LIST:
        model.setGraphConfig(m_topologyConfigManager.getConfig());
        break;
      case TOPOLOGY_GRAPH_NODE_CONFIG_ADD_OR_UPDATE:
        graphNodeConfigAddOrUpdate(payload, model);
        model.setProjects(m_globalConfigManager.queryAllProjects());
        break;
      case TOPOLOGY_GRAPH_NODE_CONFIG_ADD_OR_UPDATE_SUBMIT:
        model.setOpState(graphNodeConfigAddOrUpdateSubmit(payload, model));
        model.setGraphConfig(m_topologyConfigManager.getConfig());
        break;
      case TOPOLOGY_GRAPH_NODE_CONFIG_DELETE:
        model.setOpState(graphNodeConfigDelete(payload));
        model.setConfig(m_topologyConfigManager.getConfig());
        break;
      case TOPOLOGY_GRAPH_EDGE_CONFIG_LIST:
        model.setGraphConfig(m_topologyConfigManager.getConfig());
        model.buildEdgeInfo();
        break;
      case TOPOLOGY_GRAPH_EDGE_CONFIG_ADD_OR_UPDATE:
        graphEdgeConfigAdd(payload, model);
        model.setProjects(m_globalConfigManager.queryAllProjects());
        break;
      case TOPOLOGY_GRAPH_EDGE_CONFIG_ADD_OR_UPDATE_SUBMIT:
        model.setOpState(graphEdgeConfigAddOrUpdateSubmit(payload, model));
        model.setGraphConfig(m_topologyConfigManager.getConfig());
        model.buildEdgeInfo();
        break;
      case TOPOLOGY_GRAPH_EDGE_CONFIG_DELETE:
        model.setGraphConfig(m_topologyConfigManager.getConfig());
        model.setOpState(graphEdgeConfigDelete(payload));
        model.buildEdgeInfo();
        break;
      case TOPOLOGY_GRAPH_PRODUCT_LINE:
        model.setProductLines(m_productLineConfigManger.queryAllProductLines());
        model.setTypeToProductLines(m_productLineConfigManger.queryTypeProductLines());
        break;
      case TOPOLOGY_GRAPH_PRODUCT_LINE_ADD_OR_UPDATE:
        graphPruductLineAddOrUpdate(payload, model);
        model.setProjects(m_globalConfigManager.queryAllProjects());
        break;
      case TOPOLOGY_GRAPH_PRODUCT_LINE_DELETE:
        model.setOpState(
            m_productLineConfigManger.deleteProductLine(
                payload.getProductLineName(), payload.getType()));
        model.setProductLines(m_productLineConfigManger.queryAllProductLines());
        model.setTypeToProductLines(m_productLineConfigManger.queryTypeProductLines());
        break;
      case TOPOLOGY_GRAPH_PRODUCT_LINE_ADD_OR_UPDATE_SUBMIT:
        Pair<Boolean, String> addProductlineResult =
            graphProductLineConfigAddOrUpdateSubmit(payload, model);
        String duplicateDomains = addProductlineResult.getValue();

        model.setOpState(addProductlineResult.getKey());
        if (!StringUtils.isEmpty(duplicateDomains)) {
          model.setDuplicateDomains(addProductlineResult.getValue());
        }
        model.setProductLines(m_productLineConfigManger.queryAllProductLines());
        model.setTypeToProductLines(m_productLineConfigManger.queryTypeProductLines());
        break;
      case TOPO_GRAPH_FORMAT_CONFIG_UPDATE:
        String topoGraphFormat = payload.getContent();
        if (!StringUtils.isEmpty(topoGraphFormat)) {
          model.setOpState(m_formatConfigManager.insert(topoGraphFormat));
        }
        model.setContent(m_formatConfigManager.getConfig().toString());
        break;
      default:
        throw new RuntimeException("Error action name " + action.getName());
    }
  }
コード例 #7
0
  @SuppressWarnings("unchecked")
  protected static <T> Component A(Class<T> clazz, String enumField) {
    Named named = clazz.getAnnotation(Named.class);

    if (named == null) {
      throw new IllegalStateException(
          String.format(
              "Class(%s) is not annotated by %s.", clazz.getName(), Named.class.getName()));
    }

    Class<?> role = named.type();
    String roleHint = named.value();

    if (role == Named.Default.class) {
      role = clazz;
    } else {
      if (!role.isAssignableFrom(clazz)) {
        throw new IllegalStateException(
            String.format(
                "Class(%s) is not assignable from class(%s).",
                role.getName(), clazz, clazz.getName(), role.getName()));
      }
    }

    if (enumField != null) {
      roleHint = enumField;
    } else if (roleHint.length() == 0) {
      roleHint = null;
    }

    Component component = new Component((Class<Object>) role, roleHint, clazz);

    if (enumField != null) {
      component.is(ENUM);
    } else if (named.instantiationStrategy().length() > 0) {
      component.is(named.instantiationStrategy());
    }

    Map<Class<?>, List<Pair<Object, String>>> requires =
        new LinkedHashMap<Class<?>, List<Pair<Object, String>>>();
    Map<String, String> attributes = new LinkedHashMap<String, String>();

    collectFields(clazz, requires, attributes);

    for (Map.Entry<Class<?>, List<Pair<Object, String>>> e : requires.entrySet()) {
      List<Pair<Object, String>> list = e.getValue();

      for (Pair<Object, String> item : list) {
        Object key = item.getKey();

        if (key instanceof String[]) {
          String[] roleHints = (String[]) key;

          if (roleHints.length == 1) {
            if (list.size() == 1) {
              component.req(e.getKey(), roleHints[0]);
            } else {
              component.req(e.getKey(), roleHints[0], item.getValue());
            }
          } else {
            component.req(e.getKey(), roleHints, item.getValue());
          }
        } else {
          if (list.size() == 1) {
            component.req(e.getKey(), (String) key);
          } else {
            component.req(e.getKey(), (String) key, item.getValue());
          }
        }
      }
    }

    for (Map.Entry<String, String> attribute : attributes.entrySet()) {
      component.config(new Configuration(attribute.getKey()).value(attribute.getValue()));
    }

    return component;
  }