private void setup ( final Handler < AsyncResult < Void > > doneHandler ) { // Retrieve the component context from the coordinator (the current cluster). // If the context has changed due to a network configuration change, the // internal context and input/output connections will be automatically updated. log . debug ( String . format ( "%s - Starting cluster coordination" , DefaultComponent . this ) ) ; coordinator . start ( new Handler < AsyncResult < Void > > ( ) { @ Override public void handle ( AsyncResult < Void > result ) { if ( result . failed ( ) ) { new DefaultFutureResult < Void > ( result . cause ( ) ) . setHandler ( doneHandler ) ; } else { // We have to make sure the input and output collectors are started // simultaneously in order to support circular connections. If both // input and output aren't started at the same time then circular // connections will never open. final CountingCompletionHandler < Void > ioHandler = new CountingCompletionHandler < Void > ( 2 ) ; ioHandler . setHandler ( new Handler < AsyncResult < Void > > ( ) { @ Override public void handle ( AsyncResult < Void > result ) { if ( result . failed ( ) ) { new DefaultFutureResult < Void > ( result . cause ( ) ) . setHandler ( doneHandler ) ; } else { // Tell the coordinator we're ready for the network to start. coordinator . resume ( ) ; } } } ) ; output . open ( new Handler < AsyncResult < Void > > ( ) { @ Override public void handle ( AsyncResult < Void > result ) { if ( result . failed ( ) ) { log . error ( String . format ( "%s - Failed to open component outputs" , DefaultComponent . this ) , result . cause ( ) ) ; ioHandler . fail ( result . cause ( ) ) ; } else { ioHandler . succeed ( ) ; } } } ) ; input . open ( new Handler < AsyncResult < Void > > ( ) { @ Override public void handle ( AsyncResult < Void > result ) { if ( result . failed ( ) ) { log . error ( String . format ( "%s - Failed to open component inputs" , DefaultComponent . this ) , result . cause ( ) ) ; ioHandler . fail ( result . cause ( ) ) ; } else { ioHandler . succeed ( ) ; } } } ) ; } } } ) ; // The resume handler will be called by the coordinator once the // network's manager has indicated that all the components in the // network have finished setting up their connections. coordinator . resumeHandler ( new Handler < Void > ( ) { @ Override @ SuppressWarnings ( "unchecked" ) public void handle ( Void _ ) { if ( ! started ) { started = true ; log . debug ( String . format ( "%s - Started" , DefaultComponent . this , context . component ( ) . name ( ) , context . number ( ) ) ) ; List < ComponentHook > hooks = context . component ( ) . hooks ( ) ; for ( ComponentHook hook : hooks ) { hook . handleStart ( DefaultComponent . this ) ; } new DefaultFutureResult < Void > ( ( Void ) null ) . setHandler ( doneHandler ) ; } } } ) ; }
Sets up the component .