-
Notifications
You must be signed in to change notification settings - Fork 191
Add close on ActorSystem #2486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add close on ActorSystem #2486
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you 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. | ||
|
|
||
| # Add close to ActorSystem | ||
| ProblemFilters.exclude[ReversedMissingMethodProblem]("org.apache.pekko.actor.typed.ActorSystem.close") | ||
| ProblemFilters.exclude[InheritedNewAbstractMethodProblem]("org.apache.pekko.actor.typed.ActorSystem.close") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,6 +122,8 @@ import org.slf4j.{ Logger, LoggerFactory } | |
| override lazy val getWhenTerminated: CompletionStage[pekko.Done] = | ||
| whenTerminated.asJava | ||
|
|
||
| override def close(): Unit = system.close() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @throws(classOf[TimeoutException])
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as #2486 (comment), this is the implementation and end users won't see it (they will see the abstract method)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as #2486 (comment), this is not part of public API |
||
|
|
||
| override def systemActorOf[U](behavior: Behavior[U], name: String, props: Props): ActorRef[U] = { | ||
| val ref = system.systemActorOf( | ||
| PropsAdapter( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you 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. | ||
|
|
||
| # Add close to ActorSystem | ||
| ProblemFilters.exclude[InheritedNewAbstractMethodProblem]("org.apache.pekko.actor.ActorSystem.close") | ||
| ProblemFilters.exclude[InheritedNewAbstractMethodProblem]("org.apache.pekko.actor.ExtendedActorSystem.close") | ||
| ProblemFilters.exclude[ReversedMissingMethodProblem]("org.apache.pekko.actor.ActorSystem.close") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1244,6 +1244,12 @@ pekko { | |
| # Terminate the ActorSystem in the last phase actor-system-terminate. | ||
| terminate-actor-system = on | ||
|
|
||
| # The timeout that will be used when calling .close on an ActorSystem. | ||
| # This timeout will also be used when ActorSystem's are automatically | ||
| # terminated by using Java's try-with-resources or Scala's | ||
| # scala.util.Using | ||
| close-actor-system-timeout = 60 s | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ForkJoinPool's default is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1Day is way too much, people calling 1 minute is a good default in my view |
||
|
|
||
| # Exit the JVM (System.exit(0)) in the last phase actor-system-terminate | ||
| # if this is set to 'on'. It is done after termination of the | ||
| # ActorSystem if terminate-actor-system=on, otherwise it is done | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ import java.util.concurrent.atomic.AtomicReference | |
|
|
||
| import scala.annotation.tailrec | ||
| import scala.collection.immutable | ||
| import scala.concurrent.{ ExecutionContext, ExecutionContextExecutor, Future, Promise } | ||
| import scala.concurrent.{ Await, ExecutionContext, ExecutionContextExecutor, Future, Promise } | ||
| import scala.concurrent.blocking | ||
| import scala.concurrent.duration.Duration | ||
| import scala.jdk.CollectionConverters._ | ||
|
|
@@ -524,7 +524,7 @@ object ActorSystem { | |
| * extending [[pekko.actor.ExtendedActorSystem]] instead, but beware that you | ||
| * are completely on your own in that case! | ||
| */ | ||
| abstract class ActorSystem extends ActorRefFactory with ClassicActorSystemProvider { | ||
| abstract class ActorSystem extends ActorRefFactory with ClassicActorSystemProvider with AutoCloseable { | ||
| import ActorSystem._ | ||
|
|
||
| /** | ||
|
|
@@ -677,6 +677,26 @@ abstract class ActorSystem extends ActorRefFactory with ClassicActorSystemProvid | |
| */ | ||
| def terminate(): Future[Terminated] | ||
|
|
||
| /** | ||
| * Terminates this actor system by running [[CoordinatedShutdown]] with reason | ||
| * [[CoordinatedShutdown.ActorSystemTerminateReason]]. This method will block | ||
| * until either the actor system is terminated or | ||
| * `pekko.coordinated-shutdown.close-actor-system-timeout` timeout duration is | ||
| * passed, in which case a [[TimeoutException]] is thrown. | ||
| * | ||
| * If `pekko.coordinated-shutdown.run-by-actor-system-terminate` is configured to `off` | ||
| * it will not run `CoordinatedShutdown`, but the `ActorSystem` and its actors | ||
| * will still be terminated. | ||
| * | ||
| * This will stop the guardian actor, which in turn | ||
| * will recursively stop all its child actors, and finally the system guardian | ||
| * (below which the logging actors reside) and then execute all registered | ||
| * termination handlers (see [[ActorSystem#registerOnTermination]]). | ||
| * @since 1.3.0 | ||
| */ | ||
| @throws(classOf[TimeoutException]) | ||
| override def close(): Unit | ||
|
|
||
| /** | ||
| * Returns a Future which will be completed after the ActorSystem has been terminated | ||
| * and termination hooks have been executed. If you registered any callback with | ||
|
|
@@ -1080,6 +1100,14 @@ private[pekko] class ActorSystemImpl( | |
| whenTerminated | ||
| } | ||
|
|
||
| override def close(): Unit = { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @throws(classOf[TimeoutException])
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the implementation, the parent which defines the abstract method ( |
||
| terminate() | ||
| val duration = | ||
| Duration(settings.config.getDuration("pekko.coordinated-shutdown.close-actor-system-timeout").toMillis, | ||
| TimeUnit.MILLISECONDS) | ||
| Await.result(whenTerminated, duration) | ||
| } | ||
|
|
||
| override private[pekko] def finalTerminate(): Unit = { | ||
| terminating = true | ||
| // these actions are idempotent | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.