本文整理汇总了Java中java.nio.channels.MembershipKey类的典型用法代码示例。如果您正苦于以下问题:Java MembershipKey类的具体用法?Java MembershipKey怎么用?Java MembershipKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MembershipKey类属于java.nio.channels包,在下文中一共展示了MembershipKey类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: closeMulticast
import java.nio.channels.MembershipKey; //导入依赖的package包/类
/**
* Leaves the group and closes the multicast socket.
*
* @throws IOException
* Error reading the address or leaving the group
*/
private void closeMulticast() throws IOException {
if (pChannel == null) {
// Nothing to do
return;
}
try {
// Leave the group, on all interfaces
for (final MembershipKey key : pJoinedGroups) {
key.drop();
}
} finally {
// Close the socket
pChannel.close();
}
}
开发者ID:cohorte,项目名称:cohorte-herald,代码行数:25,代码来源:MulticastHandler.java
示例2: closeMulticast
import java.nio.channels.MembershipKey; //导入依赖的package包/类
/**
* Leaves the group and closes the multicast socket.
*
* @throws IOException
* Error reading the address or leaving the group
*/
private void closeMulticast() throws IOException {
if (pChannel == null) {
// Nothing to do
return;
}
try {
// Leave the group, on all interfaces
for (final MembershipKey key : pJoinedGroups) {
key.drop();
}
} finally {
// Close the socket
pChannel.close();
}
}
开发者ID:cohorte,项目名称:cohorte-remote-services,代码行数:25,代码来源:MulticastHandler.java
示例3: leaveGroup
import java.nio.channels.MembershipKey; //导入依赖的package包/类
@Override
public ChannelFuture leaveGroup(
InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source,
ChannelPromise promise) {
checkJavaVersion();
if (multicastAddress == null) {
throw new NullPointerException("multicastAddress");
}
if (networkInterface == null) {
throw new NullPointerException("networkInterface");
}
synchronized (this) {
if (memberships != null) {
List<MembershipKey> keys = memberships.get(multicastAddress);
if (keys != null) {
Iterator<MembershipKey> keyIt = keys.iterator();
while (keyIt.hasNext()) {
MembershipKey key = keyIt.next();
if (networkInterface.equals(key.networkInterface())) {
if (source == null && key.sourceAddress() == null ||
source != null && source.equals(key.sourceAddress())) {
key.drop();
keyIt.remove();
}
}
}
if (keys.isEmpty()) {
memberships.remove(multicastAddress);
}
}
}
}
promise.setSuccess();
return promise;
}
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:40,代码来源:NioDatagramChannel.java
示例4: block
import java.nio.channels.MembershipKey; //导入依赖的package包/类
/**
* Block the given sourceToBlock address for the given multicastAddress on the given networkInterface
*/
@Override
public ChannelFuture block(
InetAddress multicastAddress, NetworkInterface networkInterface,
InetAddress sourceToBlock, ChannelPromise promise) {
checkJavaVersion();
if (multicastAddress == null) {
throw new NullPointerException("multicastAddress");
}
if (sourceToBlock == null) {
throw new NullPointerException("sourceToBlock");
}
if (networkInterface == null) {
throw new NullPointerException("networkInterface");
}
synchronized (this) {
if (memberships != null) {
List<MembershipKey> keys = memberships.get(multicastAddress);
for (MembershipKey key: keys) {
if (networkInterface.equals(key.networkInterface())) {
try {
key.block(sourceToBlock);
} catch (IOException e) {
promise.setFailure(e);
}
}
}
}
}
promise.setSuccess();
return promise;
}
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:37,代码来源:NioDatagramChannel.java
示例5: joinGroup
import java.nio.channels.MembershipKey; //导入依赖的package包/类
@Override
public ChannelFuture joinGroup(
InetAddress multicastAddress, NetworkInterface networkInterface,
InetAddress source, ChannelPromise promise) {
if (PlatformDependent.javaVersion() >= 7) {
if (multicastAddress == null) {
throw new NullPointerException("multicastAddress");
}
if (networkInterface == null) {
throw new NullPointerException("networkInterface");
}
try {
MembershipKey key;
if (source == null) {
key = javaChannel().join(multicastAddress, networkInterface);
} else {
key = javaChannel().join(multicastAddress, networkInterface, source);
}
synchronized (this) {
List<MembershipKey> keys = memberships.get(multicastAddress);
if (keys == null) {
keys = new ArrayList<MembershipKey>();
memberships.put(multicastAddress, keys);
}
keys.add(key);
}
promise.setSuccess();
} catch (Throwable e) {
promise.setFailure(e);
}
} else {
throw new UnsupportedOperationException();
}
return promise;
}
开发者ID:kyle-liu,项目名称:netty4study,代码行数:40,代码来源:NioDatagramChannel.java
示例6: leaveGroup
import java.nio.channels.MembershipKey; //导入依赖的package包/类
@Override
public ChannelFuture leaveGroup(
InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source,
ChannelPromise promise) {
if (PlatformDependent.javaVersion() < 7) {
throw new UnsupportedOperationException();
}
if (multicastAddress == null) {
throw new NullPointerException("multicastAddress");
}
if (networkInterface == null) {
throw new NullPointerException("networkInterface");
}
synchronized (this) {
if (memberships != null) {
List<MembershipKey> keys = memberships.get(multicastAddress);
if (keys != null) {
Iterator<MembershipKey> keyIt = keys.iterator();
while (keyIt.hasNext()) {
MembershipKey key = keyIt.next();
if (networkInterface.equals(key.networkInterface())) {
if (source == null && key.sourceAddress() == null ||
source != null && source.equals(key.sourceAddress())) {
key.drop();
keyIt.remove();
}
}
}
if (keys.isEmpty()) {
memberships.remove(multicastAddress);
}
}
}
}
promise.setSuccess();
return promise;
}
开发者ID:kyle-liu,项目名称:netty4study,代码行数:41,代码来源:NioDatagramChannel.java
示例7: block
import java.nio.channels.MembershipKey; //导入依赖的package包/类
/**
* Block the given sourceToBlock address for the given multicastAddress on the given networkInterface
*/
@Override
public ChannelFuture block(
InetAddress multicastAddress, NetworkInterface networkInterface,
InetAddress sourceToBlock, ChannelPromise promise) {
if (PlatformDependent.javaVersion() < 7) {
throw new UnsupportedOperationException();
} else {
if (multicastAddress == null) {
throw new NullPointerException("multicastAddress");
}
if (sourceToBlock == null) {
throw new NullPointerException("sourceToBlock");
}
if (networkInterface == null) {
throw new NullPointerException("networkInterface");
}
synchronized (this) {
if (memberships != null) {
List<MembershipKey> keys = memberships.get(multicastAddress);
for (MembershipKey key: keys) {
if (networkInterface.equals(key.networkInterface())) {
try {
key.block(sourceToBlock);
} catch (IOException e) {
promise.setFailure(e);
}
}
}
}
}
promise.setSuccess();
return promise;
}
}
开发者ID:kyle-liu,项目名称:netty4study,代码行数:39,代码来源:NioDatagramChannel.java
示例8: channelrecv
import java.nio.channels.MembershipKey; //导入依赖的package包/类
public channelrecv (String[] args) throws IOException
{
InetAddress group = InetAddress.getByName (this.group);
ProtocolFamily pf = group instanceof Inet4Address ? StandardProtocolFamily.INET : StandardProtocolFamily.INET6;
NetworkInterface ni = NetworkInterface.getByName (this.adapter);
if (null == ni) ni = NetworkInterface.getByInetAddress (InetAddress.getByName (this.adapter));
DatagramChannel dc = DatagramChannel.open (pf)
.setOption (StandardSocketOptions.SO_REUSEADDR, true)
.bind (new InetSocketAddress (this.port))
.setOption (StandardSocketOptions.IP_MULTICAST_IF, ni);
dc.configureBlocking (false);
@SuppressWarnings("unused")
MembershipKey key = dc.join (group, ni);
ByteBuffer buffer = ByteBuffer.allocateDirect (this.max_tpdu);
Selector selector = Selector.open();
@SuppressWarnings("unused")
SelectionKey sk = dc.register (selector, SelectionKey.OP_READ);
while (true) {
int keyCount = selector.select (1000);
if (keyCount > 0) {
selector.selectedKeys().clear();
SocketAddress source = dc.receive (buffer);
buffer.flip();
byte[] bytes = new byte[buffer.remaining()];
buffer.get (bytes, 0, bytes.length);
buffer.clear();
System.out.println ("packet: { " +
"\"src\": \"" + source + "\"" +
", \"data\": \"" + new String (bytes, 0, bytes.length) + "\"" +
", \"length\": " + bytes.length + "" +
" }");
}
}
}
开发者ID:steve-o,项目名称:javapgm,代码行数:36,代码来源:channelrecv.java
示例9: joinGroup
import java.nio.channels.MembershipKey; //导入依赖的package包/类
@Override
public ChannelFuture joinGroup(
InetAddress multicastAddress, NetworkInterface networkInterface,
InetAddress source, ChannelPromise promise) {
checkJavaVersion();
if (multicastAddress == null) {
throw new NullPointerException("multicastAddress");
}
if (networkInterface == null) {
throw new NullPointerException("networkInterface");
}
try {
MembershipKey key;
if (source == null) {
key = javaChannel().join(multicastAddress, networkInterface);
} else {
key = javaChannel().join(multicastAddress, networkInterface, source);
}
synchronized (this) {
List<MembershipKey> keys = null;
if (memberships == null) {
memberships = new HashMap<InetAddress, List<MembershipKey>>();
} else {
keys = memberships.get(multicastAddress);
}
if (keys == null) {
keys = new ArrayList<MembershipKey>();
memberships.put(multicastAddress, keys);
}
keys.add(key);
}
promise.setSuccess();
} catch (Throwable e) {
promise.setFailure(e);
}
return promise;
}
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:45,代码来源:NioDatagramChannel.java
示例10: join
import java.nio.channels.MembershipKey; //导入依赖的package包/类
@Override
public MembershipKey join(InetAddress arg0, NetworkInterface arg1)
throws IOException {
throw new UnsupportedOperationException();
}
开发者ID:alei121,项目名称:rawsocketspi,代码行数:6,代码来源:RSDatagramChannel.java
注:本文中的java.nio.channels.MembershipKey类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论