import de.todesbaum.util.io.Closer;
import de.todesbaum.util.io.LineInputStream;
import de.todesbaum.util.io.StreamCopier;
+import de.todesbaum.util.io.StreamCopier.ProgressListener;
import de.todesbaum.util.io.TempFileInputStream;
/**
* Disconnects from the node.
*/
public void disconnect() {
- if (nodeWriter != null) {
- try {
- nodeWriter.close();
- } catch (IOException ioe1) {
- }
- nodeWriter = null;
- }
- if (nodeOutputStream != null) {
- try {
- nodeOutputStream.close();
- } catch (IOException ioe1) {
- }
- nodeOutputStream = null;
- }
- if (nodeInputStream != null) {
- try {
- nodeInputStream.close();
- } catch (IOException ioe1) {
- }
- nodeInputStream = null;
- }
- if (nodeSocket != null) {
- try {
- nodeSocket.close();
- } catch (IOException ioe1) {
- }
- nodeSocket = null;
- }
+ Closer.close(nodeWriter);
+ nodeWriter = null;
+ Closer.close(nodeOutputStream);
+ nodeOutputStream = null;
+ Closer.close(nodeInputStream);
+ nodeInputStream = null;
+ nodeInputStream = null;
+ Closer.close(nodeSocket);
+ nodeSocket = null;
synchronized (this) {
notify();
}
* if an I/O error occurs
*/
public synchronized void execute(Command command) throws IllegalStateException, IOException {
+ execute(command, null);
+ }
+
+ /**
+ * Executes the specified command.
+ *
+ * @param command
+ * The command to execute
+ * @param progressListener
+ * A progress listener for a payload transfer
+ * @throws IllegalStateException
+ * if the connection is not connected
+ * @throws IOException
+ * if an I/O error occurs
+ */
+ public synchronized void execute(Command command, ProgressListener progressListener) throws IllegalStateException, IOException {
if (nodeSocket == null) {
throw new IllegalStateException("connection is not connected");
}
InputStream payloadInputStream = null;
try {
payloadInputStream = command.getPayload();
- StreamCopier.copy(payloadInputStream, nodeOutputStream, command.getPayloadLength());
+ StreamCopier.copy(payloadInputStream, nodeOutputStream, command.getPayloadLength(), progressListener);
} finally {
Closer.close(payloadInputStream);
}
* Main loop of the reader. Lines are read and converted into
* {@link Message} objects.
*/
+ @SuppressWarnings("synthetic-access")
public void run() {
LineInputStream nodeReader = null;
try {