001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.ha.framework.test;
023:
024: import org.jboss.invocation.Invocation;
025: import org.jboss.ha.framework.interfaces.GenericClusteringException;
026:
027: /**
028: * Used for testing clustering: allows to explicitely makes a call to node fail
029: * This will mimic a dead server.
030: *
031: * @see org.jboss.ha.framework.test.ExplicitFailoverClientInterceptor
032: *
033: * @author <a href="mailto:sacha.labourey@cogito-info.ch">Sacha Labourey</a>.
034: * @version $Revision: 57188 $
035: *
036: * <p><b>Revisions:</b>
037: *
038: * <p><b>8 avril 2002 Sacha Labourey:</b>
039: * <ul>
040: * <li> First implementation </li>
041: * </ul>
042: */
043:
044: public class ExplicitFailoverServerInterceptor extends
045: org.jboss.ejb.plugins.AbstractInterceptor {
046:
047: // Constants -----------------------------------------------------
048:
049: // Attributes ----------------------------------------------------
050:
051: protected org.jboss.ejb.Container container;
052:
053: // Static --------------------------------------------------------
054:
055: // Constructors --------------------------------------------------
056:
057: public ExplicitFailoverServerInterceptor() {
058: }
059:
060: // Public --------------------------------------------------------
061:
062: public void setContainer(org.jboss.ejb.Container container) {
063: this .container = container;
064: }
065:
066: public org.jboss.ejb.Container getContainer() {
067: return container;
068: }
069:
070: // Z implementation ----------------------------------------------
071:
072: // AbstractInterceptor overrides ---------------------------------------------------
073:
074: public Object invokeHome(Invocation mi) throws Exception {
075: checkFailoverNeed(mi);
076:
077: return super .invokeHome(mi);
078: }
079:
080: public Object invoke(Invocation mi) throws Exception {
081: checkFailoverNeed(mi);
082:
083: return super .invoke(mi);
084: }
085:
086: // Package protected ---------------------------------------------
087:
088: // Protected -----------------------------------------------------
089:
090: protected void checkFailoverNeed(Invocation mi)
091: throws GenericClusteringException {
092: Object data = mi.getValue("DO_FAIL_DURING_NEXT_CALL");
093:
094: if (data != null && data instanceof java.lang.Boolean
095: && data.equals(java.lang.Boolean.TRUE)) {
096: // we now determine if we have already failed
097: //
098: Object alreadyDone = mi.getValue("FAILOVER_COUNTER");
099:
100: if (alreadyDone != null
101: && alreadyDone instanceof java.lang.Integer
102: && ((java.lang.Integer) alreadyDone).intValue() == 0) {
103: // we do fail
104: //
105: this .log
106: .debug("WE FAILOVER IN SERVER INTERCEPTOR (explicit failover asked by client interceptor)!");
107: throw new GenericClusteringException(
108: GenericClusteringException.COMPLETED_NO,
109: "Test failover from server interceptor", false);
110: }
111: }
112: }
113:
114: // Private -------------------------------------------------------
115:
116: // Inner classes -------------------------------------------------
117:
118: }
|