KickJava   Java API By Example, From Geeks To Geeks.

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


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.ha.framework.interfaces.GenericClusteringException;
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.ExplicitFailoverClientInterceptor
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 ExplicitFailoverServerInterceptor extends org.jboss.ejb.plugins.AbstractInterceptor
45 {
46    
47    // Constants -----------------------------------------------------
48

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

51    protected org.jboss.ejb.Container container;
52
53    // Static --------------------------------------------------------
54

55    // Constructors --------------------------------------------------
56

57    public ExplicitFailoverServerInterceptor ()
58    {
59    }
60    
61    // Public --------------------------------------------------------
62

63    public void setContainer(org.jboss.ejb.Container container)
64    {
65       this.container = container;
66    }
67     
68    public org.jboss.ejb.Container getContainer()
69    {
70       return container;
71    }
72     
73    // Z implementation ----------------------------------------------
74

75    // AbstractInterceptor overrides ---------------------------------------------------
76

77    public Object JavaDoc invokeHome(Invocation mi)
78       throws Exception JavaDoc
79    {
80       checkFailoverNeed (mi);
81       
82      return super.invokeHome (mi);
83    }
84    
85    public Object JavaDoc invoke(Invocation mi)
86       throws Exception JavaDoc
87    {
88       checkFailoverNeed (mi);
89       
90       return super.invoke (mi);
91    }
92    
93    // Package protected ---------------------------------------------
94

95    // Protected -----------------------------------------------------
96

97    protected void checkFailoverNeed (Invocation mi)
98       throws GenericClusteringException
99    {
100       Object JavaDoc data = mi.getValue ("DO_FAIL_DURING_NEXT_CALL");
101       
102       if (data != null &&
103           data instanceof java.lang.Boolean JavaDoc &&
104           data.equals (java.lang.Boolean.TRUE))
105       {
106          // we now determine if we have already failed
107
//
108
Object JavaDoc alreadyDone = mi.getValue ("FAILOVER_COUNTER");
109          
110          if (alreadyDone != null &&
111              alreadyDone instanceof java.lang.Integer JavaDoc &&
112              ((java.lang.Integer JavaDoc)alreadyDone).intValue () == 0)
113          {
114             // we do fail
115
//
116
this.log.debug ("WE FAILOVER IN SERVER INTERCEPTOR (explicit failover asked by client interceptor)!");
117             throw new GenericClusteringException
118                (GenericClusteringException.COMPLETED_NO, "Test failover from server interceptor", false);
119          }
120       }
121    }
122    
123    // Private -------------------------------------------------------
124

125    // Inner classes -------------------------------------------------
126

127 }
128
Popular Tags