-
Notifications
You must be signed in to change notification settings - Fork 12
/
FTPRunner.java
100 lines (94 loc) · 3.46 KB
/
FTPRunner.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* JPPF.
* Copyright (C) 2005-2019 JPPF Team.
* http://www.jppf.org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jppf.example.ftp.runner;
import java.util.List;
import org.jppf.client.JPPFClient;
import org.jppf.client.JPPFJob;
import org.jppf.management.JMXDriverConnectionWrapper;
import org.jppf.node.protocol.DataProvider;
import org.jppf.node.protocol.MemoryMapDataProvider;
import org.jppf.node.protocol.Task;
import org.jppf.utils.ExceptionUtils;
import org.jppf.utils.Operator;
import org.jppf.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Runner class for the matrix multiplication demo.
* @author Laurent Cohen
*/
public class FTPRunner {
/**
* Logger for this class.
*/
static Logger log = LoggerFactory.getLogger(FTPRunner.class);
/**
* JPPF client used to submit execution requests.
*/
private static JPPFClient jppfClient = null;
/**
* Entry point for this class, performs a matrix multiplication a number of times.,<br>
* The number of times is specified as a configuration property named "matrix.iterations".<br>
* The size of the matrices is specified as a configuration property named "matrix.size".<br>
* @param args not used.
*/
public static void main(final String... args) {
try {
jppfClient = new JPPFClient();
perform();
} catch (final Exception e) {
e.printStackTrace();
} finally {
if (jppfClient != null) jppfClient.close();
}
}
/**
* Perform the test.
* @throws Exception if an error is raised during the execution.
*/
private static void perform() throws Exception {
output("Running FTP demo");
long totalTime = System.nanoTime();
final JPPFJob job = new JPPFJob();
job.setName("FTP server example job");
// fetch the host from the JPPF client, so we don't have to hard-code it in the task.
final JMXDriverConnectionWrapper jmxDriver = jppfClient.awaitActiveConnectionPool().awaitJMXConnections(Operator.AT_LEAST, 1, true).get(0);
final String host = jmxDriver.getHost();
// store the host in a data provider
final DataProvider dataProvider = new MemoryMapDataProvider();
dataProvider.setParameter("ftp.host", host);
job.setDataProvider(dataProvider);
// add a single task
job.add(new FTPTask("input.txt", "output.html"));
final List<Task<?>> results = jppfClient.submit(job);
for (final Task<?> t : results) {
if (t.getThrowable() != null) System.out.println("task error: " + ExceptionUtils.getStackTrace(t.getThrowable()));
else System.out.println("task result: " + t.getResult());
}
totalTime = System.nanoTime() - totalTime;
output("Computation time: " + StringUtils.toStringDuration(totalTime / 1000000L));
}
/**
* Print a message to the console and/or log file.
* @param message the message to print.
*/
private static void output(final String message) {
System.out.println(message);
log.info(message);
}
}