2 Replies Latest reply on Jul 5, 2010 10:45 PM by ron_sigal

    How to set timeout for method invocation?

    jdabrowski

      I found an issue and I can't handle it myself.

       

      I set jnp.timeout and when I connect to remote server from jboss (there is another jboss which runs on remote machine) and server is down then I get exception after the time I've specified. But the problem is when I create InitialContext (remote server is ok) and after some time server shutdowns.

      I would like to set timeout which server waits for remote server to response to method invocation.

       

      How can I do it?

       

       

       

       

      After a long time I get:

       

      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 mycompany.application.server.access.locator.ServiceProxy.invoke(ServiceProxy.java:100)
          at $Proxy1597.getDomainByName(Unknown Source)
          at mycompany.groupwise.adminapi.shared.GroupwiseAdminDelegateImpl.getDomainByName(GroupwiseAdminDelegateImpl.java:79)
          at mycompany.application.groupwise.UserAddedReceiver.onMessage(UserAddedReceiver.java:66)
          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.invokeInCallerTx(TxPolicy.java:126)
          at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:201)
          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.mdb.MessagingContainer.localInvoke(MessagingContainer.java:245)
          at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.delivery(MessageInflowLocalProxy.java:268)
          at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.invoke(MessageInflowLocalProxy.java:138)
          at $Proxy1589.onMessage(Unknown Source)
          at org.jboss.resource.adapter.jms.inflow.JmsServerSession.onMessage(JmsServerSession.java:183)
          at org.jboss.mq.SpyMessageConsumer.sessionConsumerProcessMessage(SpyMessageConsumer.java:905)
          at org.jboss.mq.SpyMessageConsumer.addMessage(SpyMessageConsumer.java:170)
          at org.jboss.mq.SpySession.run(SpySession.java:323)
          at org.jboss.resource.adapter.jms.inflow.JmsServerSession.run(JmsServerSession.java:249)
          at org.jboss.resource.work.WorkWrapper.execute(WorkWrapper.java:204)
          at org.jboss.util.threadpool.BasicTaskWrapper.run(BasicTaskWrapper.java:275)
          at EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:743)
          at java.lang.Thread.run(Thread.java:619)
      Caused by: org.jboss.remoting.CannotConnectException: Can not get connection to server.  Problem establishing socket connection.
          at org.jboss.remoting.transport.socket.SocketClientInvoker.transport(SocketClientInvoker.java:267)
          at org.jboss.remoting.RemoteClientInvoker.invoke(RemoteClientInvoker.java:143)
          at org.jboss.remoting.Client.invoke(Client.java:525)
          at org.jboss.remoting.Client.invoke(Client.java:488)
          at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:55)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
          at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
          at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:55)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
          at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:77)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
          at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:102)
          at $Proxy1597.getDomainByName(Unknown Source)
          ... 38 more
      Caused by: java.net.ConnectException: Connection timed out
          at java.net.PlainSocketImpl.socketConnect(Native Method)
          at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
          at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
          at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
          at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
          at java.net.Socket.connect(Socket.java:519)
          at java.net.Socket.connect(Socket.java:469)
          at java.net.Socket.<init>(Socket.java:366)
          at java.net.Socket.<init>(Socket.java:180)
          at org.jboss.remoting.transport.socket.SocketClientInvoker.createSocket(SocketClientInvoker.java:535)
          at org.jboss.remoting.transport.socket.SocketClientInvoker.getConnection(SocketClientInvoker.java:471)
          at org.jboss.remoting.transport.socket.SocketClientInvoker.transport(SocketClientInvoker.java:263)
          ... 51 more

        • 1. Re: How to set timeout for method invocation?
          jdabrowski

          I found some simple example which could be easier to test:

           

          Hashtable<String, String> props = new Hashtable<String, String>();
          props.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
          props.put(InitialContext.PROVIDER_URL,"jnp://" + urlRemoteMachine);
          props.put(InitialContext.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
          props.put("jnp.timeout", "1000");
          props.put("jnp.sotimeout", "1000");
          InitialContext initialContext = new InitialContext(props);
          MyBeanRemote remote = (MyBeanRemote) initialContext.lookup("MyBean/remote");
          System.in.read();
          System.out.println("Start");
          System.out.println(remote.someMethod());
          System.out.println("Stop");

           

          When server is down lookup fails after jnp.timeout, but when I stop program on read() and then turn off remote server remote.someMethod() whaits a long time before returning with Exception:

           

          Exception in thread "Main Thread" org.jboss.remoting.CannotConnectException: Can not get connection to server.  Problem establishing socket connection.
              at org.jboss.remoting.transport.socket.SocketClientInvoker.transport(SocketClientInvoker.java:268)
              at org.jboss.remoting.RemoteClientInvoker.invoke(RemoteClientInvoker.java:143)
              at org.jboss.remoting.Client.invoke(Client.java:525)
              at org.jboss.remoting.Client.invoke(Client.java:488)
              at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:55)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
              at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
              at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:53)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
              at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:77)
              at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
              at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:102)
              at $Proxy5.someMethod(Unknown Source)
              at myapp.Test.main(Test.java:104)
          Caused by: java.net.ConnectException: Connection timed out
              at java.net.PlainSocketImpl.socketConnect(Native Method)
              at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
              at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
              at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
              at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
              at java.net.Socket.connect(Socket.java:519)
              at java.net.Socket.connect(Socket.java:469)
              at java.net.Socket.<init>(Socket.java:366)
              at java.net.Socket.<init>(Socket.java:180)
              at org.jboss.remoting.transport.socket.SocketClientInvoker.createSocket(SocketClientInvoker.java:526)
              at org.jboss.remoting.transport.socket.SocketClientInvoker.getConnection(SocketClientInvoker.java:472)
              at org.jboss.remoting.transport.socket.SocketClientInvoker.transport(SocketClientInvoker.java:264)
              ... 14 more

          • 2. Re: How to set timeout for method invocation?
            ron_sigal

            Hi Jacek,

             

            Note that I moved this thread to the Remoting users forum.

             

            I'm not really sure what your question is.  However, it seems that, on the one hand, you have successfully set the timeout value for JNDI lookups, but you want to speed up the connection failures you're showing in the stacktraces.  Is that right?  If so, then you can set the connection timeout value in one of the server configuration files.  Which file to change depends on the version of the Application Server you are using.  For AS 4, go to $JBOSS_HOME/server/$CONFIG/deploy/ejb3.deployer/META-INF/jboss-service.xml and add, for example, "timeout=60000" to the "InvokerLocator" attribute:

             

              <attribute name="InvokerLocator">socket://${jboss.bind.address}:3873/?invokerDestructionDelay=5000&timeout=60000</attribute>

             

            which will set the timeout for connections and invocations to one minute.

             

            In AS 5, go to $JBOSS_HOME/server/$CONFIG/deploy/ejb3-connectors-jboss-beans.xml and do the same thing.

             

            -Ron