Skip to content

Commit 5021255

Browse files
committed
cells: simplify initialization of LocationManagerConnector
Motivation: As a regular cell, LocationManagerConnector initialized via cell arguments. However, it uses only in a single place, where all params already known. Thus, passing params as arguments make it less obvious which options are used. Modification: Update LocationManagerConnector constructor to accept desired arguments. Result: Simplified code flow. Acked-by: Marina Sahakyan Target: master Require-book: no Require-notes: no
1 parent 34658ed commit 5021255

File tree

2 files changed

+16
-25
lines changed

2 files changed

+16
-25
lines changed

modules/cells/src/main/java/dmg/cells/network/LocationManagerConnector.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,18 @@ public class LocationManagerConnector
4242
private volatile int _retries;
4343
private volatile boolean _isRunning;
4444

45-
public LocationManagerConnector(String cellName, String args, SocketFactory socketFactory) {
46-
super(cellName, "System", args);
47-
Args a = getArgs();
48-
_domain = a.getOpt("domain");
45+
/**
46+
* Create a new connector to the location manager.
47+
* @param cellName the name of this connector as a cell
48+
* @param socketFactory the socket factory to use for creating connections
49+
* @param remoteDomain the domain name of the location manager
50+
* @param endpoint the address of the location manager
51+
*/
52+
public LocationManagerConnector(String cellName, SocketFactory socketFactory, String remoteDomain, InetSocketAddress endpoint) {
53+
super(cellName, "System");
54+
_domain = remoteDomain;
4955
_ssf = requireNonNull(socketFactory);
50-
HostAndPort where = HostAndPort.fromString(a.getOpt("where"));
51-
_address = new InetSocketAddress(where.getHost(), where.getPort());
56+
_address = endpoint;
5257
}
5358

5459
@Override

modules/cells/src/main/java/dmg/cells/services/LocationManager.java

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.io.DataInputStream;
4040
import java.io.DataOutputStream;
4141
import java.io.IOException;
42+
import java.net.InetSocketAddress;
4243
import java.net.URI;
4344
import java.net.UnknownHostException;
4445
import java.util.Arrays;
@@ -681,15 +682,6 @@ private String startConnector(String remoteDomain, CoreDomainInfo domainInfo)
681682
throws ExecutionException, InterruptedException, BadConfigException {
682683
checkArgument(args.hasOption("mode"), "No mode specified to run connector");
683684

684-
String cellName = "c-" + remoteDomain + '*';
685-
String clientKey = args.getOpt("clientKey");
686-
clientKey =
687-
(clientKey != null) && (!clientKey.isEmpty()) ? ("-clientKey=" + clientKey) : "";
688-
String clientName = args.getOpt("clientUserName");
689-
clientName =
690-
(clientName != null) && (!clientName.isEmpty()) ? ("-clientUserName=" + clientName)
691-
: "";
692-
693685
HostAndPort where;
694686
SocketFactory socketFactory;
695687
Mode mode = Mode.fromString(args.getOption("mode"));
@@ -724,16 +716,10 @@ private String startConnector(String remoteDomain, CoreDomainInfo domainInfo)
724716
"Invalid mode to start connector: " + args.getOption("mode"));
725717
}
726718

727-
String cellArgs = "-domain=" + remoteDomain + ' '
728-
+ "-lm=" + getCellName() + ' '
729-
+ "-role=" + role + ' '
730-
+ "-where=" + where + ' '
731-
+ clientKey + ' '
732-
+ clientName;
733-
734-
LOGGER.info("Starting connector with {}", cellArgs);
735-
LocationManagerConnector c = new LocationManagerConnector(cellName, cellArgs,
736-
socketFactory);
719+
String cellName = "c-" + remoteDomain + '*';
720+
LOGGER.info("Starting connector {} to {} ({})", cellName, remoteDomain, where);
721+
InetSocketAddress tunnelEndpoint = new InetSocketAddress(where.getHost(), where.getPort());
722+
LocationManagerConnector c = new LocationManagerConnector(cellName, socketFactory, remoteDomain, tunnelEndpoint);
737723
c.start().get();
738724
return c.getCellName();
739725
}

0 commit comments

Comments
 (0)