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
41 changed files
with
232 additions
and
235 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
125 changes: 10 additions & 115 deletions
125
aws2scala-core-macros/src/main/scala/com/monsanto/arch/awsutil/impl/Macros.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 |
---|---|---|
@@ -1,137 +1,32 @@ | ||
package com.monsanto.arch.awsutil.impl | ||
|
||
import com.amazonaws.AmazonWebServiceRequest | ||
import com.monsanto.arch.awsutil.{AWSAsyncCall, AWSFlowAdapter} | ||
import scala.reflect.macros.blackbox | ||
|
||
/** Contains macro implementations. */ | ||
object Macros { | ||
def nextTokenFlowAdapter[Request <: AmazonWebServiceRequest, Result] | ||
(c: blackbox.Context) | ||
(asyncCall: c.Expr[AWSAsyncCall[Request,Result]]) | ||
(implicit requestType: c.WeakTypeTag[Request], resultType: c.WeakTypeTag[Result]): c.Tree = { | ||
import c.universe._ | ||
val adapterType = weakTypeOf[AWSFlowAdapter[Request,Result]] | ||
q""" | ||
new $adapterType { | ||
def processRequest: RequestProcessor = $asyncCall | ||
def getToken(result: $resultType) = Option(result.getNextToken).filter(_.nonEmpty) | ||
def withToken(request: $requestType, token: String) = request.withNextToken(token) | ||
} | ||
""" | ||
} | ||
|
||
def pagedByNextToken[Request <: AmazonWebServiceRequest, Result] | ||
(c: blackbox.Context) | ||
(asyncCall: c.Expr[AWSAsyncCall[Request,Result]]) | ||
(implicit requestType: c.WeakTypeTag[Request], resultType: c.WeakTypeTag[Result]): c.Tree = { | ||
import c.universe._ | ||
val stageType = weakTypeTag[AWSGraphStage[Request,Result]] | ||
val flowAdapterObject = weakTypeTag[AWSFlowAdapter[Request,Result]].tpe.companion | ||
q""" | ||
akka.stream.scaladsl.Flow.fromGraph(new $stageType($flowAdapterObject.nextTokenFlowAdapter($asyncCall))) | ||
.map { | ||
case Left(exception) ⇒ throw exception | ||
case Right(result) ⇒ result | ||
} | ||
""" | ||
} | ||
|
||
def pagedByNextTokenEither[Request <: AmazonWebServiceRequest, Result] | ||
(c: blackbox.Context) | ||
(asyncCall: c.Expr[AWSAsyncCall[Request,Result]]) | ||
(implicit requestType: c.WeakTypeTag[Request], resultType: c.WeakTypeTag[Result]): c.Tree = { | ||
import c.universe._ | ||
val stageType = weakTypeTag[AWSGraphStage[Request,Result]] | ||
val flowAdapterObject = weakTypeTag[AWSFlowAdapter[Request,Result]].tpe.companion | ||
q""" | ||
akka.stream.scaladsl.Flow.fromGraph(new $stageType($flowAdapterObject.nextTokenFlowAdapter($asyncCall))) | ||
""" | ||
} | ||
|
||
def nextMarkerFlowAdapter[Request <: AmazonWebServiceRequest, Result] | ||
(c: blackbox.Context) | ||
(asyncCall: c.Expr[AWSAsyncCall[Request,Result]]) | ||
(implicit requestType: c.WeakTypeTag[Request], resultType: c.WeakTypeTag[Result]): c.Tree = { | ||
import c.universe._ | ||
val adapterType = weakTypeOf[AWSFlowAdapter[Request,Result]] | ||
q""" | ||
new $adapterType { | ||
def processRequest: RequestProcessor = $asyncCall | ||
def getToken(result: $resultType) = Option(result.getNextMarker).filter(_.nonEmpty) | ||
def withToken(request: $requestType, token: String) = request.withMarker(token) | ||
} | ||
""" | ||
} | ||
|
||
def pagedByNextMarker[Request <: AmazonWebServiceRequest, Result] | ||
(c: blackbox.Context) | ||
(asyncCall: c.Expr[AWSAsyncCall[Request,Result]]) | ||
(implicit requestType: c.WeakTypeTag[Request], resultType: c.WeakTypeTag[Result]): c.Tree = { | ||
def hasNextTokenImpl[Result](c: blackbox.Context)(implicit resultType: c.WeakTypeTag[Result]): c.Tree = { | ||
import c.universe._ | ||
val stageType = weakTypeTag[AWSGraphStage[Request,Result]] | ||
val flowAdapterObject = weakTypeTag[AWSFlowAdapter[Request,Result]].tpe.companion | ||
q""" | ||
akka.stream.scaladsl.Flow.fromGraph(new $stageType($flowAdapterObject.nextMarkerFlowAdapter($asyncCall))) | ||
.map { | ||
case Left(exception) ⇒ throw exception | ||
case Right(result) ⇒ result | ||
} | ||
""" | ||
q"new HasNextToken[$resultType] { def getToken(res: $resultType) = Option(res.getNextToken).filter(_.nonEmpty) }" | ||
} | ||
|
||
def pagedByNextMarkerEither[Request <: AmazonWebServiceRequest, Result] | ||
(c: blackbox.Context) | ||
(asyncCall: c.Expr[AWSAsyncCall[Request,Result]]) | ||
(implicit requestType: c.WeakTypeTag[Request], resultType: c.WeakTypeTag[Result]): c.Tree = { | ||
def takesNextTokenImpl[Request](c: blackbox.Context)(implicit requestType: c.WeakTypeTag[Request]): c.Tree = { | ||
import c.universe._ | ||
val stageType = weakTypeTag[AWSGraphStage[Request,Result]] | ||
val flowAdapterObject = weakTypeTag[AWSFlowAdapter[Request,Result]].tpe.companion | ||
q""" | ||
akka.stream.scaladsl.Flow.fromGraph(new $stageType($flowAdapterObject.nextMarkerFlowAdapter($asyncCall))) | ||
""" | ||
q"new TakesNextToken[$requestType] { def withToken(req: $requestType, tok: String) = req.withNextToken(tok) }" | ||
} | ||
|
||
def markerFlowAdapter[Request <: AmazonWebServiceRequest, Result] | ||
(c: blackbox.Context) | ||
(asyncCall: c.Expr[AWSAsyncCall[Request,Result]]) | ||
(implicit requestType: c.WeakTypeTag[Request], resultType: c.WeakTypeTag[Result]): c.Tree = { | ||
def hasNextMarkerImpl[Result](c: blackbox.Context)(implicit resultType: c.WeakTypeTag[Result]): c.Tree = { | ||
import c.universe._ | ||
val adapterType = weakTypeOf[AWSFlowAdapter[Request,Result]] | ||
q""" | ||
new $adapterType { | ||
def processRequest: RequestProcessor = $asyncCall | ||
def getToken(result: $resultType) = Option(result.getMarker).filter(_.nonEmpty) | ||
def withToken(request: $requestType, token: String) = request.withMarker(token) | ||
} | ||
""" | ||
q"new HasNextMarker[$resultType] { def getNextMarker(res: $resultType) = Option(res.getNextMarker).filter(_.nonEmpty) }" | ||
} | ||
|
||
def pagedByMarker[Request <: AmazonWebServiceRequest, Result] | ||
(c: blackbox.Context) | ||
(asyncCall: c.Expr[AWSAsyncCall[Request,Result]]) | ||
(implicit requestType: c.WeakTypeTag[Request], resultType: c.WeakTypeTag[Result]): c.Tree = { | ||
def hasMarkerImpl[Result](c: blackbox.Context)(implicit resultType: c.WeakTypeTag[Result]): c.Tree = { | ||
import c.universe._ | ||
val stageType = weakTypeTag[AWSGraphStage[Request,Result]] | ||
val flowAdapterObject = weakTypeTag[AWSFlowAdapter[Request,Result]].tpe.companion | ||
q""" | ||
akka.stream.scaladsl.Flow.fromGraph(new $stageType($flowAdapterObject.markerFlowAdapter($asyncCall))) | ||
.map { | ||
case Left(exception) ⇒ throw exception | ||
case Right(result) ⇒ result | ||
} | ||
""" | ||
q"new HasMarker[$resultType] { def getMarker(res: $resultType) = Option(res.getMarker).filter(_.nonEmpty) }" | ||
} | ||
|
||
def pagedByMarkerEither[Request <: AmazonWebServiceRequest, Result] | ||
(c: blackbox.Context) | ||
(asyncCall: c.Expr[AWSAsyncCall[Request,Result]]) | ||
(implicit requestType: c.WeakTypeTag[Request], resultType: c.WeakTypeTag[Result]): c.Tree = { | ||
def takesMarkerImpl[Request](c: blackbox.Context)(implicit requestType: c.WeakTypeTag[Request]): c.Tree = { | ||
import c.universe._ | ||
val stageType = weakTypeTag[AWSGraphStage[Request,Result]] | ||
val flowAdapterObject = weakTypeTag[AWSFlowAdapter[Request,Result]].tpe.companion | ||
q""" | ||
akka.stream.scaladsl.Flow.fromGraph(new $stageType($flowAdapterObject.markerFlowAdapter($asyncCall))) | ||
""" | ||
q"new TakesMarker[$requestType] { def withMarker(req: $requestType, marker:String) = req.withMarker(marker) }" | ||
} | ||
} |
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
Oops, something went wrong.