<commit_before>package org.jenkinsci.plugins.proxmox;

import java.io.IOException;
import java.util.concurrent.Future;

import org.jvnet.localizer.Localizable;
import org.jvnet.localizer.ResourceBundleHolder;

import hudson.Messages;
import hudson.model.Executor;
import hudson.model.Node;
import hudson.model.Queue;
import hudson.model.Slave;
import hudson.slaves.OfflineCause;
import hudson.slaves.SlaveComputer;

public class VirtualMachineSlaveComputer extends SlaveComputer {

	/**
	 * The resource bundle reference
	 * 
	 */
	private final static ResourceBundleHolder holder = ResourceBundleHolder.get(Messages.class);

    public VirtualMachineSlaveComputer(Slave slave) {
        super(slave);
    }

    @Override
    public void taskAccepted(Executor executor, Queue.Task task) {
        super.taskAccepted(executor, task);

        final Node node = getNode();

        if (node instanceof VirtualMachineSlave) {
            final VirtualMachineSlave slave = (VirtualMachineSlave) node;
            final VirtualMachineLauncher launcher = (VirtualMachineLauncher) slave.getLauncher();

            if (launcher.isLaunchSupported() && (slave.getRevertPolicy() == VirtualMachineLauncher.RevertPolicy.BEFORE_JOB)) {
                try {
                  disconnect(OfflineCause.create(new Localizable(holder, "Disconnect before snapshot revert")));
                  launcher.revertSnapshot(this, getListener());
                  launcher.launch(this, getListener());
                } catch (IOException | InterruptedException e) {
                  getListener().getLogger().println("ERROR: Snapshot revert failed: " + e.getMessage());
                }
            }
        }
    }
    
    @Override
    protected Future<?> _connect(boolean forceReconnect) {
        return super._connect(forceReconnect);
    }

}<commit_msg>Waiting for agent disconnect before revert (#7)<commit_after>package org.jenkinsci.plugins.proxmox;

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import org.jvnet.localizer.Localizable;
import org.jvnet.localizer.ResourceBundleHolder;

import hudson.Messages;
import hudson.model.Executor;
import hudson.model.Node;
import hudson.model.Queue;
import hudson.model.Slave;
import hudson.slaves.OfflineCause;
import hudson.slaves.SlaveComputer;

public class VirtualMachineSlaveComputer extends SlaveComputer {

	/**
	 * The resource bundle reference
	 * 
	 */
	private final static ResourceBundleHolder holder = ResourceBundleHolder.get(Messages.class);

    public VirtualMachineSlaveComputer(Slave slave) {
        super(slave);
    }

    @Override
    public void taskAccepted(Executor executor, Queue.Task task) {
        super.taskAccepted(executor, task);

        final Node node = getNode();

        if (node instanceof VirtualMachineSlave) {
            final VirtualMachineSlave slave = (VirtualMachineSlave) node;
            final VirtualMachineLauncher launcher = (VirtualMachineLauncher) slave.getLauncher();

            if (launcher.isLaunchSupported() && (slave.getRevertPolicy() == VirtualMachineLauncher.RevertPolicy.BEFORE_JOB)) {
                try {
                  final Future<?> disconnectFuture = disconnect(OfflineCause.create(new Localizable(holder, "Disconnect before snapshot revert")));
                  
                  disconnectFuture.get();
                  launcher.revertSnapshot(this, getListener());
                  launcher.launch(this, getListener());
                } catch (IOException | InterruptedException e) {
                  getListener().getLogger().println("ERROR: Snapshot revert failed: " + e.getMessage());
                } catch (ExecutionException e) {
                  getListener().getLogger().println("ERROR: Exception while performing asynchronous disconnect: " + e.getMessage());
				}
            }
        }
    }
    
    @Override
    protected Future<?> _connect(boolean forceReconnect) {
        return super._connect(forceReconnect);
    }

}
{'fraction_non_alphanumeric': 0.09523809523809523, 'fraction_numerical': 0.000248015873015873, 'mean_word_length': 3.081983805668016, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7662860', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1043, 'n_words': 224}