The public Javadoc describes the GatewayNetworkManager class, which includes several methods in its summary that return com.inductiveautomation.metro.impl.ConnectionWatcher objects, but I can’t seem to find any sort of documentation for those ConnectionWatcher objects themselves to make use of them.
Any guidance or source of info that I might be missing here?
When you see .impl in a package or class name, that is a hint that you are looking at an implementation of a public interface. If you aren't finding docs, then the implementation is deliberately not public.
Don't hold your breath.
Perhaps you should describe the problem you are trying to solve.
I had figured that was going to be the case, but found it odd that the methods that return those objects would be documented publicly, but then how to use the objects would not.
Essentially what I’m needing to accomplish is the identify if a specific gateway is reachable via the GAN, determine its state if possible, and then react to those state changes. I need to do this for multiple gateways simultaneously, which was what lead me to the GatewayNetworkManager and the getAvailableConnections method.
Consider using jython in a gateway script to introspect to find what's possible. You might find my Integration Toolkit's system.reflection.* methods helpful.
There are a couple other ways you can do this without needing to use the SDK. For example, connected gateways are available as tags under the System tag provider under this path: [System]Gateway/Gateway Network
If you are using 8.3, you can also use the OpenAPI routes to get a connected gateways list via this route: /data/api/v1/gateway-network/gateways
The SDK method is preferred, as the use-case is a custom module I’m working on, and the current target version is 8.1.50 so the OpenAPI routes approach would also not be viable.
I could see the tags as a workaround, but would really prefer to get the information from as close to the source of truth as possible to minimize the potential of failures that could be caused anywhere else along the chain of custody of that information, if that makes sense?
I think this example would cover everything that you need, and everything in here should be available via public SDK functions. Let me know if something doesn’t make sense though.
/*
Imports for convenience:
import com.inductiveautomation.ignition.common.licensing.LicenseState;
import com.inductiveautomation.ignition.gateway.model.AbstractGatewayModuleHook;
import com.inductiveautomation.ignition.gateway.model.GatewayContext;
import com.inductiveautomation.metro.api.ServerId;
import com.inductiveautomation.metro.api.ServerListener;
import com.inductiveautomation.metro.api.ServerState;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
*/
public class TestHook extends AbstractGatewayModuleHook {
GatewayContext context;
ServerId remoteServerId;
ServerListener serverListener;
Logger myLog = LoggerFactory.getLogger("MyLog");
// setup() should be present in any module that runs in the gateway scope
@Override
public void setup(GatewayContext context) {
this.context = context;
this.remoteServerId = ServerId.fromString("exampleGateway"); // Hardcoded example ServerId
// You want to save the serverListener object somewhere so you can access it on shutdown
serverListener = new ServerListener() {
@Override
public void serverStateChanged(ServerId serverId, ServerState state) {
// TODO Add whatever else is needed here
myLog.info("ServerState for server '{}' changed to '{}", serverId.toDescriptiveString(), state);
/*
ServerState possible values:
NotDefined, // Remote gateway does not exist at all
Defined_NeverConnected, // A system references the remote gateway address, but the actual gateway doesn't exist
Incompatible, // The remote gateway is 7.9, and is not allowed to connect to the local gateway
NotConnected, // The remote gateway was available at one point, but is not available now
Waiting, // The local system is waiting for the first service enumeration list from the remote gateway
Connected; // The local gateway is able to communicate with the remote gateway
*/
}
};
context.getGatewayNetworkManager().addServerListener(remoteServerId, serverListener);
}
@Override
public void startup(LicenseState activationState) {
// An example of how to look up a remote gateway's current state
ServerState serverState = context.getGatewayNetworkManager().getServerState(remoteServerId);
myLog.info("ServerState for server '{}' is currently '{}", remoteServerId.toDescriptiveString(), serverState);
}
@Override
public void shutdown() {
context.getGatewayNetworkManager().removeServerListener(remoteServerId, serverListener);
}
}