Geneos


The end of life (EOL) date for this module is on 31 January, 2020.

Connecting

Basic

Connecting your Open Access client is as simple as calling OpenAccess.connect.

At the very least you must specify the host and port of an Open Access node, in this case myhost.com at port 2551.

Using a URI:

Connection conn = OpenAccess.connect("geneos.cluster://myhost.com:2551");

Using the ConnectionParameters:

ConnectionParameters params = ConnectionParametersBuilder.builder().addresses("myhost.com:2551").build();

Connection conn = OpenAccess.connect(params);

Authentication

If you have configured the cluster with authentication (See User Authentication) you must additionally specify a username and password in the connection.

Using a URI:

Connection conn = OpenAccess.connect("geneos.cluster://myhost.com:2551?username=fred&password=secret");

Using the ConnectionParameters:

ConnectionParameters params = ConnectionParametersBuilder.builder().
        addresses("myhost.com:2551").
        user("fred", "secret").build();

Connection conn = OpenAccess.connect(params);

SSL

If you have configured the cluster with authentication (See SSL on the client and SSL in the cluster) you must specify this in the connection.

Using a URI:

Connection conn = OpenAccess.connect("geneos.cluster.ssl://myhost.com:2551");

Using the ConnectionParameters:

ConnectionParameters params = ConnectionParametersBuilder.builder().
        ssl(true).
        addresses("myhost.com:2551").build();

Connection conn = OpenAccess.connect(params);

Multiple node addresses

As of version 1.2, it is possible to specify multiple node addresses. In the event that one node is down, the client will connect to another.

This can only be done using the ConnectionParameters:

ConnectionParameters params = ConnectionParametersBuilder.builder().
        addresses("myhost.com:2551", "anotherhost.com:2551").build();

Connection conn = OpenAccess.connect(params);

or

List<String> addressList = new ArrayList<String>();
addressList.add("myhost.com:2551");
addressList.add("anotherhost.com:2551");

ConnectionParameters params = ConnectionParametersBuilder.builder().
            addresses(addressList).build();

    Connection conn = OpenAccess.connect(params);

Status and Error Callbacks

You can pass a connection status and error callback to connect to be notified of the connection status and errors respectively:

ConnectionParameters params = ConnectionParametersBuilder.builder().
        addresses("myhost.com:2551").build();

Connection conn = OpenAccess.connect(params,
        new Callback<ConnectionStatus>() {
            @Override
            public void callback(final ConnectionStatus change) {
                System.out.println(change.toString());
            }
        },
        new ErrorCallback() {
            @Override
            public void error(final Exception exception) {
                System.err.println("Connection error: " + exception);
            }
        });

Multiple cluster addresses

Warning

When connecting to multiple clusters it is important that the gateways be unique across the clusters. If the same gateway exists in mulltiple clusters and you connect to those clusters from a client, the results are undefined.

In version 2.0 you can specify a set of ConnectionParameters to establish connections to mulitple clusters. This method requires you to pass status and error callbacks in addition to the parameters:

ConnectionParametersBuilder builder = ConnectionParametersBuilder.builder();
ConnectionParameters firstConnParam = builder.addresses("myfirstcluster.com:2551", "myfirstcluster.com:2552").build();
ConnectionParameters secondConnParam = builder.addresses("mysecondcluster.com:2551", "mysecondcluster.com:2552").build();

Set<ConnectionParameters> multiClusterParams = new HashSet<ConnectionParameters>();
multiClusterParams.add(firstConnParam);
multiClusterParams.add(secondConnParam);

Connection conn = OpenAccess.connect(multiClusterParams,
            new Callback<ConnectionStatus>() {
                @Override
                public void callback(final ConnectionStatus change) {
                    System.out.println(change.toString());
                }
            },
            new ErrorCallback() {
                @Override
                public void error(final Exception exception) {
                    System.err.println("Connection error: " + exception);
                }
            });