本文整理汇总了Java中net.tomp2p.utils.Utils.nullCheck方法的典型用法代码示例。如果您正苦于以下问题:Java Utils.nullCheck方法的具体用法?Java Utils.nullCheck怎么用?Java Utils.nullCheck使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.tomp2p.utils.Utils
的用法示例。
在下文中一共展示了Utils.nullCheck方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: put
import net.tomp2p.utils.Utils; //导入方法依赖的package包/类
/**
* Stores the data either via put or putIfAbsent. This is an RPC.
*
* @param remotePeer
* The remote peer to store the data
* @param locationKey
* The location key
* @param domainKey
* The domain key
* @param dataMap
* The map with the content key and data
* @param type
* The type of put request, this depends on put/putIfAbsent/protected/not-protected
* @param signMessage
* Set to true to sign message
* @param channelCreator
* The channel creator
* @param forceUDP
* Set to true if the communication should be UDP, default is TCP
* @return FutureResponse that stores which content keys have been stored.
*/
/*
* private FutureResponse put(final PeerAddress remotePeer, final Number160 locationKey, final Number160 domainKey,
* final Map<Number160, Data> dataMap, final Type type, boolean signMessage, ChannelCreator channelCreator, boolean
* forceUDP, SenderCacheStrategy senderCacheStrategy) {
*/
private FutureResponse put(final PeerAddress remotePeer, final PutBuilder putBuilder, final Type type,
final ChannelCreator channelCreator) {
Utils.nullCheck(remotePeer, putBuilder.getLocationKey(), putBuilder.getDomainKey());
final DataMap dataMap;
if (putBuilder.getDataMap() != null) {
dataMap = new DataMap(putBuilder.getDataMap());
} else {
dataMap = new DataMap(putBuilder.getLocationKey(), putBuilder.getDomainKey(),
putBuilder.getDataMapContent());
}
final Message2 message = createMessage(remotePeer, COMMAND_PUT, type);
if (putBuilder.isSignMessage()) {
message.setPublicKeyAndSign(peerBean().getKeyPair());
}
message.setDataMap(dataMap);
final FutureResponse futureResponse = new FutureResponse(message);
final RequestHandler<FutureResponse> request = new RequestHandler<FutureResponse>(futureResponse,
peerBean(), connectionBean(), putBuilder);
if (!putBuilder.isForceUDP()) {
return request.sendTCP(channelCreator);
} else {
return request.sendUDP(channelCreator);
}
}
示例2: handleAdd
import net.tomp2p.utils.Utils; //导入方法依赖的package包/类
private Message2 handleAdd(final Message2 message, final Message2 responseMessage,
final boolean protectDomain) {
Utils.nullCheck(message.getDataMap(0));
final Collection<Number480> result = new HashSet<Number480>();
final DataMap dataMap = message.getDataMap(0);
final PublicKey publicKey = message.getPublicKey();
final boolean list = isList(message);
// here we set the map with the close peers. If we get data by a
// sender and the sender is closer than us, we assume that the sender has
// the data and we don't need to transfer data to the closest (sender)
// peer.
for (Map.Entry<Number480, Data> entry : dataMap.dataMap().entrySet()) {
Number160 contentKey = doAdd(protectDomain, entry, publicKey, list, peerBean());
if (contentKey != null) {
result.add(new Number480(entry.getKey().getLocationKey(), entry.getKey().getDomainKey(),
contentKey));
}
// check the responsibility of the newly added data, do something
// (notify) if we are responsible
if (result.size() > 0 && peerBean().replicationStorage() != null) {
peerBean().replicationStorage().updateAndNotifyResponsibilities(
entry.getKey().getLocationKey());
}
}
responseMessage.setKeys(new Keys(result));
return responseMessage;
}
示例3: addToTracker
import net.tomp2p.utils.Utils; //导入方法依赖的package包/类
public FutureResponse addToTracker(final PeerAddress remotePeer, AddTrackerBuilder builder,
ChannelCreator channelCreator) {
Utils.nullCheck(remotePeer, builder.getLocationKey(), builder.getDomainKey());
final Message2 message = createMessage(remotePeer, TRACKER_ADD_COMMAND,
builder.isPrimary() ? Type.REQUEST_3 : Type.REQUEST_1);
if (builder.isMessageSign()) {
message.setPublicKeyAndSign(peerBean().getKeyPair());
}
message.setKey(builder.getLocationKey());
message.setKey(builder.getDomainKey());
if (builder.getBloomFilter() != null) {
message.setBloomFilter(builder.getBloomFilter());
}
final FutureResponse futureResponse = new FutureResponse(message);
final TrackerRequest<FutureResponse> requestHandler = new TrackerRequest<FutureResponse>(
futureResponse, peerBean(), connectionBean(), message, builder.getLocationKey(),
builder.getDomainKey(), builder);
TrackerData trackerData = new TrackerData(new HashMap<PeerAddress, Data>(), null);
trackerData.put(peerBean().serverPeerAddress(), builder.getAttachement());
message.setTrackerData(trackerData);
if (builder.isForceTCP()) {
return requestHandler.sendTCP(channelCreator);
} else {
return requestHandler.sendUDP(channelCreator);
}
}
示例4: getFromTracker
import net.tomp2p.utils.Utils; //导入方法依赖的package包/类
public FutureResponse getFromTracker(final PeerAddress remotePeer, GetTrackerBuilder builder,
ChannelCreator channelCreator) {
//final Number160 locationKey,
//final Number160 domainKey, boolean expectAttachement, boolean signMessage,
//Set<Number160> knownPeers,
Utils.nullCheck(remotePeer, builder.getLocationKey(), builder.getDomainKey());
final Message2 message = createMessage(remotePeer, TRACKER_GET_COMMAND, Type.REQUEST_1);
if (builder.isSignMessage()) {
message.setPublicKeyAndSign(peerBean().getKeyPair());
}
message.setKey(builder.getLocationKey());
message.setKey(builder.getDomainKey());
//TODO: make this always a bloom filter
if (builder.getKnownPeers() != null && (builder.getKnownPeers() instanceof SimpleBloomFilter)) {
message.setBloomFilter((SimpleBloomFilter<Number160>) builder.getKnownPeers());
}
FutureResponse futureResponse = new FutureResponse(message);
final TrackerRequest<FutureResponse> requestHandler = new TrackerRequest<FutureResponse>(
futureResponse, peerBean(), connectionBean(), message, builder.getLocationKey(), builder.getDomainKey(), builder);
if ((builder.isExpectAttachement() || builder.isForceTCP())) {
return requestHandler.sendTCP(channelCreator);
} else {
return requestHandler.sendUDP(channelCreator);
}
}