[jboss-user] [JBossCache] - Re: Buddy replication behavior

puggelli do-not-reply at jboss.com
Thu Jan 25 10:25:03 EST 2007


Hi,
I wrote a workaround in the form of a TreeCacheListenener. Please let me know what you think about.


  | class Listener implements TreeCacheListener
  | {
  | 	private TreeCache cache;
  | 	private View view;
  | 	
  | 	private static final Fqn backupFqn = new Fqn(BuddyManager.BUDDY_BACKUP_SUBTREE);
  | 	private static final Option option = new Option();
  | 	
  | 	static
  | 	{
  | 		option.setForceDataGravitation(true);
  | 	}
  | 	
  | 	private Vector getMembersLeft(View old_view, View new_view)
  | 	{
  | 		final Vector result = new Vector();
  | 		final Vector members = old_view.getMembers();
  | 		final Vector new_members = new_view.getMembers();
  | 
  | 		for(int i=0; i < members.size(); i++) 
  | 		{
  | 			final Object mbr = members.elementAt(i);
  | 
  | 			if(!new_members.contains(mbr))
  | 			{
  | 				result.addElement(mbr);
  | 			}
  | 		}
  | 
  | 		return(result);
  | 	}
  | 
  | 	private void check(Vector membersLeft)
  | 	{
  | 		for(int i=0, n=membersLeft.size(); i<n ; i++)
  | 		{
  | 			final Address addr = (Address)membersLeft.get(i);
  | 			final Fqn fqn = new Fqn(backupFqn, 
  | 			                        new Fqn(BuddyManager.getGroupNameFromAddress(addr)));
  | 
  | 			if(cache.exists(fqn))
  | 			{
  | 				try
  | 				{
  | 					final Set children = cache.getChildrenNames(fqn);
  | 
  | 					for(final Iterator it=children.iterator() ; it.hasNext() ;)
  | 					{
  | 						cache.get(new Fqn((String)it.next()), option);
  | 					}
  | 				}
  | 				catch(CacheException ex)
  | 				{
  | 					ex.printStackTrace();
  | 				}
  | 			}
  | 		}
  | 	}
  | 	
  | 
  | 	public void cacheStarted(TreeCache cache)
  | 	{
  | 		this.cache = cache;
  | 		this.view = new View(new ViewId(cache.getCoordinator()), cache.getMembers());
  | 	}
  | 	
  | 	public void cacheStopped(TreeCache cache)	{}
  | 	public void nodeCreated(Fqn fqn) 			{}
  | 	public void nodeEvicted(Fqn fqn)			{}
  | 	public void nodeLoaded(Fqn fqn)				{}
  | 	public void nodeModified(Fqn fqn)			{}
  | 	public void nodeRemoved(Fqn fqn)			{}
  | 	public void nodeVisited(Fqn fqn)			{}
  | 
  | 	public void viewChange(View new_view)
  | 	{
  | 		if(view!=null)
  | 		{
  | 			final Vector membersLeft = getMembersLeft(view, new_view);
  | 			
  | 			if(!membersLeft.isEmpty())
  | 			{
  | 					check(membersLeft);
  | 			}
  | 		}
  | 		
  | 		view = new_view;
  | 	}
  | }
  | 
  | 

thanks and regards
gianluca 
-- 
Gianluca Puggelli
skype:pugg1138

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4006387#4006387

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4006387



More information about the jboss-user mailing list