Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #543 from jmesnil/broadcast_configuration_refactoring

refactor and simplify broadcast group configuration
  • Loading branch information...
commit 425b00cb72288448616b2510ccc8580da1a98c79 2 parents e532d71 + 1de1f1e
Andy Taylor andytaylor authored
133 hornetq-core/src/main/java/org/hornetq/api/core/AbstractJGroupsBroadcastEndpoint.java
View
@@ -1,133 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc.
- * Red Hat licenses this file to you 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.hornetq.api.core;
-
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.LinkedBlockingDeque;
-import java.util.concurrent.TimeUnit;
-
-import org.jgroups.JChannel;
-import org.jgroups.Message;
-import org.jgroups.ReceiverAdapter;
-
-
-/**
- * This class is the implementation of HornetQ members discovery that will use JGroups.
- * @author Howard Gao
- */
-public abstract class AbstractJGroupsBroadcastEndpoint implements BroadcastEndpoint
-{
- private final BlockingQueue<byte[]> dequeue = new LinkedBlockingDeque<byte[]>();
-
- private boolean clientOpened;
-
- private boolean broadcastOpened;
-
- protected final String channelName;
-
- protected JChannel channel;
-
- public AbstractJGroupsBroadcastEndpoint(final String channelName)
- {
- this.channelName = channelName;
- }
-
- public AbstractJGroupsBroadcastEndpoint(final JChannel channel, final String channelName)
- {
- this(channelName);
- this.channel = channel;
- }
-
- public void broadcast(byte[] data) throws Exception
- {
- if (broadcastOpened)
- {
- Message msg = new Message();
- msg.setBuffer(data);
- channel.send(msg);
- }
- }
-
- public byte[] receiveBroadcast() throws Exception
- {
- if (clientOpened)
- {
- return dequeue.take();
- }
- else
- {
- return null;
- }
- }
-
- public byte[] receiveBroadcast(long time, TimeUnit unit) throws Exception
- {
- if (clientOpened)
- {
- return dequeue.poll(time, unit);
- }
- else
- {
- return null;
- }
- }
-
- public synchronized void openClient() throws Exception
- {
- if (clientOpened)
- {
- return;
- }
- internalOpen();
- channel.setReceiver(new JGroupsReceiver());
- clientOpened = true;
- }
-
- public synchronized void openBroadcaster() throws Exception
- {
- if (broadcastOpened) return;
- internalOpen();
- broadcastOpened = true;
- }
-
-
- protected void internalOpen() throws Exception
- {
- if (channel.isConnected()) return;
- channel.connect(this.channelName);
- }
-
- public synchronized void close(boolean isBroadcast) throws Exception
- {
- if (isBroadcast)
- {
- broadcastOpened = false;
- }
- else
- {
- channel.setReceiver(null);
- clientOpened = false;
- }
- channel.close();
- }
-
- private class JGroupsReceiver extends ReceiverAdapter
- {
- @Override
- public void receive(org.jgroups.Message msg)
- {
- dequeue.add(msg.getBuffer());
- }
- }
-}
39 hornetq-core/src/main/java/org/hornetq/api/core/JGroupsBroadcastEndpointWithFile.java
View
@@ -1,39 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc.
- * Red Hat licenses this file to you 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.hornetq.api.core;
-
-import java.net.URL;
-
-import org.jgroups.JChannel;
-
-
-/**
- * This class is the implementation of HornetQ members discovery that will use JGroups.
- * @author Tomohisa
- * @author Howard Gao
- * @author Clebert Suconic
- */
-public class JGroupsBroadcastEndpointWithFile extends AbstractJGroupsBroadcastEndpoint
-{
- public JGroupsBroadcastEndpointWithFile(final String fileName, final String channelName) throws Exception
- {
- super(channelName);
- URL configURL = Thread.currentThread().getContextClassLoader().getResource(fileName);
- if (configURL == null)
- {
- throw new RuntimeException("couldn't find JGroups configuration " + fileName);
- }
- channel = new JChannel(configURL);
- }
-}
173 hornetq-core/src/main/java/org/hornetq/api/core/JGroupsBroadcastGroupConfiguration.java
View
@@ -0,0 +1,173 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat licenses this file to you 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.hornetq.api.core;
+
+import java.net.URL;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingDeque;
+import java.util.concurrent.TimeUnit;
+
+import org.jgroups.JChannel;
+import org.jgroups.Message;
+import org.jgroups.ReceiverAdapter;
+
+/**
+ */
+public class JGroupsBroadcastGroupConfiguration implements BroadcastEndpointFactoryConfiguration
+{
+ private static final long serialVersionUID = 8952238567248461285L;
+
+ private final BroadcastEndpointFactory factory;
+
+ public JGroupsBroadcastGroupConfiguration(final String jgroupsFile, final String channelName)
+ {
+ factory = new BroadcastEndpointFactory() {
+ @Override
+ public BroadcastEndpoint createBroadcastEndpoint() throws Exception {
+ return new JGroupsBroadcastEndpoint(jgroupsFile, channelName);
+ }
+ };
+ }
+
+ public JGroupsBroadcastGroupConfiguration(final JChannel channel, final String channelName)
+ {
+ factory = new BroadcastEndpointFactory() {
+ @Override
+ public BroadcastEndpoint createBroadcastEndpoint() throws Exception {
+ return new JGroupsBroadcastEndpoint(channel, channelName);
+ }
+ };
+ }
+
+ @Override
+ public BroadcastEndpointFactory createBroadcastEndpointFactory()
+ {
+ return factory;
+ }
+
+ /**
+ * This class is the implementation of HornetQ members discovery that will use JGroups.
+ * @author Howard Gao
+ */
+ private static class JGroupsBroadcastEndpoint implements BroadcastEndpoint
+ {
+ private BlockingQueue<byte[]> dequeue = new LinkedBlockingDeque<byte[]>();
+
+ private boolean clientOpened;
+
+ private boolean broadcastOpened;
+
+ private final String channelName;
+
+ private final JChannel channel;
+
+ public JGroupsBroadcastEndpoint(final String fileName, final String channelName) throws Exception
+ {
+ URL configURL = Thread.currentThread().getContextClassLoader().getResource(fileName);
+ if (configURL == null)
+ {
+ throw new RuntimeException("couldn't find JGroups configuration " + fileName);
+ }
+ this.channel = new JChannel(configURL);
+ this.channelName = channelName;
+ }
+
+ public JGroupsBroadcastEndpoint(final JChannel channel, final String channelName)
+ {
+ this.channel = channel;
+ this.channelName = channelName;
+ }
+
+ public void broadcast(byte[] data) throws Exception
+ {
+ if (broadcastOpened)
+ {
+ Message msg = new Message();
+ msg.setBuffer(data);
+ channel.send(msg);
+ }
+ }
+
+ public byte[] receiveBroadcast() throws Exception
+ {
+ if (clientOpened)
+ {
+ return dequeue.take();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public byte[] receiveBroadcast(long time, TimeUnit unit) throws Exception
+ {
+ if (clientOpened)
+ {
+ return dequeue.poll(time, unit);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public synchronized void openClient() throws Exception
+ {
+ if (clientOpened)
+ {
+ return;
+ }
+ internalOpen();
+ channel.setReceiver(new JGroupsReceiver());
+ clientOpened = true;
+ }
+
+ public synchronized void openBroadcaster() throws Exception
+ {
+ if (broadcastOpened) return;
+ internalOpen();
+ broadcastOpened = true;
+ }
+
+
+ protected void internalOpen() throws Exception
+ {
+ if (channel.isConnected()) return;
+ channel.connect(this.channelName);
+ }
+
+ public synchronized void close(boolean isBroadcast) throws Exception
+ {
+ if (isBroadcast)
+ {
+ broadcastOpened = false;
+ }
+ else
+ {
+ channel.setReceiver(null);
+ clientOpened = false;
+ }
+ channel.close();
+ }
+
+ private class JGroupsReceiver extends ReceiverAdapter
+ {
+ public void receive(org.jgroups.Message msg)
+ {
+ dequeue.add(msg.getBuffer());
+ }
+ }
+ }
+}
44 hornetq-core/src/main/java/org/hornetq/api/core/JGroupsBroadcastGroupConfigurationWithFile.java
View
@@ -1,44 +0,0 @@
-/*
- * Copyright 2009 Red Hat, Inc.
- * Red Hat licenses this file to you 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.hornetq.api.core;
-
-/**
- * The configuration used to determine how the server will broadcast members
- * This is analogous to {@link org.hornetq.api.core.DiscoveryGroupConfiguration}
- *
- * @author <a href="mailto:tim.fox@jboss.com">Tim Fox</a>
- *
- * Created 18 Nov 2008 08:44:30
- *
- */
-public class JGroupsBroadcastGroupConfigurationWithFile implements BroadcastEndpointFactoryConfiguration
-{
- private static final long serialVersionUID = 8952238567248461285L;
-
- private final String jgroupsFile;
-
- private final String jgroupsChannel;
-
- public JGroupsBroadcastGroupConfigurationWithFile(final String jgroupsFile, final String jgroupsChannel)
- {
- this.jgroupsFile = jgroupsFile;
- this.jgroupsChannel = jgroupsChannel;
- }
-
- @Override
- public BroadcastEndpointFactory createBroadcastEndpointFactory()
- {
- return new JGroupsFileEndpointFactory(jgroupsFile, jgroupsChannel);
- }
-}
49 hornetq-core/src/main/java/org/hornetq/api/core/JGroupsFileEndpointFactory.java
View
@@ -1,49 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source.
-* Copyright 2010, Red Hat, Inc., and individual contributors
-* as indicated by the @author tags. See the copyright.txt file in the
-* distribution for a full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.hornetq.api.core;
-
-import org.hornetq.utils.ClassloadingUtil;
-
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-
-/**
- * @author <a href="mailto:andy.taylor@jboss.org">Andy Taylor</a>
- * 9/25/12
- */
-public class JGroupsFileEndpointFactory implements BroadcastEndpointFactory
-{
- private final String fileName;
-
- private final String channelName;
-
- public JGroupsFileEndpointFactory(String fileName, String channelName)
- {
- this.fileName = fileName;
- this.channelName = channelName;
- }
-
- public BroadcastEndpoint createBroadcastEndpoint() throws Exception
- {
- return new JGroupsBroadcastEndpointWithFile(fileName, channelName);
- }
-}
201 hornetq-core/src/main/java/org/hornetq/api/core/UDPBroadcastEndpoint.java
View
@@ -1,201 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc.
- * Red Hat licenses this file to you 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.hornetq.api.core;
-
-import java.io.IOException;
-import java.io.InterruptedIOException;
-import java.net.DatagramPacket;
-import java.net.DatagramSocket;
-import java.net.Inet4Address;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.MulticastSocket;
-import java.net.UnknownHostException;
-import java.util.concurrent.TimeUnit;
-
-import org.hornetq.core.server.HornetQLogger;
-
-/**
- * <p> This is the member discovery implementation using direct UDP. It was extracted as a refactoring from
- * {@link org.hornetq.core.cluster.DiscoveryGroup}</p>
- * @author Tomohisa
- * @author Howard Gao
- * @author Clebert Suconic
- */
-public class UDPBroadcastEndpoint implements BroadcastEndpoint
-{
- private static final int SOCKET_TIMEOUT = 500;
-
- private final InetAddress localAddress;
-
- private final int localBindPort;
-
- private final InetAddress groupAddress;
-
- private final int groupPort;
-
- private DatagramSocket broadcastingSocket;
-
- private MulticastSocket receivingSocket;
-
- private volatile boolean open;
-
- public UDPBroadcastEndpoint(final InetAddress groupAddress,
- final int groupPort,
- final InetAddress localBindAddress,
- final int localBindPort) throws UnknownHostException
- {
- this.groupAddress = groupAddress;
- this.groupPort = groupPort;
- this.localAddress = localBindAddress;
- this.localBindPort = localBindPort;
- }
-
-
- public void broadcast(byte[] data) throws Exception
- {
- DatagramPacket packet = new DatagramPacket(data, data.length, groupAddress, groupPort);
- broadcastingSocket.send(packet);
- }
-
- public byte[] receiveBroadcast() throws Exception
- {
- final byte[] data = new byte[65535];
- final DatagramPacket packet = new DatagramPacket(data, data.length);
-
- while (open)
- {
- try
- {
- receivingSocket.receive(packet);
- }
- // TODO: Do we need this?
- catch (InterruptedIOException e)
- {
- continue;
- }
- catch (IOException e)
- {
- if (open)
- {
- HornetQLogger.LOGGER.warn(this + " getting exception when receiving broadcasting.", e);
- }
- }
- break;
- }
- return data;
- }
-
- public byte[] receiveBroadcast(long time, TimeUnit unit) throws Exception
- {
- // We just use the regular method on UDP, there's no timeout support
- // and this is basically for tests only
- return receiveBroadcast();
- }
-
- public void openBroadcaster() throws Exception
- {
- if (localBindPort != -1)
- {
- broadcastingSocket = new DatagramSocket(localBindPort, localAddress);
- }
- else
- {
- if (localAddress != null)
- {
- HornetQLogger.LOGGER.broadcastGroupBindError();
- }
- broadcastingSocket = new DatagramSocket();
- }
-
- open = true;
- }
-
- public void openClient() throws Exception
- {
- // HORNETQ-874
- if (checkForLinux() || checkForSolaris() || checkForHp())
- {
- try
- {
- receivingSocket = new MulticastSocket(new InetSocketAddress(groupAddress, groupPort));
- }
- catch (IOException e)
- {
- HornetQLogger.LOGGER.ioDiscoveryError(groupAddress.getHostAddress(), groupAddress instanceof Inet4Address ? "IPv4" : "IPv6");
-
- receivingSocket = new MulticastSocket(groupPort);
- }
- }
- else
- {
- receivingSocket = new MulticastSocket(groupPort);
- }
-
- if (localAddress != null)
- {
- receivingSocket.setInterface(localAddress);
- }
-
- receivingSocket.joinGroup(groupAddress);
-
- receivingSocket.setSoTimeout(SOCKET_TIMEOUT);
-
- open = true;
- }
-
- //@Todo: using isBroadcast to share endpoint between broadcast and receiving
- public void close(boolean isBroadcast) throws Exception
- {
- open = false;
-
- if (broadcastingSocket != null)
- {
- broadcastingSocket.close();
- }
-
- if (receivingSocket != null)
- {
- receivingSocket.close();
- }
- }
-
- private static boolean checkForLinux()
- {
- return checkForPresence("os.name", "linux");
- }
-
- private static boolean checkForHp()
- {
- return checkForPresence("os.name", "hp");
- }
-
- private static boolean checkForSolaris()
- {
- return checkForPresence("os.name", "sun");
- }
-
- private static boolean checkForPresence(String key, String value)
- {
- try
- {
- String tmp=System.getProperty(key);
- return tmp != null && tmp.trim().toLowerCase().startsWith(value);
- }
- catch(Throwable t)
- {
- return false;
- }
- }
-
-}
60 hornetq-core/src/main/java/org/hornetq/api/core/UDPBroadcastEndpointFactory.java
View
@@ -1,60 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source.
-* Copyright 2010, Red Hat, Inc., and individual contributors
-* as indicated by the @author tags. See the copyright.txt file in the
-* distribution for a full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.hornetq.api.core;
-
-import java.net.InetAddress;
-
-/**
- * @author <a href="mailto:andy.taylor@jboss.org">Andy Taylor</a>
- * 9/25/12
- */
-public class UDPBroadcastEndpointFactory implements BroadcastEndpointFactory
-{
- private final String groupAddress;
- private final int groupPort;
- private final String localBindAddress;
- private final int localBindPort;
-
- public UDPBroadcastEndpointFactory(String groupAddress, int groupPort, String localBindAddress, int localBindPort)
- {
- this.groupAddress = groupAddress;
- this.groupPort = groupPort;
- this.localBindAddress = localBindAddress;
- this.localBindPort = localBindPort;
- }
-
- public BroadcastEndpoint createBroadcastEndpoint() throws Exception
- {
- return createUDPEndpoint(groupAddress != null ? InetAddress.getByName(groupAddress) : null, groupPort,
- localBindAddress != null ? InetAddress.getByName(localBindAddress) : null, localBindPort);
- }
-
-
- public static BroadcastEndpoint createUDPEndpoint(final InetAddress groupAddress,
- final int groupPort,
- final InetAddress localBindAddress,
- final int localBindPort) throws Exception
- {
- return new UDPBroadcastEndpoint(groupAddress, groupPort, localBindAddress, localBindPort);
- }
-
-}
198 hornetq-core/src/main/java/org/hornetq/api/core/UDPBroadcastGroupConfiguration.java
View
@@ -13,6 +13,19 @@
package org.hornetq.api.core;
+import java.io.IOException;
+import java.io.InterruptedIOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.Inet4Address;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.MulticastSocket;
+import java.net.UnknownHostException;
+import java.util.concurrent.TimeUnit;
+
+import org.hornetq.core.server.HornetQLogger;
+
/**
* The configuration used to determine how the server will broadcast members
@@ -48,7 +61,15 @@ public UDPBroadcastGroupConfiguration(final String groupAddress,
public BroadcastEndpointFactory createBroadcastEndpointFactory()
{
- return new UDPBroadcastEndpointFactory(groupAddress, groupPort, localBindAddress, localBindPort);
+ return new BroadcastEndpointFactory() {
+ @Override
+ public BroadcastEndpoint createBroadcastEndpoint() throws Exception {
+ return new UDPBroadcastEndpoint(groupAddress != null ? InetAddress.getByName(groupAddress) : null,
+ groupPort,
+ localBindAddress != null ? InetAddress.getByName(localBindAddress) : null,
+ localBindPort);
+ }
+ };
}
public String getGroupAddress()
@@ -70,4 +91,179 @@ public String getLocalBindAddress()
{
return localBindAddress;
}
+
+ /**
+ * <p> This is the member discovery implementation using direct UDP. It was extracted as a refactoring from
+ * {@link org.hornetq.core.cluster.DiscoveryGroup}</p>
+ * @author Tomohisa
+ * @author Howard Gao
+ * @author Clebert Suconic
+ */
+ private static class UDPBroadcastEndpoint implements BroadcastEndpoint
+ {
+ private static final int SOCKET_TIMEOUT = 500;
+
+ private final InetAddress localAddress;
+
+ private final int localBindPort;
+
+ private final InetAddress groupAddress;
+
+ private final int groupPort;
+
+ private DatagramSocket broadcastingSocket;
+
+ private MulticastSocket receivingSocket;
+
+ private volatile boolean open;
+
+ public UDPBroadcastEndpoint(final InetAddress groupAddress,
+ final int groupPort,
+ final InetAddress localBindAddress,
+ final int localBindPort) throws UnknownHostException
+ {
+ this.groupAddress = groupAddress;
+ this.groupPort = groupPort;
+ this.localAddress = localBindAddress;
+ this.localBindPort = localBindPort;
+ }
+
+
+ public void broadcast(byte[] data) throws Exception
+ {
+ DatagramPacket packet = new DatagramPacket(data, data.length, groupAddress, groupPort);
+ broadcastingSocket.send(packet);
+ }
+
+ public byte[] receiveBroadcast() throws Exception
+ {
+ final byte[] data = new byte[65535];
+ final DatagramPacket packet = new DatagramPacket(data, data.length);
+
+ while (open)
+ {
+ try
+ {
+ receivingSocket.receive(packet);
+ }
+ // TODO: Do we need this?
+ catch (InterruptedIOException e)
+ {
+ continue;
+ }
+ catch (IOException e)
+ {
+ if (open)
+ {
+ HornetQLogger.LOGGER.warn(this + " getting exception when receiving broadcasting.", e);
+ }
+ }
+ break;
+ }
+ return data;
+ }
+
+ public byte[] receiveBroadcast(long time, TimeUnit unit) throws Exception
+ {
+ // We just use the regular method on UDP, there's no timeout support
+ // and this is basically for tests only
+ return receiveBroadcast();
+ }
+
+ public void openBroadcaster() throws Exception
+ {
+ if (localBindPort != -1)
+ {
+ broadcastingSocket = new DatagramSocket(localBindPort, localAddress);
+ }
+ else
+ {
+ if (localAddress != null)
+ {
+ HornetQLogger.LOGGER.broadcastGroupBindError();
+ }
+ broadcastingSocket = new DatagramSocket();
+ }
+
+ open = true;
+ }
+
+ public void openClient() throws Exception
+ {
+ // HORNETQ-874
+ if (checkForLinux() || checkForSolaris() || checkForHp())
+ {
+ try
+ {
+ receivingSocket = new MulticastSocket(new InetSocketAddress(groupAddress, groupPort));
+ }
+ catch (IOException e)
+ {
+ HornetQLogger.LOGGER.ioDiscoveryError(groupAddress.getHostAddress(), groupAddress instanceof Inet4Address ? "IPv4" : "IPv6");
+
+ receivingSocket = new MulticastSocket(groupPort);
+ }
+ }
+ else
+ {
+ receivingSocket = new MulticastSocket(groupPort);
+ }
+
+ if (localAddress != null)
+ {
+ receivingSocket.setInterface(localAddress);
+ }
+
+ receivingSocket.joinGroup(groupAddress);
+
+ receivingSocket.setSoTimeout(SOCKET_TIMEOUT);
+
+ open = true;
+ }
+
+ //@Todo: using isBroadcast to share endpoint between broadcast and receiving
+ public void close(boolean isBroadcast) throws Exception
+ {
+ open = false;
+
+ if (broadcastingSocket != null)
+ {
+ broadcastingSocket.close();
+ }
+
+ if (receivingSocket != null)
+ {
+ receivingSocket.close();
+ }
+ }
+
+ private static boolean checkForLinux()
+ {
+ return checkForPresence("os.name", "linux");
+ }
+
+ private static boolean checkForHp()
+ {
+ return checkForPresence("os.name", "hp");
+ }
+
+ private static boolean checkForSolaris()
+ {
+ return checkForPresence("os.name", "sun");
+ }
+
+ private static boolean checkForPresence(String key, String value)
+ {
+ try
+ {
+ String tmp=System.getProperty(key);
+ return tmp != null && tmp.trim().toLowerCase().startsWith(value);
+ }
+ catch(Throwable t)
+ {
+ return false;
+ }
+ }
+
+ }
}
4 hornetq-core/src/main/java/org/hornetq/core/deployers/impl/FileConfigurationParser.java
View
@@ -994,7 +994,7 @@ private void parseBroadcastGroupConfiguration(final Element e, final Configurati
if (jgroupsFile != null)
{
- endpointFactoryConfiguration = new JGroupsBroadcastGroupConfigurationWithFile(jgroupsFile, jgroupsChannel);
+ endpointFactoryConfiguration = new JGroupsBroadcastGroupConfiguration(jgroupsFile, jgroupsChannel);
}
else
{
@@ -1036,7 +1036,7 @@ private void parseDiscoveryGroupConfiguration(final Element e, final Configurati
BroadcastEndpointFactoryConfiguration endpointFactoryConfiguration;
if (jgroupsFile != null)
{
- endpointFactoryConfiguration = new JGroupsBroadcastGroupConfigurationWithFile(jgroupsFile, jgroupsChannel);
+ endpointFactoryConfiguration = new JGroupsBroadcastGroupConfiguration(jgroupsFile, jgroupsChannel);
}
else
{
6 hornetq-ra/hornetq-ra-jar/src/main/java/org/hornetq/ra/HornetQResourceAdapter.java
View
@@ -36,7 +36,7 @@
import org.hornetq.api.core.BroadcastEndpointFactoryConfiguration;
import org.hornetq.api.core.DiscoveryGroupConfiguration;
import org.hornetq.api.core.HornetQException;
-import org.hornetq.api.core.JGroupsBroadcastGroupConfigurationWithFile;
+import org.hornetq.api.core.JGroupsBroadcastGroupConfiguration;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.UDPBroadcastGroupConfiguration;
import org.hornetq.api.core.client.ClientSession;
@@ -1833,7 +1833,7 @@ public HornetQConnectionFactory createHornetQConnectionFactory(final ConnectionF
}
else
{
- endpointFactoryConfiguration = new JGroupsBroadcastGroupConfigurationWithFile(jgroupsFileName, jgroupsChannel);
+ endpointFactoryConfiguration = new JGroupsBroadcastGroupConfiguration(jgroupsFileName, jgroupsChannel);
}
Long refreshTimeout = overrideProperties.getDiscoveryRefreshTimeout() != null ? overrideProperties.getDiscoveryRefreshTimeout()
@@ -1955,7 +1955,7 @@ public HornetQConnectionFactory createRecoveryHornetQConnectionFactory(final Con
}
else
{
- endpointFactoryConfiguration = new JGroupsBroadcastGroupConfigurationWithFile(jgroupsFileName, jgroupsChannel);
+ endpointFactoryConfiguration = new JGroupsBroadcastGroupConfiguration(jgroupsFileName, jgroupsChannel);
}
Long refreshTimeout = overrideProperties.getDiscoveryRefreshTimeout() != null ? overrideProperties.getDiscoveryRefreshTimeout()
8 tests/integration-tests/src/test/java/org/hornetq/tests/integration/discovery/DiscoveryTest.java
View
@@ -30,7 +30,7 @@
import org.hornetq.api.core.BroadcastEndpoint;
import org.hornetq.api.core.HornetQIllegalStateException;
-import org.hornetq.api.core.JGroupsBroadcastGroupConfigurationWithFile;
+import org.hornetq.api.core.JGroupsBroadcastGroupConfiguration;
import org.hornetq.api.core.SimpleString;
import org.hornetq.api.core.TransportConfiguration;
import org.hornetq.api.core.UDPBroadcastGroupConfiguration;
@@ -153,7 +153,7 @@ public void testSimpleBroadcastJGropus() throws Exception
final String nodeID = RandomUtil.randomString();
bg = new BroadcastGroupImpl(new FakeNodeManager(nodeID), "broadcast", 100, null,
- new JGroupsBroadcastGroupConfigurationWithFile("test-jgroups-file_ping.xml", "tst").createBroadcastEndpointFactory());
+ new JGroupsBroadcastGroupConfiguration("test-jgroups-file_ping.xml", "tst").createBroadcastEndpointFactory());
bg.start();
@@ -162,7 +162,7 @@ public void testSimpleBroadcastJGropus() throws Exception
bg.addConnector(live1);
dg = new DiscoveryGroup(nodeID + "1", "broadcast", 5000l,
- new JGroupsBroadcastGroupConfigurationWithFile("test-jgroups-file_ping.xml", "tst").createBroadcastEndpointFactory(),
+ new JGroupsBroadcastGroupConfiguration("test-jgroups-file_ping.xml", "tst").createBroadcastEndpointFactory(),
null);
dg.start();
@@ -183,7 +183,7 @@ public void testStraightSendReceiveJGroups() throws Exception
BroadcastEndpoint client = null;
try
{
- JGroupsBroadcastGroupConfigurationWithFile jgroupsConfig = new JGroupsBroadcastGroupConfigurationWithFile("test-jgroups-file_ping.xml", "tst");
+ JGroupsBroadcastGroupConfiguration jgroupsConfig = new JGroupsBroadcastGroupConfiguration("test-jgroups-file_ping.xml", "tst");
broadcaster = jgroupsConfig.createBroadcastEndpointFactory().createBroadcastEndpoint();
broadcaster.openBroadcaster();
Please sign in to comment.
Something went wrong with that request. Please try again.