aboutsummaryrefslogtreecommitdiffstats
path: root/container-di
diff options
context:
space:
mode:
authorgjoranv <gv@oath.com>2018-04-12 17:08:29 +0200
committergjoranv <gv@oath.com>2018-04-12 17:08:29 +0200
commit5fa6164421b0b8e33fcdbbe4e51bd6fcf7cf0574 (patch)
treec8422f3480f0146d3d8eaee84b59210df50f49f1 /container-di
parentfa819874cf6a02f2cdcc8839af4ef311953f45e4 (diff)
Log whether a component is reused or (re)created.
Diffstat (limited to 'container-di')
-rw-r--r--container-di/src/main/scala/com/yahoo/container/di/componentgraph/core/Node.scala18
1 files changed, 13 insertions, 5 deletions
diff --git a/container-di/src/main/scala/com/yahoo/container/di/componentgraph/core/Node.scala b/container-di/src/main/scala/com/yahoo/container/di/componentgraph/core/Node.scala
index 9e6124cff2c..a4ec9be5c6c 100644
--- a/container-di/src/main/scala/com/yahoo/container/di/componentgraph/core/Node.scala
+++ b/container-di/src/main/scala/com/yahoo/container/di/componentgraph/core/Node.scala
@@ -1,11 +1,14 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.di.componentgraph.core
+import java.util.logging.Logger
+
import com.yahoo.component.ComponentId
import com.yahoo.container.di.ConfigKeyT
import com.yahoo.container.di.componentgraph.Provider
import com.google.inject.Key
import Node._
+import com.yahoo.log.LogLevel.{DEBUG, SPAM}
/**
* @author Tony Vaagenes
@@ -28,11 +31,15 @@ abstract class Node(val componentId: ComponentId) {
protected def newInstance() : AnyRef
def newOrCachedInstance() : AnyRef = {
- component(
- instance.getOrElse {
- instance = Some(newInstance())
- instance.get
- })
+ val inst = if (instance.isEmpty) {
+ log.log(DEBUG, s"Creating new instance for component with ID $componentId")
+ instance = Some(newInstance())
+ instance.get
+ } else {
+ log.log(SPAM, s"Reusing instance for component with ID $componentId")
+ instance.get
+ }
+ component(inst)
}
private def component(instance: AnyRef) = instance match {
@@ -76,6 +83,7 @@ abstract class Node(val componentId: ComponentId) {
}
object Node {
+ private val log = Logger.getLogger(classOf[Node].getName)
def equalEdges(edges1: List[AnyRef], edges2: List[AnyRef]): Boolean = {
def compare(objects: (AnyRef, AnyRef)): Boolean = {