本文整理汇总了Java中org.jgroups.util.Util.getIpStackType方法的典型用法代码示例。如果您正苦于以下问题:Java Util.getIpStackType方法的具体用法?Java Util.getIpStackType怎么用?Java Util.getIpStackType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jgroups.util.Util
的用法示例。
在下文中一共展示了Util.getIpStackType方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setDefaultValues
import org.jgroups.util.Util; //导入方法依赖的package包/类
public static void setDefaultValues(List<Protocol> protocols) throws Exception {
if(protocols == null)
return;
// check InetAddress related features of stack
Collection<InetAddress> addrs=getInetAddresses(protocols);
StackType ip_version=Util.getIpStackType(); // 0 = n/a, 4 = IPv4, 6 = IPv6
if(!addrs.isEmpty()) {
// check that all user-supplied InetAddresses have a consistent version:
// 1. If an addr is IPv6 and we have an IPv4 stack --> FAIL
// 2. If an address is an IPv4 class D (multicast) address and the stack is IPv6: FAIL
// Else pass
for(InetAddress addr : addrs) {
if(addr instanceof Inet6Address && ip_version == StackType.IPv4)
throw new IllegalArgumentException("found IPv6 address " + addr + " in an IPv4 stack");
if(addr instanceof Inet4Address && addr.isMulticastAddress() && ip_version == StackType.IPv6)
throw new Exception("found IPv4 multicast address " + addr + " in an IPv6 stack");
}
}
// process default values
setDefaultValues(protocols, ip_version);
}
示例2: setupProtocolStack
import org.jgroups.util.Util; //导入方法依赖的package包/类
/**
* The configuration string has a number of entries, separated by a ':' (colon).
* Each entry consists of the name of the protocol, followed by an optional configuration
* of that protocol. The configuration is enclosed in parentheses, and contains entries
* which are name/value pairs connected with an assignment sign (=) and separated by
* a semicolon.
* <pre>UDP(in_port=5555;out_port=4445):FRAG(frag_size=1024)</pre><p>
* The <em>first</em> entry defines the <em>bottommost</em> layer, the string is parsed
* left to right and the protocol stack constructed bottom up. Example: the string
* "UDP(in_port=5555):FRAG(frag_size=32000):DEBUG" results is the following stack:<pre>
*
* -----------------------
* | DEBUG |
* |-----------------------|
* | FRAG frag_size=32000 |
* |-----------------------|
* | UDP in_port=32000 |
* -----------------------
* </pre>
*/
public static Protocol setupProtocolStack(List<ProtocolConfiguration> protocol_configs, ProtocolStack st) throws Exception {
List<Protocol> protocols=createProtocols(protocol_configs, st);
if(protocols == null)
return null;
// check InetAddress related features of stack
Map<String, Map<String,InetAddressInfo>> inetAddressMap = createInetAddressMap(protocol_configs, protocols) ;
Collection<InetAddress> addrs=getAddresses(inetAddressMap);
StackType ip_version=Util.getIpStackType(); // 0 = n/a, 4 = IPv4, 6 = IPv6
if(!addrs.isEmpty()) {
// check that all user-supplied InetAddresses have a consistent version:
// 1. If an addr is IPv6 and we have an IPv4 stack --> FAIL
// 2. If an address is an IPv4 class D (multicast) address and the stack is IPv6: FAIL
// Else pass
for(InetAddress addr: addrs) {
if(addr instanceof Inet6Address && ip_version == StackType.IPv4)
throw new IllegalArgumentException("found IPv6 address " + addr + " in an IPv4 stack");
if(addr instanceof Inet4Address && addr.isMulticastAddress() && ip_version == StackType.IPv6)
throw new Exception("found IPv4 multicast address " + addr + " in an IPv6 stack");
}
}
// process default values
setDefaultValues(protocol_configs, protocols, ip_version);
ensureValidBindAddresses(protocols);
// Fixes NPE with concurrent channel creation when using a shared stack (https://issues.jboss.org/browse/JGRP-1488)
Protocol top_protocol=protocols.get(protocols.size() - 1);
top_protocol.setUpProtocol(st);
return connectProtocols(protocols);
}
示例3: startRouter
import org.jgroups.util.Util; //导入方法依赖的package包/类
@BeforeClass
void startRouter() throws Exception {
StackType type=Util.getIpStackType();
String bind_addr_str=type == StackType.IPv6? "::1" : "127.0.0.1";
bind_addr=InetAddress.getByName(bind_addr_str);
gossip_router_port=ResourceManager.getNextTcpPort(bind_addr);
gossip_router_hosts=bind_addr.getHostAddress() + "[" + gossip_router_port + "]";
gossipRouter=new GossipRouter(gossip_router_port, bind_addr_str);
gossipRouter.start();
}
示例4: initializeBase
import org.jgroups.util.Util; //导入方法依赖的package包/类
@BeforeClass
@Parameters(value = { "channel.conf", "use_blocking" })
protected void initializeBase(@Optional("udp.xml") String chconf, @Optional("false") String use_blocking) throws Exception {
log=LogFactory.getLog(this.getClass());
Test annotation = this.getClass().getAnnotation(Test.class);
// this should never ever happen!
if (annotation == null)
throw new Exception("Test is not marked with @Test annotation");
StackType type=Util.getIpStackType();
bind_addr=type == StackType.IPv6 ? "::1" : "127.0.0.1";
this.channel_conf = chconf;
bind_addr = Util.getProperty(new String[]{Global.BIND_ADDR}, null, "bind_addr", bind_addr);
System.setProperty(Global.BIND_ADDR, bind_addr);
}
示例5: setUp
import org.jgroups.util.Util; //导入方法依赖的package包/类
@BeforeClass
protected void setUp() throws Exception {
StackType type=Util.getIpStackType();
bind_addr_str=type == StackType.IPv6? "::1" : "127.0.0.1";
bind_addr=InetAddress.getByName(bind_addr_str);
gossip_router_port=ResourceManager.getNextTcpPort(bind_addr);
gossip_router_hosts=bind_addr.getHostAddress() + "[" + gossip_router_port + "]";
}
示例6: startRouter
import org.jgroups.util.Util; //导入方法依赖的package包/类
@BeforeClass
void startRouter() throws Exception {
String tmp=Util.getProperty(Global.BIND_ADDR);
if(tmp == null) {
StackType type=Util.getIpStackType();
tmp=type == StackType.IPv6? "::1" : "127.0.0.1";
}
bind_addr=InetAddress.getByName(tmp);
gossip_router_port=ResourceManager.getNextTcpPort(bind_addr);
gossipRouter=new GossipRouter(gossip_router_port, null);
gossipRouter.start();
}
示例7: setUp
import org.jgroups.util.Util; //导入方法依赖的package包/类
@BeforeMethod
void setUp() throws Exception {
StackType type=Util.getIpStackType();
if(type == StackType.IPv6)
bind_addr="::1";
else
bind_addr="127.0.0.1";
promise=new Promise<>();
gossip_router_port=ResourceManager.getNextTcpPort(InetAddress.getByName(bind_addr));
gossip_router_hosts=bind_addr + "[" + gossip_router_port + "]";
gossipRouter=new GossipRouter(gossip_router_port, bind_addr);
gossipRouter.start();
}
示例8: createStackConformantAddress
import org.jgroups.util.Util; //导入方法依赖的package包/类
private static IpAddress createStackConformantAddress(int port) throws UnknownHostException {
StackType type=Util.getIpStackType();
if(type == StackType.IPv6)
return new IpAddress("::1", port);
else
return new IpAddress("127.0.0.1", port);
}
示例9: convert
import org.jgroups.util.Util; //导入方法依赖的package包/类
public Object convert(Object obj, Class<?> propertyFieldType, String propertyName, String propertyValue, boolean check_scope) throws Exception {
if(propertyValue == null)
throw new NullPointerException("Property value cannot be null");
if(Boolean.TYPE.equals(propertyFieldType)) {
return Boolean.parseBoolean(propertyValue);
} else if (Integer.TYPE.equals(propertyFieldType)) {
// return Integer.parseInt(propertyValue);
return Util.readBytesInteger(propertyValue);
} else if (Long.TYPE.equals(propertyFieldType)) {
// return Long.parseLong(propertyValue);
return Util.readBytesLong(propertyValue);
} else if (Byte.TYPE.equals(propertyFieldType)) {
return Byte.parseByte(propertyValue);
} else if (Double.TYPE.equals(propertyFieldType)) {
// return Double.parseDouble(propertyValue);
return Util.readBytesDouble(propertyValue);
} else if (Short.TYPE.equals(propertyFieldType)) {
return Short.parseShort(propertyValue);
} else if (Float.TYPE.equals(propertyFieldType)) {
return Float.parseFloat(propertyValue);
} else if(InetAddress.class.equals(propertyFieldType)) {
InetAddress retval=null;
Util.AddressScope addr_scope=null;
try {
addr_scope=Util.AddressScope.valueOf(propertyValue.toUpperCase());
}
catch(Throwable ex) {
}
if(addr_scope != null)
retval=Util.getAddress(addr_scope);
else {
if(propertyValue.startsWith("match"))
retval=Util.getAddressByPatternMatch(propertyValue);
else
retval=InetAddress.getByName(propertyValue);
}
if(retval instanceof Inet4Address && retval.isMulticastAddress() && Util.getIpStackType() == StackType.IPv6) {
String tmp=prefix + propertyValue;
retval=InetAddress.getByName(tmp);
return retval;
}
if(check_scope && retval instanceof Inet6Address && retval.isLinkLocalAddress()) {
// check scope
Inet6Address addr=(Inet6Address)retval;
int scope=addr.getScopeId();
if(scope == 0) {
// fix scope
Inet6Address ret=getScopedInetAddress(addr);
if(ret != null) {
retval=ret;
}
}
}
return retval;
}
return propertyValue;
}
示例10: main
import org.jgroups.util.Util; //导入方法依赖的package包/类
public static void main(String[] args) {
InetAddress bind_addr=null;
List<InetAddress> addrs=new ArrayList<>();
int port=0;
int ttl=32;
long timeout=500;
final String DEFAULT_DIAG_ADDR="224.0.75.75";
final String DEFAULT_DIAG_ADDR_IPv6="ff0e::0:75:75";
final int DEFAULT_DIAG_PORT=7500;
List<String> query=new ArrayList<>();
String match=null;
boolean weed_out_duplicates=false;
String passcode=null;
try {
for(int i=0; i < args.length; i++) {
if("-addr".equals(args[i])) {
addrs.add(InetAddress.getByName(args[++i]));
continue;
}
if("-bind_addr".equals(args[i])) {
bind_addr=InetAddress.getByName(args[++i]);
continue;
}
if("-port".equals(args[i])) {
port=Integer.parseInt(args[++i]);
continue;
}
if("-ttl".equals(args[i])) {
ttl=Integer.parseInt(args[++i]);
continue;
}
if("-timeout".equals(args[i])) {
timeout=Long.parseLong(args[++i]);
continue;
}
if("-match".equals(args[i])) {
match=args[++i];
continue;
}
if("-weed_out_duplicates".equals(args[i])) {
weed_out_duplicates=true;
continue;
}
if("-passcode".equals(args[i])) {
passcode=args[++i];
continue;
}
if("-cluster".equals(args[i])) {
String cluster=args[++i];
query.add("cluster=" + cluster);
continue;
}
/* if("-node".equals(args[i])) {
String node=args[++i];
query.add("node=" + node);
continue;
}*/
if("-help".equals(args[i]) || "-h".equals(args[i]) || "--help".equals(args[i])) {
help();
return;
}
query.add(args[i]);
}
Probe p=new Probe();
if(addrs.isEmpty()) {
StackType stack_type=Util.getIpStackType();
boolean ipv6=stack_type == StackType.IPv6;
InetAddress addr=ipv6? InetAddress.getByName(DEFAULT_DIAG_ADDR_IPv6) : InetAddress.getByName(DEFAULT_DIAG_ADDR);
addrs.add(addr);
}
if(port == 0)
port=DEFAULT_DIAG_PORT;
p.start(addrs, bind_addr, port, ttl, timeout, query, match, weed_out_duplicates, passcode);
}
catch(Throwable t) {
t.printStackTrace();
}
}