Skip to content

Commit

Permalink
Clean up the resources generated by HCR provider (#300)
Browse files Browse the repository at this point in the history
* Clean up the resources generated by HCR provider

Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>

* Fix launch.json project name

Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>

* clean up hcr provider in noDebug mode

Signed-off-by: Jinbo Wang <jinbwan@microsoft.com>
  • Loading branch information
testforstephen authored Sep 23, 2019
1 parent c90a238 commit f4ad19a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"sourcePaths": [
"${workspaceRoot}/com.microsoft.java.debug.core/main/java",
"${workspaceRoot}/com.microsoft.java.debug.plugin/src/main/java"
]
],
"projectName": "com.microsoft.java.debug.plugin"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ public interface IProvider {
*/
default void initialize(IDebugAdapterContext debugContext, Map<String, Object> options) {
}

/**
* Close the provider and free all associated resources.
*/
default void close() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.microsoft.java.debug.core.Configuration;
import com.microsoft.java.debug.core.adapter.IDebugAdapterContext;
import com.microsoft.java.debug.core.adapter.IDebugRequestHandler;
import com.microsoft.java.debug.core.adapter.IHotCodeReplaceProvider;
import com.microsoft.java.debug.core.adapter.LaunchMode;
import com.microsoft.java.debug.core.protocol.Messages.Response;
import com.microsoft.java.debug.core.protocol.Requests.Arguments;
Expand Down Expand Up @@ -50,6 +51,7 @@ public CompletableFuture<Response> handle(Command command, Arguments arguments,
* @param context the debug context
*/
private void destroyResource(IDebugAdapterContext context) {
destroyProviders(context);
if (shouldDestroyLaunchFiles(context)) {
destroyLaunchFiles(context);
}
Expand Down Expand Up @@ -97,4 +99,11 @@ private void destroyLaunchFiles(IDebugAdapterContext context) {
}

protected abstract void destroyDebugSession(Command command, Arguments arguments, Response response, IDebugAdapterContext context);

protected void destroyProviders(IDebugAdapterContext context) {
IHotCodeReplaceProvider hcrProvider = context.getProvider(IHotCodeReplaceProvider.class);
if (hcrProvider != null) {
hcrProvider.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,4 @@ public void destroyDebugSession(Command command, Arguments arguments, Response r
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,16 @@ public void initialize(IDebugAdapterContext context, Map<String, Object> options
}
this.context = context;
currentDebugSession = context.getDebugSession();
}

@Override
public void close() {
if (DebugSettings.getCurrent().hotCodeReplace != DebugSettings.HotCodeReplace.NEVER) {
// Remove the listener.
ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
}

// TODO: Change IProvider interface for shutdown event
eventSubject.onComplete();
}

@Override
Expand Down

0 comments on commit f4ad19a

Please sign in to comment.