当前位置: 首页>>代码示例>>Java>>正文


Java PipeWriter.blockWriteFragment方法代码示例

本文整理汇总了Java中com.ociweb.pronghorn.pipe.PipeWriter.blockWriteFragment方法的典型用法代码示例。如果您正苦于以下问题:Java PipeWriter.blockWriteFragment方法的具体用法?Java PipeWriter.blockWriteFragment怎么用?Java PipeWriter.blockWriteFragment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.ociweb.pronghorn.pipe.PipeWriter的用法示例。


在下文中一共展示了PipeWriter.blockWriteFragment方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: flush

import com.ociweb.pronghorn.pipe.PipeWriter; //导入方法依赖的package包/类
public void flush() {
	PipeWriter.blockWriteFragment(ringBuffer,0);
	RingStreams.writeEOF(ringBuffer);
}
 
开发者ID:oci-pronghorn,项目名称:PronghornPipes,代码行数:5,代码来源:AppendableASCIIRing.java

示例2: populateRingBufferWithSequence

import com.ociweb.pronghorn.pipe.PipeWriter; //导入方法依赖的package包/类
private void populateRingBufferWithSequence(Pipe<MessageSchemaDynamic> pipe, int testSize) {
	
    
    
	int j = testSize;
       while (true) {
       	
       	if (j==0) {
       		PipeWriter.publishEOF(pipe);
       		return;//done
       	}
       	        	
       	if (PipeWriter.tryWriteFragment(pipe, MSG_TRUCKS_LOC)) { //AUTO writes template id as needed

       		PipeWriter.writeASCII(pipe, SQUAD_NAME, "TheBobSquad");     		
       		
       		//WRITE THE FIRST MEMBER OF THE SEQ
       		//block to ensure we have room for the next fragment, and ensure that bytes consumed gets recorded
       		PipeWriter.blockWriteFragment(pipe, MSG_TRUCK_SEQ_LOC);//could use tryWrite here but it would make this example more complex
       		
       		PipeWriter.writeLong(pipe, SQUAD_TRUCK_ID, 10);         
       		PipeWriter.writeDecimal(pipe, TRUCK_CAPACITY, 2, 2000);
       		PipeWriter.writeInt(pipe, THING_NO_LOC, 1);
    
       		PipeWriter.blockWriteFragment(pipe, MSG_TRUCK_THING_SEQ_LOC);
       		PipeWriter.writeInt(pipe, THING_ID_LOC, 7);
       		//
       		
       		//WRITE THE SECOND MEMBER OF THE SEQ
       		//block to ensure we have room for the next fragment, and ensure that bytes consumed gets recorded
       		PipeWriter.blockWriteFragment(pipe, MSG_TRUCK_SEQ_LOC);
       		
       		PipeWriter.writeLong(pipe, SQUAD_TRUCK_ID, 11);
       		PipeWriter.writeDouble(pipe, TRUCK_CAPACITY, 30d, 2); //alternate way of writing a decimal
       		PipeWriter.writeInt(pipe, THING_NO_LOC, 1);
  
       		PipeWriter.blockWriteFragment(pipe, MSG_TRUCK_THING_SEQ_LOC);
       		PipeWriter.writeInt(pipe, THING_ID_LOC, 7);
       		
       		//NOTE: because we are waiting until the end of the  sequence to write its length we have two rules
       		//      1. Publish can not be called between these fragments because it will publish a zero for the count
       		//      2. The RingBuffer must be large enough to hold all the fragments in the sequence.
       		//      Neither one of these apply when the length can be set first.
       		
       		PipeWriter.writeInt(pipe, SQUAD_NO_MEMBERS, 2); //NOTE: we are writing this field very late because we now know how many we wrote.
       		
       		PipeWriter.blockWriteFragment(pipe, FRAG_JOMQ_LOC);
      		
       		PipeWriter.writeInt(pipe, JOMQ_LOC, 42);
       		
       		PipeWriter.publishWrites(pipe);
       		        		        		
       		 j--;       		
   		} else {
       		//Unable to write because there is no room so do something else while we are waiting.
       		Thread.yield();
       		
       	}     
       }
}
 
开发者ID:oci-pronghorn,项目名称:PronghornPipes,代码行数:61,代码来源:StreamingConsumerTest.java

示例3: pipeDataTest

import com.ociweb.pronghorn.pipe.PipeWriter; //导入方法依赖的package包/类
@Test
public void pipeDataTest() {
	
	
	Pipe pipe = TwitterEventSchema.instance.newPipe(10, 1000);
	pipe.initBuffers();
	
	PipeWriter.blockWriteFragment(pipe, TwitterEventSchema.MSG_USERPOST_101);
	
	PipeWriter.writeUTF8(pipe, TwitterEventSchema.MSG_USERPOST_101_FIELD_CREATEDAT_57, "this is todays date");
	PipeWriter.writeUTF8(pipe, TwitterEventSchema.MSG_USERPOST_101_FIELD_LANGUAGE_60, "en");
	PipeWriter.writeUTF8(pipe, TwitterEventSchema.MSG_USERPOST_101_FIELD_NAME_52, "name");
	
	PipeWriter.publishWrites(pipe);
	
	boolean ok = PipeReader.tryReadFragment(pipe);
	assertTrue(ok);
	
	String name = PipeReader.readUTF8(pipe, TwitterEventSchema.MSG_USERPOST_101_FIELD_NAME_52, new StringBuilder()).toString();
	String lang = PipeReader.readUTF8(pipe, TwitterEventSchema.MSG_USERPOST_101_FIELD_LANGUAGE_60, new StringBuilder()).toString();
	String create = PipeReader.readUTF8(pipe, TwitterEventSchema.MSG_USERPOST_101_FIELD_CREATEDAT_57, new StringBuilder()).toString();
	
	assertEquals("name",name);
	assertEquals("en",lang);
	assertEquals("this is todays date",create);
	
	
}
 
开发者ID:oci-pronghorn,项目名称:Pronghorn,代码行数:29,代码来源:OutOfOrderPipeTest.java

示例4: pipeDataTest2

import com.ociweb.pronghorn.pipe.PipeWriter; //导入方法依赖的package包/类
@Test
public void pipeDataTest2() {
	
	
	Pipe pipe = TwitterEventSchema.instance.newPipe(10, 1000);
	pipe.initBuffers();
	DataOutputBlobWriter writer = PipeWriter.outputStream(pipe);

	PipeWriter.blockWriteFragment(pipe, TwitterEventSchema.MSG_USERPOST_101);
	//PipeWriter.tryWriteFragment(pipe, TwitterEventSchema.MSG_USERPOST_101);
	
	DataOutputBlobWriter.openField(writer);
	writer.writeUTF8Text("this is todays date");
	DataOutputBlobWriter.closeHighLevelField(writer, TwitterEventSchema.MSG_USERPOST_101_FIELD_CREATEDAT_57);
			
	DataOutputBlobWriter.openField(writer);
	writer.writeUTF8Text("en");
	DataOutputBlobWriter.closeHighLevelField(writer, TwitterEventSchema.MSG_USERPOST_101_FIELD_LANGUAGE_60);
	
	DataOutputBlobWriter.openField(writer);
	writer.writeUTF8Text("name");
	DataOutputBlobWriter.closeHighLevelField(writer, TwitterEventSchema.MSG_USERPOST_101_FIELD_NAME_52);
	
	PipeWriter.publishWrites(pipe);

	PipeWriter.tryWriteFragment(pipe, TwitterEventSchema.MSG_USERPOST_101);
	
	DataOutputBlobWriter.openField(writer);
	writer.writeUTF8Text("2 this is todays date");
	DataOutputBlobWriter.closeHighLevelField(writer, TwitterEventSchema.MSG_USERPOST_101_FIELD_CREATEDAT_57);
			
	DataOutputBlobWriter.openField(writer);
	writer.writeUTF8Text("2 en");
	DataOutputBlobWriter.closeHighLevelField(writer, TwitterEventSchema.MSG_USERPOST_101_FIELD_LANGUAGE_60);
	
	DataOutputBlobWriter.openField(writer);
	writer.writeUTF8Text("2 name");
	DataOutputBlobWriter.closeHighLevelField(writer, TwitterEventSchema.MSG_USERPOST_101_FIELD_NAME_52);
	
	PipeWriter.publishWrites(pipe);
	
			
	assertTrue(PipeReader.tryReadFragment(pipe));
	
	assertEquals("name",PipeReader.readUTF8(pipe, TwitterEventSchema.MSG_USERPOST_101_FIELD_NAME_52, new StringBuilder()).toString());
	assertEquals("en",PipeReader.readUTF8(pipe, TwitterEventSchema.MSG_USERPOST_101_FIELD_LANGUAGE_60, new StringBuilder()).toString());
	assertEquals("this is todays date",PipeReader.readUTF8(pipe, TwitterEventSchema.MSG_USERPOST_101_FIELD_CREATEDAT_57, new StringBuilder()).toString());
	
	PipeReader.releaseReadLock(pipe);
	
	assertTrue(PipeReader.tryReadFragment(pipe));
	
	assertEquals("2 name",PipeReader.readUTF8(pipe, TwitterEventSchema.MSG_USERPOST_101_FIELD_NAME_52, new StringBuilder()).toString());
	assertEquals("2 en",PipeReader.readUTF8(pipe, TwitterEventSchema.MSG_USERPOST_101_FIELD_LANGUAGE_60, new StringBuilder()).toString());
	assertEquals("2 this is todays date",PipeReader.readUTF8(pipe, TwitterEventSchema.MSG_USERPOST_101_FIELD_CREATEDAT_57, new StringBuilder()).toString());
	
	PipeReader.releaseReadLock(pipe);
	
}
 
开发者ID:oci-pronghorn,项目名称:Pronghorn,代码行数:60,代码来源:OutOfOrderPipeTest.java


注:本文中的com.ociweb.pronghorn.pipe.PipeWriter.blockWriteFragment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。