Missing Java getters for optional fields on akka.actor.Address (#28493)

This commit is contained in:
Johan Andrén 2020-01-16 02:45:38 +01:00 committed by Helena Edelson
parent 9b9972a854
commit 098118251d
2 changed files with 37 additions and 1 deletions

View file

@ -0,0 +1,25 @@
/*
* Copyright (C) 2020 Lightbend Inc. <https://www.lightbend.com>
*/
package akka.actor;
/*
* Copyright (C) 2009-2020 Lightbend Inc. <https://www.lightbend.com>
*/
import org.junit.Test;
import org.scalatest.junit.JUnitSuite;
import java.util.Optional;
import static org.junit.Assert.assertEquals;
public class AddressTest extends JUnitSuite {
@Test
public void portAddressAccessible() {
Address address = new Address("akka", "MySystem", "localhost", 2525);
assertEquals(Optional.of(2525), address.getPort());
assertEquals(Optional.of("localhost"), address.getHost());
}
}

View file

@ -6,11 +6,12 @@ package akka.actor
import java.net.URI
import java.net.URISyntaxException
import java.net.MalformedURLException
import java.util.Optional
import scala.annotation.tailrec
import scala.collection.immutable
import akka.annotation.InternalApi
import scala.compat.java8.OptionConverters._
/**
* The address specifies the physical location under which an Actor can be
@ -31,6 +32,16 @@ final case class Address private (protocol: String, system: String, host: Option
def this(protocol: String, system: String) = this(protocol, system, None, None)
def this(protocol: String, system: String, host: String, port: Int) = this(protocol, system, Option(host), Some(port))
/**
* Java API: The hostname if specified or empty optional if not
*/
def getHost(): Optional[String] = host.asJava
/**
* Java API: The port if specified or empty optional if not
*/
def getPort(): Optional[Integer] = port.asJava.asInstanceOf[Optional[Integer]]
/**
* Returns true if this Address is only defined locally. It is not safe to send locally scoped addresses to remote
* hosts. See also [[akka.actor.Address#hasGlobalScope]].