[ https://issues.apache.org/jira/browse/MRESOLVER-302?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17652315#comment-17652315 ]
ASF GitHub Bot commented on MRESOLVER-302: ------------------------------------------ cstamas commented on code in PR #232: URL: https://github.com/apache/maven-resolver/pull/232#discussion_r1057927629 ########## maven-resolver-api/src/main/java/org/eclipse/aether/RepositorySystem.java: ########## @@ -302,4 +302,39 @@ List<RemoteRepository> newResolutionRepositories( RepositorySystemSession sessio * @since 1.9.0 */ void shutdown(); + + /** + * Registers the session for lifecycle tracking: it marks that the passed in session instance is about to start. + * After this call it is possible to register "on close" handlers using + * {@link #addOnSessionEndedHandle(RepositorySystemSession, Runnable)} method that will execute once + * {@link #sessionEnded(RepositorySystemSession)} method was invoked. + * <p> + * <en>Same session instance can be started only once.</em> + * + * @param session the session that is about to start, never {@code null}. + * @since TBD + */ + void sessionStarted( RepositorySystemSession session ); + + /** + * Registers a handler to execute when this session ends. This method throws, if the passed in session instance + * was not passed to method {@link #sessionStarted(RepositorySystemSession)} beforehand. + * + * @param session the session for which the handler needs to be registered, never {@code null}. + * @param handler the handler, never {@code null}. + * @since TBD + */ + void addOnSessionEndedHandle( RepositorySystemSession session, Runnable handler ); + + /** + * Signals to repository system that passed in session ended, it will not be used anymore. Repository system + * will invoke the registered handlers for this session, if any. This method throws if the passed in session + * instance was not passed to method {@link #sessionStarted(RepositorySystemSession)} beforehand. + * <p> + * <en>Same session instance can be ended only once.</em> + * + * @param session the session that just ended, never {@code null}. + * @since TBD + */ + void sessionEnded( RepositorySystemSession session ); Review Comment: This is the least painful way with 1.x. Problem is how session instances are created (by client code, using def ctor of DefaultRepositorySystemSession, no factory for it) and _derived_. Just look thru Maven and plugin sources as example. They are not "boxed" nor are hierarchical, you can get session A and have it "derived" (using copy ctor) into session B and then continue to use it (typical when local repo is overridden in plugins), etc. And then i did not even mention "forwarding" session... So yes, ideally session would be: * created by some factory (repo system, ideally?) * closeable But doing this would be very disruptive, so baby steps... leave these changes for 2.0 > Introduce onSession close > ------------------------- > > Key: MRESOLVER-302 > URL: https://issues.apache.org/jira/browse/MRESOLVER-302 > Project: Maven Resolver > Issue Type: New Feature > Components: Resolver > Reporter: Tamas Cservenak > Assignee: Tamas Cservenak > Priority: Major > Fix For: 1.9.3 > > > The on session close callback, revisited. -- This message was sent by Atlassian Jira (v8.20.10#820010)