001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.catalina.tribes.group;
018:
019: import org.apache.catalina.tribes.ChannelException;
020: import org.apache.catalina.tribes.ChannelInterceptor;
021: import org.apache.catalina.tribes.ChannelMessage;
022: import org.apache.catalina.tribes.Member;
023:
024: /**
025: * Abstract class for the interceptor base class.
026: * @author Filip Hanik
027: * @version $Revision: 467222 $, $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $
028: */
029:
030: public abstract class ChannelInterceptorBase implements
031: ChannelInterceptor {
032:
033: protected static org.apache.juli.logging.Log log = org.apache.juli.logging.LogFactory
034: .getLog(ChannelInterceptorBase.class);
035:
036: private ChannelInterceptor next;
037: private ChannelInterceptor previous;
038: //default value, always process
039: protected int optionFlag = 0;
040:
041: public ChannelInterceptorBase() {
042:
043: }
044:
045: public boolean okToProcess(int messageFlags) {
046: if (this .optionFlag == 0)
047: return true;
048: return ((optionFlag & messageFlags) == optionFlag);
049: }
050:
051: public final void setNext(ChannelInterceptor next) {
052: this .next = next;
053: }
054:
055: public final ChannelInterceptor getNext() {
056: return next;
057: }
058:
059: public final void setPrevious(ChannelInterceptor previous) {
060: this .previous = previous;
061: }
062:
063: public void setOptionFlag(int optionFlag) {
064: this .optionFlag = optionFlag;
065: }
066:
067: public final ChannelInterceptor getPrevious() {
068: return previous;
069: }
070:
071: public int getOptionFlag() {
072: return optionFlag;
073: }
074:
075: public void sendMessage(Member[] destination, ChannelMessage msg,
076: InterceptorPayload payload) throws ChannelException {
077: if (getNext() != null)
078: getNext().sendMessage(destination, msg, payload);
079: }
080:
081: public void messageReceived(ChannelMessage msg) {
082: if (getPrevious() != null)
083: getPrevious().messageReceived(msg);
084: }
085:
086: public boolean accept(ChannelMessage msg) {
087: return true;
088: }
089:
090: public void memberAdded(Member member) {
091: //notify upwards
092: if (getPrevious() != null)
093: getPrevious().memberAdded(member);
094: }
095:
096: public void memberDisappeared(Member member) {
097: //notify upwards
098: if (getPrevious() != null)
099: getPrevious().memberDisappeared(member);
100: }
101:
102: public void heartbeat() {
103: if (getNext() != null)
104: getNext().heartbeat();
105: }
106:
107: /**
108: * has members
109: */
110: public boolean hasMembers() {
111: if (getNext() != null)
112: return getNext().hasMembers();
113: else
114: return false;
115: }
116:
117: /**
118: * Get all current cluster members
119: * @return all members or empty array
120: */
121: public Member[] getMembers() {
122: if (getNext() != null)
123: return getNext().getMembers();
124: else
125: return null;
126: }
127:
128: /**
129: *
130: * @param mbr Member
131: * @return Member
132: */
133: public Member getMember(Member mbr) {
134: if (getNext() != null)
135: return getNext().getMember(mbr);
136: else
137: return null;
138: }
139:
140: /**
141: * Return the member that represents this node.
142: *
143: * @return Member
144: */
145: public Member getLocalMember(boolean incAlive) {
146: if (getNext() != null)
147: return getNext().getLocalMember(incAlive);
148: else
149: return null;
150: }
151:
152: /**
153: * Starts up the channel. This can be called multiple times for individual services to start
154: * The svc parameter can be the logical or value of any constants
155: * @param svc int value of <BR>
156: * DEFAULT - will start all services <BR>
157: * MBR_RX_SEQ - starts the membership receiver <BR>
158: * MBR_TX_SEQ - starts the membership broadcaster <BR>
159: * SND_TX_SEQ - starts the replication transmitter<BR>
160: * SND_RX_SEQ - starts the replication receiver<BR>
161: * @throws ChannelException if a startup error occurs or the service is already started.
162: */
163: public void start(int svc) throws ChannelException {
164: if (getNext() != null)
165: getNext().start(svc);
166: }
167:
168: /**
169: * Shuts down the channel. This can be called multiple times for individual services to shutdown
170: * The svc parameter can be the logical or value of any constants
171: * @param svc int value of <BR>
172: * DEFAULT - will shutdown all services <BR>
173: * MBR_RX_SEQ - stops the membership receiver <BR>
174: * MBR_TX_SEQ - stops the membership broadcaster <BR>
175: * SND_TX_SEQ - stops the replication transmitter<BR>
176: * SND_RX_SEQ - stops the replication receiver<BR>
177: * @throws ChannelException if a startup error occurs or the service is already started.
178: */
179: public void stop(int svc) throws ChannelException {
180: if (getNext() != null)
181: getNext().stop(svc);
182: }
183:
184: public void fireInterceptorEvent(InterceptorEvent event) {
185: //empty operation
186: }
187:
188: }
|