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

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

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

Node.getId介绍

[英]Get the ID of the node.
[中]

代码示例

代码示例来源: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. 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. 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 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. /**
  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. @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: apache/karaf-cellar

  1. @Override
  2. protected Object doExecute() throws Exception {
  3. Group sourceGroup = groupManager.findGroupByName(sourceGroupName);
  4. if (sourceGroup == null) {
  5. System.err.println("Source cluster group " + sourceGroupName + " doesn't exist");
  6. return null;
  7. }
  8. Group targetGroup = groupManager.findGroupByName(targetGroupName);
  9. if (targetGroup == null) {
  10. System.err.println("Target cluster group " + targetGroupName + " doesn't exist");
  11. return null;
  12. }
  13. Set<Node> groupMembers = sourceGroup.getNodes();
  14. if (count > groupMembers.size())
  15. count = groupMembers.size();
  16. int i = 0;
  17. for (Node node : groupMembers) {
  18. if (i >= count)
  19. break;
  20. List<String> recipients = new LinkedList<String>();
  21. recipients.add(node.getId());
  22. doExecute(ManageGroupAction.SET, targetGroupName, sourceGroup, recipients);
  23. i++;
  24. }
  25. return doExecute(ManageGroupAction.LIST, null, null, new ArrayList(), false);
  26. }

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

  1. @Override
  2. public void delete(String name) throws Exception {
  3. ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
  4. try {
  5. Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
  6. Group g = groupManager.findGroupByName(name);
  7. List<String> nodes = new LinkedList<String>();
  8. if (g.getNodes() != null && !g.getNodes().isEmpty()) {
  9. for (Node n : g.getNodes()) {
  10. nodes.add(n.getId());
  11. }
  12. ManageGroupCommand command = new ManageGroupCommand(clusterManager.generateId());
  13. command.setAction(ManageGroupAction.QUIT);
  14. command.setGroupName(name);
  15. Set<Node> recipientList = clusterManager.listNodes(nodes);
  16. command.setDestination(recipientList);
  17. executionContext.execute(command);
  18. }
  19. groupManager.deleteGroup(name);
  20. } finally {
  21. Thread.currentThread().setContextClassLoader(originalClassLoader);
  22. }
  23. }

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

  1. @Override
  2. public void delete(String name) throws Exception {
  3. ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
  4. try {
  5. Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
  6. Group g = groupManager.findGroupByName(name);
  7. List<String> nodes = new LinkedList<String>();
  8. if (g.getNodes() != null && !g.getNodes().isEmpty()) {
  9. for (Node n : g.getNodes()) {
  10. nodes.add(n.getId());
  11. }
  12. ManageGroupCommand command = new ManageGroupCommand(clusterManager.generateId());
  13. command.setAction(ManageGroupAction.QUIT);
  14. command.setGroupName(name);
  15. Set<Node> recipientList = clusterManager.listNodes(nodes);
  16. command.setDestination(recipientList);
  17. executionContext.execute(command);
  18. }
  19. groupManager.deleteGroup(name);
  20. } finally {
  21. Thread.currentThread().setContextClassLoader(originalClassLoader);
  22. }
  23. }

代码示例来源:origin: apache/incubator-unomi

  1. @Override
  2. public void handle(UpdateCamelRouteEvent event) {
  3. logger.debug("Handle event");
  4. if (isAllowed(event.getSourceGroup(), Constants.CATEGORY, event.getId(), EventType.INBOUND)) {
  5. logger.debug("Event is allowed");
  6. // check if it's not a "local" event
  7. if (event.getSourceNode() != null && event.getSourceNode().getId().equalsIgnoreCase(clusterManager.getNode().getId())) {
  8. logger.debug("Cluster event is local (coming from local synchronizer or listener)");
  9. return;
  10. }
  11. try {
  12. logger.debug("Event id is {}", event.getId());
  13. if (event.getId().equals(RouterCamelContext.EVENT_ID_REMOVE) && StringUtils.isNotBlank(event.getRouteId())) {
  14. routerCamelContext.killExistingRoute(event.getRouteId(), false);
  15. } else if ((event.getId().equals(RouterCamelContext.EVENT_ID_IMPORT) || event.getId().equals(RouterCamelContext.EVENT_ID_EXPORT)) && event.getConfiguration() != null) {
  16. routerCamelContext.updateProfileReaderRoute(event.getConfiguration(), false);
  17. }
  18. } catch (Exception e) {
  19. logger.error("Error when executing event", e);
  20. }
  21. }
  22. }

代码示例来源: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: 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: 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.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. }

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

  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. }

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

  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.karaf.cellar/org.apache.karaf.cellar.core

  1. @Override
  2. public int complete(Session session, CommandLine commandLine, List<String> candidates) {
  3. StringsCompleter delegate = new StringsCompleter();
  4. try {
  5. for (Node node : clusterManager.listNodes()) {
  6. if (acceptsNode(node)) {
  7. if (addId()) {
  8. String id = node.getId();
  9. if (delegate.getStrings() != null && !delegate.getStrings().contains(id)) {
  10. delegate.getStrings().add(id);
  11. }
  12. }
  13. if (addAlias()) {
  14. String alias = node.getAlias();
  15. if (delegate.getStrings() != null && !delegate.getStrings().contains(alias)) {
  16. delegate.getStrings().add(alias);
  17. }
  18. }
  19. }
  20. }
  21. } catch (Exception e) {
  22. // Ignore
  23. }
  24. return delegate.complete(session, commandLine, candidates);
  25. }

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

  1. @Override
  2. public int complete(Session session, CommandLine commandLine, List<String> candidates) {
  3. StringsCompleter delegate = new StringsCompleter();
  4. try {
  5. for (Node node : clusterManager.listNodes()) {
  6. if (acceptsNode(node)) {
  7. if (addId()) {
  8. String id = node.getId();
  9. if (delegate.getStrings() != null && !delegate.getStrings().contains(id)) {
  10. delegate.getStrings().add(id);
  11. }
  12. }
  13. if (addAlias()) {
  14. String alias = node.getAlias();
  15. if (delegate.getStrings() != null && !delegate.getStrings().contains(alias)) {
  16. delegate.getStrings().add(alias);
  17. }
  18. }
  19. }
  20. }
  21. } catch (Exception e) {
  22. // Ignore
  23. }
  24. return delegate.complete(session, commandLine, candidates);
  25. }

代码示例来源: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 void doAppend(PaxLoggingEvent event) {
  3. Map<ClusterLogKey, ClusterLogRecord> clusterLog = clusterManager.getMap(LOG_MAP);
  4. ClusterLogRecord record = new ClusterLogRecord();
  5. ClusterLogKey key = new ClusterLogKey();
  6. Node node = clusterManager.getNode();
  7. key.setNodeId(node.getId());
  8. key.setNodeAlias(node.getAlias());
  9. key.setTimeStamp(event.getTimeStamp());
  10. key.setId(clusterManager.generateId());
  11. record.setFQNOfLoggerClass(event.getFQNOfLoggerClass());
  12. record.setLevel(event.getLevel().toString());
  13. record.setLoggerName(event.getLoggerName());
  14. record.setMessage(event.getMessage());
  15. record.setRenderedMessage(event.getRenderedMessage());
  16. record.setThreadName(event.getThreadName());
  17. record.setThrowableStringRep(event.getThrowableStrRep());
  18. clusterLog.put(key, record);
  19. }

相关文章