[Remoting] - LeasePinger error after Timer thread death + fix (happens in
by fatbatman
We're using remoting within a applet based application.
If the user navigates away from the page the browser plugin kills off various threads related to applet (I'm not 100% sure how it decides what is killed and what isn't). The JVM continues running.
If the user returns to the applet, remoting will fail if enableLease is true.
The problem is that in org.jboss.remoting.LeasePinger a static Timer timer is created once when each class is first used up. If these threads gets killed (such as by the browser plugin) all future requests to scheduled a task will fail.
The solution we used if a quick check to see that the tasks have been scheduled correctly, if not we create a new Timer.
For org.jboss.remoting.LeasePinger.java;
public void startPing()
| {
| if(trace) { log.trace(this + " starting lease timer with ping period of " + pingPeriod); }
|
| timerTask = new LeaseTimerTask(this);
|
| try{
| log("Hacked LeasePinger v0.1");
| timer.schedule(timerTask, pingPeriod, pingPeriod);
| }catch(java.lang.IllegalStateException e){
| log("LeasePinger.timer was canceled" +e.getMessage());
| log("Creating new Timer");
| timer = new Timer(true);
| timer.schedule(timerTask, pingPeriod, pingPeriod);
| }
| }
Note something similar can happen in org.jboss.remoting.util.TimerUtil
if the user doesn't manually call TimerUtil.destroy(), a similar fix is;
public static synchronized void schedule(TimerTask task, long period)
| {
| if (TimerUtil.timer == null)
| {
| TimerUtil.init();
| }
|
| if (task instanceof StoppableTimerTask)
| {
| stoppableTasks.add(task);
| }
|
| //schedule at fixed delay (not rate)
| try{
| log("Hacked TimerUtil v0.1");
| TimerUtil.timer.schedule(task, period, period);
| }catch(java.lang.IllegalStateException e){
| log("TimerUtil.timer was canceled" +e.getMessage());
| log("Creating new Timer");
| init();
| }
| }
Java 1.6.0_03
JBossRemoting remoting_2_2_2_SP2
regards
James
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4101225#4101225
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4101225
18 years, 5 months
[EJB 3.0] - Broken local-home-jndi-name in jboss.xml
by zagarol
Hi,
I think there is a bug in the handling of local-home-jndi-name when using the ejb3 deployer.
I am trying to set up some local SLSB beans to respond to a legacy SLSB. Initally when I tried this I get ClassCastExceptions on the proxy returned from JNDI. I corrected this on remote connections by replacing the jndi-name with home-jndi-name in jboss.xml.
Logically I thought the fix for local connections would be to use local-home-jndi-name, this deploys fine but the corresponding JNDI entry is actually a proxy to the local interface, not the local home interface.
Below is the test code I am using to verify this:
Remote bean:
| public class RemoteHomeTestEJB implements SessionBean {
|
| private SessionContext context = null;
|
| /*
| * (non-Javadoc)
| *
| * @see javax.ejb.SessionBean#ejbActivate()
| */
| public void ejbActivate() throws EJBException, RemoteException {
| // TODO Auto-generated method stub
|
| }
|
| /*
| * (non-Javadoc)
| *
| * @see javax.ejb.SessionBean#ejbPassivate()
| */
| public void ejbPassivate() throws EJBException, RemoteException {
| // TODO Auto-generated method stub
|
| }
|
| /*
| * (non-Javadoc)
| *
| * @see javax.ejb.SessionBean#ejbRemove()
| */
| public void ejbRemove() throws EJBException, RemoteException {
| // TODO Auto-generated method stub
|
| }
|
| public void ejbCreate() {
| //Do nothing.
| }
|
| /*
| * (non-Javadoc)
| *
| * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
| */
| public void setSessionContext(SessionContext ctx) throws EJBException,
| RemoteException {
| context = ctx;
| }
|
| public String getHello() {
| try {
| LocalHomeTestHome home = null;
| home = ServiceLocator.locateHome(LocalHomeTestHome.class,
| "java:comp/env/local/LocalHomeTest");
| return home.create().getHello();
| } catch (Exception e) {
| StringWriter stringWriter = new StringWriter();
| PrintWriter writer = new PrintWriter(stringWriter);
| e.printStackTrace(writer);
| return stringWriter.toString();
| }
| }
| }
|
ServiceLocater.java
| public class ServiceLocator {
| private static final Logger LOG = Logger.getLogger(ServiceLocator.class);
|
| @SuppressWarnings("unchecked")
| public static <T> T locateHome(Class<T> clazz, String location)
| throws NamingException {
| T home = null;
| Context ic = new InitialContext();
|
| Object potentialHome = ic.lookup(location);
| if (clazz.isInstance(potentialHome)) {
| home = (T) potentialHome;
| } else {
| home = (T) PortableRemoteObject.narrow(potentialHome, clazz);
| }
| return home;
| }
| }
|
Local bean:
| public class LocalHomeTestEJB implements SessionBean {
|
| /* (non-Javadoc)
| * @see javax.ejb.SessionBean#ejbActivate()
| */
| public void ejbActivate() throws EJBException, RemoteException {
| // TODO Auto-generated method stub
|
| }
|
| /* (non-Javadoc)
| * @see javax.ejb.SessionBean#ejbPassivate()
| */
| public void ejbPassivate() throws EJBException, RemoteException {
| // TODO Auto-generated method stub
|
| }
|
| public void ejbCreate() {
| //Do nothing.
| }
|
| /* (non-Javadoc)
| * @see javax.ejb.SessionBean#ejbRemove()
| */
| public void ejbRemove() throws EJBException, RemoteException {
| // TODO Auto-generated method stub
|
| }
|
| /* (non-Javadoc)
| * @see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)
| */
| public void setSessionContext(SessionContext ctx) throws EJBException,
| RemoteException {
| // TODO Auto-generated method stub
|
| }
|
| public String getHello() {
| return "Hello from Aerosystems";
| }
|
| }
|
ejb-jar.xml:
| <ejb-jar version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
| xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd">
|
| <description>Simple migration testing to see how to move to EJB 3</description>
| <display-name>EjbMigration</display-name>
|
| <enterprise-beans>
| <session>
| <description><![CDATA[EcardGenerationFacadeSessionEJB Bean]]></description>
| <display-name>LocalHomeTest</display-name>
|
| <ejb-name>LocalHomeTest</ejb-name>
| <remote>com.aeroint.ejbtest.common.RemoteHomeTestInterface</remote>
| <local-home>com.aeroint.ejbtest.server.session.LocalHomeTestHome</local-home>
| <local>com.aeroint.ejbtest.server.session.LocalHomeTestInterface</local>
| <ejb-class>com.aeroint.ejbtest.server.session.LocalHomeTestEJB</ejb-class>
|
| <session-type>Stateless</session-type>
| <transaction-type>Container</transaction-type>
| </session>
|
| <session>
| <description><![CDATA[EcardUpdateFacadeSessionEJB Bean]]></description>
| <display-name>RemoteHomeTest</display-name>
|
| <ejb-name>RemoteHomeTest</ejb-name>
|
| <home>com.aeroint.ejbtest.common.RemoteHomeTestHome</home>
| <remote>com.aeroint.ejbtest.common.RemoteHomeTestInterface</remote>
| <ejb-class>com.aeroint.ejbtest.server.facade.RemoteHomeTestEJB</ejb-class>
| <session-type>Stateless</session-type>
| <transaction-type>Container</transaction-type>
|
| <ejb-local-ref >
| <ejb-ref-name>local/LocalHomeTest</ejb-ref-name>
| <ejb-ref-type>Session</ejb-ref-type>
| <local-home>com.aeroint.ejbtest.server.session.LocalHomeTestHome</local-home>
| <local>com.aeroint.ejbtest.server.session.LocalHomeTestInterface</local>
| <ejb-link>LocalHomeTest</ejb-link>
| </ejb-local-ref>
|
| </session>
| </enterprise-beans>
| </ejb-jar>
|
jboss.xml
| <jboss xmlns="http://java.sun.com/xml/ns/javaee"
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
| xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
| http://www.jboss.org/j2ee/schema/jboss_5_0.xsd"
| version="3.0">
| <enterprise-beans>
| <session>
| <ejb-name>RemoteHomeTest</ejb-name>
| <home-jndi-name>remote/RemoteHomeTest</home-jndi-name>
| </session>
| <session>
| <ejb-name>LocalHomeTest</ejb-name>
| <local-home-jndi-name>local/LocalHomeTest</local-home-jndi-name>
| </session>
| </enterprise-beans>
| </jboss>
|
Thanks in advance,
Shane
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4101224#4101224
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4101224
18 years, 5 months