VisiBroker for .NET Developer’s Guide : Using Quality of Service

Using Quality of Service
Quality of Service (QoS) utilizes policies to define and manage the connection between your client applications and the servers to which they connect.
Understanding Quality of Service
Quality of Service policy management is performed through operations accessible in the following contexts:
The ORB level policies are handled by a locality constrained PolicyManager, through which you can set Policies and view the current Policy overrides. Policies set at the ORB level override system defaults.
Thread level policies are set through PolicyCurrent, which contains operations for viewing and setting Policy overrides at the thread level. Policies set at the thread level override system defaults and values set at the ORB level.
Setting policies per CORBA object
Use the CORBA.ObjectOperations methods in order to set QoS policies per CORBA object. To set QoS policies per CORBA object, one needs to cast the CORBA object to CORBA.ObjectOperations and call the method SetPolicyOverrides_() as shown in the following example.
// Set exclusive connection policy
bool deferBind = true;
Any policyValue = orb.CreateAny();
policyValue.InsertBoolean(deferBind);
Policy policies = orb.CreatePolicy(EXCLUSIVE_CONNECTION_POLICY_TYPE.Value,
policyValue);
Calc.VisiCalc calc = Calc.VisiCalcHelper.Narrow(
((CORBA.ObjectOperations)objRef).SetPolicyOverrides_(
new Policy [] {orb.CreatePolicy(
QoSExt.EXCLUSIVE_CONNECTION_POLICY_TYPE.Value, policyValue)},
SetOverrideType.SET_OVERRIDE));
Policy overrides and effective policies
The effective policy is the policy that would be applied to a request after all applicable policy overrides have been applied. The effective policy is determined by comparing the Policy as specified by the IOR with the effective override. The effective Policy is the intersection of the values allowed by the effective override and the IOR-specified Policy. If the intersection is empty a CORBA.INV_POLICY exception is raised.
QoS interfaces
The following interfaces are used to get and set QoS policies.
Object
VisiBroker for .NET extends CORBA.Object to provide additional QoS support as defined in the OMG Messaging specification. This means that there are two exposed Object interfaces.
Object methods
The CORBA.Object interface contains the following methods used to get the effective policy and get or set the policy override.
GetClientPolicy_
CORBA.Policy GetClientPolicy_(int type)
Returns the effective overriding Policy for the object reference. The effective override is obtained by first checking for an override of the given PolicyType at the Object scope, then at the Current scope, and finally at the ORB scope. If no override is present for the requested PolicyType, the system-dependent default value for that PolicyType is used. Portable applications are expected to set the desired defaults at the ORB scope since default Policy values are not specified.
The effective Policy is the one that would be used if a request were made. This Policy is determined first by obtaining the effective override for the PolicyType as returned by GetClientPolicy_.
The effective override is then compared with the Policy as specified in the IOR. The effective Policy is the intersection of the values allowed by the effective override and the IOR-specified Policy. If the intersection is empty, the system exception INV_POLICY is raised. Otherwise, a Policy with a value legally within the intersection is returned as the effective Policy. The absence of a Policy value in the IOR implies that any legal value may be used. Invoking NonExistent_ or ValidateConnection_ on an object reference prior to GetPolicy_ ensures the accuracy of the returned effective Policy.
If GetPolicy_ is invoked prior to the object reference being bound, the returned effective Policy is implementation dependent. In that situation, a compliant implementation may do any of the following: raise the exception CORBA.BAD_INV_ORDER, return some value for that PolicyType which may be subject to change once a binding is performed, or attempt a binding and then return the effective Policy.
Note that if the RebindPolicy has a value of TRANSPARENT, VB_TRANSPARENT, or VB_NOTIFY_REBIND, the effective Policy may change from invocation to invocation due to transparent rebinding.
GetPolicy_
CORBA.Policy GetPolicy_(int policy_type)
Returns the effective policy for an object reference—a Policy object of the type specified by the policy_type parameter.
GetPolicyOverrides_
CORBA.Policy[] GetPolicyOverrides_(int[] types)
Returns the list of Policy overrides (of the specified policy types) set at the Object scope. If the specified sequence is empty, all Policy overrides at this scope will be returned. If none of the requested PolicyTypes are overridden at the Object scope, an empty sequence is returned.
SetPolicyOverrides_
CORBA.Object SetPolicyOverrides_(CORBA.Policy[] policies, CORBA.SetOverrideType set_add)
Returns a new Object with the given policies either replacing any existing policies in this Object or with the given policies added to the existing ones, depending on the value of the given SetOverrideType object.
This method works in a way similar to the CORBA.PolicyManager method of the same name. However, it updates the current set of policies of an Object, thread, or ORB with the requested list of Policy overrides. In addition, this method returns a CORBA.Object whereas other methods of the same name return void.
an array of Policy objects containing the policies to be added or to be used as replacements
either SetOverrideType.SET_OVERRIDE, indicating that the given policies will replace any existing ones, or SetOverrideType.ADD_OVERRIDE, indicating that the given policies should be added to any existing ones
ValidateConnection_
bool ValidateConnection_(out CORBA.Policy[] inconsistent_policies)
Returns a boolean value based on whether the current effective policies for the object will allow an invocation to be made. It returns the value TRUE if the current effective policies for the Object allow an invocation to be made. If the object reference is not yet bound, a binding occurs as part of this operation. If the object reference is already bound, but current policy overrides have changed or for any other reason the binding is no longer valid, a rebind is attempted regardless of the setting of any RebindPolicy override.
The ValidateConnection_ operation is the only way to force such a rebind when implicit rebinds are disallowed by the current effective RebindPolicy. The attempt to bind or rebind may involve processing GIOP LocateRequests by the ORB. Returns the value FALSE if the current effective policies would cause an invocation to raise the system exception INV_POLICY.
If the current effective policies are incompatible, the out parameter inconsistent_policies contains those policies causing the incompatibility. This returned list of policies is not guaranteed to be exhaustive. If the binding fails due to some reason unrelated to policy overrides, the appropriate system exception is raised.
PolicyManager
The CORBA.PolicyManager interface provides methods for getting and setting Policy overrides at the ORB level.
PolicyManager methods
GetPolicyOverrides
CORBA.Policy[] GetPolicyOverrides(int[] ts)
This method returns a PolicyList sequence of all the overridden policies for the requested PolicyTypes. If the specified sequence is empty (that is, if the length of the list is zero), all Policy overrides at the current context level will be returned. If none of the requested PolicyTypes are overridden at the target PolicyManager, an empty sequence is returned.
SetPolicyOverrides
void SetPolicyOverrides(CORBA.Policy[] policies, CORBA.SetOverrideType set_add)
This method modifies the current set of policy overrides with the requested list of Policy overrides. Invoking SetPolicyOverrides with an empty sequence of policies and a mode of SET_OVERRIDE removes all overrides from a PolicyManager.
The first input parameter, policies, is a sequence of references to Policy objects. The second parameter, set_add, of type CORBA.SetOverrideType indicates whether these policies should be added onto any other overrides that already exist in the PolicyManager using ADD_OVERRIDE, or they should be added to a PolicyManager that doesn't contain any overrides using SET_OVERRIDES.
Only certain policies that pertain to the invocation of an operation at the client end can be overridden using this operation. Should you attempt to override policies that do not apply to your client, a CORBA.NO_PERMISSION exception will be raised. If the request would cause the specified PolicyManager to be in an inconsistent state, no policies are changed or added, and an InvalidPolicies exception is raised. There is no evaluation of compatibility with policies set within other PolicyManagers.
A parameter of type CORBA.SetOverrideType that indicates whether these policies should be added (ADD_OVERRIDE) to any other overrides that already exist in the PolicyManager, or added to a clean PolicyManager free of any other overrides (SET_OVERRIDE). If the request would cause the specified PolicyManager to be in an inconsistent state, no policies are changed or added, and an InvalidPolicies exception is raised.
PolicyCurrent
The CORBA.PolicyCurrent interface derives from PolicyManager and Current without adding new methods. Therefore all operations on the PolicyManager interface are also available in PolicyCurrent. See “PolicyManager” for a description of these methods.
PolicyCurrent provides access to the policies overridden at the thread level. A reference to a thread's PolicyCurrent is obtained by invoking ResolveInitialReferences and specifying an identifier of PolicyCurrent.
DeferBindPolicy
The QoSExt.DeferBindPolicy determines if the ORB will attempt to contact the remote object when it is first created, or to delay this contact until the first invocation is made. By default, the ORB connects to the (remote) object when on a Bind or a StringToObject call.
The valid values for DeferBindPolicy are TRUE and FALSE. If DeferBindPolicy is set to TRUE, all binds will be deferred until the first invocation of a binding instance. The default value is FALSE.
If you create a client object, and DeferBindPolicy is set to true, you may delay the server startup until the first invocation. This option existed before as an option to the Bind method on the generated helper classes.
DeferBindPolicy properties
Value
bool Value
Returns the current setting of the DeferBindPolicy.
Example
The code sample below illustrates an example for creating a DeferBindPolicy and setting the policy on the ORB.
public class DeferBindClient {
static void Main(string[] args) {
try {
CORBA.ORB orb = CORBA.ORB.Init(args);
// Initialize the flag and the references
bool deferMode = true;
Any policyValue = orb.CreateAny();
policyValue.InsertBoolean(deferMode);
Policy policies =
orb.CreatePolicy(DEFER_BIND_POLICY_TYPE.Value, policyValue);
// Get a reference to the thread manager
PolicyManager orbManager =
PolicyManagerHelper.Narrow(
orb.ResolveInitialReferences("ORBPolicyManager"));
// Set the policy on the ORB level
orbManager.SetPolicyOverrides(new Policy[] {policies},
SetOverrideType.SET_OVERRIDE);
// Get the binding method
byte[] managerId = orb.StringToObjectId("BankManager");
Bank.AccountManager manager =
Bank.AccountManagerHelper.Bind("/qos_poa", managerId);
// use Jack B. Quick as the account name.
string name = "Jack B. Quick";
// Request the account manager to open a named account.
Bank.Account account = manager.Open(name);
// Get the balance of the account.
float balance = account.Balance();
// Print out the balance.
Console.WriteLine(
"\n The balance in " + name + "'s account is $" + balance);
}
catch (Exception e) {
Console.WriteLine(e);
}
}
}
ExclusiveConnectionPolicy
The QoSExt.ExclusiveConnectionPolicy is a VisiBroker for .NET-specific policy that gives you the ability to establish an exclusive (non-shared) connection to the specified server object. This policy can have a boolean value of TRUE or FALSE. If the policy is TRUE, connections to the server object are exclusive. If the policy is FALSE, existing connections are reused if possible, and a new connection is opened only if reuse is not possible. The default value is FALSE.
ExclusiveConnectionPolicy properties
Value
bool Value
Returns the current setting of the ExclusiveConnectionPolicy.
RelativeConnectionTimeoutPolicy
The QoSExt.RelativeConnectionTimeoutPolicy indicates a timeout after which attempts to connect to an object using one of the available endpoints is aborted. The timeout situation is likely to happen with objects protected by firewalls, where HTTP tunneling is the only way to connect to the object.
Note
This Policy is not enforced for in-process communications.
The policy value of type unsigned long long specifies the timeout in 100s of nanoseconds. It is applied to every endpoint that the ORB tries to connect to. Therefore, if multiple connection attempts are made, the elapsed time will be a multiple of the configured timeout. The accuracy is also limited by the Java virtual machine implementation.
RelativeConnectionTimeoutPolicy methods
RelativeExpiry
long RelativeExpiry()
Gets the timeout in multiples of 100 nanoseconds.
Example
The following code examples illustrates how to create RelativeConnectionTimeoutPolicy.
public class ConnClient {
static void Main(string [] args) {
try {
// Initialize the ORB.
ORB orb = ORB.Init(args);
// Get the manager Id
byte[] managerId = orb.StringToObjectId("BankManager");
string name = "Jack B. Quick";
// Specify the timeout in 100s of Nanosecs.
// To set a timeout of 20 secs, set 20 * 10^7 nanosecs
int connTimeout = 20;
Any ctopolicyValue = orb.CreateAny();
ctopolicyValue.InsertUlonglong(connTimeout * 10000000);
Policy ctoPolicy = orb.CreatePolicy(
RELATIVE_CONN_TIMEOUT_POLICY_TYPE.Value, ctopolicyValue);
PolicyManager orbManager = PolicyManagerHelper.Narrow(
orb.ResolveInitialReferences("ORBPolicyManager"));
orbManager.SetPolicyOverrides(new Policy [] {ctoPolicy},
SetOverrideType.SET_OVERRIDE);
// Locate an account manager. Give the full POA name and
// the servant ID.
AccountManager source =
AccountManagerHelper.Bind("/qos_poa", managerId);
Account account = source.Open(name);
float balance = account.Balance();
Console.WriteLine("The balance in {0}'s account is {1}$", name,
balance);
}
catch (Exception e) {
Console.WriteLine(e);
}
}
}
RebindPolicy
The Messaging.RebindPolicy determines how the client-side ORB handles closed connections, GIOP location-forward messages and object failures. The ORB handles fail-overs, rebinds, and reconnections by looking at the effective policy at the CORBA.Object instance.
The OMG-defined Policy values determine whether the ORB may transparently rebind once it is successfully bound to a target server. The extended policy values determine whether the ORB may transparently failover once it is successfully bound to a target Object.
The RebindPolicy is a client-side-only policy.
Note
The RebindPolicy is enforced only after being successfully bound to an object. For GIOP-based protocols an object reference is considered bound once it is in a state where a LocateRequest message would result in a LocateReply message with status OBJECT_HERE.
The RebindPolicy is set only on the client side. It can have one of six values that determines the behavior in the case of a disconnection, an object forwarding request, or an object failure. The RebindPolicy accepts the following constants to define the behavior of the client when rebinding.
The currently supported values are:
Messaging.TRANSPARENT—allows the ORB to silently handle object-forwarding and necessary reconnections during the course of making a remote request.
Messaging.NO_REBIND—allows the ORB to silently handle reopening of closed connections while making a remote request, but prevents any transparent object-forwarding that would cause a change in client-visible effective QoS policies. When RebindMode is set to NO_REBIND, only explicit rebind is allowed.
Messaging.NO_RECONNECT—prevents the ORB from silently handling object-forwards or the reopening of closed connections. You must explicitly rebind and reconnect when RebindMode is set to NO_RECONNECT.
QoSExt.VB_TRANSPARENT—is the default policy. It extends the functionality of TRANSPARENT by allowing transparent rebinding with both implicit and explicit binding.
QoSExt.VB_NOTIFY_REBIND—throws an exception if a rebind is necessary. The client catches this exception, and binds on the second invocation.
QoSExt.VB_NO_REBIND—does not enable failover. It only allows the client ORB to reopen a closed connection to the same server; it does not allow object forwarding of any kind.
Note
Be aware that if the effective policy for your client is VB_TRANSPARENT and your client is working with servers that hold state data, VB_TRANSPARENT could connect the client to a new server without the client being aware of the change of server, any state data held by the original server will be lost.
The following table lists the behavior of the different RebindMode types.
No, throws REBIND exception.
No, throws REBIND exception.
Yes. VB_NOTIFY_REBIND throws an exception after failure detection, and then tries a failover on subsequent requests.
The appropriate CORBA exception will be thrown in the case of a communication problem or an object failure.
Example
The following example creates a RebindPolicy of type TRANSPARENT and sets the policy on the ORB, thread, and object levels.
using System;
using System.IO;
using CORBA;
using QoSExt;
using Messaging;
using Bank;
public class TransparentClient {
static void Main(string[] args) {
try {
short rebindMode = Messaging.TRANSPARENT.Value;
// initialize the ORB
CORBA.ORB orb = CORBA.ORB.Init(args);
// get the object Id
byte[] managerId = orb.StringToObjectId("BankManager");
// locate an account manager; give the full POA name and the object Id
Bank.AccountManager manager =
Bank.AccountManagerHelper.Bind("/qos_poa", managerId);
string s = orb.ObjectToString(manager);
CORBA.Object obj = orb.StringToObject(s);
// Create the client side policy so that we can receive TRANSIENT
// exception thrown by the server side orb.
Any policyValue = orb.CreateAny();
RebindModeHelper.Insert(policyValue, rebindMode);
Policy myRebindPolicy =
orb.CreatePolicy(REBIND_POLICY_TYPE.Value, policyValue);
// Set the policy on the AccountManager object.
Bank.AccountManager manager = Bank.AccountManager.Narrow(
((CORBA.ObjectOperations)obj.SetPolicyOverrides_(
new Policy [] {orb.CreatePolicy(
QoSExt.EXCLUSIVE_CONNECTION_POLICY_TYPE.Value,
policyValue)},
SetOverrideType.SET_OVERRIDE));
//get a reference to the ORB policy manager
PolicyManager orbManager = null;
try {
orbManager =
PolicyManagerHelper.Narrow(orb.ResolveInitialReferences(
"ORBPolicyManager"));
}
catch (CORBA.ORBNS.InvalidName e) {
}
//get a reference to the per-thread manager
CORBA.PolicyManager current = null;
try {
current =
PolicyManagerHelper.Narrow(orb.ResolveInitialReferences(
"PolicyCurrent"));
}
catch (CORBA.ORBNS.InvalidName e) {
}
//set the policy on the orb level
try {
orbManager.SetPolicyOverrides(new Policy[] {myRebindPolicy},
SetOverrideType.SET_OVERRIDE);
}
catch (CORBA.InvalidPolicies e) {
}
// set the policy on the Thread level
try {
current.SetPolicyOverrides(new Policy[] {myRebindPolicy},
SetOverrideType.SET_OVERRIDE);
}
catch (CORBA.InvalidPolicies e) {
}
CORBA.Object oldObjectReference =
Bank.AccountManagerHelper.Bind("/qos_poa", managerId);
CORBA.Object newObjectReference =
((CORBA.ObjectOperations)oldObjectReference).SetPolicyOverrides_(
new Policy [] {myRebindPolicy}, SetOverrideType.SET_OVERRIDE);
}
catch (Exception e) {
Console.WriteLine(e);
}
}
}
RebindForwardPolicy
The QoSExt.RebindForwardPolicy determines whether the client ORB attempts to rebind in the case of a failure to connect during a LOCATION_FORWARD. When the client is forwarded to a new object, an attempt is made to connect to a new destination object. If this attempt fails, the ORB transparently connects back to the original object (the source of the forward), under the following circumstances:
The vbroker.orb.rebindForward property sets the value for forward_count at the ORB level. You can override the value for forward_count at the ORB, thread or object level programmatically, as in any QoS policy. The default value of 0 (zero) for the property indicates that no limit has been specified.
RebindForwardPolicy methods
ForwardCount
short ForwardCount()
Returns the current setting for forward_count of the RebindForward policy.
RelativeRequestTimeoutPolicy
The Messaging.RelativeRequestTimeoutPolicy indicates the relative amount of time which a Request or its responding Reply may be delivered. After this amount of time, the Request is canceled. This policy applies to both synchronous and asynchronous invocations. Assuming the request completes within the specified timeout, the Reply will never be discarded due to timeout. Timeout value is specified in 100s of nanoseconds.
Example
The following code illustrates how to create RelativeRequestTimeoutPolicy.
public class RequestTimeoutClient {
static void Main(string[] args) {
try {
CORBA.ORB orb = CORBA.ORB.Init(args);
// get the object Id
byte[] managerId = orb.StringToObjectId("BankManager");
// locate an account manager; give the full POA name and the object Id
Bank.AccountManager manager =
Bank.AccountManagerHelper.Bind("/qos_poa", managerId);
string s = orb.ObjectToString(manager);
// Specify the timeout in 100s of Nanosecs.
// To set a timeout of 50 secs, set 50 * 10^7 nanosecs
int reqTimeout = 20;
CORBA.Any policyValue = orb.CreateAny();
policyValue.InsertUlonglong(reqTimeout * 10000000);
//set the RelativeRequestTimeoutPolicy
CORBA.Policy reqPolicy = orb.CreatePolicy(
RELATIVE_REQ_TIMEOUT_POLICY_TYPE.Value, policyValue);
// Get a reference to the thread manager
PolicyManager orbManager = PolicyManagerHelper.Narrow(
orb.ResolveInitialReferences("ORBPolicyManager"));
//Set the policy on the ORB level
orbManager.SetPolicyOverrides(new Policy[] {reqPolicy},
SetOverrideType.SET_OVERRIDE);
}
catch (Exception e) {
Console.WriteLine(e);
}
}
}
RelativeRoundTripTimeoutPolicy
The Messaging.RelativeRoundtripTimeoutPolicy specifies the relative amount of time for which a Request or its corresponding Reply may be delivered. If a response has not yet been delivered after this amount of time, the Request is canceled. Also, if a Request had already been delivered and a Reply is returned from the target, the Reply is discarded after this amount of time. This policy applies to both synchronous and asynchronous invocations. Assuming the request completes within the specified timeout, the Reply will never be discarded due to timeout. Timeout value is specified in 100s of nanoseconds.
Example
The following code illustrates how to create RelativeRoundTripTimeoutPolicy.
public class RoundtripTimeoutClient {
static void Main(string[] args) {
try {
CORBA.ORB orb = CORBA.ORB.Init(args);
// get the object Id
byte[] managerId = orb.StringToObjectId("BankManager");
// locate an account manager; give the full POA name and the object Id
Bank.AccountManager manager =
Bank.AccountManagerHelper.Bind("/qos_poa", managerId);
string s = orb.ObjectToString(manager);
// Specify the timeout in 100s of Nanosecs.
// To set a timeout of 20 secs, set 20 * 10^7 nanosecs
int rttTimeout = 50;
Any policyValue = orb.CreateAny();
policyValue.InsertUlonglong(rttTimeout * 10000000);
// Create Policy
CORBA.Policy rttPolicy =
orb.CreatePolicy(RELATIVE_RT_TIMEOUT_POLICY_TYPE.Value,policyValue);
// Get a reference to the thread manager
PolicyManager orbManager = PolicyManagerHelper.Narrow(
orb.ResolveInitialReferences("ORBPolicyManager"));
// Set the policy on the ORB level
orbManager.SetPolicyOverrides(new Policy[] {rttPolicy},
SetOverrideType.SET_OVERRIDE);
}
catch (Exception e) {
Console.WriteLine(e);
}
}
}
SyncScopePolicy
The Messaging.SyncScopePolicy defines the level of synchronization for a request with respect to the target. This interface is a local object derived from CORBA.Policy.
Values of type SyncScope are used in conjunction with a SyncScopePolicy to control the behavior of one-way operations. It is applied to one-way operations to indicate the synchronization scope with respect to the target of that operation request. It is ignored when any non-one-way operation is invoked.
This policy is also applied when the DII is used with a flag of INV_NO_RESPONSE since the implementation of the DII is not required to consult an interface definition to determine if an operation is declared one way.
The default SyncScopePolicy is SYNC_WITH_TRANSPORT.
Applications must explicitly set an ORB-level SyncScopePolicy to ensure portability across ORB implementations. When instances of SyncScopePolicy are created, a value of type Messaging.SyncScope is passed to CORBA.ORB.CreatePolicy. This policy is only applicable as a client-side override.
The following table lists the behavior of the different SyncScope values:
The server-side ORB is to send a reply before invoking the target implementation. If a reply of NO_EXCEPTION is sent, any necessary location-forwarding has already occurred. Upon receipt of this reply, the client-side ORB shall return control to the client application. The client blocks until all location-forwarding has been completed. For a server using a POA, the reply would be sent after invoking any ServantManager, but before delivering the request to the target Servant.
Equivalent to a synchronous, non-one way operation in CORBA 2.2. The server-side ORB will only send the reply message after the target has completed the invoked operation. Note that any LOCATION_FORWARD reply will already have been sent prior to invoking the target and that a SYSTEM_EXCEPTION reply may be sent at anytime (depending on the semantics of the exception). Even though it was declared one way, the operation actually behaves like a synchronous operation. This form of synchronization guarantees that the client knows that the target has seen and acted upon a request. As with CORBA 2.2, only with this highest level of synchronization can the OTS be used. Any operations invoked with lesser synchronization precludes the target from participating in the client's current transaction.
QoS exceptions
CORBA.INV_POLICY is raised when there is an incompatibility between Policy overrides.
CORBA.REBIND is raised when the RebindPolicy has a value of NO_REBIND, NO_RECONNECT, or VB_NOTIFY_REBIND and an invocation on a bound object references results in an object-forward or location-forward message.
CORBA.PolicyError is raised when the requested Policy is not supported.
CORBA.InvalidPolicies can be raised when an operation is passed a PolicyList sequence. The exception body contains the policies from the sequence that are not valid, either because the policies are already overridden within the current scope, or are not valid in conjunction with other requested policies.