Intercept

The main distro/cvs/etc has moved to java.net. Right now ongoing work on this library has mostly stopped in favor of work on DynAOP.

It provides all the spiffies I want, and that others seem to want in very few classes. Its very optimized for wrapping objects and executing invocation stacks (ie, intercepted method calls) rather than for adding new interceptors. Making a typical call to an intercepted method doesn't involve any reflection (it uses cglib). The first time an instance of a given class is wrapped it is slow (bytecode generation) and when a new interceptor is added it is slow (needs to traverse its cache and figure out what it applies to) but the common stuff is fast and that's what counts =)

Using it is pretty easy, and works like:


    InterceptionBroker broker = new InterceptionBroker();
    broker.addInterceptor(new LoggingInterceptor(), new Signature()
    {
        public boolean match(Method m)
        {
            // Match every method call on every object
            return true;
        }
    });
    
    Map example = new HashMap();
    Map same = broker.wrap(example);
    // same is the interception wrapped version of example
    example.put("foo", "bar");  // Will not be intercepted
    same.get("foo");            // Will be intercepted and logged
It supports singleton interceptors like the above example, or per-invocation style interceptors where it creates a new one for each invocation.

In addition to providing the basic interception broker, base implementations for several (eventually most) of the common uses for interception are implemented in the library. This includes managed transactions, actor-based security constraints, logging, etc.

Current Javadocs

Development Snapshot

Source Tarball -- Binary Tarball

Contributors

Chris Nokleberg, Brian McCallister

License

Copyright (c) 2003, Brian McCallister
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

HIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.