本文整理了Java中org.apache.karaf.cellar.core.Node.getId()
方法的一些代码示例,展示了Node.getId()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.getId()
方法的具体详情如下:
包路径:org.apache.karaf.cellar.core.Node
类名称:Node
方法名:getId
[英]Get the ID of the node.
[中]
代码示例来源:origin: org.apache.karaf.cellar/org.apache.karaf.cellar.hazelcast
@Override
public String getId(String alias) throws Exception {
Node node = clusterManager.findNodeByAlias(alias);
if (node != null) {
return node.getId();
}
return null;
}
代码示例来源:origin: apache/karaf-cellar
@Override
public String getId(String alias) throws Exception {
Node node = clusterManager.findNodeByAlias(alias);
if (node != null) {
return node.getId();
}
return null;
}
代码示例来源:origin: apache/karaf-cellar
public Map<String, List<String>> getServices() {
Map<String, List<String>> services = new HashMap<String, List<String>>();
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
Map<String, EndpointDescription> remoteEndpoints = clusterManager.getMap(Constants.REMOTE_ENDPOINTS);
if (remoteEndpoints != null && !remoteEndpoints.isEmpty()) {
for (Map.Entry<String, EndpointDescription> entry : remoteEndpoints.entrySet()) {
EndpointDescription endpointDescription = entry.getValue();
String serviceClass = endpointDescription.getServiceClass();
Set<Node> nodes = endpointDescription.getNodes();
LinkedList<String> providers = new LinkedList<String>();
for (Node node : nodes) {
providers.add(node.getId());
}
services.put(serviceClass, providers);
}
}
} finally {
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
return services;
}
代码示例来源:origin: apache/karaf-cellar
@Override
public Object doExecute() throws Exception {
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
try {
Map<ClusterLogKey, ClusterLogRecord> clusterLog = clusterManager.getMap(LogAppender.LOG_MAP);
if (nodeIdOrAlias == null) {
clusterLog.clear();
} else {
Node node = clusterManager.findNodeByIdOrAlias(nodeIdOrAlias);
if (node == null) {
System.err.println("Node " + nodeIdOrAlias + " doesn't exist");
return null;
}
for (ClusterLogKey key : clusterLog.keySet()) {
if (key.getNodeId().equals(node.getId())) {
clusterLog.remove(key);
}
}
}
} finally {
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
return null;
}
代码示例来源:origin: apache/karaf-cellar
/**
* Check if there is a match for the current {@link ListenerInfo}.
*
* @param listenerInfo the listener info.
*/
private void checkListener(ListenerInfo listenerInfo) {
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
// iterate through known services and import them if needed
Set<EndpointDescription> matches = new LinkedHashSet<EndpointDescription>();
for (Map.Entry<String, EndpointDescription> entry : remoteEndpoints.entrySet()) {
EndpointDescription endpointDescription = entry.getValue();
if (endpointDescription.matches(listenerInfo.getFilter()) && !endpointDescription.getNodes().contains(clusterManager.getNode().getId())) {
matches.add(endpointDescription);
}
}
for (EndpointDescription endpoint : matches) {
importService(endpoint, listenerInfo);
}
} finally {
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
}
代码示例来源:origin: apache/karaf-cellar
@Override
public void doStart() throws Exception {
ClusterManager clusterManager = getTrackedService(ClusterManager.class);
if (clusterManager == null)
return;
String nodeId = clusterManager.getNode().getId();
GreeterImpl greeter = new GreeterImpl(nodeId);
Hashtable props = new Hashtable();
props.put("service.exported.interfaces", "*");
register(Greeter.class, greeter, props);
}
代码示例来源: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 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
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/incubator-unomi
@Override
public void handle(UpdateCamelRouteEvent event) {
logger.debug("Handle event");
if (isAllowed(event.getSourceGroup(), Constants.CATEGORY, event.getId(), EventType.INBOUND)) {
logger.debug("Event is allowed");
// check if it's not a "local" event
if (event.getSourceNode() != null && event.getSourceNode().getId().equalsIgnoreCase(clusterManager.getNode().getId())) {
logger.debug("Cluster event is local (coming from local synchronizer or listener)");
return;
}
try {
logger.debug("Event id is {}", event.getId());
if (event.getId().equals(RouterCamelContext.EVENT_ID_REMOVE) && StringUtils.isNotBlank(event.getRouteId())) {
routerCamelContext.killExistingRoute(event.getRouteId(), false);
} else if ((event.getId().equals(RouterCamelContext.EVENT_ID_IMPORT) || event.getId().equals(RouterCamelContext.EVENT_ID_EXPORT)) && event.getConfiguration() != null) {
routerCamelContext.updateProfileReaderRoute(event.getConfiguration(), false);
}
} catch (Exception e) {
logger.error("Error when executing event", e);
}
}
}
代码示例来源:origin: org.apache.karaf.cellar/org.apache.karaf.cellar.hazelcast
@Override
public TabularData getNodes() throws Exception {
CompositeType nodeType = new CompositeType("Node", "Karaf Cellar cluster node",
new String[]{ "id", "alias", "hostname", "port", "local" },
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" },
new OpenType[]{ SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.INTEGER, SimpleType.BOOLEAN });
TabularType tableType = new TabularType("Nodes", "Table of all Karaf Cellar nodes", nodeType, new String[]{ "id" });
TabularData table = new TabularDataSupport(tableType);
Set<Node> nodes = clusterManager.listNodes();
for (Node node : nodes) {
boolean local = (node.equals(clusterManager.getNode()));
CompositeData data = new CompositeDataSupport(nodeType,
new String[]{ "id", "alias", "hostname", "port", "local" },
new Object[]{ node.getId(), node.getAlias(), node.getHost(), node.getPort(), local });
table.put(data);
}
return table;
}
代码示例来源:origin: apache/karaf-cellar
@Override
public TabularData getNodes() throws Exception {
CompositeType nodeType = new CompositeType("Node", "Karaf Cellar cluster node",
new String[]{ "id", "alias", "hostname", "port", "local" },
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" },
new OpenType[]{ SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.INTEGER, SimpleType.BOOLEAN });
TabularType tableType = new TabularType("Nodes", "Table of all Karaf Cellar nodes", nodeType, new String[]{ "id" });
TabularData table = new TabularDataSupport(tableType);
Set<Node> nodes = clusterManager.listNodes();
for (Node node : nodes) {
boolean local = (node.equals(clusterManager.getNode()));
CompositeData data = new CompositeDataSupport(nodeType,
new String[]{ "id", "alias", "hostname", "port", "local" },
new Object[]{ node.getId(), node.getAlias(), node.getHost(), node.getPort(), local });
table.put(data);
}
return table;
}
代码示例来源:origin: org.apache.karaf.cellar/org.apache.karaf.cellar.hazelcast
@Override
public TabularData producerStatus() throws Exception {
ProducerSwitchCommand command = new ProducerSwitchCommand(clusterManager.generateId());
command.setStatus(null);
Map<Node, ProducerSwitchResult> results = executionContext.execute(command);
CompositeType compositeType = new CompositeType("Event Producer", "Karaf Cellar cluster event producer",
new String[]{"node", "status", "local"},
new String[]{"Node hosting event producer", "Current status of the event producer", "True if the node is local"},
new OpenType[]{SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.BOOLEAN});
TabularType tableType = new TabularType("Event Producers", "Table of Karaf Cellar cluster event producers",
compositeType, new String[]{"node"});
TabularDataSupport table = new TabularDataSupport(tableType);
for (Node node : results.keySet()) {
boolean local = (node.equals(clusterManager.getNode()));
ProducerSwitchResult producerSwitchResult = results.get(node);
String nodeName = node.getAlias();
if (nodeName == null) {
nodeName = node.getId();
}
CompositeDataSupport data = new CompositeDataSupport(compositeType,
new String[]{"node", "status", "local"},
new Object[]{nodeName, producerSwitchResult.getStatus(), local});
table.put(data);
}
return table;
}
代码示例来源:origin: org.apache.karaf.cellar/org.apache.karaf.cellar.hazelcast
@Override
public TabularData consumerStatus() throws Exception {
ConsumerSwitchCommand command = new ConsumerSwitchCommand(clusterManager.generateId());
command.setStatus(null);
Map<Node, ConsumerSwitchResult> results = executionContext.execute(command);
CompositeType compositeType = new CompositeType("Event Consumer", "Karaf Cellar cluster event consumer",
new String[]{"node", "status", "local"},
new String[]{"Node hosting event consumer", "Current status of the event consumer", "True if the node is local"},
new OpenType[]{SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.BOOLEAN});
TabularType tableType = new TabularType("Event Consumers", "Table of Karaf Cellar cluster event consumers",
compositeType, new String[]{"node"});
TabularDataSupport table = new TabularDataSupport(tableType);
for (Node node : results.keySet()) {
boolean local = (node.equals(clusterManager.getNode()));
ConsumerSwitchResult consumerSwitchResult = results.get(node);
String nodeName = node.getAlias();
if (nodeName == null) {
nodeName = node.getId();
}
CompositeDataSupport data = new CompositeDataSupport(compositeType,
new String[]{"node", "status", "local"},
new Object[]{nodeName, consumerSwitchResult.getStatus(), local});
table.put(data);
}
return table;
}
代码示例来源:origin: apache/karaf-cellar
@Override
public TabularData consumerStatus() throws Exception {
ConsumerSwitchCommand command = new ConsumerSwitchCommand(clusterManager.generateId());
command.setStatus(null);
Map<Node, ConsumerSwitchResult> results = executionContext.execute(command);
CompositeType compositeType = new CompositeType("Event Consumer", "Karaf Cellar cluster event consumer",
new String[]{"node", "status", "local"},
new String[]{"Node hosting event consumer", "Current status of the event consumer", "True if the node is local"},
new OpenType[]{SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.BOOLEAN});
TabularType tableType = new TabularType("Event Consumers", "Table of Karaf Cellar cluster event consumers",
compositeType, new String[]{"node"});
TabularDataSupport table = new TabularDataSupport(tableType);
for (Node node : results.keySet()) {
boolean local = (node.equals(clusterManager.getNode()));
ConsumerSwitchResult consumerSwitchResult = results.get(node);
String nodeName = node.getAlias();
if (nodeName == null) {
nodeName = node.getId();
}
CompositeDataSupport data = new CompositeDataSupport(compositeType,
new String[]{"node", "status", "local"},
new Object[]{nodeName, consumerSwitchResult.getStatus(), local});
table.put(data);
}
return table;
}
代码示例来源:origin: apache/karaf-cellar
@Override
public TabularData producerStatus() throws Exception {
ProducerSwitchCommand command = new ProducerSwitchCommand(clusterManager.generateId());
command.setStatus(null);
Map<Node, ProducerSwitchResult> results = executionContext.execute(command);
CompositeType compositeType = new CompositeType("Event Producer", "Karaf Cellar cluster event producer",
new String[]{"node", "status", "local"},
new String[]{"Node hosting event producer", "Current status of the event producer", "True if the node is local"},
new OpenType[]{SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.BOOLEAN});
TabularType tableType = new TabularType("Event Producers", "Table of Karaf Cellar cluster event producers",
compositeType, new String[]{"node"});
TabularDataSupport table = new TabularDataSupport(tableType);
for (Node node : results.keySet()) {
boolean local = (node.equals(clusterManager.getNode()));
ProducerSwitchResult producerSwitchResult = results.get(node);
String nodeName = node.getAlias();
if (nodeName == null) {
nodeName = node.getId();
}
CompositeDataSupport data = new CompositeDataSupport(compositeType,
new String[]{"node", "status", "local"},
new Object[]{nodeName, producerSwitchResult.getStatus(), local});
table.put(data);
}
return table;
}
代码示例来源:origin: org.apache.karaf.cellar/org.apache.karaf.cellar.core
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
StringsCompleter delegate = new StringsCompleter();
try {
for (Node node : clusterManager.listNodes()) {
if (acceptsNode(node)) {
if (addId()) {
String id = node.getId();
if (delegate.getStrings() != null && !delegate.getStrings().contains(id)) {
delegate.getStrings().add(id);
}
}
if (addAlias()) {
String alias = node.getAlias();
if (delegate.getStrings() != null && !delegate.getStrings().contains(alias)) {
delegate.getStrings().add(alias);
}
}
}
}
} catch (Exception e) {
// Ignore
}
return delegate.complete(session, commandLine, candidates);
}
代码示例来源:origin: apache/karaf-cellar
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
StringsCompleter delegate = new StringsCompleter();
try {
for (Node node : clusterManager.listNodes()) {
if (acceptsNode(node)) {
if (addId()) {
String id = node.getId();
if (delegate.getStrings() != null && !delegate.getStrings().contains(id)) {
delegate.getStrings().add(id);
}
}
if (addAlias()) {
String alias = node.getAlias();
if (delegate.getStrings() != null && !delegate.getStrings().contains(alias)) {
delegate.getStrings().add(alias);
}
}
}
}
} catch (Exception e) {
// Ignore
}
return delegate.complete(session, commandLine, candidates);
}
代码示例来源:origin: apache/karaf-cellar
@Override
protected Object doExecute() throws Exception {
Set<Node> nodes = clusterManager.listNodes();
if (nodes != null && !nodes.isEmpty()) {
ShellTable table = new ShellTable();
table.column(" ");
table.column("Id");
table.column("Alias");
table.column("Host Name");
table.column("Port");
for (Node node : nodes) {
String local = "";
if (node.equals(clusterManager.getNode()))
local = "x";
table.addRow().addContent(local, node.getId(), node.getAlias(), node.getHost(), node.getPort());
}
table.print(System.out);
} else {
System.err.println("No node found in the cluster");
}
return null;
}
代码示例来源:origin: apache/karaf-cellar
@Override
public void doAppend(PaxLoggingEvent event) {
Map<ClusterLogKey, ClusterLogRecord> clusterLog = clusterManager.getMap(LOG_MAP);
ClusterLogRecord record = new ClusterLogRecord();
ClusterLogKey key = new ClusterLogKey();
Node node = clusterManager.getNode();
key.setNodeId(node.getId());
key.setNodeAlias(node.getAlias());
key.setTimeStamp(event.getTimeStamp());
key.setId(clusterManager.generateId());
record.setFQNOfLoggerClass(event.getFQNOfLoggerClass());
record.setLevel(event.getLevel().toString());
record.setLoggerName(event.getLoggerName());
record.setMessage(event.getMessage());
record.setRenderedMessage(event.getRenderedMessage());
record.setThreadName(event.getThreadName());
record.setThrowableStringRep(event.getThrowableStrRep());
clusterLog.put(key, record);
}
内容来源于网络,如有侵权,请联系作者删除!