8 Replies Latest reply on Nov 11, 2011 1:24 PM by johncenapsna

    How to programmatically create datasource without configurin

    dkoon

      Hi, we are migrating from weblogic to JBoss. So far things are working well, but recently we encounter a show-stopper.

      Part of the application code creates new datasources dynamically. In weblogic, JMX MBeans api are published and can be used to do that dynamically without shutting down application server.

      I saw from another JBoss forum article dated Nov 2004 that it is a things to do list for JBoss to do the same, but so far no work has been completed.

      Does anyone know any back door/undocumented way to create a datasource dynamically without shutting down the server? If so, could you post a code fragment?

      Appreciate all the help as this is the show stopper right now. I know that we can programmatically modify the datasource info in one of the xml configuration files, but doing so would require rebooting the server, which is unacceptable to our customer.

        • 1. Re: How to programmatically create datasource without config
          starksm64

          Write a *-ds.xml descriptor into the deploy directory.

          • 2. Re: How to programmatically create datasource without config
            dkoon

            Does the *-ds.xml file have to be brand new, or can it be existing? I created the new datasource definitions in an existing mssql-ds.xml and the datasource was not bound until we reboot JBoss.

            So what you are suggesting is to create the new datasource definitions in brand new *-ds.xml file, is this correct?

            Thanks,

            Derrick Koon

            • 3. Re: How to programmatically create datasource without config
              starksm64

              It can be an existing datasource definition file unless you have hot deploy disabled. In that case you would have to invoke the MainDeployer deploy method passing in the url to the mssql-ds.xml.

              • 4. Re: How to programmatically create datasource without config
                dkoon

                OK, you are right. JBoss does hot-deply when *-ds.xml got modified. My problem was that the default "ScanPeriod=5000" in jboss-service.xml was too large for the application, cause right after the datasource was defined in *-ds.xml, it will be used almost immediately and 5 secs are too large.

                Now I have changed the ScanPeriod to a smaller value of 100. But I found out the hot-deploy still does not work with the following exception after undeploying *-ds.xml and during redeplying the updated *-ds.xml:

                2005-01-10 12:09:24,234 1057438 ERROR [ScannerThread] - Starting failed jboss:service=KeyGeneratorFactory,type=HiLo
                javax.naming.CommunicationException. Root exception is
                java.io.NotSerializableException: org.jboss.tm.TxManager
                at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)
                at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1330)
                at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1302)
                at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1245)
                at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
                at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
                at java.rmi.MarshalledObject.(MarshalledObject.java:92)
                at org.jnp.interfaces.MarshalledValuePair.(MarshalledValuePair.java:41)
                at org.jnp.interfaces.NamingContext.rebind(NamingContext.java:434)
                at org.jnp.interfaces.NamingContext.rebind(NamingContext.java:413)
                at javax.naming.InitialContext.rebind(InitialContext.java:363)
                at org.jboss.naming.Util.rebind(Util.java:109)
                at org.jboss.naming.Util.rebind(Util.java:96)
                at org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory.startService(HiLoKeyGeneratorFactory.java:205)
                at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:271)
                at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:221)
                at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                at java.lang.reflect.Method.invoke(Method.java:324)
                at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
                at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
                at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
                at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:242)
                at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:642)
                at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:891)
                at $Proxy0.start(Unknown Source)
                at org.jboss.system.ServiceController.start(ServiceController.java:416)
                at org.jboss.system.ServiceController.start(ServiceController.java:438)
                at org.jboss.system.ServiceController.start(ServiceController.java:438)
                at org.jboss.system.ServiceController.start(ServiceController.java:438)
                at org.jboss.system.ServiceController.start(ServiceController.java:438)
                at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                at java.lang.reflect.Method.invoke(Method.java:324)
                at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
                at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
                at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
                at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:242)
                at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:642)
                at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
                at $Proxy4.start(Unknown Source)
                at org.jboss.deployment.SARDeployer.start(SARDeployer.java:261)
                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:324)
                at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
                at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
                at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
                at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:242)
                at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:642)
                at org.jboss.mx.util.JMXInvocationHandler.invoke(JMXInvocationHandler.java:272)
                at $Proxy32.start(Unknown Source)
                at org.jboss.deployment.XSLSubDeployer.start(XSLSubDeployer.java:222)
                at org.jboss.deployment.MainDeployer.start(MainDeployer.java:935)
                at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:746)
                at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:709)
                at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                at java.lang.reflect.Method.invoke(Method.java:324)
                at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
                at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
                at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:119)
                at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
                at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:131)
                at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
                at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:242)
                at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:642)
                at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:176)
                at $Proxy8.deploy(Unknown Source)
                at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:305)
                at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:463)
                at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:204)
                at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:215)
                at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:194)

                Also the following exception when application attempts to get a JDBC connection from these rebound/redeployed datasouces:

                2005-01-10 12:09:24,796 1058000 DEBUG [Thread-50] - SERVER IP : 127.0.0.1; BVConnection::getConnection() SQLException Error : org.jboss.util.NestedSQLException: You are trying to use a connection factory that has been shut down: ManagedConnectionFactory is null.; - nested throwable: (javax.resource.ResourceException: You are trying to use a connection factory that has been shut down: ManagedConnectionFactory is null.)

                Appreciate the insight and help.

                • 5. Re: How to programmatically create datasource without config
                  zjchen98

                  We are migration from JBoss 3.2 to JBoss 4.02 for live production application. Everything goes well, exception hot deployment seems break. It used to pick up new datasource, now I got following error:

                  16:47:54,067 INFO [ConnectionFactoryBindingService] Unbound connection factory for resource adapter
                  for ConnectionManager 'jboss.jca:service=DataSourceBinding,name=PostgresDSMember from JNDI name 'ja
                  va:PostgresDSMember'
                  16:47:54,067 INFO [ConnectionFactoryBindingService] Unbound connection factory for resource adapter
                  for ConnectionManager 'jboss.jca:service=DataSourceBinding,name=PostgresDSFare from JNDI name 'java
                  :PostgresDSFare'
                  16:47:54,082 INFO [ConnectionFactoryBindingService] Unbound connection factory for resource adapter
                  for ConnectionManager 'jboss.jca:service=DataSourceBinding,name=PostgresDS from JNDI name 'java:Pos
                  tgresDS'
                  16:47:54,395 INFO [WrapperDataSourceService] Bound connection factory for resource adapter for Conn
                  ectionManager 'jboss.jca:service=DataSourceBinding,name=PostgresDS to JNDI name 'java:PostgresDS'
                  16:47:54,426 INFO [WrapperDataSourceService] Bound connection factory for resource adapter for Conn
                  ectionManager 'jboss.jca:service=DataSourceBinding,name=PostgresDSFare to JNDI name 'java:PostgresDS
                  Fare'
                  16:47:54,442 INFO [WrapperDataSourceService] Bound connection factory for resource adapter for Conn
                  ectionManager 'jboss.jca:service=DataSourceBinding,name=PostgresDSMember to JNDI name 'java:Postgres
                  DSMember'
                  16:47:54,457 INFO [JCAResource] Registration is not done -> stop
                  16:49:06,350 INFO [AirSearch] <<* SEARCH START *>> <BOS-NYC 10DEC-24DEC RT> [C075C9B
                  9C330FEF637F3CF7F422C4B30]
                  16:49:06,350 INFO [FareDBManager] Getting Round Trip Deals for <BOS|NYC|12-10-2005|NYC|BOS|12-24-20
                  05> [C075C9B9C330FEF637F3CF7F422C4B30]
                  16:49:06,381 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: null
                  16:49:06,381 ERROR [JDBCExceptionReporter] You are trying to use a connection factory that has been
                  shut down: ManagedConnectionFactory is null.; - nested throwable: (javax.resource.ResourceException:
                  You are trying to use a connection factory that has been shut down: ManagedConnectionFactory is nul
                  l.)
                  16:49:06,396 ERROR [JMXPersistentSession] org.hibernate.exception.GenericJDBCException: Cannot open
                  connection
                  16:49:06,396 WARN [DAOUtils] Exception getting hibernate session, try #1 : com.aaacomp.fram
                  ework.persistent.StoreNotFoundException: org.hibernate.exception.GenericJDBCException: Cannot open c
                  onnection
                  16:49:07,396 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: null
                  16:49:07,396 ERROR [JDBCExceptionReporter] You are trying to use a connection factory that has been
                  shut down: ManagedConnectionFactory is null.; - nested throwable: (javax.resource.ResourceException:
                  You are trying to use a connection factory that has been shut down: ManagedConnectionFactory is nul
                  l.)
                  16:49:07,396 ERROR [JMXPersistentSession] org.hibernate.exception.GenericJDBCException: Cannot open
                  connection
                  16:49:07,396 WARN [DAOUtils] Exception getting hibernate session, try #2 : com.aaacomp.fram
                  ework.persistent.StoreNotFoundException: org.hibernate.exception.GenericJDBCException: Cannot open c
                  onnection
                  16:49:08,396 WARN [JDBCExceptionReporter] SQL Error: 0, SQLState: null
                  16:49:08,396 ERROR [JDBCExceptionReporter] You are trying to use a connection factory that has been
                  shut down: ManagedConnectionFactory is null.; - nested throwable: (javax.resource.ResourceException:
                  You are trying to use a connection factory that has been shut down: ManagedConnectionFactory is nul
                  l.)
                  16:49:08,396 ERROR [JMXPersistentSession] org.hibernate.exception.GenericJDBCException: Cannot open
                  connection
                  16:49:08,412 WARN [DAOUtils] Exception getting hibernate session, try #3 : com.aaacomp.fram
                  ework.persistent.StoreNotFoundException: org.hibernate.exception.GenericJDBCException: Cannot open c
                  onnection


                  NEED HELP!

                  • 6. Re: How to programmatically create datasource without config
                    hbentel

                    Hi

                    I'm also interested in this topic but this thread seems to have died away.

                    Are there any way to programmatically configure new datasources in JBoss 4.0?

                    We also use Weblogic and it's JMX api to create connection pool and datasources on demand without restarting the server.
                    It's all abstracted away, and I'm looking to implement a version for JBoss 4.0 so we can deploy in JBoss also.

                    I've looked through some of the API and I've found
                    org.jboss.management.j2ee.JDBCDataSource
                    which seems like a place to start.
                    Some of the replies suggest dropping in Datasource descriptor files at runtime is the only way.

                    thanks,
                    Henrik

                    • 7. Re: How to programmatically create datasource without config

                      http://wiki.jboss.org/wiki/Wiki.jsp?page=JBossHelp
                      Hijacking somebody else's thread just means you are ignored.