The Artima Developer Community
Sponsored Link

Java Buzz Forum
Intercept Library Initial Release

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Brian McCallister

Posts: 1282
Nickname: frums
Registered: Sep, 2003

Brian McCallister is JustaProgrammer who thinks too much.
Intercept Library Initial Release Posted: Dec 1, 2003 12:33 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Brian McCallister.
Original Post: Intercept Library Initial Release
Feed Title: Waste of Time
Feed URL: http://kasparov.skife.org/blog/index.rss
Feed Description: A simple waste of time and weblog experiment
Latest Java Buzz Posts
Latest Java Buzz Posts by Brian McCallister
Latest Posts From Waste of Time

Advertisement

This past weekend, my girlfriend being out of town, I got to hack a lot. It was nice. At one point I needed a general purpose interceptor tool and went digging through the various ones out there. XWork is tightly coupled to its Command stuff. Spring is tightly coupled to its IoC stuff and XML configuration. HiveMind is temporarily unavailable. AspectJ and AspectWerkz are not simple interceptor libraries, they are full fledged languages for all practical purposes.

So, in good old itchy fashion I tossed together a bare-bones interception library. It doesn't do IoC, it doesn't do XML configuration, it doesn't include a web application framework, it doesn't include an EJB container, or service definitions, or dependencies on commons-*. It just does interception of arbitrary method calls with arbitrary interceptors in 332 lines of code =)

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 instane 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.

Source code , Binary Distribution and javadocs are all available. It's BSD licensed for now. If anyone else uses it or contibutes then I may look into moving it into the Apache Commons Sandbox, but I won't bother as long as I am the sole contributor =)

Read: Intercept Library Initial Release

Topic: Game addiction Previous Topic   Next Topic Topic: Approaching Menus in Cocoa

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use