Skip to content

Commit

Permalink
DUBBO-478 multicast注册中心取消注册时出现端口-1
Browse files Browse the repository at this point in the history
  • Loading branch information
liangfei0201 committed Aug 1, 2012
1 parent 6255010 commit 7fce13d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ public int getPort() {
}

public int getPort(int defaultPort) {
return port == 0 ? defaultPort : port;
return port <= 0 ? defaultPort : port;
}

public String getAddress() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public class MulticastRegistry extends FailbackRegistry {

private final MulticastSocket mutilcastSocket;

private final int mutilcastPort;

private final ConcurrentMap<URL, Set<URL>> received = new ConcurrentHashMap<URL, Set<URL>>();

private final ScheduledExecutorService cleanExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("DubboMulticastRegistryCleanTimer", true));
Expand All @@ -79,7 +81,8 @@ public MulticastRegistry(URL url) {
}
try {
mutilcastAddress = InetAddress.getByName(url.getHost());
mutilcastSocket = new MulticastSocket(url.getPort() == 0 ? DEFAULT_MULTICAST_PORT : url.getPort());
mutilcastPort = url.getPort() <= 0 ? DEFAULT_MULTICAST_PORT : url.getPort();
mutilcastSocket = new MulticastSocket(mutilcastPort);
mutilcastSocket.setLoopbackMode(false);
mutilcastSocket.joinGroup(mutilcastAddress);
Thread thread = new Thread(new Runnable() {
Expand Down Expand Up @@ -153,7 +156,9 @@ private void clean() {
}

private boolean isExpired(URL url) {
if (Constants.CONSUMER_PROTOCOL.equals(url.getProtocol())
if (! url.getParameter(Constants.DYNAMIC_KEY, true)
|| url.getPort() <= 0
|| Constants.CONSUMER_PROTOCOL.equals(url.getProtocol())
|| Constants.ROUTE_PROTOCOL.equals(url.getProtocol())
|| Constants.OVERRIDE_PROTOCOL.equals(url.getProtocol())) {
return false;
Expand Down Expand Up @@ -223,11 +228,11 @@ private void receive(String msg, InetSocketAddress remoteAddress) {

private void broadcast(String msg) {
if (logger.isInfoEnabled()) {
logger.info("Send broadcast message: " + msg + " to " + mutilcastAddress + ":" + mutilcastSocket.getLocalPort());
logger.info("Send broadcast message: " + msg + " to " + mutilcastAddress + ":" + mutilcastPort);
}
try {
byte[] data = (msg + "\n").getBytes();
DatagramPacket hi = new DatagramPacket(data, data.length, mutilcastAddress, mutilcastSocket.getLocalPort());
DatagramPacket hi = new DatagramPacket(data, data.length, mutilcastAddress, mutilcastPort);
mutilcastSocket.send(hi);
} catch (Exception e) {
throw new IllegalStateException(e.getMessage(), e);
Expand All @@ -236,11 +241,11 @@ private void broadcast(String msg) {

private void unicast(String msg, String host) {
if (logger.isInfoEnabled()) {
logger.info("Send unicast message: " + msg + " to " + host + ":" + mutilcastSocket.getLocalPort());
logger.info("Send unicast message: " + msg + " to " + host + ":" + mutilcastPort);
}
try {
byte[] data = (msg + "\n").getBytes();
DatagramPacket hi = new DatagramPacket(data, data.length, InetAddress.getByName(host), mutilcastSocket.getLocalPort());
DatagramPacket hi = new DatagramPacket(data, data.length, InetAddress.getByName(host), mutilcastPort);
mutilcastSocket.send(hi);
} catch (Exception e) {
throw new IllegalStateException(e.getMessage(), e);
Expand Down

0 comments on commit 7fce13d

Please sign in to comment.