Skip to content

Commit 27168c3

Browse files
committed
add generic ClientCompanion
1 parent 67b95c9 commit 27168c3

File tree

5 files changed

+40
-11
lines changed

5 files changed

+40
-11
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ ThisBuild / organization := "app.softnetwork"
1919

2020
name := "softclient4es"
2121

22-
ThisBuild / version := "0.10.0"
22+
ThisBuild / version := "0.10.1"
2323

2424
ThisBuild / scalaVersion := scala213
2525

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package app.softnetwork
2+
3+
import org.slf4j.Logger
4+
5+
import java.io.Closeable
6+
7+
package object common {
8+
9+
trait ClientCompanion extends Closeable { _: { def logger: Logger } =>
10+
11+
/** Check if client is initialized and connected
12+
*/
13+
def isInitialized: Boolean
14+
15+
/** Test connection
16+
* @return
17+
* true if connection is successful
18+
*/
19+
def testConnection(): Boolean
20+
}
21+
22+
}

core/src/main/scala/app/softnetwork/elastic/client/ElasticClientApi.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package app.softnetwork.elastic.client
1818

19+
import app.softnetwork.common.ClientCompanion
1920
import com.typesafe.config.{Config, ConfigFactory}
2021
import org.json4s.jackson
2122
import org.json4s.jackson.Serialization
@@ -44,7 +45,7 @@ trait ElasticClientApi
4445
with FlushApi
4546
with VersionApi
4647
with SerializationApi
47-
with Closeable {
48+
with ClientCompanion {
4849

4950
protected def logger: Logger
5051

core/src/main/scala/app/softnetwork/elastic/client/ElasticClientCompanion.scala

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package app.softnetwork.elastic.client
1818

19+
import app.softnetwork.common.ClientCompanion
1920
import org.apache.http.HttpHost
2021
import org.slf4j.Logger
2122

@@ -25,7 +26,7 @@ import java.util.concurrent.atomic.AtomicInteger
2526
import scala.language.reflectiveCalls
2627
import scala.util.{Failure, Success, Try}
2728

28-
trait ElasticClientCompanion[T <: Closeable] extends Closeable { _: { def logger: Logger } =>
29+
trait ElasticClientCompanion[T <: Closeable] extends ClientCompanion { _: { def logger: Logger } =>
2930

3031
def elasticConfig: ElasticConfig
3132

@@ -140,13 +141,7 @@ trait ElasticClientCompanion[T <: Closeable] extends Closeable { _: { def logger
140141

141142
/** Check if client is initialized and connected
142143
*/
143-
def isInitialized: Boolean = client.isDefined
144-
145-
/** Test connection to Elasticsearch cluster
146-
* @return
147-
* true if connection is successful
148-
*/
149-
def testConnection(): Boolean
144+
override def isInitialized: Boolean = client.isDefined
150145

151146
/** Close the client and release resources Idempotent - safe to call multiple times
152147
*/

core/src/main/scala/app/softnetwork/elastic/client/ElasticClientDelegator.scala

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,21 @@ trait ElasticClientDelegator extends ElasticClientApi with BulkTypes {
4141
// Delegate config to the underlying client
4242
override lazy val config: Config = delegate.config
4343

44-
// ==================== Closeable ====================
44+
// ==================== ClientCompanion ====================
4545

4646
override def close(): Unit = delegate.close()
4747

48+
/** Check if client is initialized and connected
49+
*/
50+
override def isInitialized: Boolean = delegate.isInitialized
51+
52+
/** Test connection
53+
*
54+
* @return
55+
* true if connection is successful
56+
*/
57+
override def testConnection(): Boolean = delegate.testConnection()
58+
4859
// ==================== VersionApi ====================
4960

5061
/** Get Elasticsearch version.

0 commit comments

Comments
 (0)