Skip to content

Commit

Permalink
Fix #6094 "Data sources are available from java:comp/env in WildFly"
Browse files Browse the repository at this point in the history
  • Loading branch information
ebruchez committed Feb 23, 2024
1 parent cd2064c commit b2eb40c
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 11 deletions.
Expand Up @@ -13,6 +13,7 @@
*/
package org.orbeon.oxf.util

import cats.effect.unsafe.IORuntime
import org.orbeon.dom.QName
import org.orbeon.oxf.externalcontext.ExternalContext
import org.orbeon.oxf.properties.PropertySet
Expand All @@ -25,6 +26,7 @@ trait CoreCrossPlatformSupportTrait {
type FileItemType

implicit def executionContext: ExecutionContext
implicit def runtime: IORuntime

def logger: org.log4s.Logger
def isPE: Boolean
Expand Down
Expand Up @@ -13,14 +13,14 @@
*/
package org.orbeon.oxf.fr

import cats.effect.unsafe.implicits.global
import cats.syntax.option._
import org.orbeon.connection.ConnectionContextSupport
import org.orbeon.oxf.externalcontext.ExternalContext
import org.orbeon.oxf.fr.FormRunner._
import org.orbeon.oxf.fr.FormRunnerPersistence.FormXhtml
import org.orbeon.oxf.fr.library.FRComponentParamSupport
import org.orbeon.oxf.fr.persistence.relational.Version
import org.orbeon.oxf.util.CoreCrossPlatformSupport.runtime
import org.orbeon.oxf.util.PathUtils._
import org.orbeon.oxf.util.StringUtils._
import org.orbeon.oxf.util.{CoreCrossPlatformSupport, CoreCrossPlatformSupportTrait, IndentedLogger}
Expand Down
Expand Up @@ -13,14 +13,13 @@
*/
package org.orbeon.oxf.fr

import cats.effect.unsafe.implicits.global
import org.orbeon.connection.ConnectionContextSupport
import org.orbeon.oxf.externalcontext.ExternalContext
import org.orbeon.oxf.fr.FormRunner._
import org.orbeon.oxf.fr.FormRunnerPersistence.{DataFormatVersionName, DataXml}
import org.orbeon.oxf.fr.persistence.relational.index.Index
import org.orbeon.oxf.fr.process.RenderedFormat
import org.orbeon.oxf.util.CoreCrossPlatformSupport.properties
import org.orbeon.oxf.util.CoreCrossPlatformSupport.{properties, runtime}
import org.orbeon.oxf.util.StringUtils._
import org.orbeon.oxf.util.{CoreCrossPlatformSupport, CoreCrossPlatformSupportTrait, IndentedLogger, PathUtils}
import org.orbeon.oxf.xforms.XFormsContainingDocument
Expand Down
Expand Up @@ -14,12 +14,11 @@
package org.orbeon.oxf.fr.process

import cats.effect.IO
import cats.effect.unsafe.implicits.global
import org.orbeon.oxf.fr.process.ProcessInterpreter._
import org.orbeon.oxf.fr.process.ProcessParser._
import org.orbeon.oxf.fr.process.TestProcessInterpreter.ConstantProcessId
import org.orbeon.oxf.test.{DocumentTestBase, ResourceManagerSupport}
import org.orbeon.oxf.util.CoreCrossPlatformSupport.executionContext
import org.orbeon.oxf.util.CoreCrossPlatformSupport.{executionContext, runtime}
import org.orbeon.oxf.util.StringUtils._
import org.orbeon.oxf.util.{IndentedLogger, LoggerFactory}
import org.orbeon.saxon.om.{Item, NodeInfo}
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/org/orbeon/oxf/servlet/OrbeonServlet.scala
Expand Up @@ -13,10 +13,10 @@
*/
package org.orbeon.oxf.servlet

import cats.effect.unsafe.IORuntime
import org.orbeon.oxf.externalcontext.ServletWebAppContext
import org.orbeon.oxf.http.{PropertiesApacheHttpClient, StatusCode}
import org.orbeon.oxf.pipeline.api._
import org.orbeon.oxf.util.CoreCrossPlatformSupport
import org.orbeon.oxf.webapp.ServletPortlet._
import org.orbeon.oxf.webapp.{ProcessorService, ServletPortlet}

Expand Down Expand Up @@ -70,7 +70,7 @@ abstract class OrbeonServletImpl(servletContextProvider: ServletContextProvider)
// Unclear whether there is a better place to do this
webAppContext.addListener(() => {
PropertiesApacheHttpClient.shutdown()
cats.effect.unsafe.implicits.global.shutdown()
CoreCrossPlatformSupport.runtime.shutdown()
})
}

Expand Down
Expand Up @@ -13,6 +13,7 @@
*/
package org.orbeon.oxf.util

import cats.effect.unsafe.{IORuntime, IORuntimeConfig}
import org.apache.commons.fileupload.disk.DiskFileItem
import org.orbeon.dom.QName
import org.orbeon.oxf.common.Version
Expand All @@ -21,14 +22,54 @@ import org.orbeon.oxf.pipeline.InitUtils
import org.orbeon.oxf.pipeline.api.PipelineContext
import org.orbeon.oxf.properties.{Properties, PropertySet}

import javax.enterprise.concurrent.ManagedExecutorService
import javax.naming.InitialContext
import scala.collection.mutable
import scala.concurrent.ExecutionContext
import scala.util.{Failure, Success, Try}


object CoreCrossPlatformSupport extends CoreCrossPlatformSupportTrait {

type FileItemType = DiskFileItem

implicit def executionContext: ExecutionContext = ExecutionContext.global
implicit def executionContext: ExecutionContext = runtime.compute

private val DefaultJndiName = "java:comp/DefaultManagedExecutorService"
private val PropertyName = "oxf.managed-executor-service.jndi-name"

// If we don't make this lazy, things don't work down the line for some reason!
private lazy val _runtime = {

val buffer = mutable.ListBuffer.empty[String]

buffer += "IORuntime initialization:"

def logTry[U](t: Try[U])(m: String): Try[U] = {
t match {
case Success(b) => buffer += (s"- found $m: $b")
case Failure(t) => buffer += (s"- failed to find $m: ${t.getMessage}")
}
t
}

def fromJndi: Try[IORuntime] =
for {
jndiName <- logTry(Try(CoreCrossPlatformSupport.properties.getString(PropertyName, DefaultJndiName)))("JNDI name")
managedExecutorService <- logTry(Try((new InitialContext).lookup(jndiName).asInstanceOf[ManagedExecutorService]))("`ManagedExecutorService`")
executionContext = ExecutionContext.fromExecutorService(managedExecutorService)
scheduler = IORuntime.global.scheduler
} yield
IORuntime(executionContext, executionContext, scheduler, () => (), IORuntimeConfig())

fromJndi.getOrElse {
buffer += s"Using default IORuntime."
logger.info(buffer.mkString("\n"))
IORuntime.global
}
}

implicit def runtime: IORuntime = _runtime

def logger: org.log4s.Logger = Properties.logger
def isPE: Boolean = Version.isPE
Expand Down
Expand Up @@ -13,6 +13,7 @@
*/
package org.orbeon.oxf.util

import cats.effect.unsafe.IORuntime
import org.orbeon.dom.QName
import org.orbeon.oxf.externalcontext.ExternalContext
import org.orbeon.oxf.properties.PropertySet
Expand All @@ -26,9 +27,12 @@ object CoreCrossPlatformSupport extends CoreCrossPlatformSupportTrait {

type FileItemType = Unit // TODO

// Q: Could we/should we use `runtime.compute` instead?
implicit def executionContext: ExecutionContext =
org.scalajs.macrotaskexecutor.MacrotaskExecutor.Implicits.global

implicit def runtime: IORuntime = IORuntime.global

val logger: org.log4s.Logger = LoggerFactory.createLogger("org.orbeon.properties")

def isPE: Boolean = true
Expand Down
@@ -1,9 +1,9 @@
package org.orbeon.oxf.xforms.submission

import cats.effect.IO
import cats.effect.unsafe.implicits.global
import org.orbeon.connection.AsyncConnectionResult
import org.orbeon.oxf.externalcontext.ExternalContext
import org.orbeon.oxf.util.CoreCrossPlatformSupport.runtime


object XFormsModelSubmissionSupport extends XFormsModelSubmissionSupportTrait {
Expand Down
@@ -1,8 +1,7 @@
package org.orbeon.oxf.xforms.submission

import cats.effect.IO
import cats.effect.unsafe.implicits.global
import org.orbeon.oxf.util.CoreCrossPlatformSupport.executionContext
import org.orbeon.oxf.util.CoreCrossPlatformSupport.{executionContext, runtime}
import org.orbeon.oxf.util.IndentedLogger
import org.orbeon.oxf.util.Logging.{debug, debugResults, error, withDebug}
import org.orbeon.oxf.xforms.XFormsContainingDocument
Expand Down

0 comments on commit b2eb40c

Please sign in to comment.