This file contains hidden or 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
import io.circe.{Encoder, Decoder} | |
import cats.effect.Concurrent | |
import cats.syntax.either._ | |
case class JmsMessage[T](value: T, metadata: Metadata) | |
class JmsParentController[ | |
F[_] : Concurrent, | |
Request : Encoder, | |
SuccessResponse : Decoder, |
This file contains hidden or 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
trait ParentService[F[_], Request, SuccessResponse, FailureResponse] { ... } |
This file contains hidden or 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
javaOptions in run ++= { | |
getWeaver.value.toSeq.map("-javaagent:" + _) | |
} | |
fork in run := true |
This file contains hidden or 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
def getWeaver = Def.task { | |
update.value.matching { | |
moduleFilter(organization = "org.aspectj", name = "aspectjweaver") && | |
artifactFilter(`type` = "jar") | |
}.headOption | |
} |
This file contains hidden or 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
<!DOCTYPE aspectj PUBLIC "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd"> | |
<aspectj> | |
<weaver> | |
<include within="com.github..*"/> | |
<include within="scala.concurrent..*"/> | |
<include within="cats.effect..*"/> | |
</weaver> | |
<aspects> |
This file contains hidden or 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
@Aspect | |
class ExecutorAspect extends ContextPopulationWrapper { | |
@Pointcut(value = "call( * java.util.concurrent.Executor+.execute(Runnable))") | |
def executePointcut(): Unit = () | |
@Around(value = "executePointcut()", argNames = "jp") | |
def executeHandle(jp: ProceedingJoinPoint): Object = { | |
handleRunnableArgument(jp) | |
} |
This file contains hidden or 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
object ConcurrentNoAccessToExecutor extends IOApp { | |
def part1(text: String, id: String): IO[String] = { | |
for { | |
_ <- log.info(s"start part1 [static id = $id]") | |
result <- IO(text) | |
_ <- log.info(s"end part1 [static id = $id]") | |
} yield result | |
} |
This file contains hidden or 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
class ThirdParty(executor: Executor) { | |
def access(id: String, cb: Either[Throwable, String] => Unit): Unit = { | |
executor.execute { () => | |
executor.execute { () => | |
cb(Right(id)) | |
} | |
} | |
} | |
} |
This file contains hidden or 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
object Concurrent extends IOApp { | |
override protected implicit def contextShift: ContextShift[IO] = IO.contextShift( | |
ExecutionContext.global.wrapLogging | |
) | |
override protected implicit def timer: Timer[IO] = IO.timer( | |
ExecutionContext.global.wrapLogging, | |
Executors.newScheduledThreadPool(2).wrapLogging | |
) |
This file contains hidden or 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
class LoggingExecutionContext(ec: ExecutionContext) extends ExecutionContext { | |
override def execute(runnable: Runnable): Unit = { | |
val context = LoggingContext.localContext.value | |
ec.execute(new WrappedRunnable(runnable, context)) | |
} | |
override def reportFailure(cause: Throwable): Unit = ec.reportFailure(cause) | |
} |