title: Jetty Clustering via the Database Overrides Web Application Specified Data Source Pool
body: <p>The goal is to create a clustered environment for a web application that is currently running in a single Jetty instance. When clustering configuration is added, it appears to prevent the applications data source pool from initializing. Attaching a remote debugging session and stepping through the code shows the application hanging on startup while waiting for a connection to free up from the pool. Inspecting the details of the pool shows no connections have been created. c3p0 is used for the pooling implementation. When the server starts without the clustering configuration, c3p0 generates a log message showing it is initializing. When started with clustering configured, the log message is not seen. Leading me to believe the application data source pool is never initialized because the clustering data source pool is  usurping it in some way. </p>
  
  <p>To get the clustering behavior I added the following to %JETTY_HOME%/etc/jetty.xml.</p>
  
  <pre><code>&lt;New id="DSClustering" class="org.eclipse.jetty.plus.jndi.Resource"&gt;
      &lt;Arg&gt;&lt;/Arg&gt;
      &lt;Arg&gt;jdbc/DSClustering&lt;/Arg&gt;
      &lt;Arg&gt;
          &lt;New class="com.mchange.v2.c3p0.ComboPooledDataSource"&gt;            
              &lt;Set name="driverClass"&gt;oracle.jdbc.OracleDriver&lt;/Set&gt;
              &lt;Set name="jdbcUrl"&gt;jdbc:oracle:thin:@xxxxx:1521:xe&lt;/Set&gt;
              &lt;Set name="User"&gt;xxxx&lt;/Set&gt;
              &lt;Set name="Password"&gt;xxxx&lt;/Set&gt;
  
          &lt;/New&gt;
      &lt;/Arg&gt;
  &lt;/New&gt;
  
  
  &lt;Set name="sessionIdManager"&gt;
      &lt;New id="jdbcidmgr" class="org.eclipse.jetty.server.session.JDBCSessionIdManager"&gt;
          &lt;Arg&gt;&lt;Ref id="Server"/&gt;&lt;/Arg&gt;
          &lt;Set name="workerName"&gt;jetty1&lt;/Set&gt;
          &lt;Set name="DatasourceName"&gt;jdbc/DSClustering&lt;/Set&gt;
          &lt;Set name="scavengeInterval"&gt;60&lt;/Set&gt;
      &lt;/New&gt;
  &lt;/Set&gt;
  &lt;Call name="setAttribute"&gt;
      &lt;Arg&gt;jdbcIdMgr&lt;/Arg&gt;
      &lt;Arg&gt;&lt;Ref id="jdbcidmgr"/&gt;&lt;/Arg&gt;
  &lt;/Call&gt;
  </code></pre>
  
  <p><br><br>
  And added the following to the applications jetty-web.xml</p>
  
  <pre><code>&lt;Set name="sessionHandler"&gt;
      &lt;New class="org.eclipse.jetty.server.session.SessionHandler"&gt;
          &lt;Arg&gt;
              &lt;New class="org.eclipse.jetty.server.session.JDBCSessionManager"&gt;
                  &lt;Set name="idManager"&gt;
                      &lt;Ref id="jdbcidmgr"/&gt;
                  &lt;/Set&gt;
              &lt;/New&gt;
          &lt;/Arg&gt;
      &lt;/New&gt;
  &lt;/Set&gt;
  </code></pre>
  
  <p><br><br>
  The applications data source pool is configured as a Spring bean -</p>
  
  <pre><code>&lt;bean id="sysContextAwareDataSource" class="com.mycompany.datasource.SysContextAwareDataSource"&gt;
      &lt;property name="targetDataSource" ref="myPoolDataSource"/&gt;
      &lt;property name="connectionWaitLoggingThreshold" value="1000"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="myPoolDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"&gt;
      &lt;property name="driverClass" value="${jdbc.driverClassName}"/&gt;
      &lt;property name="jdbcUrl" value="${jdbc.url}"/&gt;
      &lt;property name="user" value="${jdbc.username}"/&gt;
      &lt;property name="password" value="${jdbc.password}"/&gt;
      &lt;property name="acquireIncrement" value="${jdbc.pool.acquireIncrement}"/&gt;
      &lt;property name="minPoolSize" value="${jdbc.pool.minPoolSize}"/&gt;
      &lt;property name="maxPoolSize" value="${jdbc.pool.maxPoolSize}"/&gt;
      &lt;property name="initialPoolSize" value="${jdbc.pool.initialPoolSize}"/&gt;
      &lt;property name="acquireRetryAttempts" value="${jdbc.pool.acquireRetryAttempts}"/&gt;
      &lt;property name="testConnectionOnCheckin" value="${jdbc.pool.testConnectionOnCheckin}"/&gt;
      &lt;property name="idleConnectionTestPeriod" value="${jdbc.pool.idleConnectionTestPeriod}"/&gt;
      &lt;property name="preferredTestQuery" value="${jdbc.pool.preferredTestQuery}"/&gt;
      &lt;property name="maxIdleTime" value="${jdbc.pool.maxIdleTime}"/&gt;
      &lt;property name="acquireRetryDelay" value="${jdbc.pool.acquireRetryDelay}"/&gt;
      &lt;property name="maxStatements" value="${jdbc.pool.maxStatements}"/&gt;
      &lt;property name="maxStatementsPerConnection" value="${jdbc.pool.maxStatementsPerConnection}"/&gt;
  &lt;/bean&gt;
  
  
  &lt;bean id="userDAO" class="com.mycompany.dataaccess.UserDAOImpl"&gt;
      &lt;property name="sessionFactory" ref="sessionFactory"/&gt;
      &lt;property name="dataSource" ref="transactionAwareDataSourceProxy"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>Environment: jetty 8.1.9, Oracle 11g, Windows 7 Enterprise, JDK 1.6.0_38</p>