-
Notifications
You must be signed in to change notification settings - Fork 12
/
JPPFCsvFileConnectionStrategy.java
74 lines (68 loc) · 3.07 KB
/
JPPFCsvFileConnectionStrategy.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
/*
* JPPF.
* Copyright (C) 2005-2017 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.node.connection;
import java.io.Reader;
import java.util.*;
import org.jppf.utils.*;
import org.slf4j.*;
/**
* This implementation of {@link DriverConnectionStrategy} reads a list of drivers
* from a CSV file where each line has the following format:
* <p><code>secure, host, port, recovery_port</code>
* <p>where:
* <ul>
* <li><i>secure</i> is a boolean value (either 'true' or 'false', case-insenssitive) indicating whether a SSL/TLS connection should be established.
* any value that is not 'true' will be interpreted as 'false'.</li>
* <li><i>host</i> is the host name or ip address of the driver to connect to</li>
* <li><i>port</i> is the port to connect to on the driver host</li>
* <li><i>recovery_port</i> is a valid port number for the recovery heartbeat mechanism, or a negative value to disable recovery for the node</li>
* </ul>
* <p>Additionally, any line starting with a '#' (after trimming) will be considered as a comment and ignored.
* <p>The file location is read from the configuration property {@code 'jppf.node.connection.strategy.file'}.
* It will first be looked up in the file system, then in the classpath if it is not found in the file system.
* If no file is found at all, the node will fall back to the {@link JPPFDefaultConnectionStrategy JPPF default strategy} and use the configuration to find the driver connection information.
* <p>The listed drivers will be used as if they were arrayed in a "circle",
* with the driver selection mechanism rotating one tick each time {@code nextConnectionInfo()} is invoked.
* @author Laurent Cohen
* @since 4.1
*/
public class JPPFCsvFileConnectionStrategy extends AbstractCsvConnectionStrategy {
/**
* Logger for this class.
*/
private static Logger log = LoggerFactory.getLogger(JPPFCsvFileConnectionStrategy.class);
/**
* Find and read the CSV file.
*/
public JPPFCsvFileConnectionStrategy() {
super();
}
@Override
List<String> getConnectionInfoAsLines() {
try {
String path = JPPFConfiguration.getProperties().getString("jppf.server.connection.strategy.file");
if ((path != null) && !(path = path.trim()).isEmpty()) {
final Reader reader = FileUtils.getFileReader(path);
if (reader != null) return FileUtils.textFileAsLines(reader);
}
} catch (final Exception e) {
log.error(e.getMessage(), e);
}
return Collections.emptyList();
}
}