avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Neeme Praks <ne...@apache.org>
Subject Re: fortress .roles file doc?
Date Mon, 16 Jun 2003 20:38:48 GMT

Yep, I just figured also that it is probably better to explain my 
problem than to hack something together on my own... ;-)
Ok, so the problem.

I'm using Fortress inside JBoss stateless EJB and I need to give clients 
(servlets/cli) access to this fortress instance that is running inside 
that EJB. So I figured that I would expose a generic invoke() method on 
my EJB that would use the supplied arguments to delegate the actual work 
to Fortress components.

The generic method on EJB:
    public Object invoke(String role, String methodName, Class[] 
argumentTypes, Object[] argumentValues) throws Exception {
        //TODO reflection is slow, replace it with some bytecode 
generated optimizer
        if (getLogger().isDebugEnabled()) getLogger().debug("invoking: 
role=" + role + ", methodName=" + methodName + ", argumentValues=" + 
        ServiceManager sm = getServiceManager();
        Object component = null;
        try {
            component = sm.lookup(role);
            Method method = component.getClass().getMethod(methodName, 
            return method.invoke(component, argumentValues);
        } catch (Exception e) {
            getLogger().error("error while invoking: role=" + role + ", 
methodName=" + methodName + ", argumentValues=" + argumentValues, e);
            throw e;
        } finally {
            if (component != null) sm.release(component);

Ok, so far so good, this works ok if I invoke it straight from Java. 
Now, as you know, developers are lazy and I'm not an exception. I want 
to create a object factory that would allow me to specify in the .roles 
file if the component should be executed locally or if it should be 
executed remotely. So, I would like to be able to have all my remote 
components to implement the same code for every exposed method, example:

    public Screen getCurrentScreen(Long serviceInstanceId) throws 
Exception {
        Screen screen = null;
        Context context = getContext();
        if (context != null) {
            Object o = context.lookup(ApplicationHome.JNDI_NAME);
            Application a = null;
            try {
                ApplicationHome home = (ApplicationHome) 
PortableRemoteObject.narrow(o, ApplicationHome.class);
                a = home.create();
                return (Screen) a.invoke(ScreenManager.ROLE, 
"getCurrentScreen", new Class[] {Long.class}, new Object[] 
            } finally {
                try {
                    if (a != null) a.remove();
                } catch (Exception e) {
        return screen;

Now I figured out that probably I should extend the BCEL generator to 
achieve this... or is there an easier way?
Also, I'm not sure if it is possible for the local proxy component to 
know the ROLE string it is providing? I need this to look up the correct 
component remotely...


Berin Loritsch wrote:

> What problem are you trying to solve?
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
> For additional commands, e-mail: dev-help@avalon.apache.org

To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org

View raw message