@Override public String getRawPort() { return serverName.getFullPort(); }
private Collection<ServerConnectionState> getStatesFor(P4ServerName name) { List<ServerConnectionState> ret = new ArrayList<>(); synchronized (stateCache) { for (ServerConnectionState state : stateCache.values()) { if (state.config.getServerName().equals(name)) { ret.add(state); } } } return ret; }
public MockConfigPart withServerName(String s) { serverName = P4ServerName.forPort(s); return this; }
@NotNull public static P4ServerName forPortNotNull(@Nullable final String portText) { P4ServerName ret = forPort(portText); if (ret == null) { ret = new P4ServerName("unknown server", IServerAddress.Protocol.P4JAVA); } return ret; }
@NotNull public String getUrl() { // Trim the config port. See bug #23 return getServerProtocol() + PROTOCOL_SEP + getServerPort().trim(); }
@SuppressWarnings("SameParameterValue") @NotNull private static String portName(@NotNull String serverName) { return Objects.requireNonNull(P4ServerName.forPort(serverName)).getDisplayName(); } }
@Test void forPort_justPort() { P4ServerName name = P4ServerName.forPort("1667"); assertThat("null", name, notNullValue()); assertThat("secure", name.isSecure(), is(false)); assertThat("connection type", name.getServerProtocol(), is(IServerAddress.Protocol.P4JRPCNTS)); assertThat("port", name.getServerPort(), is("localhost:1667")); assertThat("display", name.getDisplayName(), is("localhost:1667")); assertThat("url", name.getUrl(), is("p4jrpcnts://localhost:1667")); assertThat("full port", name.getFullPort(), is("localhost:1667")); assertThat("protocol name", name.getProtocolName(), is("java")); }
@Override public String toString() { return clientName + "@" + serverName.getDisplayName(); } }
@ExtendWith(TemporaryFolderExtension.class) @Test void forPort_rsh(TemporaryFolder tmpDir) { // This is what the TestServer uses as the protocol. String port = "p4jrsh://" + tmpDir.newFile("p4d").getAbsolutePath() + " -r " + tmpDir.newFile("root").getAbsolutePath() + ' ' + " -L log -i --java"; P4ServerName name = P4ServerName.forPort(port); assertNotNull(name); assertThat(name.getServerProtocol(), is(IServerAddress.Protocol.P4JRSHNTS)); }
@NotNull public static ClientServerRef readState(@NotNull Map<String, Object> data) { return new ClientServerRef( P4ServerName.forPortNotNull((String) data.get("csr:port")), (String) data.get("csr:clientname") ); }
public static String getSourceId(P4ServerName config) { return "server:" + config.getUrl(); }
@Test void forPort_simpleProtocolPort() { P4ServerName name = P4ServerName.forPort("tcp:host:1234"); assertThat("null", name, notNullValue()); assertThat("secure", name.isSecure(), is(false)); assertThat("connection type", name.getServerProtocol(), is(IServerAddress.Protocol.P4JRPCNTS)); assertThat("port", name.getServerPort(), is("host:1234")); assertThat("display", name.getDisplayName(), is("host:1234")); assertThat("url", name.getUrl(), is("p4jrpcnts://host:1234")); assertThat("full port", name.getFullPort(), is("host:1234")); assertThat("protocol name", name.getProtocolName(), is("java")); }
@NotNull public String getDisplayName() { if (getServerProtocol().isSecure()) { return "ssl:" + getServerPort(); } return getServerPort(); }
@Override public String toString() { if (clientName != null) { return serverConfig.getServerName().getDisplayName() + "@" + clientName; } return serverConfig.getServerName().getDisplayName(); }
@NotNull public static ClientServerRef read(@NotNull State state) { P4ServerName server = P4ServerName.forPortNotNull(state.serverPort); return new ClientServerRef(server, state.clientName); }
final String uri = serverName.getUrl();
@Test void forPort_hostPort() { P4ServerName name = P4ServerName.forPort("host:1234"); assertThat("null", name, notNullValue()); assertThat("secure", name.isSecure(), is(false)); assertThat("connection type", name.getServerProtocol(), is(IServerAddress.Protocol.P4JRPCNTS)); assertThat("port", name.getServerPort(), is("host:1234")); assertThat("display", name.getDisplayName(), is("host:1234")); assertThat("url", name.getUrl(), is("p4jrpcnts://host:1234")); assertThat("full port", name.getFullPort(), is("host:1234")); assertThat("protocol name", name.getProtocolName(), is("java")); }
private void setServerName(@Nullable P4ServerName port) { setTrimmed(PORT_KEY, port == null ? null : port.getFullPort()); }
@Nullable @Override public P4ServerName getServerName() { return P4ServerName.forPort(trimmedProperty(PORT_KEY)); }
" is not the same ref as " + ref); LOG.debug("param ref: clientname: [" + ref.getClientName() + "]; server [" + ref.getServerName().getServerPort() + "]; protocol [" + ref.getServerName().getServerProtocol() + "]"); ClientServerRef rt = root.getClientConfig().getClientServerRef(); LOG.debug("root ref: clientname: [" + rt.getClientName() + "]; server [" + rt.getServerName().getServerPort() + "]; protocol [" + rt.getServerName().getServerProtocol() + "]");