Publish Using Callback

Publishing in callback mode can be used in special cases, but is not recommended.

PublisherOptions.Builder builder = new PublisherOptions.Builder();
builder.setAccessMode(AccessMode.CALLBACK);
builder.setPulseInterval(pulseInterval);
PublisherOptions opts = builder.create();
	Publisher pub = project.createPublisher(opts);
	pub.setCallback(EnumSet.allOf(PublisherEvent.Type.class), new PublisherHandler(project));
	pub.connect();

PublisherHandler implements Callback<PublisherEvent>. It also implements two methods: getName() and processEvent(PublisherEvent event).

The script for implementing processEvent should look like this:

public void processEvent(PublisherEvent event) {
	 switch (event.getType()) {
		 case CONNECTED: 	mwriter = event.getPublisher().getMessageWriter(mstr);
				rowwriter = mwriter.getRelativeRowWriter(); break;
		 case READY: mwriter.startTransaction(0); 	
			 for (int j = 0; j < 100; ++j) {
			        mrowwriter.startRow(); 
			         mrowwriter.setOperation(Operation.INSERT);
			         for (int i = 0; i < mschema.getColumnCount(); ++i) {
				switch (mtypes[i]) {
				 case INTEGER: mrowwriter.setInteger(int_value++);break;
				case DOUBLE: mrowwriter.setDouble(double_value+=1.0); break;
				}
			          }//columns
			          mrowwriter.endRow();
			}//for
			 event.getPublisher().publish(mwriter);
		 case ERROR: break;
		case DISCONNECTD:break;
	}//switch
}//processEvent