Home > Articles > Programming > C#

  • Print
  • + Share This
Like this article? We recommend

Get, Set, and Notify

At the start of this article, I said that management uses a simple get/set/notify model. These elements are all contained in Listing 2. The get and set facilities are in the property definition for RequiredBandwidth. You can see these semantics in action in the ForwardSomeData() method. Let’s take a look at that method in more detail (see Listing 3).

Listing 3 The ForwardSomeData() method.

public void ForwardSomeData(int requiredBandwidth)
{
RequiredBandwidth += requiredBandwidth;

// If the Lsp is congested, fire the FullyCongested event.
if (LspCanForwardData)
{
// Check for the worst case to begin with
if (MaximumBandwidth - RequiredBandwidth <= 0 &&
  FullyCongested != null)
{
LspCanForwardData = false;
FullyCongested(LspName + " is congested, can’t forward data.");
}
else
if (MaximumBandwidth - RequiredBandwidth <= 50
  && GettingCongested != null)
{
GettingCongested("Congestion is looming. Max. bandwidth on " + LspName + ": " +
       MaximumBandwidth + ". Required bandwidth: " +
       RequiredBandwidth);
}
else
  Console.WriteLine("Currently forwarding data at bandwidth" +
                " {0} Mbps", RequiredBandwidth);
}
else
{
  // If the Lsp is congested, fire the Congested event.
  if (CannotForwardData != null)
      CannotForwardData(LspName + " is disabled, can’t forward data.");
}
#endregion
}
}

Basically, ForwardSomeData() works by attempting to push some data into the LSP. (Obviously, it’s only modeling this action.) Once the method is called, it increments the current value of RequiredBandwidth by an amount equal to requiredBandwidth. The remainder of the method then checks the value of requiredBandwidth to see if it’s within the designated limits. These rules then result in events being generated; for example, calls to the method FullyCongested(). If you look back at Figures 2 and 3, you can see that the text displayed there is actually from C# event handlers.

  • + Share This
  • 🔖 Save To Your Account