Package org.apache.catalina.tribes.group
Class ChannelInterceptorBase
- java.lang.Object
-
- org.apache.catalina.tribes.group.ChannelInterceptorBase
-
- All Implemented Interfaces:
ChannelInterceptor
,Heartbeat
,MembershipListener
- Direct Known Subclasses:
ChannelCoordinator
,DomainFilterInterceptor
,EncryptInterceptor
,FragmentationInterceptor
,GroupChannel
,GzipInterceptor
,MessageDispatchInterceptor
,NonBlockingCoordinator
,OrderInterceptor
,SimpleCoordinator
,StaticMembershipInterceptor
,TcpFailureDetector
,TcpPingInterceptor
,ThroughputInterceptor
,TwoPhaseCommitInterceptor
public abstract class ChannelInterceptorBase extends java.lang.Object implements ChannelInterceptor
Abstract class for the interceptor base class.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.catalina.tribes.ChannelInterceptor
ChannelInterceptor.InterceptorEvent
-
-
Field Summary
Fields Modifier and Type Field Description protected int
optionFlag
-
Constructor Summary
Constructors Constructor Description ChannelInterceptorBase()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
fireInterceptorEvent(ChannelInterceptor.InterceptorEvent event)
Fire an event.Channel
getChannel()
Return the channel that is related to this interceptorMember
getLocalMember(boolean incAlive)
Intercepts theChannel.getLocalMember(boolean)
methodMember
getMember(Member mbr)
Intercepts theChannel.getMember(Member)
methodMember[]
getMembers()
Intercepts theChannel.getMembers()
methodChannelInterceptor
getNext()
Retrieve the next interceptor in the listint
getOptionFlag()
An interceptor can react to a message based on a set bit on the message options.ChannelInterceptor
getPrevious()
Retrieve the previous interceptor in the listboolean
hasMembers()
Intercepts theChannel.hasMembers()
methodvoid
heartbeat()
Theheartbeat()
method gets invoked periodically to allow interceptors to clean up resources, time out object and perform actions that are unrelated to sending/receiving data.void
memberAdded(Member member)
A member was added to the groupvoid
memberDisappeared(Member member)
A member was removed from the group
If the member left voluntarily, the Member.getCommand will contain the Member.SHUTDOWN_PAYLOAD datavoid
messageReceived(ChannelMessage msg)
ThemessageReceived
is invoked when a message is received.boolean
okToProcess(int messageFlags)
void
sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload)
ThesendMessage
method is called when a message is being sent to one more destinations.void
setChannel(Channel channel)
Set the channel that is related to this interceptorvoid
setNext(ChannelInterceptor next)
Set the next interceptor in the list of interceptorsvoid
setOptionFlag(int optionFlag)
Sets the option flagvoid
setPrevious(ChannelInterceptor previous)
Set the previous interceptor in the listvoid
start(int svc)
Starts up the channel.void
stop(int svc)
Shuts down the channel.
-
-
-
Method Detail
-
okToProcess
public boolean okToProcess(int messageFlags)
-
setNext
public final void setNext(ChannelInterceptor next)
Description copied from interface:ChannelInterceptor
Set the next interceptor in the list of interceptors- Specified by:
setNext
in interfaceChannelInterceptor
- Parameters:
next
- ChannelInterceptor
-
getNext
public final ChannelInterceptor getNext()
Description copied from interface:ChannelInterceptor
Retrieve the next interceptor in the list- Specified by:
getNext
in interfaceChannelInterceptor
- Returns:
- ChannelInterceptor - returns the next interceptor in the list or null if no more interceptors exist
-
setPrevious
public final void setPrevious(ChannelInterceptor previous)
Description copied from interface:ChannelInterceptor
Set the previous interceptor in the list- Specified by:
setPrevious
in interfaceChannelInterceptor
- Parameters:
previous
- ChannelInterceptor
-
setOptionFlag
public void setOptionFlag(int optionFlag)
Description copied from interface:ChannelInterceptor
Sets the option flag- Specified by:
setOptionFlag
in interfaceChannelInterceptor
- Parameters:
optionFlag
- int- See Also:
ChannelInterceptor.getOptionFlag()
-
getPrevious
public final ChannelInterceptor getPrevious()
Description copied from interface:ChannelInterceptor
Retrieve the previous interceptor in the list- Specified by:
getPrevious
in interfaceChannelInterceptor
- Returns:
- ChannelInterceptor - returns the previous interceptor in the list or null if no more interceptors exist
-
getOptionFlag
public int getOptionFlag()
Description copied from interface:ChannelInterceptor
An interceptor can react to a message based on a set bit on the message options. When a message is sent, the options can be retrieved from ChannelMessage.getOptions() and if the bit is set, this interceptor will react to it.A simple evaluation if an interceptor should react to the message would be:
boolean react = (getOptionFlag() == (getOptionFlag() & ChannelMessage.getOptions()));
The default option is 0, meaning there is no way for the application to trigger the interceptor. The interceptor itself will decide.- Specified by:
getOptionFlag
in interfaceChannelInterceptor
- Returns:
- int
- See Also:
ChannelMessage.getOptions()
-
sendMessage
public void sendMessage(Member[] destination, ChannelMessage msg, InterceptorPayload payload) throws ChannelException
Description copied from interface:ChannelInterceptor
ThesendMessage
method is called when a message is being sent to one more destinations. The interceptor can modify any of the parameters and then pass on the message down the stack by invokinggetNext().sendMessage(destination,msg,payload)
.Alternatively the interceptor can stop the message from being sent by not invoking
getNext().sendMessage(destination,msg,payload)
.If the message is to be sent asynchronous the application can be notified of completion and errors by passing in an error handler attached to a payload object.
The ChannelMessage.getAddress contains Channel.getLocalMember, and can be overwritten to simulate a message sent from another node.
- Specified by:
sendMessage
in interfaceChannelInterceptor
- Parameters:
destination
- Member[] - the destination for this messagemsg
- ChannelMessage - the message to be sentpayload
- InterceptorPayload - the payload, carrying an error handler and future useful data, can be null- Throws:
ChannelException
- if a serialization error happens.- See Also:
ErrorHandler
,InterceptorPayload
-
messageReceived
public void messageReceived(ChannelMessage msg)
Description copied from interface:ChannelInterceptor
ThemessageReceived
is invoked when a message is received.ChannelMessage.getAddress()
is the sender, or the reply-to address if it has been overwritten.- Specified by:
messageReceived
in interfaceChannelInterceptor
- Parameters:
msg
- ChannelMessage
-
memberAdded
public void memberAdded(Member member)
Description copied from interface:MembershipListener
A member was added to the group- Specified by:
memberAdded
in interfaceMembershipListener
- Parameters:
member
- Member - the member that was added
-
memberDisappeared
public void memberDisappeared(Member member)
Description copied from interface:MembershipListener
A member was removed from the group
If the member left voluntarily, the Member.getCommand will contain the Member.SHUTDOWN_PAYLOAD data- Specified by:
memberDisappeared
in interfaceMembershipListener
- Parameters:
member
- Member- See Also:
Member.SHUTDOWN_PAYLOAD
-
heartbeat
public void heartbeat()
Description copied from interface:ChannelInterceptor
Theheartbeat()
method gets invoked periodically to allow interceptors to clean up resources, time out object and perform actions that are unrelated to sending/receiving data.- Specified by:
heartbeat
in interfaceChannelInterceptor
- Specified by:
heartbeat
in interfaceHeartbeat
-
hasMembers
public boolean hasMembers()
Description copied from interface:ChannelInterceptor
Intercepts theChannel.hasMembers()
method- Specified by:
hasMembers
in interfaceChannelInterceptor
- Returns:
- boolean - if the channel has members in its membership group
- See Also:
Channel.hasMembers()
-
getMembers
public Member[] getMembers()
Description copied from interface:ChannelInterceptor
Intercepts theChannel.getMembers()
method- Specified by:
getMembers
in interfaceChannelInterceptor
- Returns:
- the members
- See Also:
Channel.getMembers()
-
getMember
public Member getMember(Member mbr)
Description copied from interface:ChannelInterceptor
Intercepts theChannel.getMember(Member)
method- Specified by:
getMember
in interfaceChannelInterceptor
- Parameters:
mbr
- Member- Returns:
- Member - the actual member information, including stay alive
- See Also:
Channel.getMember(Member)
-
getLocalMember
public Member getLocalMember(boolean incAlive)
Description copied from interface:ChannelInterceptor
Intercepts theChannel.getLocalMember(boolean)
method- Specified by:
getLocalMember
in interfaceChannelInterceptor
- Parameters:
incAlive
- boolean- Returns:
- the member that represents this node
- See Also:
Channel.getLocalMember(boolean)
-
start
public void start(int svc) throws ChannelException
Description copied from interface:ChannelInterceptor
Starts up the channel. This can be called multiple times for individual services to start The svc parameter can be the logical or value of any constants- Specified by:
start
in interfaceChannelInterceptor
- Parameters:
svc
- one of:- Channel.DEFAULT - will start all services
- Channel.MBR_RX_SEQ - starts the membership receiver
- Channel.MBR_TX_SEQ - starts the membership broadcaster
- Channel.SND_TX_SEQ - starts the replication transmitter
- Channel.SND_RX_SEQ - starts the replication receiver
- Throws:
ChannelException
- if a startup error occurs or the service is already started.- See Also:
Channel
-
stop
public void stop(int svc) throws ChannelException
Description copied from interface:ChannelInterceptor
Shuts down the channel. This can be called multiple times for individual services to shutdown The svc parameter can be the logical or value of any constants- Specified by:
stop
in interfaceChannelInterceptor
- Parameters:
svc
- one of:- Channel.DEFAULT - will shutdown all services
- Channel.MBR_RX_SEQ - stops the membership receiver
- Channel.MBR_TX_SEQ - stops the membership broadcaster
- Channel.SND_TX_SEQ - stops the replication transmitter
- Channel.SND_RX_SEQ - stops the replication receiver
- Throws:
ChannelException
- if a startup error occurs or the service is already started.- See Also:
Channel
-
fireInterceptorEvent
public void fireInterceptorEvent(ChannelInterceptor.InterceptorEvent event)
Description copied from interface:ChannelInterceptor
Fire an event.- Specified by:
fireInterceptorEvent
in interfaceChannelInterceptor
- Parameters:
event
- the event
-
getChannel
public Channel getChannel()
Description copied from interface:ChannelInterceptor
Return the channel that is related to this interceptor- Specified by:
getChannel
in interfaceChannelInterceptor
- Returns:
- Channel
-
setChannel
public void setChannel(Channel channel)
Description copied from interface:ChannelInterceptor
Set the channel that is related to this interceptor- Specified by:
setChannel
in interfaceChannelInterceptor
- Parameters:
channel
- The channel
-
-