org.apache.karaf.cellar.core.Node类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(15.2k)|赞(0)|评价(0)|浏览(128)

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

Node介绍

[英]Generic cluster node interface.
[中]通用集群节点接口。

代码示例

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

  1. @Override
  2. public String getId(String alias) throws Exception {
  3. Node node = clusterManager.findNodeByAlias(alias);
  4. if (node != null) {
  5. return node.getId();
  6. }
  7. return null;
  8. }

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

  1. @Override
  2. protected Object doExecute() throws Exception {
  3. if (idLookup != null) {
  4. Node node = clusterManager.findNodeById(idLookup);
  5. System.out.println(node.getAlias());
  6. return null;
  7. }
  8. if (aliasLookup != null) {
  9. Node node = clusterManager.findNodeByAlias(aliasLookup);
  10. System.out.println(node.getId());
  11. return null;
  12. }
  13. if (alias != null) {
  14. if (clusterManager.findNodeByAlias(alias) != null) {
  15. System.err.println("Alias " + alias + " already exists");
  16. return null;
  17. }
  18. clusterManager.setNodeAlias(alias);
  19. } else {
  20. Node node = clusterManager.getNode();
  21. if (node.getAlias() == null) {
  22. System.out.println("");
  23. } else {
  24. System.out.println(node.getAlias());
  25. }
  26. }
  27. return null;
  28. }

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

  1. @Override
  2. public TabularData getNodes() throws Exception {
  3. CompositeType nodeType = new CompositeType("Node", "Karaf Cellar cluster node",
  4. new String[]{ "id", "alias", "hostname", "port", "local" },
  5. new String[]{ "ID of the node", "Alias of the node", "Hostname of the node", "Port number of the node", "Flag defining if the node is local" },
  6. new OpenType[]{ SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.INTEGER, SimpleType.BOOLEAN });
  7. TabularType tableType = new TabularType("Nodes", "Table of all Karaf Cellar nodes", nodeType, new String[]{ "id" });
  8. TabularData table = new TabularDataSupport(tableType);
  9. Set<Node> nodes = clusterManager.listNodes();
  10. for (Node node : nodes) {
  11. boolean local = (node.equals(clusterManager.getNode()));
  12. CompositeData data = new CompositeDataSupport(nodeType,
  13. new String[]{ "id", "alias", "hostname", "port", "local" },
  14. new Object[]{ node.getId(), node.getAlias(), node.getHost(), node.getPort(), local });
  15. table.put(data);
  16. }
  17. return table;
  18. }

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

  1. @Override
  2. public String getAlias(String id) throws Exception {
  3. Node node = clusterManager.findNodeById(id);
  4. if (node != null) {
  5. return node.getAlias();
  6. }
  7. return null;
  8. }

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

  1. public String constructLocation(String alias) {
  2. String httpHost = clusterManager.getNode().getHost();
  3. String httpPort = null;
  4. try {
  5. Configuration configuration = configurationAdmin.getConfiguration("org.ops4j.pax.web", null);
  6. if (configuration != null) {
  7. Dictionary properties = configuration.getProperties();
  8. if (properties != null) {
  9. httpPort = (String) properties.get("org.osgi.service.http.port");
  10. }
  11. }
  12. } catch (Exception e) {
  13. LOGGER.warn("CELLAR HTTP BALANCER: can't get HTTP port number from configuration", e);
  14. }
  15. if (httpPort == null)
  16. httpPort = "8181";
  17. String location = "http://" + httpHost + ":" + httpPort + alias;
  18. return location;
  19. }

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

  1. @Override
  2. public String getAlias(String id) throws Exception {
  3. Node node = clusterManager.findNodeById(id);
  4. if (node != null) {
  5. return node.getAlias();
  6. }
  7. return null;
  8. }

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

  1. @Override
  2. public String getId(String alias) throws Exception {
  3. Node node = clusterManager.findNodeByAlias(alias);
  4. if (node != null) {
  5. return node.getId();
  6. }
  7. return null;
  8. }

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

  1. @Override
  2. public TabularData getGroups() throws Exception {
  3. Set<Group> allGroups = groupManager.listAllGroups();
  4. CompositeType groupType = new CompositeType("Group", "Karaf Cellar cluster group",
  5. new String[]{ "name", "members"},
  6. new String[]{ "Name of the cluster group", "Members of the cluster group" },
  7. new OpenType[]{ SimpleType.STRING, SimpleType.STRING });
  8. TabularType tableType = new TabularType("Groups", "Table of all Karaf Cellar groups", groupType,
  9. new String[]{ "name" });
  10. TabularData table = new TabularDataSupport(tableType);
  11. for (Group group : allGroups) {
  12. StringBuffer members = new StringBuffer();
  13. for (Node node : group.getNodes()) {
  14. // display only up and running nodes in the cluster
  15. if (clusterManager.findNodeById(node.getId()) != null) {
  16. if (node.getAlias() != null) {
  17. members.append(node.getAlias());
  18. } else {
  19. members.append(node.getId());
  20. }
  21. members.append(" ");
  22. }
  23. }
  24. CompositeData data = new CompositeDataSupport(groupType,
  25. new String[]{ "name", "members" },
  26. new Object[]{ group.getName(), members.toString() });
  27. table.put(data);
  28. }
  29. return table;
  30. }

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

  1. @Override
  2. public TabularData getNodes() throws Exception {
  3. CompositeType nodeType = new CompositeType("Node", "Karaf Cellar cluster node",
  4. new String[]{ "id", "alias", "hostname", "port", "local" },
  5. new String[]{ "ID of the node", "Alias of the node", "Hostname of the node", "Port number of the node", "Flag defining if the node is local" },
  6. new OpenType[]{ SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.INTEGER, SimpleType.BOOLEAN });
  7. TabularType tableType = new TabularType("Nodes", "Table of all Karaf Cellar nodes", nodeType, new String[]{ "id" });
  8. TabularData table = new TabularDataSupport(tableType);
  9. Set<Node> nodes = clusterManager.listNodes();
  10. for (Node node : nodes) {
  11. boolean local = (node.equals(clusterManager.getNode()));
  12. CompositeData data = new CompositeDataSupport(nodeType,
  13. new String[]{ "id", "alias", "hostname", "port", "local" },
  14. new Object[]{ node.getId(), node.getAlias(), node.getHost(), node.getPort(), local });
  15. table.put(data);
  16. }
  17. return table;
  18. }

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

  1. public Map<String, List<String>> getServices() {
  2. Map<String, List<String>> services = new HashMap<String, List<String>>();
  3. ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
  4. try {
  5. Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
  6. Map<String, EndpointDescription> remoteEndpoints = clusterManager.getMap(Constants.REMOTE_ENDPOINTS);
  7. if (remoteEndpoints != null && !remoteEndpoints.isEmpty()) {
  8. for (Map.Entry<String, EndpointDescription> entry : remoteEndpoints.entrySet()) {
  9. EndpointDescription endpointDescription = entry.getValue();
  10. String serviceClass = endpointDescription.getServiceClass();
  11. Set<Node> nodes = endpointDescription.getNodes();
  12. LinkedList<String> providers = new LinkedList<String>();
  13. for (Node node : nodes) {
  14. providers.add(node.getId());
  15. }
  16. services.put(serviceClass, providers);
  17. }
  18. }
  19. } finally {
  20. Thread.currentThread().setContextClassLoader(originalClassLoader);
  21. }
  22. return services;
  23. }

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

  1. @Override
  2. public TabularData getGroups() throws Exception {
  3. Set<Group> allGroups = groupManager.listAllGroups();
  4. CompositeType groupType = new CompositeType("Group", "Karaf Cellar cluster group",
  5. new String[]{ "name", "members"},
  6. new String[]{ "Name of the cluster group", "Members of the cluster group" },
  7. new OpenType[]{ SimpleType.STRING, SimpleType.STRING });
  8. TabularType tableType = new TabularType("Groups", "Table of all Karaf Cellar groups", groupType,
  9. new String[]{ "name" });
  10. TabularData table = new TabularDataSupport(tableType);
  11. for (Group group : allGroups) {
  12. StringBuffer members = new StringBuffer();
  13. for (Node node : group.getNodes()) {
  14. // display only up and running nodes in the cluster
  15. if (clusterManager.findNodeById(node.getId()) != null) {
  16. if (node.getAlias() != null) {
  17. members.append(node.getAlias());
  18. } else {
  19. members.append(node.getId());
  20. }
  21. members.append(" ");
  22. }
  23. }
  24. CompositeData data = new CompositeDataSupport(groupType,
  25. new String[]{ "name", "members" },
  26. new Object[]{ group.getName(), members.toString() });
  27. table.put(data);
  28. }
  29. return table;
  30. }

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

  1. @Override
  2. protected Object doExecute() throws Exception {
  3. Set<Node> nodes = clusterManager.listNodes();
  4. if (nodes != null && !nodes.isEmpty()) {
  5. ShellTable table = new ShellTable();
  6. table.column(" ");
  7. table.column("Id");
  8. table.column("Alias");
  9. table.column("Host Name");
  10. table.column("Port");
  11. for (Node node : nodes) {
  12. String local = "";
  13. if (node.equals(clusterManager.getNode()))
  14. local = "x";
  15. table.addRow().addContent(local, node.getId(), node.getAlias(), node.getHost(), node.getPort());
  16. }
  17. table.print(System.out);
  18. } else {
  19. System.err.println("No node found in the cluster");
  20. }
  21. return null;
  22. }

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

  1. @Override
  2. public Object doExecute() throws Exception {
  3. ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
  4. Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
  5. try {
  6. Map<ClusterLogKey, ClusterLogRecord> clusterLog = clusterManager.getMap(LogAppender.LOG_MAP);
  7. if (nodeIdOrAlias == null) {
  8. clusterLog.clear();
  9. } else {
  10. Node node = clusterManager.findNodeByIdOrAlias(nodeIdOrAlias);
  11. if (node == null) {
  12. System.err.println("Node " + nodeIdOrAlias + " doesn't exist");
  13. return null;
  14. }
  15. for (ClusterLogKey key : clusterLog.keySet()) {
  16. if (key.getNodeId().equals(node.getId())) {
  17. clusterLog.remove(key);
  18. }
  19. }
  20. }
  21. } finally {
  22. Thread.currentThread().setContextClassLoader(originalClassLoader);
  23. }
  24. return null;
  25. }

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

  1. String nodeName = node.getAlias();
  2. if (nodeName == null) {
  3. nodeName = node.getId();

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

  1. /**
  2. * Check if there is a match for the current {@link ListenerInfo}.
  3. *
  4. * @param listenerInfo the listener info.
  5. */
  6. private void checkListener(ListenerInfo listenerInfo) {
  7. ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
  8. try {
  9. Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
  10. // iterate through known services and import them if needed
  11. Set<EndpointDescription> matches = new LinkedHashSet<EndpointDescription>();
  12. for (Map.Entry<String, EndpointDescription> entry : remoteEndpoints.entrySet()) {
  13. EndpointDescription endpointDescription = entry.getValue();
  14. if (endpointDescription.matches(listenerInfo.getFilter()) && !endpointDescription.getNodes().contains(clusterManager.getNode().getId())) {
  15. matches.add(endpointDescription);
  16. }
  17. }
  18. for (EndpointDescription endpoint : matches) {
  19. importService(endpoint, listenerInfo);
  20. }
  21. } finally {
  22. Thread.currentThread().setContextClassLoader(originalClassLoader);
  23. }
  24. }

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

  1. Set<Node> nodes = endpointDescription.getNodes();
  2. for (Node node : nodes) {
  3. String nodeName = node.getAlias();
  4. if (nodeName == null) {
  5. nodeName = node.getId();

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

  1. @Override
  2. public void doStart() throws Exception {
  3. ClusterManager clusterManager = getTrackedService(ClusterManager.class);
  4. if (clusterManager == null)
  5. return;
  6. String nodeId = clusterManager.getNode().getId();
  7. GreeterImpl greeter = new GreeterImpl(nodeId);
  8. Hashtable props = new Hashtable();
  9. props.put("service.exported.interfaces", "*");
  10. register(Greeter.class, greeter, props);
  11. }

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

  1. @Override
  2. public TabularData producerStatus() throws Exception {
  3. ProducerSwitchCommand command = new ProducerSwitchCommand(clusterManager.generateId());
  4. command.setStatus(null);
  5. Map<Node, ProducerSwitchResult> results = executionContext.execute(command);
  6. CompositeType compositeType = new CompositeType("Event Producer", "Karaf Cellar cluster event producer",
  7. new String[]{"node", "status", "local"},
  8. new String[]{"Node hosting event producer", "Current status of the event producer", "True if the node is local"},
  9. new OpenType[]{SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.BOOLEAN});
  10. TabularType tableType = new TabularType("Event Producers", "Table of Karaf Cellar cluster event producers",
  11. compositeType, new String[]{"node"});
  12. TabularDataSupport table = new TabularDataSupport(tableType);
  13. for (Node node : results.keySet()) {
  14. boolean local = (node.equals(clusterManager.getNode()));
  15. ProducerSwitchResult producerSwitchResult = results.get(node);
  16. String nodeName = node.getAlias();
  17. if (nodeName == null) {
  18. nodeName = node.getId();
  19. }
  20. CompositeDataSupport data = new CompositeDataSupport(compositeType,
  21. new String[]{"node", "status", "local"},
  22. new Object[]{nodeName, producerSwitchResult.getStatus(), local});
  23. table.put(data);
  24. }
  25. return table;
  26. }

代码示例来源:origin: org.apache.unomi/unomi-services

  1. private void updateSystemStats() {
  2. final RuntimeMXBean remoteRuntime = ManagementFactory.getRuntimeMXBean();
  3. long uptime = remoteRuntime.getUptime();
  4. ObjectName operatingSystemMXBeanName = ManagementFactory.getOperatingSystemMXBean().getObjectName();
  5. Double systemCpuLoad = null;
  6. try {
  7. systemCpuLoad = (Double) ManagementFactory.getPlatformMBeanServer().getAttribute(operatingSystemMXBeanName, "SystemCpuLoad");
  8. } catch (MBeanException e) {
  9. logger.error("Error retrieving system CPU load", e);
  10. } catch (AttributeNotFoundException e) {
  11. logger.error("Error retrieving system CPU load", e);
  12. } catch (InstanceNotFoundException e) {
  13. logger.error("Error retrieving system CPU load", e);
  14. } catch (ReflectionException e) {
  15. logger.error("Error retrieving system CPU load", e);
  16. }
  17. final OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
  18. double systemLoadAverage = operatingSystemMXBean.getSystemLoadAverage();
  19. ClusterSystemStatisticsEvent clusterSystemStatisticsEvent = new ClusterSystemStatisticsEvent("org.apache.unomi.cluster.system.statistics");
  20. Map<String,Serializable> systemStatistics = new TreeMap<>();
  21. ArrayList<Double> systemLoadAverageArray = new ArrayList<>();
  22. systemLoadAverageArray.add(systemLoadAverage);
  23. systemStatistics.put("systemLoadAverage", systemLoadAverageArray);
  24. systemStatistics.put("systemCpuLoad", systemCpuLoad);
  25. systemStatistics.put("uptime", uptime);
  26. clusterSystemStatisticsEvent.setStatistics(systemStatistics);
  27. nodeSystemStatistics.put(karafCellarClusterManager.getNode().getId(), systemStatistics);
  28. sendEvent(clusterSystemStatisticsEvent);
  29. }

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

  1. @Override
  2. public TabularData consumerStatus() throws Exception {
  3. ConsumerSwitchCommand command = new ConsumerSwitchCommand(clusterManager.generateId());
  4. command.setStatus(null);
  5. Map<Node, ConsumerSwitchResult> results = executionContext.execute(command);
  6. CompositeType compositeType = new CompositeType("Event Consumer", "Karaf Cellar cluster event consumer",
  7. new String[]{"node", "status", "local"},
  8. new String[]{"Node hosting event consumer", "Current status of the event consumer", "True if the node is local"},
  9. new OpenType[]{SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.BOOLEAN});
  10. TabularType tableType = new TabularType("Event Consumers", "Table of Karaf Cellar cluster event consumers",
  11. compositeType, new String[]{"node"});
  12. TabularDataSupport table = new TabularDataSupport(tableType);
  13. for (Node node : results.keySet()) {
  14. boolean local = (node.equals(clusterManager.getNode()));
  15. ConsumerSwitchResult consumerSwitchResult = results.get(node);
  16. String nodeName = node.getAlias();
  17. if (nodeName == null) {
  18. nodeName = node.getId();
  19. }
  20. CompositeDataSupport data = new CompositeDataSupport(compositeType,
  21. new String[]{"node", "status", "local"},
  22. new Object[]{nodeName, consumerSwitchResult.getStatus(), local});
  23. table.put(data);
  24. }
  25. return table;
  26. }

相关文章