本文整理了Java中org.jgroups.protocols.UDP
类的一些代码示例,展示了UDP
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。UDP
类的具体详情如下:
包路径:org.jgroups.protocols.UDP
类名称:UDP
[英]IP multicast transport based on UDP. Messages to the group (msg.dest == null) will be multicast (to all group members), whereas point-to-point messages (msg.dest != null) will be unicast to a single member. Uses a multicast and a unicast socket.
The following properties are read by the UDP protocol:
代码示例来源:origin: apache/geode
@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);
}
代码示例来源:origin: wildfly/wildfly
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);
}
代码示例来源:origin: wildfly/wildfly
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());
代码示例来源:origin: wildfly/wildfly
protected void destroySockets() {
closeMulticastSocket();
closeUnicastSocket();
}
代码示例来源:origin: wildfly/wildfly
/**
* 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);
}
代码示例来源:origin: org.jgroups/com.springsource.org.jgroups
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());
代码示例来源:origin: org.jgroups/com.springsource.org.jgroups
/**
* 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();
}
代码示例来源:origin: wildfly/wildfly
public static void main(String[] args) throws Exception {
Protocol[] prot_stack={
new UDP().setValue("bind_addr", InetAddress.getByName("127.0.0.1")),
new PING(),
new MERGE3(),
代码示例来源:origin: wildfly/wildfly
public void sendUnicast(PhysicalAddress dest, byte[] data, int offset, int length) throws Exception {
_send(((IpAddress)dest).getIpAddress(), ((IpAddress)dest).getPort(), data, offset, length);
}
代码示例来源:origin: org.jgroups/com.springsource.org.jgroups
/**
* Closed UDP unicast and multicast sockets
*/
void closeSockets() {
// 1. Close multicast socket
closeMulticastSocket();
// 2. Close socket
closeSocket();
}
代码示例来源:origin: wildfly/wildfly
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);
}
代码示例来源:origin: wildfly/wildfly
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();
}
代码示例来源:origin: wildfly/wildfly
protected void handleConnect() throws Exception {
startThreads();
}
代码示例来源:origin: org.jgroups/com.springsource.org.jgroups
/**
* 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;
}
}
代码示例来源:origin: org.infinispan/infinispan-core
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);
}
}
代码示例来源:origin: org.jboss.eap/wildfly-client-all
/**
* 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);
}
代码示例来源:origin: org.jboss.eap/wildfly-client-all
protected void destroySockets() {
closeMulticastSocket();
closeUnicastSocket();
}
代码示例来源:origin: org.jboss.eap/wildfly-client-all
public static void main(String[] args) throws Exception {
Protocol[] prot_stack={
new UDP().setValue("bind_addr", InetAddress.getByName("127.0.0.1")),
new PING(),
new MERGE3(),
代码示例来源:origin: org.jgroups/com.springsource.org.jgroups
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);
}
}
}
代码示例来源:origin: org.jgroups/com.springsource.org.jgroups
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);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!