Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -637,10 +637,7 @@ private[client] object NewHostConnectionPool {

private val safeCallback = getAsyncCallback[() => Unit](f => f())
private def safely[T, U](f: T => Unit): T => Unit = t => safeCallback.invoke(() => f(t))
private def safeRunnable(body: => Unit): Runnable =
new Runnable {
def run(): Unit = safeCallback.invoke(() => body)
}
private def safeRunnable(body: => Unit): Runnable = () => safeCallback.invoke(() => body)
private def createNewTimeoutId(): Long = {
lastTimeoutId += 1
lastTimeoutId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ private[http] object HttpServerBluePrint {
}
}
private def schedule(delay: FiniteDuration, handler: HttpRequest => HttpResponse): Cancellable =
materializer.scheduleOnce(delay, new Runnable { def run() = trigger.invoke((self, handler(request))) })
materializer.scheduleOnce(delay, () => trigger.invoke((self, handler(request))))

import pekko.http.impl.util.JavaMapping.Implicits._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ private[http] object StreamUtils {
* Schedule a block to be run once after the given duration in the context of this graph stage.
*/
def scheduleOnce(delay: FiniteDuration)(block: => Unit): Cancellable =
materializer.scheduleOnce(delay, new Runnable { def run() = runInContext(block) })
materializer.scheduleOnce(delay, () => runInContext(block))

def runInContext(block: => Unit): Unit = getAsyncCallback[AnyRef](_ => block).invoke(null)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ abstract class ClientConnectionSettings private[pekko] () { self: ClientConnecti
final def getStreamCancellationDelay: JDuration = streamCancellationDelay.toJava
final def getRequestHeaderSizeHint: Int = requestHeaderSizeHint
final def getWebsocketSettings: WebSocketSettings = websocketSettings
final def getWebsocketRandomFactory: Supplier[Random] = new Supplier[Random] {
override def get(): Random = websocketRandomFactory()
}
final def getWebsocketRandomFactory: Supplier[Random] = () => websocketRandomFactory()
final def getLocalAddress: Optional[InetSocketAddress] = localAddress.toJava

/** The underlying transport used to connect to hosts. By default [[ClientTransport.TCP]] is used. */
Expand Down Expand Up @@ -106,9 +104,7 @@ abstract class ClientConnectionSettings private[pekko] () { self: ClientConnecti
def withLogUnencryptedNetworkBytes(newValue: Optional[Int]): ClientConnectionSettings =
self.copy(logUnencryptedNetworkBytes = newValue.toScala)
def withWebsocketRandomFactory(newValue: java.util.function.Supplier[Random]): ClientConnectionSettings =
self.copy(websocketSettings = websocketSettings.withRandomFactoryFactory(new Supplier[Random] {
override def get(): Random = newValue.get()
}))
self.copy(websocketSettings = websocketSettings.withRandomFactoryFactory(() => newValue.get()))
def withWebsocketSettings(newValue: WebSocketSettings): ClientConnectionSettings =
self.copy(websocketSettings = newValue.asScala)
def withSocketOptions(newValue: java.lang.Iterable[SocketOption]): ClientConnectionSettings =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ abstract class ClientConnectionSettings private[pekko] ()
def withWebsocketSettings(newValue: WebSocketSettings): ClientConnectionSettings =
self.copy(websocketSettings = newValue)
def withWebsocketRandomFactory(newValue: () => Random): ClientConnectionSettings =
withWebsocketSettings(self.websocketSettings.withRandomFactoryFactory(new Supplier[Random] {
override def get(): Random = newValue()
}))
withWebsocketSettings(self.websocketSettings.withRandomFactoryFactory(() => newValue()))
def withUserAgentHeader(newValue: Option[`User-Agent`]): ClientConnectionSettings =
self.copy(userAgentHeader = newValue)
def withLogUnencryptedNetworkBytes(newValue: Option[Int]): ClientConnectionSettings =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,13 @@ abstract class ParserSettings private[pekko] () extends pekko.http.javadsl.setti
override def getIllegalResponseHeaderValueProcessingMode = this.illegalResponseHeaderValueProcessingMode
override def getConflictingContentTypeHeaderProcessingMode = this.conflictingContentTypeHeaderProcessingMode

override def getCustomMethods = new Function[String, Optional[pekko.http.javadsl.model.HttpMethod]] {
override def apply(t: String) = (self.customMethods(t): Option[pekko.http.javadsl.model.HttpMethod]).toJava
}
override def getCustomStatusCodes = new Function[Int, Optional[pekko.http.javadsl.model.StatusCode]] {
override def apply(t: Int) = (self.customStatusCodes(t): Option[pekko.http.javadsl.model.StatusCode]).toJava
}
override def getCustomMethods =
(t: String) => (self.customMethods(t): Option[pekko.http.javadsl.model.HttpMethod]).toJava
override def getCustomStatusCodes =
(t: Int) => (self.customStatusCodes(t): Option[pekko.http.javadsl.model.StatusCode]).toJava
override def getCustomMediaTypes =
new pekko.japi.function.Function2[String, String, Optional[pekko.http.javadsl.model.MediaType]] {
override def apply(mainType: String, subType: String): Optional[model.MediaType] =
(self.customMediaTypes(mainType, subType): Option[pekko.http.javadsl.model.MediaType]).toJava
}
(mainType: String, subType: String) =>
(self.customMediaTypes(mainType, subType): Option[pekko.http.javadsl.model.MediaType]).toJava
def getModeledHeaderParsing: Boolean = this.modeledHeaderParsing

// override for more specific return type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ import scala.concurrent.duration._
@DoNotInherit
abstract class WebSocketSettings extends pekko.http.javadsl.settings.WebSocketSettings { self: WebSocketSettingsImpl =>
def randomFactory: () => Random
override final val getRandomFactory: Supplier[Random] = new Supplier[Random] {
override def get(): Random = self.randomFactory()
}
override final val getRandomFactory: Supplier[Random] = () => self.randomFactory()
override def periodicKeepAliveMode: String
override def periodicKeepAliveMaxIdle: Duration

Expand All @@ -37,9 +35,7 @@ abstract class WebSocketSettings extends pekko.http.javadsl.settings.WebSocketSe
* so keep in mind to keep it relatively small, in order not to make the frames too bloated.
*/
def periodicKeepAliveData: () => ByteString
final def getPeriodicKeepAliveData: Supplier[ByteString] = new Supplier[ByteString] {
override def get(): ByteString = self.periodicKeepAliveData()
}
final def getPeriodicKeepAliveData: Supplier[ByteString] = () => self.periodicKeepAliveData()

override def withRandomFactoryFactory(newValue: Supplier[Random]): WebSocketSettings =
copy(randomFactory = () => newValue.get())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,10 @@ class HttpExtensionApiSpec extends PekkoSpecWithMaterializer(

val successResponse = HttpResponse.create().withStatus(200)

val httpSuccessFunction = new Function[HttpRequest, HttpResponse] {
@throws(classOf[Exception])
override def apply(param: HttpRequest): HttpResponse = successResponse
}
val httpSuccessFunction: Function[HttpRequest, HttpResponse] = (_: HttpRequest) => successResponse

val asyncHttpSuccessFunction = new Function[HttpRequest, CompletionStage[HttpResponse]] {
@throws(classOf[Exception])
override def apply(param: HttpRequest): CompletionStage[HttpResponse] =
CompletableFuture.completedFuture(successResponse)
}
val asyncHttpSuccessFunction: Function[HttpRequest, CompletionStage[HttpResponse]] =
(_: HttpRequest) => CompletableFuture.completedFuture(successResponse)

"The Java HTTP extension" should {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ object Coroner {
watchedHandle.finished()
}
}
new Thread(new Runnable { def run = triggerReportIfOverdue(duration) }, "Coroner").start()
new Thread(() => triggerReportIfOverdue(duration), "Coroner").start()
watchedHandle.waitForStart()
watchedHandle
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ class RouteJavaScalaDslConversionSpec extends AnyWordSpec {
import org.apache.pekko

val javaRoute =
pekko.http.javadsl.server.Directives.get(new Supplier[pekko.http.javadsl.server.Route] {
override def get(): Route = pekko.http.javadsl.server.Directives.complete("ok")
})
pekko.http.javadsl.server.Directives.get(() => pekko.http.javadsl.server.Directives.complete("ok"))

// Remember that Route in Scala is just a type alias:
// type Route = RequestContext => Future[RouteResult]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ object PartialApplication {
* @return the function partially applied
*/
@ApiMayChange
def bindParameter[A, B, R](f: BiFunction[A, B, R], a: A): Function[B, R] = {
new Function[B, R] {
override def apply(b: B): R = f.apply(a, b)
}
}
def bindParameter[A, B, R](f: BiFunction[A, B, R], a: A): Function[B, R] = (b: B) => f.apply(a, b)

}
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ object Directives extends AllDirectives {
@ApiMayChange
def allOf(first: Function[Supplier[Route], Route], second: Function[Supplier[Route], Route], inner: Supplier[Route])
: Route = {
first.apply(new Supplier[Route] {
override def get(): Route =
second.apply(inner)
})
first.apply(() => second.apply(inner))
}

/**
Expand All @@ -102,13 +99,7 @@ object Directives extends AllDirectives {
@ApiMayChange
def allOf[A, B](first: Function[Function[A, Route], Route], second: Function[Function[B, Route], Route],
inner: BiFunction[A, B, Route]): Route = {
first.apply(new Function[A, Route] {
override def apply(a: A): Route =
second.apply(new Function[B, Route] {
override def apply(b: B): Route =
inner.apply(a, b)
})
})
first.apply((a: A) => second.apply((b: B) => inner.apply(a, b)))
}

/**
Expand All @@ -124,12 +115,6 @@ object Directives extends AllDirectives {
@ApiMayChange
def allOf[A](first: Function[Supplier[Route], Route], second: Function[Function[A, Route], Route],
inner: Function[A, Route]): Route = {
first.apply(new Supplier[Route] {
override def get(): Route =
second.apply(new Function[A, Route] {
override def apply(a: A): Route =
inner.apply(a)
})
})
first.apply(() => second.apply((a: A) => inner.apply(a)))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -310,15 +310,13 @@ final case class ValidationRejection(message: String, cause: Option[Throwable] =
*/
final case class TransformationRejection(transform: immutable.Seq[Rejection] => immutable.Seq[Rejection])
extends jserver.TransformationRejection with Rejection {
override def getTransform = new Function[Iterable[jserver.Rejection], Iterable[jserver.Rejection]] {
override def apply(t: Iterable[jserver.Rejection]): Iterable[jserver.Rejection] = {
// explicit collects assignment is because of unidoc failing compilation on .asScala and .asJava here
val transformed: Seq[jserver.Rejection] =
transform(Util.convertIterable[jserver.Rejection, jserver.Rejection](t).collect { case r: Rejection =>
r
}).collect { case j: jserver.Rejection => j }
transformed.asJava // TODO "asJavaDeep" and optimise?
}
override def getTransform = (t: Iterable[jserver.Rejection]) => {
// explicit collects assignment is because of unidoc failing compilation on .asScala and .asJava here
val transformed: Seq[jserver.Rejection] =
transform(Util.convertIterable[jserver.Rejection, jserver.Rejection](t).collect { case r: Rejection =>
r
}).collect { case j: jserver.Rejection => j }
transformed.asJava // TODO "asJavaDeep" and optimise?
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,9 @@ trait Http2FrameHpackSupport extends Http2FrameProbeDelegator with Http2FrameSen
def decodeHeaders(bytes: ByteString): Seq[(String, String)] = {
val hs = new VectorBuilder[(String, String)]()
decoder.decode(bytes.compact.asInputStream,
new HeaderListener {
def addHeader(name: String, value: String, parsedValue: AnyRef, sensitive: Boolean): AnyRef = {
hs += name -> value
parsedValue
}
(name: String, value: String, parsedValue: AnyRef, _: Boolean) => {
hs += name -> value
parsedValue
})
hs.result()
}
Expand Down