summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorn.christian@seime.no>2018-04-12 17:15:31 +0200
committerGitHub <noreply@github.com>2018-04-12 17:15:31 +0200
commit3eb37969b303648f4074d70aff81d1889484f9e3 (patch)
tree09f2ad3c093f593003d5d5d795e4c2dee7b4b190
parent0fa3c056f33064a353fbfa54f3684f1b13c2cc76 (diff)
parent5dc166937ddd578b4dc69c054c5ab13e9cee4670 (diff)
Merge pull request #5567 from vespa-engine/gjoranv/log-component-reuse
Log whether a component is reused or (re)created.
-rw-r--r--container-di/src/main/scala/com/yahoo/container/di/componentgraph/core/Node.scala22
1 files changed, 15 insertions, 7 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..d2476904e39 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.google.inject.Key
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.container.di.componentgraph.core.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 = {