[JBossCache] - Re: Buddy replication behavior
by puggelli
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
19 years, 2 months
[JBoss Seam] - @Startup help...
by bsmithjj
Hello,
I am trying to do the following:
On startup of my application, create an EJB Timer (javax.ejb.Timer) using the EJB TimerService (javax.ejb.TimerService).
The timer bean that I am trying to install is a stateless session bean.
I initially tried to use @PostConstruct on a method that would use the TimerService (@Resource private TimerService timerService) to create my timer. This didn't work immediately, so I figured, no instances of my stateless session bean have been created - fine, I turned to @Startup to create bootstrap component that gets a handle to the stateless session bean and invokes its starter method. Now I'm not sure what dependencies I need to add to the @Startup(depends={...}) list.
I know that I need the following resources available before my @Startup component's @Create method is called:
- my stateless session bean needs to be deployed
- the persistence context for my EJB jar needs to be available for injection
I've noticed that the @In annotation doesn't seem to work for my @Startup component (i.e. I can't get a reference to my stateless session bean); so I looked up the reference manually:
| MyBean myBean = null;
| try {
| myBean = (MyBean)Naming.getInitialContext().lookup("my-ear/MyBean/local");
| mailReader.startReading();
| } catch (NamingException e) {
| log.error(e,e);
| }
|
I can get a reference but invariably some other dependency fails (a @Factory component, etc...).
Is there someway of telling @Startup something to the effect of:
"start me up after everything else" ?
Is there a better way of installing a timer in Seam?
Thanks,
Brad Smith
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4006380#4006380
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4006380
19 years, 2 months