-
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.
move more classes out of org.apache.pekko package (#5)
* move more classes out of org.apache.pekko package * move more code * broken tests * stray imports
- Loading branch information
Showing
21 changed files
with
153 additions
and
132 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
3 changes: 1 addition & 2 deletions
3
...che/pekko/sensors/DispatcherMetrics.scala → ...oft/pekko/sensors/DispatcherMetrics.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
7 changes: 3 additions & 4 deletions
7
...patch/DispatcherMetricsRegistration.scala → ...patch/DispatcherMetricsRegistration.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
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
5 changes: 3 additions & 2 deletions
5
...o/sensors/metered/MeteredDispatcher.scala → ...o/sensors/metered/MeteredDispatcher.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
19 changes: 16 additions & 3 deletions
19
...tered/MeteredDispatcherConfigurator.scala → ...tered/MeteredDispatcherConfigurator.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
9 changes: 4 additions & 5 deletions
9
...s/metered/MeteredDispatcherSettings.scala → ...s/metered/MeteredDispatcherSettings.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
2 changes: 1 addition & 1 deletion
2
sensors/src/main/scala/nl/pragmasoft/pekko/sensors/metered/MeteredDispatcherSetup.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
7 changes: 3 additions & 4 deletions
7
sensors/src/main/scala/nl/pragmasoft/pekko/sensors/metered/MeteredDispatcherWrapper.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
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
6 changes: 3 additions & 3 deletions
6
sensors/src/main/scala/org/apache/pekko/sensors/actor/ActorMetrics.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
64 changes: 64 additions & 0 deletions
64
sensors/src/main/scala/org/apache/pekko/sensors/dispatch/InstrumentedDispatcherBase.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,64 @@ | ||
package org.apache.pekko.sensors.dispatch | ||
|
||
import nl.pragmasoft.pekko.sensors.PekkoSensors | ||
import nl.pragmasoft.pekko.sensors.dispatch.{DispatcherInstrumentationWrapper, DispatcherMetricsRegistration} | ||
import org.apache.pekko.dispatch.{Dispatcher, Mailbox} | ||
import org.apache.pekko.event.Logging.Error | ||
|
||
import java.lang.management.{ManagementFactory, ThreadMXBean} | ||
import java.util.concurrent.RejectedExecutionException | ||
|
||
trait InstrumentedDispatcherBase extends Dispatcher { | ||
|
||
def actorSystemName: String | ||
private lazy val wrapper = new DispatcherInstrumentationWrapper(configurator.config) | ||
|
||
private val threadMXBean: ThreadMXBean = ManagementFactory.getThreadMXBean | ||
private val interestingStateNames = Set("runnable", "waiting", "timed_waiting", "blocked") | ||
private val interestingStates = Thread.State.values.filter(s => interestingStateNames.contains(s.name().toLowerCase)) | ||
|
||
PekkoSensors.schedule( | ||
s"$id-states", | ||
() => { | ||
val threads = threadMXBean | ||
.getThreadInfo(threadMXBean.getAllThreadIds, 0) | ||
.filter(t => | ||
t != null | ||
&& t.getThreadName.startsWith(s"$actorSystemName-$id") | ||
) | ||
|
||
interestingStates foreach { state => | ||
val stateLabel = state.toString.toLowerCase | ||
DispatcherMetricsRegistration.threadStates | ||
.labels(id, stateLabel) | ||
.set(threads.count(_.getThreadState.name().equalsIgnoreCase(stateLabel))) | ||
} | ||
DispatcherMetricsRegistration.threads | ||
.labels(id) | ||
.set(threads.length) | ||
} | ||
) | ||
|
||
override def execute(runnable: Runnable): Unit = wrapper(runnable, super.execute) | ||
|
||
protected[pekko] override def registerForExecution(mbox: Mailbox, hasMessageHint: Boolean, hasSystemMessageHint: Boolean): Boolean = | ||
if (mbox.canBeScheduledForExecution(hasMessageHint, hasSystemMessageHint)) | ||
if (mbox.setAsScheduled()) | ||
try { | ||
wrapper(mbox, executorService.execute) | ||
true | ||
} catch { | ||
case _: RejectedExecutionException => | ||
try { | ||
wrapper(mbox, executorService.execute) | ||
true | ||
} catch { //Retry once | ||
case e: RejectedExecutionException => | ||
mbox.setAsIdle() | ||
eventStream.publish(Error(e, getClass.getName, getClass, "registerForExecution was rejected twice!")) | ||
throw e | ||
} | ||
} | ||
else false | ||
else false | ||
} |
27 changes: 27 additions & 0 deletions
27
sensors/src/main/scala/org/apache/pekko/sensors/dispatch/PekkoRunnableWrapper.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,27 @@ | ||
package org.apache.pekko.sensors.dispatch | ||
|
||
import nl.pragmasoft.pekko.sensors.dispatch.DispatcherInstrumentationWrapper.Run | ||
import org.apache.pekko.dispatch.{Batchable, Mailbox} | ||
|
||
import java.util.concurrent.ForkJoinTask | ||
import scala.PartialFunction.condOpt | ||
|
||
object PekkoRunnableWrapper { | ||
def unapply(runnable: Runnable): Option[Run => Runnable] = | ||
condOpt(runnable) { | ||
case runnable: Batchable => new BatchableWrapper(runnable, _) | ||
case runnable: Mailbox => new MailboxWrapper(runnable, _) | ||
} | ||
|
||
class BatchableWrapper(self: Batchable, r: Run) extends Batchable { | ||
def run(): Unit = r(() => self.run()) | ||
def isBatchable: Boolean = self.isBatchable | ||
} | ||
|
||
class MailboxWrapper(self: Mailbox, r: Run) extends ForkJoinTask[Unit] with Runnable { | ||
def getRawResult: Unit = self.getRawResult() | ||
def setRawResult(v: Unit): Unit = self.setRawResult(v) | ||
def exec(): Boolean = r(() => self.exec()) | ||
def run(): Unit = { exec(); () } | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
sensors/src/main/scala/org/apache/pekko/sensors/dispatch/ScalaRunnableWrapper.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
Oops, something went wrong.