001/*
002 * Copyright 2009 Red Hat, Inc.
003 * Red Hat licenses this file to you under the Apache License, version
004 * 2.0 (the "License"); you may not use this file except in compliance
005 * with the License.  You may obtain a copy of the License at
006 *    http://www.apache.org/licenses/LICENSE-2.0
007 * Unless required by applicable law or agreed to in writing, software
008 * distributed under the License is distributed on an "AS IS" BASIS,
009 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
010 * implied.  See the License for the specific language governing
011 * permissions and limitations under the License.
012 */
013
014package org.hornetq.api.core;
015
016import org.hornetq.api.core.client.ClientSessionFactory;
017import org.hornetq.core.protocol.core.Packet;
018import org.hornetq.spi.core.protocol.RemotingConnection;
019
020/**
021 * This is class is a simple way to intercepting calls on HornetQ client and servers.
022 * <p/>
023 * To add an interceptor to HornetQ server, you have to modify hornetq-configuration.xml.
024 * To add it to a client, use {@link ClientSessionFactory#addInterceptor(Interceptor)}
025 *
026 * @author clebert.suconic@jboss.com
027 * @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
028 */
029public interface Interceptor
030{
031   /**
032    * Intercepts a packet which is received before it is sent to the channel
033    *
034    * @param packet     the packet being received
035    * @param connection the connection the packet was received on
036    * @return {@code true} to process the next interceptor and handle the packet,
037    *         {@code false} to abort processing of the packet
038    * @throws HornetQException
039    */
040   boolean intercept(Packet packet, RemotingConnection connection) throws HornetQException;
041}