0

我在这里使用以下示例:

 void someMethod(FilePath file) {
     // make 'file' a fresh empty directory.
     file.act(new Freshen());
 }
 // if 'file' is on a different node, this FileCallable will
 // be transferred to that node and executed there.
 private static final class Freshen implements FileCallable<Void> {
     private static final long serialVersionUID = 1;
     @Override public Void invoke(File f, VirtualChannel channel) {
         // f and file represent the same thing
         f.deleteContents();
         f.mkdirs();
         return null;
     }
 }

Freshen 类将被序列化并发送到从属设备执行。如何从我的 Freshen 课程中访问并记录主记录器的进度?

4

2 回答 2

2

Freshen 类……并被送到奴隶处决。

不,执行将在从属设备上执行,FilePath 表示特定从属设备或主设备上的文件路径。见文档

尝试使用此代码将记录器传递给 Freshen(未经测试):

void someMethod(FilePath file, PrintStream logger) {
    // make 'file' a fresh empty directory.
    file.act(new Freshen(logger));
}
// if 'file' is on a different node, this FileCallable will
// be transferred to that node and executed there.
private static final class Freshen implements FileCallable<Void> {
    private static final long serialVersionUID = 1;

    private final PrintStream logger;

    public Freshen(PrintStream logger) {
        this.logger = logger;
    }

    @Override public Void invoke(File f, VirtualChannel channel) {
        // f and file represent the same thing
        logger.println("test");
        f.deleteContents();
        f.mkdirs();
        return null;
    }
}
于 2013-11-14T16:18:20.897 回答
2

我参加聚会有点晚了,但我偶然发现了同样的问题并通过传递TaskListener给解决了它FileCallable

private static final class Freshen implements FileCallable<Void> {
    private static final long serialVersionUID = 1;

    private final TaskListener listener;

    public Freshen(TaskListener listener) {
        this.listener = listener;
    }

    @Override public Void invoke(File f, VirtualChannel channel) {
        RemoteOutputStream ros = new RemoteOutputStream(listener.getLogger());
        ros.write("hello there".getBytes(StandardCharsets.UTF_8));

        return null;
    }
}
于 2017-10-13T00:03:30.360 回答