1 /* 2 * Copyright 2006 Simon Raess 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package net.sf.beep4j; 17 18 /** 19 * A ChannelFilter is meant to be used to implement cross-cutting concerns, such 20 * as logging, message transformations, and security. Each channel can have 21 * 0 or more such filters that are arranged in a chain. 22 * 23 * @author Simon Raess 24 */ 25 public interface ChannelFilter { 26 27 /** 28 * Filters {@link Channel#sendMessage(Message, ReplyHandler)}. 29 * 30 * @param next the next filter in the chain 31 * @param message the message that is to be sent 32 * @param listener the listener that processes the reply for this message 33 */ 34 void filterSendMessage(NextFilter next, Object message, ReplyHandler listener); 35 36 /** 37 * Filters {@link Channel#close(CloseChannelCallback)}. 38 * 39 * @param next the next filter in the chain 40 */ 41 void filterClose(NextFilter next); 42 43 /** 44 * Filters {@link ChannelHandler#channelOpened(Channel)}. 45 * 46 * @param next the next filter in the chain 47 * @param channel the channel that was opened 48 */ 49 void filterChannelOpened(NextFilter next, Channel channel); 50 51 /** 52 * Filters {@link ChannelHandler#messageReceived(Message, Reply)}. 53 * 54 * @param next the next filter in the chain 55 * @param message the message that is received 56 * @param responseHandler to be used to create the response for the received message 57 */ 58 void filterMessageReceived(NextFilter next, Message message, Reply responseHandler); 59 60 /** 61 * Filters {@link ChannelHandler#channelCloseRequested(CloseChannelRequest)}. 62 * 63 * @param next the next filter in the chain 64 * @param request the close channel request 65 */ 66 void filterChannelCloseRequested(NextFilter next, CloseChannelRequest request); 67 68 /** 69 * Filters {@link ChannelHandler#channelClosed()}. 70 * 71 * @param next the next filter in the chain 72 */ 73 void filterChannelClosed(NextFilter next); 74 75 /** 76 * Interface of the next filter in the chain. 77 */ 78 interface NextFilter { 79 80 void filterSendMessage(Message message, ReplyHandler listener); 81 82 void filterClose(CloseChannelCallback callback); 83 84 void filterChannelOpened(Channel channel); 85 86 void filterMessageReceived(Message message, Reply reply); 87 88 void filterChannelCloseReqested(CloseChannelRequest request); 89 90 void filterChannelClosed(); 91 92 } 93 94 }