org.jboss.cache.interceptors
Class InterceptorChain

java.lang.Object
  extended by org.jboss.cache.interceptors.InterceptorChain

public class InterceptorChain
extends Object

Knows how to build and manage an chain of interceptors. Also in charge with invoking methods on the chain.

Since:
2.2
Author:
Mircea.Markus@jboss.com

Constructor Summary
InterceptorChain(CommandInterceptor first)
          Constructs an interceptor chain having the supplied interceptor as first.
 
Method Summary
 boolean addInterceptor(CommandInterceptor toAdd, Class<? extends CommandInterceptor> afterInterceptor)
          Adds a new interceptor in list after an interceptor of a given type.
 void addInterceptor(CommandInterceptor interceptor, int position)
          Inserts the given interceptor at the specified position in the chain (o based indexing).
 void appendIntereceptor(CommandInterceptor ci)
          Appends at the end.
 List<CommandInterceptor> asList()
          Returns the chain as a list.
 CommandInterceptor getFirstInChain()
           
 List<CommandInterceptor> getInterceptorsAsList()
          Returns an unmofiable list with all the interceptors in sequence.
 InvocationContext getInvocationContext()
           
 void initialize(InvocationContextContainer invocationContextContainer)
           
 Object invoke(InvocationContext ctx, VisitableCommand command)
          Walks the command through the interceptor chain.
 Object invoke(VisitableCommand cacheCommand)
          Similar to #invoke(org.jboss.cache.InvocationContext, org.jboss.cache.commands.ReplicableCommand), but constructs a invocation context on the fly, using ThreadLocal.get() and setting the origin local flag to it's default value.
 Object invokeRemote(VisitableCommand cacheCommand)
          Similar to #invoke(org.jboss.cache.InvocationContext, org.jboss.cache.commands.ReplicableCommand), but constructs a invocation context on the fly, using ThreadLocal.get()
 void removeInterceptor(Class<? extends CommandInterceptor> clazz)
          Removes all the occurences of supplied interceptor type from the chain.
 void removeInterceptor(int position)
          Removes the interceptor at the given postion.
 void setFirstInChain(CommandInterceptor interceptor)
          Mainly used by unit tests to replace the interceptor chain with the starting point passed in.
 int size()
          Returns the number of interceptors in the chain.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InterceptorChain

public InterceptorChain(CommandInterceptor first)
Constructs an interceptor chain having the supplied interceptor as first.

Method Detail

initialize

public void initialize(InvocationContextContainer invocationContextContainer)

addInterceptor

public void addInterceptor(CommandInterceptor interceptor,
                           int position)
Inserts the given interceptor at the specified position in the chain (o based indexing).

Throws:
IllegalArgumentException - if the position is invalid (e.g. 5 and there are only 2 interceptors in the chain)

removeInterceptor

public void removeInterceptor(int position)
Removes the interceptor at the given postion.

Throws:
IllegalArgumentException - if the position is invalid (e.g. 5 and there are only 2 interceptors in the chain)

size

public int size()
Returns the number of interceptors in the chain.


getInterceptorsAsList

public List<CommandInterceptor> getInterceptorsAsList()
Returns an unmofiable list with all the interceptors in sequence. If first in chain is null an empty list is returned.


removeInterceptor

public void removeInterceptor(Class<? extends CommandInterceptor> clazz)
Removes all the occurences of supplied interceptor type from the chain.


addInterceptor

public boolean addInterceptor(CommandInterceptor toAdd,
                              Class<? extends CommandInterceptor> afterInterceptor)
Adds a new interceptor in list after an interceptor of a given type.

Returns:
true if the interceptor was added; i.e. the afterInterceptor exists

asList

public List<CommandInterceptor> asList()
Returns the chain as a list.


appendIntereceptor

public void appendIntereceptor(CommandInterceptor ci)
Appends at the end.


invoke

public Object invoke(InvocationContext ctx,
                     VisitableCommand command)
Walks the command through the interceptor chain. The received ctx is being passed in.


invokeRemote

public Object invokeRemote(VisitableCommand cacheCommand)
                    throws Throwable
Similar to #invoke(org.jboss.cache.InvocationContext, org.jboss.cache.commands.ReplicableCommand), but constructs a invocation context on the fly, using ThreadLocal.get()

Throws:
Throwable

invoke

public Object invoke(VisitableCommand cacheCommand)
              throws Throwable
Similar to #invoke(org.jboss.cache.InvocationContext, org.jboss.cache.commands.ReplicableCommand), but constructs a invocation context on the fly, using ThreadLocal.get() and setting the origin local flag to it's default value.

Throws:
Throwable

getFirstInChain

public CommandInterceptor getFirstInChain()
Returns:
the first interceptor in the chain.

setFirstInChain

public void setFirstInChain(CommandInterceptor interceptor)
Mainly used by unit tests to replace the interceptor chain with the starting point passed in.

Parameters:
interceptor - interceptor to be used as the first interceptor in the chain.

getInvocationContext

public InvocationContext getInvocationContext()

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2008 JBoss, a division of Red Hat. All Rights Reserved.