How to: Add a Failure Notification Callback (Velocity)

05/24/2009

Similar to adding a callback for cache notifications, adding a callback for failure notifications involves two steps. First, create a method that should be invoked when a failure notification is triggered. The method you invoke with the failure notification must accept the same parameters as the DataCacheFailureNotificationCallback delegate. Second, add a callback for the failure notification using the AddFailureNotificationCallback method. Use the name of the method you created in the first step for the failureDelegate parameter.

Note 
In order for your application to use notifications, you need to enable them on a named cache. Use the notificationsEnabled parameter with the New-Cache or Set-CacheConfig commands. For more information, see Cache Administration with PowerShell (Velocity).

How to add a failure notification callback
Create the method you want to be triggered by the failure notification. Make sure that the method you invoke with the failure notification accepts the same parameters as the DataCacheFailureNotificationCallback delegate.

Add a callback for the failure notification using the AddFailureNotificationCallback method. Use the name of the method that you want to invoke when the failure notification occurs in the failureDelegate parameter.

Example
The first step when adding a failure notification callback is to create a method that you want to be invoked by the notification. The method called by the notification must accept the same parameters as the DataCacheFailureNotificationCallback delegate. This example shows one example of a method that can be invoked by a failure notification.

Visual Basic  Copy Code
'method invoked by failure notification "ndNotificationFailure"
Public Sub myNotificationFailureDelegate(ByVal myCacheName As String, _
    ByVal nd As DataCacheNotificationDescriptor)

    Console.WriteLine("===============================")
    Console.WriteLine("Invoked by failure notification")
    Console.WriteLine("===============================")
End Sub

C#  Copy Code
//method invoked by failure notification "ndNotificationFailure"
public void myNotificationFailureDelegate(string myCacheName,
    DataCacheNotificationDescriptor nd)
{
    Console.WriteLine("===============================");
    Console.WriteLine(" Invoked by failure notification");
    Console.WriteLine("===============================");
}

The second step is to add a callback for the failure notification. In this example, a failure notification is created to invoke the method from the previous example.

Visual Basic  Copy Code
'add failure notification callback
Dim ndNotificationFailure As DataCacheNotificationDescriptor
ndNotificationFailure = _
    myTestCache.AddFailureNotificationCallback(AddressOf myNotificationFailureDelegate)

C#  Copy Code
//add failure notification callback
DataCacheNotificationDescriptor ndNotificationFailure
    = myTestCache.AddFailureNotificationCallback(myNotificationFailureDelegate);

Posted in: .Net Programming| Tags: .net 4.0 CTP CTP 3 Microsoft Velocity cache use delegate notification method callback datacachefailurenotificationcallback addfailurenotificationcallback failure

How to: Remove a Cache Notification Callback (Velocity)

05/24/2009

Use the RemoveCallback method to remove a cache notification callback. To identify the notification, this method requires the DataCacheNotificationDescriptor object that was returned when you added the callback. To facilitate this requirement, declare your DataCacheNotificationDescriptor object at a scope that is accessible to the code in your application and that adds the callback and the code in the application that removes the callback. The DataCacheNotificationDescriptor object returned to the method invoked by the cache notification can also be used to remove a callback.

Note 
In order for your application to use notifications, you need to enable them on a named cache. Use the notificationsEnabled parameter with the New-Cache or Set-CacheConfig commands. For more information, see Cache Administration with PowerShell (Velocity).

How to remove a callback cache notification
Declare the DataCacheNotificationDescriptor object you use to add a callback at a scope that is accessible to the code that will remove the callback.

Use the RemoveCallback method to remove the cache notification callback. Use the appropriate DataCacheNotificationDescriptor object for the nd parameter.

Posted in: .Net Programming| Tags: .net 4.0 Application CTP CTP 3 Microsoft Velocity cache code use notification method callback remove datacachenotificationdescriptor

How to: Add a Cache Notification Callback (Velocity)

05/24/2009

Adding a cache notification callback requires two steps. First, create a method that should be invoked when a cache notification is triggered by one or more cache operations. The method you invoke with the cache notifications must accept the same parameters as the DataCacheNotificationCallback delegate. Second, add a callback using one of the three available methods from the DataCache object: AddCacheLevelCallback, AddRegionLevelCallback, or AddItemLevelCallback. Use the filter parameter to define the types of cache operations you want to trigger cache notifications. Use the name of the method you created in the first step for the clientDelegate parameter.

Note 
In order for your application to use notifications, you need to enable them on a named cache. Use the notificationsEnabled parameter with the New-Cache or Set-CacheConfig commands. For more information, see Cache Administration with PowerShell (Velocity).

How to add a callback for one or more cache operations
Create the method you want to be triggered by the cache notification. Make sure the method accepts the same parameters as the DataCacheNotificationCallback delegate.

Add a callback. Use one of the three available methods from the DataCache object to define the notification scope: AddCacheLevelCallback, AddRegionLevelCallback, or AddItemLevelCallback.

Use the DataCacheOperation enumeration in the filter parameter to specify what type of cache operations you want to trigger notifications. Select more than one enumeration by separating the enumerations with the binary OR operator to perform a bitwise OR. To do this, use the | character in C#, and the Or operator in Visual Basic.

Use the name of the method you want to invoke when these notifications occur in the clientDelegate parameter.

Set the add callback method equal to a DataCacheNotificationDescriptor object that you can use elsewhere in your program to remove the cache notification callback.

Posted in: .Net Programming| Tags: .net 4.0 parameter CTP CTP 3 Microsoft Velocity cache use delegate datacachenotificationcallback notification datacache method callback

How to: Set Log Sink Levels (Code) (Velocity)

05/24/2009

On the server side, log sinks can only be configured in the cache host configuration file. For more information about these settings, see Log Sink Settings (Velocity).

To programmatically enable log sinks on the cache client, use the DataCacheFactory class static methods CreateLogSinks or EnableAllAvailableSinks. To disable log sinks programmatically, use the DisableLogSinks static method. For more information about log sink settings, see Log Sink Settings (Velocity).

Note 
These procedures assume that you have already prepared your development environment and set references to the "Velocity" assemblies, and so on. For more information, see How to: Prepare the Development Environment (Velocity)

To create log sinks programmatically on the cache client
Create a list of type DataCacheLogSink to contain the log sinks you want to enable.

Create a DataCacheLogSink object for each log sink you want to enable.

Specify the type of log sink you want by using the DataCacheSinkType enumeration in the sinkType parameter of the DataCacheLogSink constructor.

Specify the trace level of the log sink by using the System.Diagnostics.TraceLevel enumeration in the logLevel parameter of the DataCacheLogSink constructor.

(optional) If you are creating a file-based log sink, and you want to change the log file naming convention and storage location, define the log file naming convention with the sinkParam parameter of the DataCacheLogSink constructor. For more information about the file naming convention, see Log Sink Settings (Velocity).

Add each log sink that you created to the list you created in the first step.

Pass the list of log sinks to the sinkList parameter of the CreateLogSinks method to enable the log sinks on your cache client.

To enable all available log sinks programmatically on the cache client
Call the EnableAllAvailableSinks static method to enable the log sinks on your cache client.

To disable all log sinks programmatically on the cache client
Call the DisableLogSinks static method to enable the log sinks on your cache client.

Posted in: .Net Programming| Tags: .net 4.0 CTP CTP 3 Microsoft Velocity cache code set use sink settings log information levels

Hot Posts

Latest posts

Tags

Others

Sponsors