Navigation:  Clustering >

Stateful Remoting Services

Previous pageReturn to chapter overviewNext page

Stateless .NET classes and services are cluster-enabled by definition. Since stateless objects do not contain any state, remoting clients can invoke their methods on any node in the cluster in the equal capacity. Stateful services operate differently in a cluster. When a client modifies a service's state, the change must be replicated to other computers in the cluster. To enable state synchronization for a service, WebORB provides a .NET attribute. Consider the following example:

using System;
using Weborb.Cluster;
 
namespace Weborb.Examples.Cluster
{
 [ClusterSingleton]
 public class SingletonCounterService
 {
   private int count = 0;
 
   public int getCount()
   {
     return count;
   }
 
   public int increment()
   {
     return count++;
   }
 }
}

The class is the most basic stateful service. Some clients can invoke the increment() method to modify the object's state (expressed as the private int field). Other clients can invoke the getCount() method to receive the value. The service turns into a clusterable stateful service via the attribute:

[ClusterSingleton]

The annotation instructs WebORB to share the service's state between all nodes in the cluster.