Let us digest all this by example and see if we're on the same page...
Consider (bear with me on the IoC type 3; it saves typing):
public interface PingServer // fragments
{
String echo(String input);
}
public interface Stage
{
void process( Request req, Response res );
}
public class PingServerStage implements Stage
{
private PingServer m_server; public void PingServerStage( PingServer server )
{
m_server = server;
} public void process( Request req, Response res )
{
modifyInput( req ); // poor man's AOP
String input = req.getMessageAsString();
String output = m_server.echo( input );
res.setMessage( output ); modifyOutput( res ); // poor man's AOP
res.writeMessage();
} public void modifyInput( Request input ) {}
public void modifyOutput( Response output ) {}
}
public class ExampleOfPoorMansAOPPersonalizedServerStage
extends PingServerStage
{
public ExampleOfPoorMansAOPPersonalizedServerStage(
PingServer server ) { super( server ); } public void modifyInput( Request req )
{
if( req.getSession().get("username") == null )
reg.getSession().set("username", "Anonymous");
} public void modifyInput( Response res )
{
res.setMessage(
"Hello " + res.getSession().get("username") +
"! Did you know: " + res.getMessage() );
}The PingServer just does its thing; the PingServerStage adds pipeline-style request/response processing. I muddied up the example with some "poor man's AOP" just to point out how AOP is such a natural thing to apply to EBP (we should take that into account early on).
Basically, I think you're looking for a way to have the container provide the PingServerStage, or at least make it as easy as possible to write, so that you can just do a wiring like (again forgive the not using of XML):
container.newPipeline( SocketServer.class, Parser.class, EchoServer.class, Logger.class, Cleanup.class );
something like that is, unfortunately, a pipe dream. The EBP<->IoC connection
String input = req.getMessageAsString();
String output = m_server.echo( input );
res.setMessage( output );
res.writeMessage();will remain component specific. So what we're doing is looking for a way to make the creation of these stages as easy as possible, while remaining true to our performance and stability criteria. That's the goal, right?
Question: how does the component writer like to write his EBP<->IoC connection? Your idea:
interface EchoServer
{
String echo(Request request, String input);
}
class EchoServerImpl implements EchoServer
{
String echo(String input) { /* ... */ }
}
class RequestEchoServer extends EchoServerImpl
{
String echo(Request request, String input)
{
/* ... interact with Request ... */
String output = echo( input );
/* ... interact with Request ... */
}
}but how do I access the response? We'd probably need
String echo(Request request, Response response, Session session,
String input)or
String echo(Event event, String input)
Leo Sutic says:
class ContextAwareEchoServer extends AbstractInvocationContextAware
implements EchoServer
{
ContextAwareEchoServer( EchoServer delegate ) { /* ... */ } String echo( String input )
{
/* ... interact with getInvocationContext() ... */
String output = m_delegate.echo( input );
/* ... interact with getInvocationContext() ... */
}
}that certainly looks very nice. I wrote
http://cvs.sourceforge.net/viewcvs.py/*checkout*/jicarilla/jicarilla-sandbox/platform/framework/api/src/java/com/leosimons/jicarilla/framework/AsyncEnabled.java?content-type=text%2Fplain&rev=1.2
which had a similar idea behind it. AOP beefs will likely opt for something like
class ContextAwareInterceptor extends
AbstractInterceptor
{
String intercept( Invocation invocation )
{
/* ... interact with invocation ... */
Object output = invocation.invoke();
/* ... interact with invocation ... */
}
}But how do I implement the generic
container.newPipeline( ContextAwareSocketServer.class, ContextAwareParser.class, ContextAwareEchoServer.class, ContextAwareLogger.class, ContextAwareCleanup.class );
in this setup? Metadata? The key difference between an approach like this and the servlet approach is that with servlets, the container knows how to route things because of the explicit request/response servlet interface. I know that, with interception, you don't. It looks like this:
Aspect.add( SocketServerImpl.class, new ContextAwareInterceptor() ); container.newPipeline( SocketServerStage.class, ParserStage.class, EchoServerStage.class, LoggerStage.class, CleanupStage.class );
Isn't that true for all these alternatives as well? If so, we have to create ****Stage classes anyway. And if that is true, what is the net value of all this magic? What am I missing?
cheers!
-LSD
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
