Class NSLookup
java.lang.Object
com.tangosol.discovery.NSLookup
NSLookup is a helper class for performing lookup from the Coherence NameService.
This helper class has no dependency on any other Coherence class and can be used to perform NameService lookup without requiring coherence jar.
List of Service Endpoints registered in NameService
ExtendClient Proxy socket address(es)GRPC Proxy socket address(es)HTTP Health URL(s)HTTP Management URL(s)HTTP Metrics URL(s)JMX Service URL
Here is an example using the NSLookup class for JMX query, assuming cluster running on local host with cluster port of 7574.
JMXServiceURL jmxServiceURL = NSLookup.lookupJMXServiceURL(new InetSocketAddress("127.0.0.1", 7574));
JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxServiceURL, null);
MBeanServerConnection conn = jmxConnector.getMBeanServerConnection();
System.out.println(conn.queryNames(new javax.management.ObjectName("Coherence:type=Cluster,*"), null));
- Since:
- 12.2.1
- Author:
- bb 2014.04.24
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThis utility must support running on JDK 7 platform. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringCluster info lookup name.static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final intDefault cluster portstatic final StringDefault host.static final StringDefault name.static final intDefault timeout in millisecondsstatic final intDefault TTL.static final StringThe gRPC Proxy lookup name.static final StringHTTP Health URL lookup name.static final StringManagement over HTTP URL lookup name.static final StringHTTP Metrics URL lookup name.static final StringManagement Node JMX Connector URL lookup name.static final StringPrefix for NS lookups which ensure result will be in string formatstatic final String[]static final String[]Valid predefined lookup names. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddatagramLookup(String sCluster, String sName, InetSocketAddress addrGroup, InetAddress addrLocal, int cTimeoutMillis, int nTTL, byte[] abMemberClient, NSLookup.BiConsumer<String, String> consumerResult) Lookup a name via UDP (generally multicast) and consume the result as a string.static DataInputStreamdatagramLookupRaw(String sCluster, String sName, InetSocketAddress addrGroup, InetAddress addrLocal, int cTimeoutMillis, int nTTL, byte[] abMemberClient) Lookup a name via UDP (generally multicast).static voiddatagramLookupRaw(String sCluster, String sName, InetSocketAddress addrGroup, InetAddress addrLocal, int cTimeoutMillis, int nTTL, byte[] abMemberClient, NSLookup.BiConsumer<String, DataInputStream> consumerResult) Lookup a name via UDP (generally multicast).static Stringlookup(String sCluster, String sName, SocketAddress socketAddr, int cTimeOutMillis) Lookup the given name from the NameService.static Stringlookup(String sName, SocketAddress socketAddr, int cTimeOutMillis) Lookup the given name from the NameService.static Collection<SocketAddress> lookupExtendProxy(String sCluster, SocketAddress socketAddr, String sName) Lookup the extend proxy serviceSocketAddress(es)for specified cluster.static Collection<SocketAddress> lookupExtendProxy(SocketAddress socketAddr, String sName) Lookup the extend proxy serviceSocketAddress(es)for current cluster.static Collection<SocketAddress> lookupGrpcProxy(String sCluster, SocketAddress socketAddr) Lookup the Grpc Proxy socket address(es) for a specified cluster.static Collection<SocketAddress> lookupGrpcProxy(SocketAddress socketAddr) Lookup the Grpc Proxy service socket address(es)static Collection<URL> lookupHTTPHealthURL(String sCluster, SocketAddress socketAddr) Lookup the current health check HTTP connector URLs for a specified cluster.static Collection<URL> lookupHTTPHealthURL(SocketAddress socketAddr) Lookup the current health check HTTP connector URLs for current cluster.static Collection<URL> lookupHTTPManagementURL(String sCluster, SocketAddress socketAddr) Lookup the current management HTTP connector URL.static Collection<URL> lookupHTTPManagementURL(SocketAddress socketAddr) Lookup the current management HTTP connector URL.static Collection<URL> lookupHTTPMetricsURL(String sCluster, SocketAddress socketAddr) Lookup the current metrics HTTP connector URLs for a specified cluster.static Collection<URL> lookupHTTPMetricsURL(SocketAddress socketAddr) Lookup the current metrics HTTP connector URLs for current cluster.static JMXServiceURLlookupJMXServiceURL(String sCluster, SocketAddress socketAddr) Lookup the current management node mbean connector url.static JMXServiceURLlookupJMXServiceURL(SocketAddress socketAddr) Lookup the current management node mbean connector url.static voidParse and validate the command-line parameters and do the lookup.static LinkedHashMapparseArguments(String[] asArg, String[] asCommand, boolean fCaseSens) Parses the array of arguments into a map.protected static byte[]read(DataInputStream inStream) Read length encoded message.protected static intreadPackedInt(DataInputStream inStream) Read packed int.static StringRead a String from a streamprotected static voidreportNameWarning(String sName) Reports-nameparameter warning when appropriate to standard error.protected static voidDisplay the command-line instructions.protected static StringvalidateCommand(String sCommand, String[] asCommand, boolean fCaseSens) Validate a command parameter.protected static StringvalidateName(String sName) Descriptive error feedback for a failed lookup of provided -name parameter.protected static voidwrite(DataOutputStream outStream, byte[] ab) Write length encoded message.protected static voidwritePackedInt(DataOutputStream outStream, int n) Write packed int.
-
Field Details
-
COMMAND_HELP
- See Also:
-
COMMAND_HOST
- See Also:
-
COMMAND_LOCAL
- See Also:
-
COMMAND_TTL
- See Also:
-
COMMAND_PORT
- See Also:
-
COMMAND_TIMEOUT
- See Also:
-
COMMAND_CLUSTER
- See Also:
-
COMMAND_NAME
- See Also:
-
VALID_COMMANDS
-
NS_STRING_PREFIX
Prefix for NS lookups which ensure result will be in string format- See Also:
-
JMX_CONNECTOR_URL
Management Node JMX Connector URL lookup name.- See Also:
-
HTTP_MANAGEMENT_URL
Management over HTTP URL lookup name.- Since:
- 12.2.1.3.2
- See Also:
-
HTTP_METRICS_URL
HTTP Metrics URL lookup name.- Since:
- 12.2.1.4.0
- See Also:
-
HTTP_HEALTH_URL
-
CLUSTER_INFO
-
GRPC_PROXY_URL
-
VALID_PREDEFINED_LOOKUP_NAMES
Valid predefined lookup names.- Since:
- 25.03
-
DEFAULT_TIMEOUT
public static final int DEFAULT_TIMEOUTDefault timeout in milliseconds- See Also:
-
DEFAULT_CLUSTERPORT
public static final int DEFAULT_CLUSTERPORTDefault cluster port- See Also:
-
DEFAULT_HOST
-
DEFAULT_TTL
public static final int DEFAULT_TTLDefault TTL.- See Also:
-
DEFAULT_NAME
-
-
Constructor Details
-
NSLookup
public NSLookup()
-
-
Method Details
-
lookupJMXServiceURL
Lookup the current management node mbean connector url.- Parameters:
socketAddr- unicast socket address of a coherence cluster node and cluster port- Returns:
- JMXServiceURL for the management node
- Throws:
IOException- if an I/O error occurs while doing the JMXServiceURL lookup
-
lookupJMXServiceURL
public static JMXServiceURL lookupJMXServiceURL(String sCluster, SocketAddress socketAddr) throws IOException Lookup the current management node mbean connector url.- Parameters:
sCluster- the target clustersocketAddr- unicast socket address of a coherence cluster node and cluster port- Returns:
- JMXServiceURL for the management node
- Throws:
IOException- if an I/O error occurs while doing the JMXServiceURL lookup
-
lookupHTTPManagementURL
Lookup the current management HTTP connector URL.- Parameters:
socketAddr- unicast socket address of a coherence cluster node and cluster port- Returns:
- a collection of URLs which can be used to access an HTTP management service
- Throws:
IOException- if an I/O error occurs while doing the URL lookup- Since:
- 12.2.1.4.0
-
lookupHTTPManagementURL
public static Collection<URL> lookupHTTPManagementURL(String sCluster, SocketAddress socketAddr) throws IOException Lookup the current management HTTP connector URL.- Parameters:
sCluster- the target clustersocketAddr- unicast socket address of a coherence cluster node and cluster port- Returns:
- a collection of URLs which can be used to access an HTTP management service
- Throws:
IOException- if an I/O error occurs while doing the URL lookup- Since:
- 12.2.1.4.0
-
lookupHTTPMetricsURL
Lookup the current metrics HTTP connector URLs for current cluster.- Parameters:
socketAddr- unicast socket address of a coherence cluster node and cluster port- Returns:
- a collection of URLs which can be used to access a HTTP metrics endpoints
- Throws:
IOException- if an I/O error occurs while doing the URL lookup- Since:
- 12.2.1.4.0
-
lookupHTTPMetricsURL
public static Collection<URL> lookupHTTPMetricsURL(String sCluster, SocketAddress socketAddr) throws IOException Lookup the current metrics HTTP connector URLs for a specified cluster.- Parameters:
sCluster- the target clustersocketAddr- unicast socket address of a coherence cluster node and cluster port- Returns:
- a collection of URLs which can be used to access a HTTP metrics endpoint
- Throws:
IOException- if an I/O error occurs while doing the URL lookup- Since:
- 12.2.1.4.0
-
lookupHTTPHealthURL
Lookup the current health check HTTP connector URLs for current cluster.- Parameters:
socketAddr- unicast socket address of a coherence cluster node and cluster port- Returns:
- a collection of URLs which can be used to access a HTTP health check endpoints
- Throws:
IOException- if an I/O error occurs while doing the URL lookup- Since:
- 22.06
-
lookupHTTPHealthURL
public static Collection<URL> lookupHTTPHealthURL(String sCluster, SocketAddress socketAddr) throws IOException Lookup the current health check HTTP connector URLs for a specified cluster.- Parameters:
sCluster- the target clustersocketAddr- unicast socket address of a coherence cluster node and cluster port- Returns:
- a collection of URLs which can be used to access a HTTP health check endpoint
- Throws:
IOException- if an I/O error occurs while doing the URL lookup- Since:
- 22.06
-
lookupGrpcProxy
public static Collection<SocketAddress> lookupGrpcProxy(SocketAddress socketAddr) throws IOException Lookup the Grpc Proxy service socket address(es)- Parameters:
socketAddr- unicast socket address of a coherence cluster node and cluster port- Returns:
- a collection of
SocketAddresswhich can be used to access a proxy endpoints in the target cluster - Throws:
IOException- if an I/O error occurs while doing the URL lookup- Since:
- 22.06.2
-
lookupGrpcProxy
public static Collection<SocketAddress> lookupGrpcProxy(String sCluster, SocketAddress socketAddr) throws IOException Lookup the Grpc Proxy socket address(es) for a specified cluster.- Parameters:
sCluster- the target cluster namesocketAddr- unicast socket address of a coherence cluster node and cluster port- Returns:
- a collection of
SocketAddresswhich can be used to access grpc proxy endpoints in the target cluster - Throws:
IOException- if an I/O error occurs while doing the URL lookup- Since:
- 22.06.2
-
lookupExtendProxy
public static Collection<SocketAddress> lookupExtendProxy(SocketAddress socketAddr, String sName) throws IOException Lookup the extend proxy serviceSocketAddress(es)for current cluster.- Parameters:
socketAddr- unicast socket address of a coherence cluster node and cluster portsName- proxy service name, must be fully scoped service name when application scoping is enabled- Returns:
- a collection of socket address(es) which can be used to access extend client proxy's endpoint(s)
- Throws:
IOException- if an I/O error occurs while doing the extend client proxy service lookup- Since:
- 24.09
-
lookupExtendProxy
public static Collection<SocketAddress> lookupExtendProxy(String sCluster, SocketAddress socketAddr, String sName) throws IOException Lookup the extend proxy serviceSocketAddress(es)for specified cluster.- Parameters:
sCluster- the target cluster namesocketAddr- unicast socket address of a coherence cluster node and cluster portsName- proxy service name, must be fully scoped service name when application scoping is enabled- Returns:
- a collection of socket addresses which can be used to access extend proxy endpoints in the target cluster
- Throws:
IOException- if an I/O error occurs while doing the extend client proxy service lookup- Since:
- 24.09
-
lookup
public static String lookup(String sName, SocketAddress socketAddr, int cTimeOutMillis) throws IOException Lookup the given name from the NameService. The object bound to the NameService should be a String.The
sNameparameter string consists of"NameService/string/"followed by one of the following:- service name when application scoping is not enabled
- a fully scoped service name, i.e
application-scope-name:proxy-service-name
- Parameters:
sName- name service name, syntax provided abovesocketAddr- unicast socket address of a coherence cluster node and the cluster portcTimeOutMillis- timeout in millis- Returns:
- String bound to the NameService with the given name
- Throws:
IOException- if an I/O error occurs while doing the lookup
-
lookup
public static String lookup(String sCluster, String sName, SocketAddress socketAddr, int cTimeOutMillis) throws IOException Lookup the given name from the NameService. The object bound to the NameService should be a String.The
sNameparameter string consists of"NameService/string/"followed by one of the following:- service name when application scoping is not enabled
- a fully scoped service name, i.e application-scope-name:proxy-service-name
- Parameters:
sCluster- target cluster namesName- name service name, syntax provided abovesocketAddr- unicast socket address of a coherence cluster node and cluster portcTimeOutMillis- timeout in millis- Returns:
- String bound to the NameService with the given name
- Throws:
IOException- if an I/O error occurs while doing the lookup
-
write
Write length encoded message.- Parameters:
outStream- socket output streamab- message byte[] to write- Throws:
IOException- if an I/O error occurs while writing to the socket stream
-
read
Read length encoded message.- Parameters:
inStream- socket input stream- Returns:
- message byte[]
- Throws:
IOException- if an I/O error occurs while reading from the socket stream
-
writePackedInt
Write packed int.- Parameters:
outStream- socket output streamn- int to write- Throws:
IOException- if an I/O error occurs while writing to the socket stream
-
readPackedInt
Read packed int.- Parameters:
inStream- socket input stream- Returns:
- int read
- Throws:
IOException- if an I/O error occurs while reading from the socket stream
-
validateCommand
-
parseArguments
Parses the array of arguments into a map. Assume that a java tool starts by command line having the following syntax: cmd-line ::== (command space)* (argument space)* command ::== "-" cmd-name ("=" | ":" | space) (cmd-value)? cmd-name ::== word cmd-value ::== word ("," word)* argument ::== word ("," word)* space ::== (" ")+ When java starts an application the arguments in the command line are placed into a string array by breaking at spaces. The purpose of this method is to place the command line into a LinkedHashMap where each<command>would represent an entry in this map with values equal to<cmd-value>(null if not present) and each<argument>represented with an entry that has the key equal to an Integer object holding on the 0-based argument number and the value equal to the argument itself.- Parameters:
asArg- an array of arguments from "public static main(String[])"asCommand- an array of valid commands (if null, anything is allowed)fCaseSens- if true, uses the commands the way they are typed in; if false, converts all the commands to lowercase.- Returns:
- a map of arguments with their corresponding values
- Throws:
IllegalArgumentException- if the syntax is unexpected or an invalid command has been encountered; a caller is supposed to output the "Usage: ... " message if this exception is thrown.
-
datagramLookupRaw
public static void datagramLookupRaw(String sCluster, String sName, InetSocketAddress addrGroup, InetAddress addrLocal, int cTimeoutMillis, int nTTL, byte[] abMemberClient, NSLookup.BiConsumer<String, DataInputStream> consumerResult) throws IOException Lookup a name via UDP (generally multicast).- Parameters:
sCluster- the cluster of addresssName- the name to lookupaddrGroup- the cluster addressaddrLocal- the NIC to usecTimeoutMillis- the discovery timeoutnTTL- the multicast TTLabMemberClient- optional serialized Member object representing the clientconsumerResult- the consumer for results- Throws:
IOException
-
datagramLookupRaw
public static DataInputStream datagramLookupRaw(String sCluster, String sName, InetSocketAddress addrGroup, InetAddress addrLocal, int cTimeoutMillis, int nTTL, byte[] abMemberClient) throws IOException Lookup a name via UDP (generally multicast).- Parameters:
sCluster- the cluster of addresssName- the name to lookupaddrGroup- the cluster addressaddrLocal- the NIC to usecTimeoutMillis- the discovery timeoutnTTL- the multicast TTLabMemberClient- optional serialized Member object representing the client- Throws:
IOException
-
datagramLookup
public static void datagramLookup(String sCluster, String sName, InetSocketAddress addrGroup, InetAddress addrLocal, int cTimeoutMillis, int nTTL, byte[] abMemberClient, NSLookup.BiConsumer<String, String> consumerResult) throws IOExceptionLookup a name via UDP (generally multicast) and consume the result as a string.- Parameters:
sCluster- the cluster of addresssName- the name to lookupaddrGroup- the cluster addressaddrLocal- the NIC to usecTimeoutMillis- the discovery timeoutnTTL- the multicast TTLabMemberClient- optional serialized Member object representing the clientconsumerResult- the consumer for results- Throws:
IOException
-
readString
Read a String from a stream- Parameters:
in- a DataInputStream containing the result- Returns:
- the String
-
main
Parse and validate the command-line parameters and do the lookup.- Parameters:
asArg- an array of command line parameters- Throws:
IOException- if an I/O error occurs while doing the lookup
-
showInstructions
protected static void showInstructions()Display the command-line instructions. -
validateName
-
reportNameWarning
Reports-nameparameter warning when appropriate to standard error.- Parameters:
sName- Name Service looked up
-