@Override public void receive(Address sender, byte[] data, int offset, int length) { if (data == null || length <= 0) { // GEODE-1596 - check for empty messages return; } // drop message from self; it has already been looped back up // (https://issues.jboss.org/browse/JGRP-1765) if (local_physical_addr != null && local_physical_addr.equals(sender)) return; if (length - offset == 4 && data[offset] == 'p' && data[offset + 1] == 'i' && data[offset + 2] == 'n' && data[offset + 3] == 'g') { // AvailablePort check data[offset + 1] = 'o'; try { sendToSingleMember(sender, data, offset, length); } catch (Exception e) { log.fatal("Unable to respond to available-port check", e); } return; } super.receive(sender, data, offset, length); }
public void sendMulticast(byte[] data, int offset, int length) throws Exception { if(ip_mcast && mcast_addr != null) _send(mcast_addr.getIpAddress(), mcast_addr.getPort(), data, offset, length); else sendToMembers(members, data, offset, length); }
throw new IllegalArgumentException("bind_addr cannot be null") ; Util.checkIfValidAddress(bind_addr, getName()); if(log.isDebugEnabled()) log.debug("sockets will use interface " + bind_addr.getHostAddress()); sock=createMulticastSocketWithBindPort(); else sock=createMulticastSocket("jgroups.udp.sock", 0); setTimeToLive(ip_ttl, sock); mcast_sock=Util.createMulticastSocket(getSocketFactory(), "jgroups.udp.mcast_sock", mcast_group_addr, mcast_port, log); else mcast_sock=getSocketFactory().createMulticastSocket("jgroups.udp.mcast_sock", mcast_port); else interfaces=Util.getAllAvailableInterfaces(); bindToInterfaces(interfaces, mcast_sock, mcast_addr.getIpAddress()); setInterface(bind_addr, mcast_sock); // not strictly needed for receiving, only for sending of mcasts mcast_sock.joinGroup(mcast_group_addr); setBufferSizes(); log.debug("socket information:\n%s", dumpSocketInfo());
protected void destroySockets() { closeMulticastSocket(); closeUnicastSocket(); }
/** * Creates the unicast and multicast sockets and starts the unicast and multicast receiver threads */ public void start() throws Exception { try { createSockets(); super.start(); } catch(Exception ex) { destroySockets(); throw ex; } ucast_receivers=createReceivers(unicast_receiver_threads, sock, UCAST_NAME); if(ip_mcast) mcast_receivers=createReceivers(multicast_receiver_threads, mcast_sock, MCAST_NAME); }
sock=createDatagramSocketWithBindPort(); sock=createEphemeralDatagramSocket(); else interfaces=Util.getAllAvailableInterfaces(); bindToInterfaces(interfaces, mcast_sock, mcast_addr.getIpAddress()); setBufferSizes(); if(log.isDebugEnabled()) log.debug("socket information:\n" + dumpSocketInfo());
/** * Creates the unicast and multicast sockets and starts the unicast and multicast receiver threads */ public void start() throws Exception { if(log.isDebugEnabled()) log.debug("creating sockets and starting threads"); try { createSockets(); } catch(Exception ex) { String tmp="problem creating sockets (bind_addr=" + bind_addr + ", mcast_addr=" + mcast_addr + ")"; throw new Exception(tmp, ex); } super.start(); startThreads(); }
public void sendUnicast(PhysicalAddress dest, byte[] data, int offset, int length) throws Exception { _send(((IpAddress)dest).getIpAddress(), ((IpAddress)dest).getPort(), data, offset, length); }
/** * Closed UDP unicast and multicast sockets */ void closeSockets() { // 1. Close multicast socket closeMulticastSocket(); // 2. Close socket closeSocket(); }
void setBufferSizes() { if(sock != null) setBufferSize(sock, ucast_send_buf_size, ucast_recv_buf_size); if(mcast_sock != null) setBufferSize(mcast_sock, mcast_send_buf_size, mcast_recv_buf_size); }
protected void handleConfigEvent(Map<String,Object> map) { boolean set_buffers=false; if(map == null) return; if(map.containsKey("send_buf_size")) { mcast_send_buf_size=(Integer)map.get("send_buf_size"); ucast_send_buf_size=mcast_send_buf_size; set_buffers=true; } if(map.containsKey("recv_buf_size")) { mcast_recv_buf_size=(Integer)map.get("recv_buf_size"); ucast_recv_buf_size=mcast_recv_buf_size; set_buffers=true; } if(set_buffers) setBufferSizes(); }
protected void handleConnect() throws Exception { startThreads(); }
/** * Stops unicast and multicast receiver threads */ void stopThreads() { Thread tmp; // 1. Stop the multicast receiver thread if(mcast_receiver != null) { if(mcast_receiver.isAlive()) { tmp=mcast_receiver; mcast_receiver=null; closeMulticastSocket(); // will cause the multicast thread to terminate tmp.interrupt(); try { tmp.join(Global.THREAD_SHUTDOWN_WAIT_TIME); } catch(InterruptedException e) { Thread.currentThread().interrupt(); // set interrupt flag again } tmp=null; } mcast_receiver=null; } // 2. Stop the unicast receiver thread if(ucast_receiver != null) { ucast_receiver.stop(); ucast_receiver=null; } }
public void channelLookupTest() { when(mockChannel.getAddress()).thenReturn(a); when(mockChannel.down(isA(Event.class))).thenReturn(a); when(mockChannel.getView()).thenReturn(v); when(mockChannel.getProtocolStack()).thenReturn(ps); when(ps.getTransport()).thenReturn(new UDP()); EmbeddedCacheManager cm = null; try { GlobalConfigurationBuilder gc = GlobalConfigurationBuilder.defaultClusteredBuilder(); gc.transport().defaultTransport().addProperty("channelLookup", DummyLookup.class.getName()); cm = TestCacheManagerFactory.createClusteredCacheManager(gc, new ConfigurationBuilder()); cm.start(); cm.getCache(); GlobalComponentRegistry gcr = TestingUtil.extractGlobalComponentRegistry(cm); Transport t = gcr.getComponent(Transport.class); assertNotNull(t); assertTrue(t instanceof JGroupsTransport); assertNotSame(JChannel.class, ((JGroupsTransport) t).getChannel().getClass()); } finally { TestingUtil.killCacheManagers(cm); } }
/** * Creates the unicast and multicast sockets and starts the unicast and multicast receiver threads */ public void start() throws Exception { try { createSockets(); super.start(); } catch(Exception ex) { destroySockets(); throw ex; } ucast_receivers=createReceivers(unicast_receiver_threads, sock, UCAST_NAME); if(ip_mcast) mcast_receivers=createReceivers(multicast_receiver_threads, mcast_sock, MCAST_NAME); }
protected void destroySockets() { closeMulticastSocket(); closeUnicastSocket(); }
public void sendToAllMembers(byte[] data, int offset, int length) throws Exception { if(ip_mcast && mcast_addr != null) { _send(mcast_addr.getIpAddress(), mcast_addr.getPort(), true, data, offset, length); } else { ArrayList<Address> mbrs=new ArrayList<Address>(members); for(Address mbr: mbrs) { _send(((IpAddress)mbr).getIpAddress(), ((IpAddress)mbr).getPort(), false, data, offset, length); } } }
void setBufferSizes() { if(sock != null) setBufferSize(sock, ucast_send_buf_size, ucast_recv_buf_size); if(mcast_sock != null) setBufferSize(mcast_sock, mcast_send_buf_size, mcast_recv_buf_size); if(mcast_send_sockets != null) { for(int i=0; i < mcast_send_sockets.length; i++) { setBufferSize(mcast_send_sockets[i], mcast_send_buf_size, mcast_recv_buf_size); } } }