public void publish ( final String channel , String message , final int ttl , OnPublishResult callback ) { // CAUSE: Assignment to method parameter final Pair < Boolean , String > sendValidation = isSendValid ( channel , message ) ; //String lMessage = message.replace("\n", "\\n"); if ( sendValidation != null && sendValidation . first ) { try { final String messageId = Strings . randomString ( 8 ) ; final ArrayList < Pair < String , String > > messagesToSend = multiPartMessage ( message , messageId ) ; CountDownTimer ackTimeout = new CountDownTimer ( this . publishTimeout , 100 ) { public void onTick ( long millisUntilFinished ) { } public void onFinish ( ) { if ( pendingPublishMessages . containsKey ( messageId ) ) { String err = String . format ( "Message publish timeout after %l seconds" , publishTimeout ) ; if ( pendingPublishMessages != null && ( ( HashMap ) pendingPublishMessages . get ( messageId ) ) . containsKey ( "callback" ) ) { OnPublishResult callbackP = ( OnPublishResult ) ( ( HashMap ) pendingPublishMessages . get ( messageId ) ) . get ( "callback" ) ; callbackP . run ( err , null ) ; pendingPublishMessages . remove ( messageId ) ; } pendingPublishMessages . remove ( messageId ) ; } } } . start ( ) ; Map pendingMsg = new HashMap ( ) ; pendingMsg . put ( "totalNumOfParts" , messagesToSend . size ( ) ) ; pendingMsg . put ( "callback" , callback ) ; pendingMsg . put ( "timeout" , ackTimeout ) ; this . pendingPublishMessages . put ( messageId , pendingMsg ) ; if ( messagesToSend . size ( ) < 20 ) { for ( Pair < String , String > messageToSend : messagesToSend ) { publish ( channel , messageToSend . second , ttl , messageToSend . first , sendValidation . second ) ; } } else { partSendInterval = new CountDownTimer ( messagesToSend . size ( ) * 100 , 100 ) { int partsSent = 0 ; public void onTick ( long millisUntilFinished ) { int currentPart = partsSent + 1 ; if ( isConnected ) { Pair < String , String > messageToSend = messagesToSend . get ( currentPart ) ; publish ( channel , messageToSend . second , ttl , messageToSend . first , sendValidation . second ) ; partsSent ++ ; } } public void onFinish ( ) { } } . start ( ) ; } } catch ( IOException e ) { raiseOrtcEvent ( EventEnum . OnException , this , e ) ; } } }
Publish a message to a channel .