com.github.dynamicextensionsalfresco.policy.DefaultBehaviourProxyFactory.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of annotations-runtime Show documentation
Show all versions of annotations-runtime Show documentation
Adds an OSGi container to alfresco repository supporting dynamic code reloading, classpath isolation and a bunch of other useful features
package com.github.dynamicextensionsalfresco.policy
import com.github.dynamicextensionsalfresco.debug
import java.util.ArrayList
import com.github.dynamicextensionsalfresco.metrics.Timer
import org.alfresco.repo.policy.Behaviour
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.ApplicationListener
import org.springframework.context.event.ContextClosedEvent
/**
* Default [BehaviourProxyFactory] implementation intended for use in a Spring application context. This
* implementation releases references to [Behaviour]s when the [ContextClosedEvent] occurs.
* @author Laurens Fridael
*/
public class DefaultBehaviourProxyFactory @Autowired constructor(private val timer: Timer) : BehaviourProxyFactory, ApplicationListener {
private val logger = LoggerFactory.getLogger(javaClass)
/* State */
private val behaviourProxies = ArrayList()
/* Main operations */
override fun createBehaviourProxy(behaviour: Behaviour): BehaviourProxy {
logger.debug {
"Creating BehaviourProxy for ${behaviour.javaClass.name} instance."
}
val behaviourProxy = BehaviourProxy(behaviour, timer)
behaviourProxies.add(behaviourProxy)
return behaviourProxy
}
/* Callback operations */
override fun onApplicationEvent(event: ContextClosedEvent) {
releaseBehaviourReferences()
}
/* Utility operations */
protected fun releaseBehaviourReferences() {
for (behaviourProxy in behaviourProxies) {
logger.debug { "Releasing reference from BehaviourProxy to $behaviourProxy instance." }
behaviourProxy.release()
}
behaviourProxies.clear()
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy