KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > clusteredsession > ExplicitFailoverInterceptor


1 /*
2  * JBoss, Home of Professional Open Source
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package org.jboss.ejb3.test.clusteredsession;
9
10 import org.jboss.ha.framework.interfaces.GenericClusteringException;
11 import org.jboss.logging.Logger;
12
13 import javax.interceptor.AroundInvoke;
14 import javax.interceptor.InvocationContext;
15
16 /**
17  * Used for testing clustering: allows to explicitly makes a call to node fail
18  * This will mimic a dead server. This is used as a ejb3 interceptor now.
19  * @author Ben Wang
20  *
21  */

22 public class ExplicitFailoverInterceptor
23 {
24    private Logger log = Logger.getLogger(ExplicitFailoverInterceptor.class);
25
26    @AroundInvoke
27    public Object JavaDoc invoke(InvocationContext ctx)
28       throws Exception JavaDoc
29    {
30       checkFailoverNeed (ctx);
31       return ctx.proceed();
32    }
33
34    protected void checkFailoverNeed (InvocationContext ctx)
35       throws Exception JavaDoc
36    {
37       if(ctx.getMethod().getName().equals("setUpFailover"))
38       {
39          return;
40       }
41
42       String JavaDoc failover = (String JavaDoc)System.getProperty ("JBossCluster-DoFail");
43       boolean doFail = false;
44
45       if (failover != null)
46       {
47          String JavaDoc strFailover = failover;
48          if (strFailover.equalsIgnoreCase ("true"))
49          {
50             doFail = true;
51          }
52          else if (strFailover.equalsIgnoreCase ("once"))
53          {
54             doFail = true;
55             System.setProperty ("JBossCluster-DoFail", "false");
56          }
57       }
58
59       if (doFail)
60       {
61          log.debug ("WE FAILOVER IN EJB INTERCEPTOR (explicit failover)!");
62
63          throw new GenericClusteringException
64             (GenericClusteringException.COMPLETED_NO, "Test failover from ejb interceptor", false);
65       }
66    }
67 }
68
Popular Tags