Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
util-logging: New way to construct ScribeHandler for java interoperab…
…ility Problem The ScribeHandler class currently does not have good interoperability with Java while constructing the ScribeHandler object because of Scala's default parameters to constructors/companion object apply method. Java when calling the Scala's method needs to provide values to all those default arguments which is not ideal especially if those default arguments are not surfaced to the client building the ScribeHandler. Solution The solution is to have an easy way to create the ScribeHandler instance when it only needs the category and formatter as the parameters. This is not meant to have all the possible ways of creating this object as a solution (for example, by using a Builder Pattern in the ScribeHandler class) Result With this change there will be an additional way to construct a ScribeHandler instance - especially for use in Java. JIRA Issues: CSL-6923 Differential Revision: https://phabricator.twitter.biz/D208928
- Loading branch information
Praneeth Yenugutala
authored and
jenkins
committed
Aug 31, 2018
1 parent
1a7c54f
commit 845620b
Showing
4 changed files
with
51 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
util-logging/src/main/scala/com/twitter/logging/ScribeHandlers.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.twitter.logging | ||
|
||
import com.twitter.finagle.stats.NullStatsReceiver | ||
import com.twitter.logging.ScribeHandler._ | ||
|
||
object ScribeHandlers { | ||
/** | ||
* For Java compatibility. Calls [[ScribeHandler.apply()]] method with | ||
* the provided arguments, so Java users don't need to provide the | ||
* other default arguments in the call. | ||
*/ | ||
def apply( | ||
category: String, | ||
formatter: Formatter | ||
): () => ScribeHandler = | ||
ScribeHandler.apply( | ||
hostname = DefaultHostname, | ||
port = DefaultPort, | ||
category = category, | ||
bufferTime = DefaultBufferTime, | ||
connectBackoff = DefaultConnectBackoff, | ||
maxMessagesPerTransaction = DefaultMaxMessagesPerTransaction, | ||
maxMessagesToBuffer = DefaultMaxMessagesToBuffer, | ||
formatter = formatter, | ||
level = None, | ||
statsReceiver = NullStatsReceiver | ||
) | ||
} |
14 changes: 14 additions & 0 deletions
14
util-logging/src/test/java/com/twitter/logging/ScribeHandlersCompilationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.twitter.logging; | ||
|
||
import scala.Function0; | ||
|
||
/** | ||
* Basic compilation test for calling {{{@link ScribeHandlers}}} | ||
* methods from java | ||
*/ | ||
public class ScribeHandlersCompilationTest { | ||
public void testScribeHandlers() { | ||
Function0<ScribeHandler> scribeHandlerFunc = | ||
ScribeHandlers.apply("category", BareFormatter$.MODULE$); | ||
} | ||
} |