4 Replies Latest reply on Oct 23, 2006 4:08 PM by danliang

    Embedding MySQL as an MBean with Connector/MXJ

    danliang

      Hello,
      This is perhaps more closely related to Connector/MXJ than jBoss, but I am hoping for someone here has experience with the two that can lend a hand...

      Currently I am developing an application using Java JDK 1.4.2, mySQL 5.0.19, jBoss 4.0.2, Connector/J 5.0, and Connector/MXJ 5.0.

      I am attempting to embedd mySQL by using MXJ act as an MBean that jBoss will control. I have the database to communicate with the application, but am interested in passing options to MySQL on startup. What I would like to is:

      1.) Specify a datadir and basedir
      I have added the attributes to my "mysqld-service.xml", but get an error stating that the specified directory is not equal to "C:\Documents and Settings\user\Temp\mysql-c.mxj\" How can I specify the directory for MXJ to setup the data dir in? This works with MXJ 1.1. NOTE - I have gotten this to work by changing the source so that the method 'ensureDir' in 'MysqldResource.java' to change the base and data dir if they are different then the expected. I have also changed the order of the calls to:
      adjustParameterMap(mysqldArgs)
      makeMysqld();
      ensureEssentialFilesExist();
      To the above order in the meth0d 'exec' in the 'MMysqldResource.java' so that the baseDir and dataDir are changed prior to creating the files.
      So far, this seems to work as expected, but does anyone see if this will cause problems?

      2.) call mySQLd with a defaults-file.
      I have modified the source to allow me to pass in a defaults-file, but was wondering if this was left out intentially as it is not good practice to start the MySQL with a defaults file through MXJ.

      3.) Connect to MySQL through named pipes as a datasource in jBoss.
      For example in my 'mysql-ds.xml' in my jboss/deploy folder:
      <connection-url>jdbc:mysql:mxj://localhost:3306/DB</connection-url>

      connects via TCP/IP;

      where:

      <connection-url>jdbc:mysql:mxj://./DB</connection-url>
      <connection-property name="socketFactory">com.mysql.jdbc.NamedPipeSocketFactory</connection-property>

      would connect via named-pipe

      This causes an error to occur when jBoss attempts to connect to mySQL.

      Any insight on how to get named-pipe connections to work?

      Thanks,


      Dan

        • 1. Re: Embedding MySQL as an MBean with Connector/MXJ
          swany

          Dan,

          I'd be interested in what needed to be changed to pass in a defaults file. I am working on embedding MySQL into JBoss as well, and I need to ensure it (and JBoss) runs on a non-default port, to peacefully co-exist with another potential MySQL installation. A defaults file is the only way I can think of to do this. I'll be attempting your other code change to fix the "basedir" and "datadir" issue (I've seen the same thing). Can you share your source changes?

          As an aside, I was able to get MySQL to start by omitting the "datadir" MBean attribute entirely and letting it automatically select my temporary directory. But I'm sure you already knew that. And it's not what either of us are looking for.

          Sorry I have more questions than answers.

          Mark

          • 2. Re: Embedding MySQL as an MBean with Connector/MXJ
            danliang

            Mark,

            Sorry I haven't replied sooner, this is because I have since solved the issue to where Connector/MXJ works as I need it to and has since worked as expected.

            The changes that needed to be made were simple and I can post them if still you or anyone is interested.

            BTW: I still can not connect through named-pipes, and when Connector/MXJ shuts down it hangs and issues a "force-kill" everytime to shut MySQL down.

            Dan

            • 3. Re: Embedding MySQL as an MBean with Connector/MXJ
              swany

              Dan,

              I'd still be very interested in your solution. I attempted to make the changes you described, but I wasn't quite able to make it work (I still get errors when attempting to relocate the base and data directories). And I have not yet attempted to figure out how to pass parameters to the MySQL runtime (like a custom "ini" file location).

              The project I'm currently on could benefit greatly from an embedded MySQL instance inside JBoss, so your timing is impeccable. :-) Any help is greatly appreciated.

              Thanks.

              Mark

              • 4. Re: Embedding MySQL as an MBean with Connector/MXJ
                danliang

                These changes are made in MysqldResource.java:

                To allow a defaults file
                Line 514 was changed to:

                String[] constructArgs(Map mysqldArgs)
                {
                 List strs = new ArrayList();
                 strs.add(utils.files().getPath(getMysqldFilePointer()));
                
                 //This line was previously "no-defaults" or something to this effect
                 //The defaults file "my.ini" now is expected to be in the "datadir"
                 //NOTE: This can be changed to any directory, but is hardcoded
                 //so it is not very portable.
                 strs.add("--defaults-file=\".\\my.ini\"");
                
                 if (isWindows()) {
                 strs.add("--console");
                 }
                


                Code changes to use specified data and base dirs:

                Line 414:
                /** called from option parser as well */
                 synchronized Shell exec(String threadName, Map mysqldArgs,
                 PrintStream outStream, PrintStream errStream, boolean withListeners) {
                
                 //Change the order these calls were made so that the files will be
                 //created prior to making sure the files exist.
                 makeMysqld();
                 ensureEssentialFilesExist();
                 adjustParameterMap(mysqldArgs);
                 //end changes made
                
                
                 String[] args = constructArgs(mysqldArgs);
                 outStream.println(new ListToString().toString(args));
                



                Line 441:

                
                 private void adjustParameterMap(Map mysqldArgs) {
                /*
                 //Commented out the ensureDir, this is one major cause of the problem.
                 //since it checks the base and data dir against the defaults.
                 //It appeared there were other constructors to allow for the data and
                 //base dir to be specified but these can not be called through JBoss.
                
                 ensureDir(mysqldArgs, baseDir, MysqldResourceI.BASEDIR);
                 ensureDir(mysqldArgs, dataDir, MysqldResourceI.DATADIR);
                */
                 mysqldArgs.put(MysqldResourceI.PID_FILE, utils.files().getPath(
                 pidFile()));
                 ensureSocket(mysqldArgs);
                 }
                



                As far as I remember these were all the changes that had to be made, it has been a while so I may be wrong.
                I remember recompiling the source was a real PITA, as there were alot of dependencies on other files.