org.apache.karaf.cellar.core.Group.getNodes()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(12.5k)|赞(0)|评价(0)|浏览(69)

本文整理了Java中org.apache.karaf.cellar.core.Group.getNodes()方法的一些代码示例,展示了Group.getNodes()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Group.getNodes()方法的具体详情如下:
包路径:org.apache.karaf.cellar.core.Group
类名称:Group
方法名:getNodes

Group.getNodes介绍

暂无

代码示例

代码示例来源:origin: org.apache.karaf.cellar/org.apache.karaf.cellar.hazelcast

/**
 * List the nodes in a given cluster group.
 *
 * @param group the cluster group.
 * @return a Set with the nodes.
 */
@Override
public Set<Node> listNodesByGroup(Group group) {
  return group.getNodes();
}

代码示例来源:origin: apache/karaf-cellar

/**
 * List the nodes in a given cluster group.
 *
 * @param group the cluster group.
 * @return a Set with the nodes.
 */
@Override
public Set<Node> listNodesByGroup(Group group) {
  return group.getNodes();
}

代码示例来源:origin: org.apache.karaf.cellar/org.apache.karaf.cellar.core

/**
 * Add cluster groups where the local node is belonging.
 *
 * @param group the cluster group candidate for completion.
 * @return true if the cluster group has been accepted, false else.
 */
@Override
protected boolean acceptsGroup(Group group) {
  Node node = groupManager.getNode();
  if (group.getNodes().contains(node))
    return true;
  else return false;
}

代码示例来源:origin: org.apache.karaf.cellar/org.apache.karaf.cellar.core

/**
 * Accept the cluster groups which don't include the local node.
 *
 * @param group the cluster group to check.
 * @return true if the cluster group doesn't include the local node, false else.
 */
@Override
protected boolean acceptsGroup(Group group) {
  Node node = groupManager.getNode();
  if (group.getNodes().contains(node))
    return false;
  else return true;
}

代码示例来源:origin: apache/karaf-cellar

/**
 * Accept the cluster groups which don't include the local node.
 *
 * @param group the cluster group to check.
 * @return true if the cluster group doesn't include the local node, false else.
 */
@Override
protected boolean acceptsGroup(Group group) {
  Node node = groupManager.getNode();
  if (group.getNodes().contains(node))
    return false;
  else return true;
}

代码示例来源:origin: apache/karaf-cellar

/**
 * Add cluster groups where the local node is belonging.
 *
 * @param group the cluster group candidate for completion.
 * @return true if the cluster group has been accepted, false else.
 */
@Override
protected boolean acceptsGroup(Group group) {
  Node node = groupManager.getNode();
  if (group.getNodes().contains(node))
    return true;
  else return false;
}

代码示例来源:origin: apache/karaf-cellar

@Override
protected Object doExecute() throws Exception {
  // check if the group exists
  Group group = groupManager.findGroupByName(groupName);
  if (group == null) {
    System.err.println("Cluster group " + groupName + " doesn't exist");
    return null;
  }
  // check if the group doesn't contain nodes
  if (group.getNodes() != null && !group.getNodes().isEmpty()) {
    System.err.println("Cluster group " + groupName  + " is not empty");
    return null;
  }
  groupManager.deleteGroup(groupName);
  return null;
}

代码示例来源:origin: org.apache.karaf.cellar/org.apache.karaf.cellar.core

/**
 * Remove a {@link Node} from the target {@link Group}.
 *
 * @param targetGroupName the target group name where to remove the node.
 */
public void quitGroup(String targetGroupName) {
  Node node = clusterManager.getNode();
  Map<String, Group> groups = groupManager.listGroups();
  if (groups != null && !groups.isEmpty()) {
    Group targetGroup = groups.get(targetGroupName);
    if (targetGroup.getNodes().contains(node)) {
      targetGroup.getNodes().remove(node);
      groupManager.unRegisterGroup(targetGroup);
    }
  }
}

代码示例来源:origin: org.apache.karaf.cellar/org.apache.karaf.cellar.hazelcast

@Override
public Set<String> listGroupNames(Node node) {
  Set<String> names = new HashSet<String>();
  ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
  try {
    Thread.currentThread().setContextClassLoader(combinedClassLoader);
    Map<String, Group> groups = listGroups();
    if (groups != null && !groups.isEmpty()) {
      for (Group group : groups.values()) {
        if (group.getNodes().contains(node)) {
          names.add(group.getName());
        }
      }
    }
  } finally {
    Thread.currentThread().setContextClassLoader(originalClassLoader);
  }
  return names;
}

代码示例来源:origin: apache/karaf-cellar

@Override
public Set<String> listGroupNames(Node node) {
  Set<String> names = new HashSet<String>();
  ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
  try {
    Thread.currentThread().setContextClassLoader(combinedClassLoader);
    Map<String, Group> groups = listGroups();
    if (groups != null && !groups.isEmpty()) {
      for (Group group : groups.values()) {
        if (group.getNodes().contains(node)) {
          names.add(group.getName());
        }
      }
    }
  } finally {
    Thread.currentThread().setContextClassLoader(originalClassLoader);
  }
  return names;
}

代码示例来源:origin: apache/karaf-cellar

/**
 * Remove a {@link Node} from the target {@link Group}.
 *
 * @param targetGroupName the target group name where to remove the node.
 */
public void quitGroup(String targetGroupName) {
  Node node = clusterManager.getNode();
  Map<String, Group> groups = groupManager.listGroups();
  if (groups != null && !groups.isEmpty()) {
    Group targetGroup = groups.get(targetGroupName);
    if (targetGroup.getNodes().contains(node)) {
      targetGroup.getNodes().remove(node);
      groupManager.unRegisterGroup(targetGroup);
    }
  }
}

代码示例来源:origin: org.apache.karaf.cellar/org.apache.karaf.cellar.hazelcast

@Override
public Map<String, Group> listGroups() {
  ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
  try {
    Map<String, Group> res = new HashMap<String, Group>();
    Thread.currentThread().setContextClassLoader(combinedClassLoader);
    Map<Node, Set<String>> nodes = getClusterGroups();
    Set<String> groups = convertStringToSet((String) localConfig.get(Configurations.GROUPS_KEY));
    groups.add(Configurations.DEFAULT_GROUP_NAME);
    for (String groupName : groups) {
      Group group = new Group(groupName);
      res.put(groupName, group);
      for (Map.Entry<Node, Set<String>> entry : nodes.entrySet()) {
        if (entry.getValue().contains(groupName)) {
          group.getNodes().add(entry.getKey());
        }
      }
    }
    return res;
  } finally {
    Thread.currentThread().setContextClassLoader(originalClassLoader);
  }
}

代码示例来源:origin: apache/karaf-cellar

@Override
public Map<String, Group> listGroups() {
  ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
  try {
    Map<String, Group> res = new HashMap<String, Group>();
    Thread.currentThread().setContextClassLoader(combinedClassLoader);
    Map<Node, Set<String>> nodes = getClusterGroups();
    Set<String> groups = convertStringToSet((String) localConfig.get(Configurations.GROUPS_KEY));
    groups.add(Configurations.DEFAULT_GROUP_NAME);
    for (String groupName : groups) {
      Group group = new Group(groupName);
      res.put(groupName, group);
      for (Map.Entry<Node, Set<String>> entry : nodes.entrySet()) {
        if (entry.getValue().contains(groupName)) {
          group.getNodes().add(entry.getKey());
        }
      }
    }
    return res;
  } finally {
    Thread.currentThread().setContextClassLoader(originalClassLoader);
  }
}

代码示例来源:origin: org.apache.karaf.cellar/org.apache.karaf.cellar.core

/**
 * Add {@link Node} to the target {@link Group}.
 *
 * @param targetGroupName the target group name where to add the node.
 */
public void joinGroup(String targetGroupName) {
  Node node = clusterManager.getNode();
  Map<String, Group> groups = groupManager.listGroups();
  if (groups != null && !groups.isEmpty()) {
    Group targetGroup = groups.get(targetGroupName);
    if (targetGroup == null) {
      groupManager.registerGroup(targetGroupName);
    } else if (!targetGroup.getNodes().contains(node)) {
      targetGroup.getNodes().add(node);
      groupManager.listGroups().put(targetGroupName, targetGroup);
      groupManager.registerGroup(targetGroup);
    }
  }
}

代码示例来源:origin: apache/karaf-cellar

/**
 * Add {@link Node} to the target {@link Group}.
 *
 * @param targetGroupName the target group name where to add the node.
 */
public void joinGroup(String targetGroupName) {
  Node node = clusterManager.getNode();
  Map<String, Group> groups = groupManager.listGroups();
  if (groups != null && !groups.isEmpty()) {
    Group targetGroup = groups.get(targetGroupName);
    if (targetGroup == null) {
      groupManager.registerGroup(targetGroupName);
    } else if (!targetGroup.getNodes().contains(node)) {
      targetGroup.getNodes().add(node);
      groupManager.listGroups().put(targetGroupName, targetGroup);
      groupManager.registerGroup(targetGroup);
    }
  }
}

代码示例来源:origin: apache/karaf-cellar

@Override
public void delete(String name) throws Exception {
  ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
  try {
    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    Group g = groupManager.findGroupByName(name);
    List<String> nodes = new LinkedList<String>();
    if (g.getNodes() != null && !g.getNodes().isEmpty()) {
      for (Node n : g.getNodes()) {
        nodes.add(n.getId());
      }
      ManageGroupCommand command = new ManageGroupCommand(clusterManager.generateId());
      command.setAction(ManageGroupAction.QUIT);
      command.setGroupName(name);
      Set<Node> recipientList = clusterManager.listNodes(nodes);
      command.setDestination(recipientList);
      executionContext.execute(command);
    }
    groupManager.deleteGroup(name);
  } finally {
    Thread.currentThread().setContextClassLoader(originalClassLoader);
  }
}

代码示例来源:origin: org.apache.karaf.cellar/org.apache.karaf.cellar.hazelcast

@Override
public void delete(String name) throws Exception {
  ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
  try {
    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    Group g = groupManager.findGroupByName(name);
    List<String> nodes = new LinkedList<String>();
    if (g.getNodes() != null && !g.getNodes().isEmpty()) {
      for (Node n : g.getNodes()) {
        nodes.add(n.getId());
      }
      ManageGroupCommand command = new ManageGroupCommand(clusterManager.generateId());
      command.setAction(ManageGroupAction.QUIT);
      command.setGroupName(name);
      Set<Node> recipientList = clusterManager.listNodes(nodes);
      command.setDestination(recipientList);
      executionContext.execute(command);
    }
    groupManager.deleteGroup(name);
  } finally {
    Thread.currentThread().setContextClassLoader(originalClassLoader);
  }
}

代码示例来源:origin: apache/karaf-cellar

@Override
protected Object doExecute() throws Exception {
  Group sourceGroup = groupManager.findGroupByName(sourceGroupName);
  if (sourceGroup == null) {
    System.err.println("Source cluster group " + sourceGroupName + " doesn't exist");
    return null;
  }
  Group targetGroup = groupManager.findGroupByName(targetGroupName);
  if (targetGroup == null) {
    System.err.println("Target cluster group " + targetGroupName + " doesn't exist");
    return null;
  }
  Set<Node> groupMembers = sourceGroup.getNodes();
  if (count > groupMembers.size())
    count = groupMembers.size();
  int i = 0;
  for (Node node : groupMembers) {
    if (i >= count)
      break;
    List<String> recipients = new LinkedList<String>();
    recipients.add(node.getId());
    doExecute(ManageGroupAction.SET, targetGroupName, sourceGroup, recipients);
    i++;
  }
  return doExecute(ManageGroupAction.LIST, null, null, new ArrayList(), false);
}

代码示例来源:origin: org.apache.karaf.cellar/org.apache.karaf.cellar.hazelcast

@Override
public TabularData getGroups() throws Exception {
  Set<Group> allGroups = groupManager.listAllGroups();
  CompositeType groupType = new CompositeType("Group", "Karaf Cellar cluster group",
      new String[]{ "name", "members"},
      new String[]{ "Name of the cluster group", "Members of the cluster group" },
      new OpenType[]{ SimpleType.STRING, SimpleType.STRING });
  TabularType tableType = new TabularType("Groups", "Table of all Karaf Cellar groups", groupType,
      new String[]{ "name" });
  TabularData table = new TabularDataSupport(tableType);
  for (Group group : allGroups) {
    StringBuffer members = new StringBuffer();
    for (Node node : group.getNodes()) {
      // display only up and running nodes in the cluster
      if (clusterManager.findNodeById(node.getId()) != null) {
        if (node.getAlias() != null) {
          members.append(node.getAlias());
        } else {
          members.append(node.getId());
        }
        members.append(" ");
      }
    }
    CompositeData data = new CompositeDataSupport(groupType,
        new String[]{ "name", "members" },
        new Object[]{ group.getName(), members.toString() });
    table.put(data);
  }
  return table;
}

代码示例来源:origin: apache/karaf-cellar

@Override
public TabularData getGroups() throws Exception {
  Set<Group> allGroups = groupManager.listAllGroups();
  CompositeType groupType = new CompositeType("Group", "Karaf Cellar cluster group",
      new String[]{ "name", "members"},
      new String[]{ "Name of the cluster group", "Members of the cluster group" },
      new OpenType[]{ SimpleType.STRING, SimpleType.STRING });
  TabularType tableType = new TabularType("Groups", "Table of all Karaf Cellar groups", groupType,
      new String[]{ "name" });
  TabularData table = new TabularDataSupport(tableType);
  for (Group group : allGroups) {
    StringBuffer members = new StringBuffer();
    for (Node node : group.getNodes()) {
      // display only up and running nodes in the cluster
      if (clusterManager.findNodeById(node.getId()) != null) {
        if (node.getAlias() != null) {
          members.append(node.getAlias());
        } else {
          members.append(node.getId());
        }
        members.append(" ");
      }
    }
    CompositeData data = new CompositeDataSupport(groupType,
        new String[]{ "name", "members" },
        new Object[]{ group.getName(), members.toString() });
    table.put(data);
  }
  return table;
}

相关文章

微信公众号

最新文章

更多