public ApiFuture < String > publish ( PubsubMessage message ) { if ( shutdown . get ( ) ) { throw new IllegalStateException ( "Cannot publish on a shut-down publisher." ) ; } final OutstandingPublish outstandingPublish = new OutstandingPublish ( messageTransform . apply ( message ) ) ; List < OutstandingBatch > batchesToSend ; messagesBatchLock . lock ( ) ; try { batchesToSend = messagesBatch . add ( outstandingPublish ) ; // Setup the next duration based delivery alarm if there are messages batched. setupAlarm ( ) ; } finally { messagesBatchLock . unlock ( ) ; } messagesWaiter . incrementPendingMessages ( 1 ) ; if ( ! batchesToSend . isEmpty ( ) ) { for ( final OutstandingBatch batch : batchesToSend ) { logger . log ( Level . FINER , "Scheduling a batch for immediate sending." ) ; executor . execute ( new Runnable ( ) { @ Override public void run ( ) { publishOutstandingBatch ( batch ) ; } } ) ; } } return outstandingPublish . publishResult ; }
Schedules the publishing of a message . The publishing of the message may occur immediately or be delayed based on the publisher batching options .