[jboss-user] [EJB 3.0] - Re: ejb3.0 problem, container not yet available??

moksha2007 do-not-reply at jboss.com
Sat Apr 5 07:05:16 EDT 2008


Oke, going to put in some background:

Instance A:

>From boot.log:
15:56:18,265 DEBUG [ServiceCreator] Created bean: jboss:service=Naming
	15:56:18,265 DEBUG [ServiceConfigurator] CallByValue set to false in jboss:service=Naming
	15:56:18,266 DEBUG [ServiceConfigurator] Port set to 1099 in jboss:service=Naming
	15:56:18,267 DEBUG [ServiceConfigurator] BindAddress set to 127.0.0.106 in jboss:service=Naming
	15:56:18,267 DEBUG [ServiceConfigurator] RmiPort set to 1098 in jboss:service=Naming
	15:56:18,268 DEBUG [ServiceConfigurator] RmiBindAddress set to 127.0.0.106 in jboss:service=Naming

Instance B:

>From boot.log:
15:57:29,698 DEBUG [ServiceCreator] Created bean: jboss:service=Naming
	15:57:29,698 DEBUG [ServiceConfigurator] CallByValue set to false in jboss:service=Naming
	15:57:29,699 DEBUG [ServiceConfigurator] Port set to 1099 in jboss:service=Naming
	15:57:29,700 DEBUG [ServiceConfigurator] BindAddress set to 127.0.0.107 in jboss:service=Naming
	15:57:29,701 DEBUG [ServiceConfigurator] RmiPort set to 1098 in jboss:service=Naming
	15:57:29,701 DEBUG [ServiceConfigurator] RmiBindAddress set to 127.0.0.107 in jboss:service=Naming

I can telnet to both, so I guess those are running fine.

In instance A, I have a method that does this (basically setting up some context to be used for the callback/invocation as soon the timer goes off at B):

public void schedule(...) {
    ...
    Properties props = new Properties();
    props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
    props.put(Context.PROVIDER_URL, "127.0.0.106:1099");
    ...
    ScheduleRequest request = new ScheduleRequest();
    request.setApplicationContext(phoneMessage.getId());
    request.setStartTime(startTime);
    request.setEndTime(endTime);
    request.setAverageDuration(new Long(duration).intValue());
    request.setCallbackMethod("deliver");
    request.setJndiContext(props);
    request.setJndiReferenceLookup(CallHandlerService.class.getName());
    request.setPreferredDeliveryDate(phoneMessage.getPreferredDeliveryDate());
    request.setTimezone(phoneMessage.getTimeZone());
    request.setTotalCalls(this.phoneMessageRepository.getNumberOfRecipients(phoneMessage.getId()));
    this.getScheduler().schedule(request);
    if (log.isInfoEnabled()) {
        log.info("Done scheduling PhoneMesage with id: " + phoneMessage.getId());
    }
}

As you can see, I am avoiding cyclic dependencies, as I try to keep the applications 'unaware' of each other, by passing primitives.
>From the logs in A, I do see the scheduling is done. The lookup is done as follow:

protected Scheduler getScheduler() {
    return (Scheduler) this.lookupService(Scheduler.class.getName());
}

protected Object lookupService(String serviceName) {
    // Set security policy
    if(System.getSecurityManager() == null) {
        this.log.info("Using security policy file: " + System.getProperty("java.security.policy"));
        System.setSecurityManager(new RMISecurityManager());
    }
    Properties props = new Properties();
    props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
    props.put(Context.PROVIDER_URL, "jnp://127.0.0.107:1099");
		
    try {
        this.log.info("Lookup called in CallHandlerServiceBean...");
        Context ctx = new InitialContext(props);
        return ctx.lookup(serviceName);
    } catch (NamingException e) {
        log.fatal("Unable to lookup service interface: " + serviceName);
        e.printStackTrace();
    }
    return null;
}

The callback method:

public void deliver(Serializable applicationContext, int numberOfCalls) {
    this.log.info("Deliver called with serializable: " + applicationContext);
    ...
}

In instance B:

@Timeout
public void handleTimeout(Timer timer) {
    // Fetch context from timer
    if(timer.getInfo() instanceof ScheduleContext) {
        try {
            ScheduleContext scheduleContext = (ScheduleContext) timer.getInfo();
            // Set security policy
            if(System.getSecurityManager() == null) {
                if(this.log.isDebugEnabled()) {
                    this.log.debug("Using security policy file: " + System.getProperty("java.security.policy"));
                }
                System.setSecurityManager(new RMISecurityManager());
            }
            // Obtain reference of remote interface
            if(this.log.isDebugEnabled()) {
                this.log.debug("Lookup called in ScheduleBean...");
            }
            InitialContext initialContext = new InitialContext(scheduleContext.getJndiContext());
            Object remoteInterface = initialContext.lookup(scheduleContext.getJndiReferenceLookup());
            if(this.log.isDebugEnabled()) {
                this.log.debug("Lookup result (using: " + scheduleContext.getJndiContext().getProperty(Context.PROVIDER_URL) + "): " + remoteInterface);
            }
            // Obtain method
            Method method = remoteInterface.getClass().getMethod(scheduleContext.getMethodName(), new Class[] {Serializable.class, int.class});
            // Invoke call back
            if(this.log.isInfoEnabled()) {
                this.log.info("About to invoke a callback on: '" + scheduleContext.getJndiReferenceLookup() + "'");
            }
            method.invoke(remoteInterface, new Object[] {scheduleContext.getApplicationContext(), scheduleContext.getTotalCalls()});
            if(this.log.isInfoEnabled()) {
                this.log.info("Callback succeeded...");
            }
        } catch (NamingException e) {
            this.log.error("Unable to handle timer: " + e.getMessage(), e);
        } catch (SecurityException e) {
            this.log.error("Unable to handle timer: " + e.getMessage(), e);
        } catch (NoSuchMethodException e) {
            this.log.error("Unable to handle timer: " + e.getMessage(), e);
        } catch (IllegalArgumentException e) {
            this.log.error("Unable to handle timer: " + e.getMessage(), e);
        } catch (IllegalAccessException e) {
            this.log.error("Unable to handle timer: " + e.getMessage(), e);
        } catch (InvocationTargetException e) {
            this.log.error("Unable to handle timer: " + e.getMessage(), e);
        } catch (Exception e) {
            this.log.error("Unable to handle timer: " + e.getMessage(), e);
        }
    } else {
        if(this.log.isWarnEnabled()) {
            this.log.warn("Unable to handle timer event, missing ScheduleContext...");
    }
}

I agree the try catch is verbose and could be optimized, but hey...

Is this a classloading issue? Call by value? LocalProxy should be something remote? Hopefully you can grasp the picture of what I am trying todo here.

Thanks in advance,
Mike

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4141826#4141826

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4141826



More information about the jboss-user mailing list