private synchronized Long getAvailableTxId ( ) throws TCAPException { if ( this . dialogs . size ( ) >= this . stack . getMaxDialogs ( ) ) throw new TCAPException ( "Current dialog count exceeds its maximum value" ) ; while ( true ) { // Long id; // if (!currentDialogId.compareAndSet(this.stack.getDialogIdRangeEnd(), this.stack.getDialogIdRangeStart() + 1)) { // id = currentDialogId.getAndIncrement(); // } else { // id = this.stack.getDialogIdRangeStart(); // } // if (checkAvailableTxId(id)) // return id; if ( this . curDialogId < this . stack . getDialogIdRangeStart ( ) ) this . curDialogId = this . stack . getDialogIdRangeStart ( ) - 1 ; if ( ++ this . curDialogId > this . stack . getDialogIdRangeEnd ( ) ) this . curDialogId = this . stack . getDialogIdRangeStart ( ) ; Long id = this . curDialogId ; if ( checkAvailableTxId ( id ) ) return id ; } }
some help methods ... crude but will work for first impl .