Gridarta Editor
Collector.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.commands;
21 
22 import java.io.File;
23 import java.io.IOException;
25 import net.sf.japi.swing.misc.Progress;
26 import org.jetbrains.annotations.NotNull;
27 import org.jetbrains.annotations.Nullable;
28 
35 public class Collector {
36 
40  @NotNull
42 
46  @NotNull
47  private final File collectedDirectory;
48 
52  @NotNull
53  private final Progress progress;
54 
58  @Nullable
59  private Thread thread;
60 
65  @Nullable
66  private IOException ioException;
67 
74  public Collector(@NotNull final Progress progress, @NotNull final AbstractResources<?, ?, ?> resources, @NotNull final File collectedDirectory) {
76  throw new IllegalArgumentException("can't collect already collected archetypes");
77  }
78  this.progress = progress;
79  this.resources = resources;
80  this.collectedDirectory = collectedDirectory;
81  }
82 
86  public void start() {
87  thread = new Thread(() -> {
88  try {
89  run();
90  } catch (final IOException e) {
91  ioException = e;
92  }
93  });
94  thread.start();
95  }
96 
102  public void waitUntilFinished() throws InterruptedException, IOException {
103  if (thread != null) {
104  thread.join();
105  thread = null;
106  }
107  if (ioException != null) {
108  throw ioException;
109  }
110  }
111 
120  private void run() throws IOException {
121  try {
123  } finally {
124  progress.finished();
125  }
126  }
127 
128 }
net.sf.gridarta.commands.Collector.progress
final Progress progress
The Progress to use.
Definition: Collector.java:53
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.commands.Collector
A Collector is capable of iterating over a collection of {Collectables} and collecting them in a sepa...
Definition: Collector.java:35
net.sf.gridarta.model.resource.AbstractResources.writeCollected
void writeCollected(@NotNull final Progress progress, @NotNull final File collectedDirectory)
Writes the resources in collected form.
Definition: AbstractResources.java:131
net.sf
net.sf.gridarta.commands.Collector.waitUntilFinished
void waitUntilFinished()
Waits until collection has finished.
Definition: Collector.java:102
net
net.sf.gridarta.commands.Collector.start
void start()
Starts collecting.
Definition: Collector.java:86
net.sf.gridarta.model.resource.AbstractResources.canWriteCollected
boolean canWriteCollected()
Whether the resources can be written in collected form.
Definition: AbstractResources.java:119
net.sf.gridarta.model.resource.AbstractResources
Maintains resources.
Definition: AbstractResources.java:40
net.sf.gridarta.commands.Collector.ioException
IOException ioException
The I/O error if collection fails or.
Definition: Collector.java:66
net.sf.gridarta.commands.Collector.collectedDirectory
final File collectedDirectory
The destination directory to write files to.
Definition: Collector.java:47
net.sf.gridarta.commands.Collector.run
void run()
Collect the existing arches and create archive-files for editor use as well as the Crossfire or Daimo...
Definition: Collector.java:120
net.sf.gridarta.commands.Collector.Collector
Collector(@NotNull final Progress progress, @NotNull final AbstractResources<?, ?, ?> resources, @NotNull final File collectedDirectory)
Creates a new instance.
Definition: Collector.java:74
net.sf.gridarta.model.resource
Definition: AbstractCollectedResourcesReader.java:20
net.sf.gridarta.model
net.sf.gridarta.commands.Collector.resources
final AbstractResources<?, ?, ?> resources
The Collectables.
Definition: Collector.java:41
net.sf.gridarta.commands.Collector.thread
Thread thread
The worker thread.
Definition: Collector.java:59