Skip to main content
Version: 24.3

Creating a Services Object

Once you have created a V1Connector instance, you'll need to create an instance of the Services class, which is the primary object that you will use to perform actions with the Agility API. There are three constructors for the Services class. All of them require a V1Connector instance, however.

Creating a V1Connector Instance

Here's a simple example of creating a V1Connector instance. This example uses an Access Token. For other types of connections, see the Creating a Connection topic.

            V1Connector connector = V1Connector
.withInstanceUrl("<Server Base URI>")
.withUserAgentHeader("AppName", "1.0")
.withAccessToken("1.rWM8lKLk+PnyFxkEWVX5Kl2u6Jk=")
.build();

Services(V1Connector v1Connector)

To create an instance of Services that creates an IMetaModel instance for you automatically, just use the one-parameter version of the constructor, passing in your V1Connector instance. By default, the connector will not pre-load the Retrieve metadata for all system assets information. If you need to do that, see the next overload.

                IServices services = new Services(connector);

Services(V1Connector connector, boolean preLoadMeta)

If you'd like to force the connector to pre-load the Meta information before you work with the Services instance, call this version of the constructor and specify true for the second parameter. Note that this can cause the start-up time for your code to take a long time, but it is ultimately faster if you do a significant number of queries against a large variety of Asset types or Attributes. If you work with a smaller variety, then allowing the connector to dynamically fetch Meta is a better approach.

                    IServices services = new Services(connector, true);

Services(V1Connector connector, IMetaModel metaModel)

Though it would rarely be needed for most purposes, if you want complete control over creating the IMetaModel instance that you configure your Services instance with, you can use the third overload of the Services constructor. One scenario for when you would use this is if you wish to create your own implementation of the IMetaModel interface instead of relying upon the library-provided MetaModelclass.You might do this if you wanted to cache definitions on disk instead of reaching out to the instance for every call.

The following sample produces the same result as the previous constructor example:

                // Using the library-provided MetaModel class's constructor
IMetaModel metaModel = new MetaModel(connector, false); // false indicates to NOT pre-load meta
IServices services = new Services(connector, metaModel);

If you do implement your own implementation of the IMetaModel interface, then your code would look something like this:

                // Creating an instance of IMetaModel via your own implementation...
IMetaModel metaModel = createCustomIMetaModelImplementation();
IServices services = new Services(connector, metaModel);