01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * 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: 57188 $
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
45: org.jboss.proxy.Interceptor {
46:
47: // Constants -----------------------------------------------------
48:
49: // Attributes ----------------------------------------------------
50:
51: // Static --------------------------------------------------------
52:
53: // Constructors --------------------------------------------------
54:
55: public ExplicitFailoverClientInterceptor() {
56: }
57:
58: // Public --------------------------------------------------------
59:
60: // Z implementation ----------------------------------------------
61:
62: // Interceptor overrides ---------------------------------------------------
63:
64: public Object invoke(Invocation mi) throws Throwable {
65: Object failover = System.getProperty("JBossCluster-DoFail");
66: boolean doFail = false;
67:
68: if (failover != null && failover instanceof java.lang.String) {
69: String strFailover = (java.lang.String) failover;
70: if (strFailover.equalsIgnoreCase("true")) {
71: doFail = true;
72: } else if (strFailover.equalsIgnoreCase("once")) {
73: doFail = true;
74: System.setProperty("JBossCluster-DoFail", "false");
75: }
76: }
77:
78: if (doFail) {
79: mi.setValue("DO_FAIL_DURING_NEXT_CALL", Boolean.TRUE,
80: PayloadKey.AS_IS);
81: System.out.println("SYSTEM : We fail during next call!!!");
82: } else
83: mi.setValue("DO_FAIL_DURING_NEXT_CALL", Boolean.FALSE,
84: PayloadKey.AS_IS);
85:
86: return getNext().invoke(mi);
87: }
88:
89: // Package protected ---------------------------------------------
90:
91: // Protected -----------------------------------------------------
92:
93: // Private -------------------------------------------------------
94:
95: // Inner classes -------------------------------------------------
96:
97: }
|