public synchronized WorkManager createWorkManager ( String id , String name ) { if ( id == null || id . trim ( ) . equals ( "" ) ) throw new IllegalArgumentException ( "The id of WorkManager is invalid: " + id ) ; // Check for an active work manager if ( activeWorkmanagers . keySet ( ) . contains ( id ) ) { if ( trace ) log . tracef ( "RefCounting WorkManager: %s" , id ) ; Integer i = refCountWorkmanagers . get ( id ) ; refCountWorkmanagers . put ( id , Integer . valueOf ( i . intValue ( ) + 1 ) ) ; WorkManager wm = activeWorkmanagers . get ( id ) ; if ( wm instanceof DistributedWorkManager ) { DistributedWorkManager dwm = ( DistributedWorkManager ) wm ; if ( dwm . getTransport ( ) != null ) dwm . getTransport ( ) . register ( new Address ( wm . getId ( ) , wm . getName ( ) , dwm . getTransport ( ) . getId ( ) ) ) ; } return wm ; } try { // Create a new instance WorkManager template = null ; if ( name != null ) { template = workmanagers . get ( name ) ; } else { template = defaultWorkManager ; } if ( template == null ) throw new IllegalArgumentException ( "The WorkManager wasn't found: " + name ) ; WorkManager wm = template . clone ( ) ; wm . setId ( id ) ; if ( wm instanceof DistributedWorkManager ) { DistributedWorkManager dwm = ( DistributedWorkManager ) wm ; dwm . initialize ( ) ; if ( dwm . getTransport ( ) != null ) { dwm . getTransport ( ) . register ( new Address ( wm . getId ( ) , wm . getName ( ) , dwm . getTransport ( ) . getId ( ) ) ) ; try { ( ( DistributedWorkManager ) wm ) . getTransport ( ) . startup ( ) ; } catch ( Throwable t ) { throw new ApplicationServerInternalException ( "Unable to start the DWM Transport ID:" + ( ( DistributedWorkManager ) wm ) . getTransport ( ) . getId ( ) , t ) ; } } else { throw new ApplicationServerInternalException ( "DistributedWorkManager " + dwm . getName ( ) + " doesn't have a transport associated" ) ; } } activeWorkmanagers . put ( id , wm ) ; refCountWorkmanagers . put ( id , Integer . valueOf ( 1 ) ) ; if ( trace ) log . tracef ( "Created WorkManager: %s" , wm ) ; return wm ; } catch ( Throwable t ) { throw new IllegalStateException ( "The WorkManager couldn't be created: " + name , t ) ; } }
Create a work manager