public class Pathfinder extends Object
The Pathfinder class is the main entry point to the Pathfinder API. To create the Pathfinder class you need a valid application identifier provided from your Pathfinder service manager, we provide the ability to get an application identifier from thepathfinder.xyz. The connection also requires a JWT in the form of a String to authenticate the user. The URI to your pathfinder provider is also required to initiate the connection.
The default cluster is available via the getDefaultCluster() method. Any other cluster available to
the user may be obtained through the getCluster(String) method, where the path is of the form
"/default/clusterName/subclusterName/subsubclusterName".
Note, when connecting thePathfinder object the thread is blocked until the web socket to the
Pathfinder service is opened.
Pathfinder pathfinder = new Pathfinder("myAppId", "userJWT");
pathfinder.addAuthenticationListener(new MyAuthListener());
pathfinder.connect();
Cluster cluster = pathfinder.getCluster("/root/cluster1/subcluster2");
MyClusterListener clusterListener = new MyClusterListener();
cluster.addListener(clusterListener);
cluster.connect();
// more code ...
pathfinder.close();| Modifier and Type | Field and Description |
|---|---|
private String |
applicationIdentifier
Application Identifier that identifies the application on the pathfinder server.
|
private Authenticator |
authenticator
The authenticator controlling the authentication sequence.
|
private static String |
DEFAULT_AUTH_URI
The default authentication server URI.
|
private static String |
DEFAULT_WEBSOCKET_URI
The default web socket URI.
|
private static org.slf4j.Logger |
logger
Logs actions performed by the class.
|
private PathfinderServices |
services
Keeps track of all the Pathfinder models and connection to the server.
|
private URI |
webSocketUrl
URL to the Pathfinder server being connected to.
|
| Modifier | Constructor and Description |
|---|---|
|
Pathfinder(String applicationIdentifier,
String userCredentials)
Constructs a Pathfinder object.
|
|
Pathfinder(String applicationIdentifier,
String userCredentials,
String authenticationServerURL)
Constructs a Pathfinder object.
|
protected |
Pathfinder(String applicationIdentifier,
String userCredentials,
URI webSocketUrl)
Constructs a Pathfinder object.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAuthenticationListener(AuthenticationListener listener)
Adds an
AuthenticationListener to listen for the success or failure
of the authentication sequence. |
void |
close()
Closes the web socket connection to the Pathfinder server with a normal close condition.
|
void |
close(CloseReason reason)
Closes the web socket connection to the Pathfinder server, if it is still open, with the specified reason.
|
void |
connect()
Establishes a connection to the Pathfinder server, if the connection is not already open.
|
void |
connect(boolean isAsync)
Establishes a connection to the Pathfinder server, if the connection is not already open.
|
private void |
constructPathfinderServices(String applicationIdentifier,
String userCredentials,
String authenticationServerURL)
Sets the
PathfinderServices object. |
Cluster |
getCluster(String path)
Gets an unconnected cluster pointing to the path specified.
|
Commodity |
getCommodity(String path)
Gets an unconnected commodity pointing to the path specified.
|
Cluster |
getDefaultCluster()
Gets an unconnected cluster pointing to the default cluster for the application identifier provided.
|
protected long |
getReceivedMessageCount()
Returns the number of web socket messages received from the Pathfinder server.
|
protected long |
getSentMessageCount()
Returns the number of web socket messages sent to the Pathfinder server.
|
Transport |
getTransport(String path)
Gets an unconnected transport pointing to the path specified.
|
boolean |
isConnected()
Returns true if the web socket connection to the Pathfinder server is open.
|
void |
removeAuthenticationListener(AuthenticationListener listener)
Removes an
AuthenticationListener. |
private static final org.slf4j.Logger logger
private static final String DEFAULT_AUTH_URI
private static final String DEFAULT_WEBSOCKET_URI
private final String applicationIdentifier
private Authenticator authenticator
private PathfinderServices services
private URI webSocketUrl
public Pathfinder(String applicationIdentifier, String userCredentials)
applicationIdentifier - application Identifier provided by a Pathfinder service provideruserCredentials - JWT of the user's credentialspublic Pathfinder(String applicationIdentifier, String userCredentials, String authenticationServerURL)
applicationIdentifier - application Identifier provided by a Pathfinder service provideruserCredentials - JWT of the user's credentialsauthenticationServerURL - URL to use when authenticating usersprotected Pathfinder(String applicationIdentifier, String userCredentials, URI webSocketUrl)
applicationIdentifier - application Identifier provided by a Pathfinder service provideruserCredentials - JWT of the user's credentialswebSocketUrl - URL to the Pathfinder web socket service providerprivate void constructPathfinderServices(String applicationIdentifier, String userCredentials, String authenticationServerURL)
PathfinderServices object.applicationIdentifier - application Identifier provided by a Pathfinder service provideruserCredentials - the user's identity JWT.authenticationServerURL - URL to use when authenticating userspublic void connect()
RuntimeException - if could not connect to the Pathfinder server.public void connect(boolean isAsync)
isAsync - if true it will asynchronously connect to the Pathfinder server, if
false it will synchronously connect to the Pathfinder serverRuntimeException - if could not connect to the Pathfinder server.public void addAuthenticationListener(AuthenticationListener listener)
AuthenticationListener to listen for the success or failure
of the authentication sequence.listener - to add.public void removeAuthenticationListener(AuthenticationListener listener)
AuthenticationListener.listener - to remove.public Cluster getDefaultCluster()
public Cluster getCluster(String path)
path - to the clusterpublic Commodity getCommodity(String path)
path - to the commoditypublic Transport getTransport(String path)
path - to the transportpublic boolean isConnected()
protected long getSentMessageCount()
protected long getReceivedMessageCount()
public void close()
throws IOException
IOException - If there was error closing the connection.public void close(CloseReason reason) throws IOException
reason - The reason to close the connection.IOException - If there was error closing the connection.