本文整理汇总了Java中com.ociweb.pronghorn.pipe.PipeWriter.writeSpecialBytesPosAndLen方法的典型用法代码示例。如果您正苦于以下问题:Java PipeWriter.writeSpecialBytesPosAndLen方法的具体用法?Java PipeWriter.writeSpecialBytesPosAndLen怎么用?Java PipeWriter.writeSpecialBytesPosAndLen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ociweb.pronghorn.pipe.PipeWriter
的用法示例。
在下文中一共展示了PipeWriter.writeSpecialBytesPosAndLen方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: publishOnPrivateTopic
import com.ociweb.pronghorn.pipe.PipeWriter; //导入方法依赖的package包/类
private boolean publishOnPrivateTopic(int token) {
//this is a private topic
Pipe<MessagePrivate> output = publishPrivateTopics.getPipe(token);
if (PipeWriter.tryWriteFragment(output, MessagePrivate.MSG_PUBLISH_1)) {
PipeWriter.writeSpecialBytesPosAndLen(output, MessagePrivate.MSG_PUBLISH_1_FIELD_PAYLOAD_3, -1, 0);
PipeWriter.publishWrites(output);
return true;
} else {
return false;
}
}
示例2: requestConnect
import com.ociweb.pronghorn.pipe.PipeWriter; //导入方法依赖的package包/类
public static boolean requestConnect(CharSequence url, int conFlags, byte[] willTopic, int willTopicIdx,
int willTopicLength, int willTopicMask, byte[] willMessageBytes, int willMessageBytesIdx,
int willMessageBytesLength, int willMessageBytesMask, byte[] username, byte[] passwordBytes,
Pipe<MQTTConnectionInSchema> toBroker, byte[] clientId, int ttlSec) {
if (PipeWriter.tryWriteFragment(toBroker, MQTTConnectionInSchema.MSG_CONNECT_2)) {
PipeWriter.writeASCII(toBroker, MQTTConnectionInSchema.MSG_CONNECT_2_FIELD_HOST_401, url);
//this is the high level API however we are writing bytes to to the end of the unstructured buffer.
final int bytePos = Pipe.getWorkingBlobHeadPosition(toBroker);
byte[] byteBuffer = Pipe.blob(toBroker);
int byteMask = Pipe.blobMask(toBroker);
int len = buildConnectPacket(bytePos, byteBuffer, byteMask, ttlSec, conFlags,
clientId, 0 , clientId.length, 0xFFFF,
willTopic, willTopicIdx , willTopicLength, willTopicMask,
willMessageBytes, willMessageBytesIdx, willMessageBytesLength, willMessageBytesMask,
username, 0, username.length, 0xFFFF, //TODO: add rest of fields
passwordBytes, 0, passwordBytes.length, 0xFFFF);//TODO: add rest of fields
assert(len>0);
PipeWriter.writeSpecialBytesPosAndLen(toBroker, MQTTConnectionInSchema.MSG_CONNECT_2_FIELD_PACKETDATA_300, len, bytePos);
PipeWriter.publishWrites(toBroker);
return true;
} else {
return false;
}
}
示例3: requestPublish
import com.ociweb.pronghorn.pipe.PipeWriter; //导入方法依赖的package包/类
public static int requestPublish(byte[] topic, int topicIdx, int topicLength, int topicMask, int qualityOfService,
int retain, byte[] payload, int payloadIdx, int payloadLength, int payloadMask,
Pipe<MQTTConnectionInSchema> toBroker, IdGenCache genCache, Pipe<MQTTIdRangeSchema> idGenIn) {
boolean hasId = hasPacketId(genCache, idGenIn);
if (!hasId) {
return -1;
}
////
if (PipeWriter.tryWriteFragment(toBroker, MQTTConnectionInSchema.MSG_PUBLISH_1)) {
PipeWriter.writeInt(toBroker, MQTTConnectionInSchema.MSG_PUBLISH_1_FIELD_QOS_100, qualityOfService);
int localPacketId = (0==qualityOfService) ? -1 : IdGenCache.nextPacketId(genCache);
PipeWriter.writeInt(toBroker, MQTTConnectionInSchema.MSG_PUBLISH_1_FIELD_PACKETID_200, localPacketId);
final int bytePos = Pipe.getWorkingBlobHeadPosition(toBroker);
byte[] byteBuffer = Pipe.blob(toBroker);
int byteMask = Pipe.blobMask(toBroker);
int len = buildPublishPacket(bytePos, byteBuffer, byteMask, qualityOfService, retain,
topic, topicIdx, topicLength, topicMask,
payload, payloadIdx, payloadLength, payloadMask, localPacketId);
PipeWriter.writeSpecialBytesPosAndLen(toBroker, MQTTConnectionInSchema.MSG_PUBLISH_1_FIELD_PACKETDATA_300, len, bytePos);
PipeWriter.publishWrites(toBroker);
return localPacketId<0 ? 0 : localPacketId;//NOTE: we have no id for qos 0
} else {
return -1;
}
}
示例4: requestConnect
import com.ociweb.pronghorn.pipe.PipeWriter; //导入方法依赖的package包/类
protected boolean requestConnect(CharSequence url, int conFlags, byte[] willTopic, int willTopicIdx, int willTopicLength, int willTopicMask,
byte[] willMessageBytes, int willMessageBytesIdx, int willMessageBytesLength, int willMessageBytesMask,
byte[] username, byte[] passwordBytes) {
if (PipeWriter.tryWriteFragment(toCon, ConInConst.MSG_CON_IN_CONNECT)) {
PipeWriter.writeASCII(toCon, ConInConst.CON_IN_CONNECT_FIELD_URL, url);
//this is the high level API however we are writing bytes to to the end of the unstructured buffer.
final int bytePos = Pipe.bytesWorkingHeadPosition(toCon);
byte[] byteBuffer = Pipe.byteBuffer(toCon);
int byteMask = Pipe.blobMask(toCon);
int len = MQTTEncoder.buildConnectPacket(bytePos, byteBuffer, byteMask, ttlSec, conFlags,
clientId, 0 , clientId.length, 0xFFFF,
willTopic, willTopicIdx , willTopicLength, willTopicMask,
willMessageBytes, willMessageBytesIdx, willMessageBytesLength, willMessageBytesMask,
username, 0, username.length, 0xFFFF, //TODO: add rest of fields
passwordBytes, 0, passwordBytes.length, 0xFFFF);//TODO: add rest of fields
assert(len>0);
PipeWriter.writeSpecialBytesPosAndLen(toCon, ConInConst.CON_IN_CONNECT_FIELD_PACKETDATA, len, bytePos);
PipeWriter.publishWrites(toCon);
return true;
} else {
return false;
}
}
示例5: requestPublish
import com.ociweb.pronghorn.pipe.PipeWriter; //导入方法依赖的package包/类
protected int requestPublish(byte[] topic, int topicIdx, int topicLength, int topicMask,
int qualityOfService, int retain,
byte[] payload, int payloadIdx, int payloadLength, int payloadMask) {
if (nextFreePacketId >= nextFreePacketIdLimit) {
//get next range
if (Pipe.hasContentToRead(idGenIn, sizeOfPacketIdFragment)) {
loadNextPacketIdRange();
} else {
return -1;
}
}
////
if (PipeWriter.tryWriteFragment(toCon, ConInConst.MSG_CON_IN_PUBLISH)) {
PipeWriter.writeInt(toCon, ConInConst.CON_IN_PUBLISH_FIELD_QOS, qualityOfService);
int localPacketId = (0==qualityOfService) ? -1 : nextFreePacketId++;
PipeWriter.writeInt(toCon, ConInConst.CON_IN_PUBLISH_FIELD_PACKETID, localPacketId);
final int bytePos = Pipe.bytesWorkingHeadPosition(toCon);
byte[] byteBuffer = Pipe.byteBuffer(toCon);
int byteMask = Pipe.blobMask(toCon);
int len = MQTTEncoder.buildPublishPacket(bytePos, byteBuffer, byteMask, qualityOfService, retain,
topic, topicIdx, topicLength, topicMask,
payload, payloadIdx, payloadLength, payloadMask, localPacketId);
PipeWriter.writeSpecialBytesPosAndLen(toCon, ConInConst.CON_IN_PUBLISH_FIELD_PACKETDATA, len, bytePos);
PipeWriter.publishWrites(toCon);
return localPacketId<0 ? 0 : localPacketId;//TODO: we have no id for qos 0 this is dirty.
} else {
return -1;
}
}
示例6: run
import com.ociweb.pronghorn.pipe.PipeWriter; //导入方法依赖的package包/类
@Override
public void run() {
while ( PipeWriter.hasRoomForFragmentOfSize(toCon, sizeOfPubRel) && PipeReader.tryReadFragment(fromCon)) {
int msgIdx = PipeReader.getMsgIdx(fromCon);
System.out.println("got message: "+msgIdx);
int packetId;
switch(msgIdx) {
case ConOutConst.MSG_CON_OUT_CONNACK_OK:
newConnection();
break;
case ConOutConst.MSG_CON_OUT_CONNACK_ID:
case ConOutConst.MSG_CON_OUT_CONNACK_AUTH:
case ConOutConst.MSG_CON_OUT_CONNACK_PROTO:
case ConOutConst.MSG_CON_OUT_CONNACK_SERVER:
case ConOutConst.MSG_CON_OUT_CONNACK_USER:
newConnectionError(msgIdx);
break;
case ConOutConst.MSG_CON_OUT_PUB_REL:
packetId = PipeReader.readInt(fromCon, ConOutConst.CON_OUT_PUB_REL_FIELD_PACKETID);
//subscriber logic
//TODO: now send pubcomp message to be sent
break;
case ConOutConst.MSG_CON_OUT_PUB_ACK:
packetId = PipeReader.readInt(fromCon, ConOutConst.CON_OUT_PUB_ACK_FIELD_PACKETID);
//System.out.println("ack packet "+packetId+" "+fromCon);
ackReceived1(packetId);
break;
case ConOutConst.MSG_CON_OUT_PUB_REC:
System.out.println("ZZZZZZZZZZZZZZZZZZZZZZZZZZZzz Got PubRec fromserver ");
packetId = PipeReader.readInt(fromCon, ConOutConst.CON_OUT_PUB_REC_FIELD_PACKETID);
System.out.println("for packet:"+packetId);
ackReceived2(packetId);
if (!PipeWriter.tryWriteFragment(toCon, ConInConst.MSG_CON_IN_PUB_REL)) {
throw new UnsupportedOperationException("Expected room in pipe due to the hasRoomForFragmentOfSize check.");
}
PipeWriter.writeInt(toCon, ConInConst.CON_IN_PUB_REL_FIELD_PACKETID, packetId);
final int bytePos = Pipe.bytesWorkingHeadPosition(toCon);
byte[] byteBuffer = Pipe.byteBuffer(toCon);
int byteMask = Pipe.blobMask(toCon);
int len = MQTTEncoder.buildPubRelPacket(bytePos, byteBuffer, byteMask, packetId);
PipeWriter.writeSpecialBytesPosAndLen(toCon, ConInConst.CON_IN_PUB_REL_FIELD_PACKETDATA, len, bytePos);
PipeWriter.publishWrites(toCon);
break;
default:
throw new UnsupportedOperationException("Unknown Mesage: "+msgIdx);
}
PipeReader.releaseReadLock(fromCon);
}
businessLogic();
}