[EJB 3.0] - Re: ejb3.0 problem, container not yet available??
by moksha2007
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
18 years
[EJB 3.0] - Re: ejb3.0 problem, container not yet available??
by moksha2007
Oke, heres the stacktrace:
2008-04-04 18:38:42,531 WARN [org.jboss.ejb3.LocalProxy] Container jboss.j2ee:ear=phonemessage-1.0.0.ear,jar=phonemessage-engine-1.0.0.jar,name=CallHandlerServiceBean,service=EJB3,VMID=ff2143713a7260c3:-350bd643:1191a4ce5d2:-7ffd is not yet available
2008-04-04 18:38:42,531 ERROR [com.thespeechcorporation.service.timer.ScheduleBean] Unable to handle timer: null
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.thespeechcorporation.service.timer.ScheduleBean.handleTimeout(ScheduleBean.java:273)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:95)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:108)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at org.jboss.ejb3.stateless.StatelessContainer.callTimeout(StatelessContainer.java:175)
at org.jboss.ejb.txtimer.TimerImpl$TimerTaskImpl.run(TimerImpl.java:561)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
Caused by: javax.ejb.EJBException: Invalid (i.e. remote) invocation of local interface (null container)
at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:80)
at $Proxy88.deliver(Unknown Source)
... 34 more
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4141822#4141822
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4141822
18 years
[EJB 3.0] - ejb3.0 problem, container not yet available??
by moksha2007
Hi,
Brief situation:
A -> B (remote ejb lookup + invocation -> success)
B performs some ejbTimer logic, in the timeout I proceed
B -> A (remote ejb lookup + reflection/invocation -> fails due container not yet available)
I'm using Jboss 4.2.2.GA and pass the JNDI properties, as well as the interface (name) and method from A to B. From there I do some reflection to invoke a method. A and B are seperate Jboss instances on a single machine, using virtual ip's.
In a single JVM this works.
At first I discovered I had to set a RMISecurityManager at both machines, and so I did. Both sides have all permissions/grant. Based on the fact I succeed from A to B I get the feeling this is done ok, but perhaps I forgot something?
A snippet of the log/stacktrace:
2008-04-04 18:38:42,497 DEBUG [org.jboss.ejb.txtimer.TimerImpl] setTimerState: in_timeout
2008-04-04 18:38:42,531 WARN [org.jboss.ejb3.LocalProxy] Container jboss.j2ee:ear=phonemessage-1.0.0.ear,jar=phonemessage-engine-1.0.0.jar,name=CallHandlerServiceBean,service=EJB3,VMID=ff2143713a7260c3:-350bd643:1191a4ce5d2:-7ffd is not yet available
2008-04-04 18:38:42,531 DEBUG [com.thespeechcorporation.service.timer.ScheduleBean] Lookup result (using: 127.0.0.106:1099): CallHandlerServiceBean
2008-04-04 18:38:42,531 INFO [com.thespeechcorporation.service.timer.ScheduleBean] About to invoke a callback on: 'com.phonemessage.service.CallHandlerService'
2008-04-04 18:38:42,531 WARN [org.jboss.ejb3.LocalProxy] Container jboss.j2ee:ear=phonemessage-1.0.0.ear,jar=phonemessage-engine-1.0.0.jar,name=CallHandlerServiceBean,service=EJB3,VMID=ff2143713a7260c3:-350bd643:1191a4ce5d2:-7ffd is not yet available
and from there it breaks...
Any suggestions? If more information is required, let me know.
PS> I did a cross post, not sure where the post should go to:
http://www.jboss.com/index.html?module=bb&op=viewtopic&t=133106
Thanks in advance,
Mike Ahlers
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4141820#4141820
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4141820
18 years