KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ha > framework > test > ExplicitFailoverClientInterceptor


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.ha.framework.test;
23
24 import org.jboss.invocation.Invocation;
25 import org.jboss.invocation.PayloadKey;
26
27 /**
28  * Used for testing clustering: allows to explicitely makes a call to node fail
29  * This will mimic a dead server.
30  *
31  * @see org.jboss.ha.framework.test.ExplicitFailoverServerInterceptor
32  *
33  * @author <a HREF="mailto:sacha.labourey@cogito-info.ch">Sacha Labourey</a>.
34  * @version $Revision: 37459 $
35  *
36  * <p><b>Revisions:</b>
37  *
38  * <p><b>8 avril 2002 Sacha Labourey:</b>
39  * <ul>
40  * <li> First implementation </li>
41  * </ul>
42  */

43
44 public class ExplicitFailoverClientInterceptor extends org.jboss.proxy.Interceptor
45 {
46    
47    // Constants -----------------------------------------------------
48

49    // Attributes ----------------------------------------------------
50

51    // Static --------------------------------------------------------
52

53    // Constructors --------------------------------------------------
54

55    public ExplicitFailoverClientInterceptor ()
56    {
57    }
58    
59    // Public --------------------------------------------------------
60

61    // Z implementation ----------------------------------------------
62

63    // Interceptor overrides ---------------------------------------------------
64

65    public Object JavaDoc invoke (Invocation mi) throws Throwable JavaDoc
66    {
67       Object JavaDoc failover = System.getProperty ("JBossCluster-DoFail");
68       boolean doFail = false;
69       
70       if (failover != null &&
71           failover instanceof java.lang.String JavaDoc)
72       {
73          String JavaDoc strFailover = (java.lang.String JavaDoc)failover;
74          if (strFailover.equalsIgnoreCase ("true"))
75          {
76             doFail = true;
77          }
78          else if (strFailover.equalsIgnoreCase ("once"))
79          {
80             doFail = true;
81             System.setProperty ("JBossCluster-DoFail", "false");
82          }
83       }
84       
85       if (doFail)
86       {
87          mi.setValue ("DO_FAIL_DURING_NEXT_CALL", Boolean.TRUE, PayloadKey.AS_IS);
88          System.out.println("SYSTEM : We fail during next call!!!");
89       }
90       else
91          mi.setValue ("DO_FAIL_DURING_NEXT_CALL", Boolean.FALSE, PayloadKey.AS_IS);
92          
93
94       return getNext().invoke(mi);
95    }
96    
97    // Package protected ---------------------------------------------
98

99    // Protected -----------------------------------------------------
100

101    // Private -------------------------------------------------------
102

103    // Inner classes -------------------------------------------------
104

105 }
106
Popular Tags