-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
459 additions
and
109 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
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
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
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
53 changes: 53 additions & 0 deletions
53
reader/src/main/scala/za/co/absa/atum/reader/server/future/ArmeriaServerConnection.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,53 @@ | ||
/* | ||
* Copyright 2024 ABSA Group Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package za.co.absa.atum.reader.server.future | ||
|
||
import com.typesafe.config.{Config, ConfigFactory} | ||
import scala.concurrent.{ExecutionContext, Future} | ||
import sttp.client3.armeria.future.ArmeriaFutureBackend | ||
import sttp.client3.SttpBackend | ||
|
||
import za.co.absa.atum.reader.server.GenericServerConnection | ||
|
||
class ArmeriaServerConnection private(serverUrl: String, closeable: Boolean)(implicit executor: ExecutionContext) | ||
extends FutureServerConnection(serverUrl, closeable) { | ||
|
||
def this(serverUrl: String)(implicit executor: ExecutionContext) = { | ||
this(serverUrl, true)(executor) | ||
} | ||
|
||
def this(config: Config = ConfigFactory.load())(implicit executor: ExecutionContext) = { | ||
this(GenericServerConnection.atumServerUrl(config))(executor) | ||
} | ||
|
||
override protected val backend: SttpBackend[Future, Any] = ArmeriaFutureBackend() | ||
|
||
} | ||
|
||
object ArmeriaServerConnection { | ||
lazy implicit val serverConnection: ArmeriaServerConnection = new ArmeriaServerConnection()(ExecutionContext.Implicits.global) | ||
|
||
def use[R](serverUrl: String)(fnc: ArmeriaServerConnection => Future[R]) | ||
(implicit executor: ExecutionContext): Future[R] = { | ||
val serverConnection = new ArmeriaServerConnection(serverUrl, false) | ||
try { | ||
fnc(serverConnection) | ||
} finally { | ||
serverConnection.backend.close() | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
reader/src/main/scala/za/co/absa/atum/reader/server/future/FutureServerConnection.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,44 @@ | ||
/* | ||
* Copyright 2024 ABSA Group Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package za.co.absa.atum.reader.server.future | ||
|
||
import scala.concurrent.{ExecutionContext, Future} | ||
import sttp.client3.{Identity, RequestT, SttpBackend} | ||
|
||
import za.co.absa.atum.reader.server.GenericServerConnection | ||
import za.co.absa.atum.reader.server.GenericServerConnection.RequestResult | ||
|
||
|
||
abstract class FutureServerConnection(serverUrl: String, closeable: Boolean)(implicit executor: ExecutionContext) | ||
extends GenericServerConnection[Future](serverUrl) { | ||
|
||
protected val backend: SttpBackend[Future, Any] | ||
|
||
override protected def executeRequest[R](request: RequestT[Identity, RequestResult[R], Any]): Future[RequestResult[R]] = { | ||
request.send(backend).map(_.body) | ||
} | ||
|
||
override def close(): Future[Unit] = { | ||
if (closeable) { | ||
backend.close() | ||
} else { | ||
Future.successful(()) | ||
} | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.