Open topic with navigation

TIBCO GridServer® 7.1.0

# Setting Discriminators Programmatically

You can use the GridServer API to set Discriminators for a Service or task. Create Discriminators with the `SchedulingConditionFactory`. In Java, this is located in `com.datasynapse.gridserver.client`. You can use the factory to create several Conditions. The method to use to create Discriminators is `createPropertyDiscriminator`.

The following example in Java code creates a `SchedulingConditionFactory`, which you then use to create a Discriminator Condition to run a Service or task only on Engines where the operating system is Linux:

    SchedulingConditionFactory schedFactory = SchedulingConditionFactory.getInstance();
    Condition isLinux = schedFactory.createPropertyDiscriminator(EngineProperties.OS, SchedulingConditionFactory.CONTAINS, "Linux", false);

The `createPropertyDiscriminator` method takes four parameters:

| • | The first parameter is the name of an Engine property.

| • | The second parameter is a comparator used to compare the Engine property to the property value. You can use several comparators to compare numbers or strings. (See details in the `SchedulingConditionFactory` API documentation.) For example, the `CONTAINS` comparator is true if an Engine property matches any one of a comma-delimited list of properties. `MATCHES` compares against a Java regular expression; `EQUAL` checks if parsed numerical values are equal.

| • | The third parameter is a property value.

| • | The fourth parameter defines what happens if the property is not set on an Engine. In this case, the Engine is not considered. In some situations, you might want the opposite behavior, such as when you are using a Discriminator to exclude a subset of Engines with a specific property, but allowing any other Engines.

After you create a Condition such as a Discriminator, you can use it when creating or submitting Services. The following example in Java code creates a Discriminator and sets it in a Service:

    SchedulingConditionFactory schedFactory = SchedulingConditionFactory.getInstance();
    //Only run on Linux Engines
    Condition isLinux = schedFactory.createPropertyDiscriminator(EngineProperties.OS, SchedulingConditionFactory.CONTAINS, "Linux", false);
    Service s = ServiceFactory.getInstance().createService("MyService", null, null, null, isLinux);

If you change the properties of Engines, the changes take effect during the execution of a Service. For example, if you configure a Discriminator attached to a running Service to look for a certain Engine property, changing this property can change what Engines work on that Service.

Discriminators are, however, attached to a Service at Service creation, so changes you make to the Discriminator affect only subsequently submitted Services, not Services that are already running.

Did you find this helpful?

Yes No
Great!
Thanks for taking the time to give us some feedback.
Sorry about that

Why wasn't this helpful? (check all that apply)

Could not find what I was looking for
Instructions confusing or unclear
Instructions did not work

Want to tell us more?

Please select at least one option or provide details about the issue!!

Error occurred while submitting feedback.

Error2 occurred while submitting feedback.

TIBCO GridServer®

Copyright © 2001-2022. TIBCO Software Inc. All Rights Reserved.