idx
int64
0
165k
question
stringlengths
73
4.15k
target
stringlengths
5
918
len_question
int64
21
890
len_target
int64
3
255
14,800
public static synchronized void unknownCCMConnection ( String poolName , Object mcp , Object cl , Object connection , String key ) { log . tracef ( "%s" , new TraceEvent ( poolName , Integer . toHexString ( System . identityHashCode ( mcp ) ) , TraceEvent . UNKNOWN_CCM_CONNECTION , Integer . toHexString ( System . identityHashCode ( cl ) ) , Integer . toHexString ( System . identityHashCode ( connection ) ) , key ) ) ; }
Unknown CCM connection
113
4
14,801
public static synchronized void closeCCMConnection ( String poolName , Object mcp , Object cl , Object connection , String key ) { log . tracef ( "%s" , new TraceEvent ( poolName , Integer . toHexString ( System . identityHashCode ( mcp ) ) , TraceEvent . CLOSE_CCM_CONNECTION , Integer . toHexString ( System . identityHashCode ( cl ) ) , Integer . toHexString ( System . identityHashCode ( connection ) ) , key ) ) ; }
Close CCM connection
113
4
14,802
public static synchronized void ccmUserTransaction ( String poolName , Object mcp , Object cl , Object connection , String key ) { log . tracef ( "%s" , new TraceEvent ( poolName , Integer . toHexString ( System . identityHashCode ( mcp ) ) , TraceEvent . CCM_USER_TRANSACTION , Integer . toHexString ( System . identityHashCode ( cl ) ) , Integer . toHexString ( System . identityHashCode ( connection ) ) , key ) ) ; }
CCM user transaction
112
4
14,803
public < T > T lookup ( String name , Class < T > expectedType ) throws Throwable { if ( name == null ) throw new IllegalArgumentException ( "Name is null" ) ; if ( expectedType == null ) throw new IllegalArgumentException ( "ExpectedType is null" ) ; if ( ! started ) throw new IllegalStateException ( "Container not started" ) ; return kernel . getBean ( name , expectedType ) ; }
Lookup a bean
96
4
14,804
private void removeDeployment ( File deployment ) throws IOException { if ( deployment == null ) throw new IllegalArgumentException ( "Deployment is null" ) ; if ( deployment . exists ( ) || ( shrinkwrapDeployments != null && shrinkwrapDeployments . contains ( deployment ) ) ) { shrinkwrapDeployments . remove ( deployment ) ; if ( shrinkwrapDeployments . isEmpty ( ) ) shrinkwrapDeployments = null ; recursiveDelete ( deployment ) ; } }
Remove ShrinkWrap deployment
99
7
14,805
public String getValue ( ) { return StringUtils . isEmptyTrimmed ( resolvedValue ) ? ( StringUtils . isEmptyTrimmed ( defaultValue ) ? "" : defaultValue ) : resolvedValue ; }
Resolves the expression
47
4
14,806
private Context currentContext ( ) { LinkedList < Context > stack = threadContexts . get ( ) ; if ( stack != null && ! stack . isEmpty ( ) ) { return stack . getLast ( ) ; } return null ; }
Look at the current context
51
5
14,807
private boolean closeAll ( Context context ) { boolean unclosed = false ; CloseConnectionSynchronization ccs = getCloseConnectionSynchronization ( true ) ; for ( org . ironjacamar . core . connectionmanager . ConnectionManager cm : context . getConnectionManagers ( ) ) { for ( org . ironjacamar . core . connectionmanager . listener . ConnectionListener cl : context . getConnectionListeners ( cm ) ) { for ( Object c : context . getConnections ( cl ) ) { if ( ccs == null ) { unclosed = true ; if ( Tracer . isEnabled ( ) ) { Tracer . closeCCMConnection ( cl . getManagedConnectionPool ( ) . getPool ( ) . getConfiguration ( ) . getId ( ) , cl . getManagedConnectionPool ( ) , cl , c , context . toString ( ) ) ; } closeConnection ( c ) ; } else { ccs . add ( c ) ; } } } } return unclosed ; }
Close all connections for a context
210
6
14,808
private CloseConnectionSynchronization getCloseConnectionSynchronization ( boolean createIfNotFound ) { try { Transaction tx = null ; if ( transactionIntegration != null ) tx = transactionIntegration . getTransactionManager ( ) . getTransaction ( ) ; if ( tx != null && TxUtils . isActive ( tx ) ) { CloseConnectionSynchronization ccs = ( CloseConnectionSynchronization ) transactionIntegration . getTransactionSynchronizationRegistry ( ) . getResource ( CLOSE_CONNECTION_SYNCHRONIZATION ) ; if ( ccs == null && createIfNotFound ) { ccs = new CloseConnectionSynchronization ( ) ; transactionIntegration . getTransactionSynchronizationRegistry ( ) . putResource ( CLOSE_CONNECTION_SYNCHRONIZATION , ccs ) ; transactionIntegration . getTransactionSynchronizationRegistry ( ) . registerInterposedSynchronization ( ccs ) ; } return ccs ; } } catch ( Throwable t ) { log . debug ( "Unable to synchronize with transaction" , t ) ; } return null ; }
Get the CloseConnectionSynchronization instance
238
8
14,809
private void closeConnection ( Object connectionHandle ) { try { Throwable exception = null ; synchronized ( connectionStackTraces ) { exception = connectionStackTraces . remove ( connectionHandle ) ; } Method m = SecurityActions . getMethod ( connectionHandle . getClass ( ) , "close" , new Class [ ] { } ) ; try { if ( exception != null ) { log . closingConnection ( connectionHandle , exception ) ; } else { log . closingConnection ( connectionHandle ) ; } m . invoke ( connectionHandle , new Object [ ] { } ) ; } catch ( Throwable t ) { log . closingConnectionThrowable ( t ) ; } } catch ( NoSuchMethodException nsme ) { log . closingConnectionNoClose ( connectionHandle . getClass ( ) . getName ( ) ) ; } }
Close connection handle
171
3
14,810
public static boolean isActive ( Transaction tx ) { if ( tx == null ) return false ; try { int status = tx . getStatus ( ) ; return status == Status . STATUS_ACTIVE ; } catch ( SystemException error ) { throw new RuntimeException ( "Error during isActive()" , error ) ; } }
Is the transaction active
68
4
14,811
public static boolean isUncommitted ( Transaction tx ) { if ( tx == null ) return false ; try { int status = tx . getStatus ( ) ; return status == Status . STATUS_ACTIVE || status == Status . STATUS_MARKED_ROLLBACK ; } catch ( SystemException error ) { throw new RuntimeException ( "Error during isUncommitted()" , error ) ; } }
Is the transaction uncommitted
87
5
14,812
public static boolean isCompleted ( Transaction tx ) { if ( tx == null ) return true ; try { int status = tx . getStatus ( ) ; return status == Status . STATUS_COMMITTED || status == Status . STATUS_ROLLEDBACK || status == Status . STATUS_NO_TRANSACTION ; } catch ( SystemException error ) { throw new RuntimeException ( "Error during isCompleted()" , error ) ; } }
Is the transaction completed
95
4
14,813
public static String getStatusAsString ( int status ) { if ( status >= Status . STATUS_ACTIVE && status <= Status . STATUS_ROLLING_BACK ) { return TX_STATUS_STRINGS [ status ] ; } else { return "STATUS_INVALID(" + status + ")" ; } }
Converts a transaction status to a text representation
70
9
14,814
public void store ( Activations metadata , XMLStreamWriter writer ) throws Exception { if ( metadata != null && writer != null ) { writer . writeStartElement ( XML . ELEMENT_RESOURCE_ADAPTERS ) ; for ( Activation a : metadata . getActivations ( ) ) { writer . writeStartElement ( XML . ELEMENT_RESOURCE_ADAPTER ) ; if ( a . getId ( ) != null ) writer . writeAttribute ( XML . ATTRIBUTE_ID , a . getValue ( XML . ATTRIBUTE_ID , a . getId ( ) ) ) ; writer . writeStartElement ( XML . ELEMENT_ARCHIVE ) ; writer . writeCharacters ( a . getValue ( XML . ELEMENT_ARCHIVE , a . getArchive ( ) ) ) ; writer . writeEndElement ( ) ; storeCommon ( a , writer ) ; writer . writeEndElement ( ) ; } writer . writeEndElement ( ) ; } }
Store a - ra . xml file
206
7
14,815
public int compareTo ( Object o ) { MBeanData md = ( MBeanData ) o ; String d1 = objectName . getDomain ( ) ; String d2 = md . objectName . getDomain ( ) ; int compare = d1 . compareTo ( d2 ) ; if ( compare == 0 ) { String p1 = objectName . getCanonicalKeyPropertyListString ( ) ; String p2 = md . objectName . getCanonicalKeyPropertyListString ( ) ; compare = p1 . compareTo ( p2 ) ; } return compare ; }
Compares MBeanData based on the ObjectName domain name and canonical key properties
124
17
14,816
public static ConnectionManager createConnectionManager ( TransactionSupportEnum tse , ManagedConnectionFactory mcf , CachedConnectionManager ccm , ConnectionManagerConfiguration cmc , TransactionIntegration ti ) { if ( tse == TransactionSupportEnum . NoTransaction ) { return new NoTransactionConnectionManager ( mcf , ccm , cmc ) ; } else if ( tse == TransactionSupportEnum . LocalTransaction ) { return new LocalTransactionConnectionManager ( mcf , ccm , cmc , ti ) ; } else { return new XATransactionConnectionManager ( mcf , ccm , cmc , ti ) ; } }
Create a connection manager
133
4
14,817
public static MBeanServer getMBeanServer ( String domain ) { try { ArrayList < MBeanServer > l = MBeanServerFactory . findMBeanServer ( null ) ; if ( l != null ) { for ( MBeanServer ms : l ) { String [ ] domains = ms . getDomains ( ) ; if ( domains != null ) { for ( String d : domains ) { if ( domain . equals ( d ) ) { return ms ; } } } } } } catch ( SecurityException se ) { // Ignore } return null ; }
Get the MBeanServer instance
122
7
14,818
public static MBeanData getMBeanData ( String name ) throws JMException { MBeanServer server = getMBeanServer ( ) ; ObjectName objName = new ObjectName ( name ) ; MBeanInfo info = server . getMBeanInfo ( objName ) ; return new MBeanData ( objName , info ) ; }
Get MBean data
77
5
14,819
public static Object getMBeanAttributeObject ( String name , String attrName ) throws JMException { MBeanServer server = getMBeanServer ( ) ; ObjectName objName = new ObjectName ( name ) ; return server . getAttribute ( objName , attrName ) ; }
Get MBean attribute object
63
6
14,820
public static String getMBeanAttribute ( String name , String attrName ) throws JMException { MBeanServer server = getMBeanServer ( ) ; ObjectName objName = new ObjectName ( name ) ; String value = null ; try { Object attr = server . getAttribute ( objName , attrName ) ; if ( attr != null ) value = attr . toString ( ) ; } catch ( JMException e ) { value = e . getMessage ( ) ; } return value ; }
Get MBean attribute
110
5
14,821
public static AttrResultInfo getMBeanAttributeResultInfo ( String name , MBeanAttributeInfo attrInfo ) throws JMException { ClassLoader loader = SecurityActions . getThreadContextClassLoader ( ) ; MBeanServer server = getMBeanServer ( ) ; ObjectName objName = new ObjectName ( name ) ; String attrName = attrInfo . getName ( ) ; String attrType = attrInfo . getType ( ) ; Object value = null ; Throwable throwable = null ; if ( attrInfo . isReadable ( ) ) { try { value = server . getAttribute ( objName , attrName ) ; } catch ( Throwable t ) { throwable = t ; } } Class typeClass = null ; try { typeClass = Classes . getPrimitiveTypeForName ( attrType ) ; if ( typeClass == null ) typeClass = loader . loadClass ( attrType ) ; } catch ( ClassNotFoundException cnfe ) { // Ignore } PropertyEditor editor = null ; if ( typeClass != null ) editor = PropertyEditorManager . findEditor ( typeClass ) ; return new AttrResultInfo ( attrName , editor , value , throwable ) ; }
Get MBean attribute result info
263
7
14,822
public static AttributeList setAttributes ( String name , HashMap attributes ) throws JMException { MBeanServer server = getMBeanServer ( ) ; ObjectName objName = new ObjectName ( name ) ; MBeanInfo info = server . getMBeanInfo ( objName ) ; MBeanAttributeInfo [ ] attributesInfo = info . getAttributes ( ) ; AttributeList newAttributes = new AttributeList ( ) ; for ( int a = 0 ; a < attributesInfo . length ; a ++ ) { MBeanAttributeInfo attrInfo = attributesInfo [ a ] ; String attrName = attrInfo . getName ( ) ; if ( ! attributes . containsKey ( attrName ) ) continue ; String value = ( String ) attributes . get ( attrName ) ; if ( value . equals ( "null" ) && server . getAttribute ( objName , attrName ) == null ) { if ( trace ) log . trace ( "ignoring 'null' for " + attrName ) ; continue ; } String attrType = attrInfo . getType ( ) ; Attribute attr = null ; try { Object realValue = PropertyEditors . convertValue ( value , attrType ) ; attr = new Attribute ( attrName , realValue ) ; } catch ( ClassNotFoundException e ) { if ( trace ) log . trace ( "Failed to load class for attribute: " + attrType , e ) ; throw new ReflectionException ( e , "Failed to load class for attribute: " + attrType ) ; } catch ( IntrospectionException e ) { if ( trace ) log . trace ( "Skipped setting attribute: " + attrName + ", cannot find PropertyEditor for type: " + attrType ) ; continue ; } server . setAttribute ( objName , attr ) ; newAttributes . add ( attr ) ; } return newAttributes ; }
Set MBean attributes
412
5
14,823
public static OpResultInfo invokeOp ( String name , int index , String [ ] args ) throws JMException { MBeanServer server = getMBeanServer ( ) ; ObjectName objName = new ObjectName ( name ) ; MBeanInfo info = server . getMBeanInfo ( objName ) ; MBeanOperationInfo [ ] opInfo = info . getOperations ( ) ; MBeanOperationInfo op = opInfo [ index ] ; MBeanParameterInfo [ ] paramInfo = op . getSignature ( ) ; String [ ] argTypes = new String [ paramInfo . length ] ; for ( int p = 0 ; p < paramInfo . length ; p ++ ) argTypes [ p ] = paramInfo [ p ] . getType ( ) ; return invokeOpByName ( name , op . getName ( ) , argTypes , args ) ; }
Invoke an operation
187
4
14,824
public static OpResultInfo invokeOpByName ( String name , String opName , String [ ] argTypes , String [ ] args ) throws JMException { MBeanServer server = getMBeanServer ( ) ; ObjectName objName = new ObjectName ( name ) ; int length = argTypes != null ? argTypes . length : 0 ; Object [ ] typedArgs = new Object [ length ] ; for ( int p = 0 ; p < typedArgs . length ; p ++ ) { String arg = args [ p ] ; try { Object argValue = PropertyEditors . convertValue ( arg , argTypes [ p ] ) ; typedArgs [ p ] = argValue ; } catch ( ClassNotFoundException e ) { if ( trace ) log . trace ( "Failed to load class for arg" + p , e ) ; throw new ReflectionException ( e , "Failed to load class for arg" + p ) ; } catch ( java . beans . IntrospectionException e ) { // If the type is not java.lang.Object throw an exception if ( ! argTypes [ p ] . equals ( "java.lang.Object" ) ) throw new javax . management . IntrospectionException ( "Failed to find PropertyEditor for type: " + argTypes [ p ] ) ; // Just use the String arg typedArgs [ p ] = arg ; continue ; } } Object opReturn = server . invoke ( objName , opName , typedArgs , argTypes ) ; return new OpResultInfo ( opName , argTypes , args , opReturn ) ; }
Invoke an operation by name
332
6
14,825
@ Override public List < ConnectionDefinition > getConnectionDefinitions ( ) { if ( connectionDefinitions == null ) return null ; return Collections . unmodifiableList ( connectionDefinitions ) ; }
Get the connectionFactories .
41
6
14,826
@ Override public List < AdminObject > getAdminObjects ( ) { return adminObjects == null ? null : Collections . unmodifiableList ( adminObjects ) ; }
Get the adminObjects .
38
6
14,827
@ Override public Map < String , String > getConfigProperties ( ) { return configProperties == null ? null : Collections . unmodifiableMap ( configProperties ) ; }
Get the configProperties .
39
6
14,828
@ Override public List < String > getBeanValidationGroups ( ) { return beanValidationGroups == null ? null : Collections . unmodifiableList ( beanValidationGroups ) ; }
Get the beanValidationGroups .
44
8
14,829
public void addProvider ( UserTransactionProvider provider ) { UserTransactionProviderImpl impl = new UserTransactionProviderImpl ( provider ) ; delegator . addProvider ( impl ) ; providers . put ( provider , impl ) ; }
Add a provider
45
3
14,830
public void removeProvider ( UserTransactionProvider provider ) { UserTransactionProviderImpl impl = providers . get ( provider ) ; if ( impl != null ) { delegator . removeProvider ( impl ) ; providers . remove ( provider ) ; } }
Remove a provider
49
3
14,831
public void setDefaultGroups ( String [ ] value ) { if ( value != null ) { defaultGroups = Arrays . copyOf ( value , value . length ) ; } else { defaultGroups = null ; } }
Set the default groups
48
4
14,832
public static org . ironjacamar . core . connectionmanager . pool . Capacity create ( org . ironjacamar . common . api . metadata . common . Capacity metadata , ClassLoaderPlugin classLoaderPlugin ) { if ( metadata == null ) return DefaultCapacity . INSTANCE ; CapacityIncrementer incrementer = null ; CapacityDecrementer decrementer = null ; // Incrementer if ( metadata . getIncrementer ( ) != null && metadata . getIncrementer ( ) . getClassName ( ) != null ) { incrementer = loadIncrementer ( metadata . getIncrementer ( ) , classLoaderPlugin ) ; if ( incrementer != null ) { injectProperties ( metadata . getIncrementer ( ) . getConfigPropertiesMap ( ) , incrementer ) ; } else { log . invalidCapacityIncrementer ( metadata . getIncrementer ( ) . getClassName ( ) ) ; } } if ( incrementer == null ) incrementer = DefaultCapacity . DEFAULT_INCREMENTER ; // Decrementer if ( metadata . getDecrementer ( ) != null && metadata . getDecrementer ( ) . getClassName ( ) != null ) { decrementer = loadDecrementer ( metadata . getDecrementer ( ) , classLoaderPlugin ) ; if ( decrementer != null ) { injectProperties ( metadata . getDecrementer ( ) . getConfigPropertiesMap ( ) , decrementer ) ; } else { // Explicit allow TimedOutDecrementer, MinPoolSizeDecrementer and SizeDecrementer for CRI based pools if ( TimedOutDecrementer . class . getName ( ) . equals ( metadata . getDecrementer ( ) . getClassName ( ) ) || TimedOutFIFODecrementer . class . getName ( ) . equals ( metadata . getDecrementer ( ) . getClassName ( ) ) || MinPoolSizeDecrementer . class . getName ( ) . equals ( metadata . getDecrementer ( ) . getClassName ( ) ) || SizeDecrementer . class . getName ( ) . equals ( metadata . getDecrementer ( ) . getClassName ( ) ) ) { decrementer = loadDecrementer ( metadata . getDecrementer ( ) , classLoaderPlugin ) ; injectProperties ( metadata . getDecrementer ( ) . getConfigPropertiesMap ( ) , decrementer ) ; } else { log . invalidCapacityDecrementer ( metadata . getDecrementer ( ) . getClassName ( ) ) ; } } } if ( decrementer == null ) decrementer = DefaultCapacity . DEFAULT_DECREMENTER ; return new ExplicitCapacity ( incrementer , decrementer ) ; }
Create a capacity instance based on the metadata
592
8
14,833
private static CapacityIncrementer loadIncrementer ( Extension incrementer , ClassLoaderPlugin classLoaderPlugin ) { Object result = loadExtension ( incrementer , classLoaderPlugin ) ; if ( result != null && result instanceof CapacityIncrementer ) { return ( CapacityIncrementer ) result ; } log . debugf ( "%s wasn't a CapacityIncrementer" , incrementer . getClassName ( ) ) ; return null ; }
Load the incrementer
93
4
14,834
private static CapacityDecrementer loadDecrementer ( Extension decrementer , ClassLoaderPlugin classLoaderPlugin ) { Object result = loadExtension ( decrementer , classLoaderPlugin ) ; if ( result != null && result instanceof CapacityDecrementer ) { return ( CapacityDecrementer ) result ; } log . debugf ( "%s wasn't a CapacityDecrementer" , decrementer . getClassName ( ) ) ; return null ; }
Load the decrementer
96
5
14,835
private static Object loadExtension ( Extension extension , ClassLoaderPlugin classLoaderPlugin ) { try { Class < ? > c = classLoaderPlugin . loadClass ( extension . getClassName ( ) , extension . getModuleName ( ) , extension . getModuleSlot ( ) ) ; return c . newInstance ( ) ; } catch ( Throwable t ) { log . tracef ( "Throwable while loading %s using own classloader: %s" , extension . getClassName ( ) , t . getMessage ( ) ) ; } return null ; }
Load the class
116
3
14,836
private void getPropsString ( StringBuilder strProps , List < ConfigPropType > propsList , int indent ) { for ( ConfigPropType props : propsList ) { for ( int i = 0 ; i < indent ; i ++ ) strProps . append ( " " ) ; strProps . append ( "<config-property name=\"" ) ; strProps . append ( props . getName ( ) ) ; strProps . append ( "\">" ) ; strProps . append ( props . getValue ( ) ) ; strProps . append ( "</config-property>" ) ; strProps . append ( "\n" ) ; } }
generate properties String
142
4
14,837
public static TransactionIsolation forName ( String v ) { if ( v != null && ! v . trim ( ) . equals ( "" ) ) { if ( "TRANSACTION_READ_UNCOMMITTED" . equalsIgnoreCase ( v ) || "1" . equalsIgnoreCase ( v ) ) { return TRANSACTION_READ_UNCOMMITTED ; } else if ( "TRANSACTION_READ_COMMITTED" . equalsIgnoreCase ( v ) || "2" . equalsIgnoreCase ( v ) ) { return TRANSACTION_READ_COMMITTED ; } else if ( "TRANSACTION_REPEATABLE_READ" . equalsIgnoreCase ( v ) || "4" . equalsIgnoreCase ( v ) ) { return TRANSACTION_REPEATABLE_READ ; } else if ( "TRANSACTION_SERIALIZABLE" . equalsIgnoreCase ( v ) || "8" . equalsIgnoreCase ( v ) ) { return TRANSACTION_SERIALIZABLE ; } else if ( "TRANSACTION_NONE" . equalsIgnoreCase ( v ) || "0" . equalsIgnoreCase ( v ) ) { return TRANSACTION_NONE ; } } return null ; }
Static method to get an instance
270
6
14,838
public boolean start ( String home , File options ) { File homeDirectory = new File ( home ) ; if ( ! homeDirectory . exists ( ) ) return false ; stop ( home ) ; try { List < String > command = new ArrayList < String > ( ) ; command . add ( java ) ; command . add ( "-Dironjacamar.home=" + home ) ; if ( options != null && options . exists ( ) ) command . add ( "-Dironjacamar.options=" + options . getAbsolutePath ( ) ) ; command . add ( "-Djava.net.preferIPv4Stack=true" ) ; command . add ( "-Djgroups.bind_addr=127.0.0.1" ) ; command . add ( "-Dorg.jboss.logging.Logger.pluginClass=org.jboss.logging.logmanager.LoggerPluginImpl" ) ; command . add ( "-Dlog4j.defaultInitOverride=true" ) ; command . add ( "-jar" ) ; command . add ( home + "/bin/ironjacamar-sjc.jar" ) ; ProcessBuilder pb = new ProcessBuilder ( command ) ; pb . redirectErrorStream ( true ) ; Map < String , String > environment = pb . environment ( ) ; environment . put ( "ironjacamar.home" , home ) ; Process p = pb . start ( ) ; instances . put ( home , p ) ; return true ; } catch ( Throwable t ) { // Ignore } return false ; }
Start an instance
332
3
14,839
public int stop ( String home ) { Process p = instances . get ( home ) ; if ( p != null ) { try { p . destroy ( ) ; return p . exitValue ( ) ; } catch ( Throwable t ) { return - 1 ; } finally { instances . remove ( home ) ; } } return 0 ; }
Stop an instance
69
3
14,840
public void registerBootstrapContext ( CloneableBootstrapContext bc ) { if ( bc != null ) { if ( bc . getName ( ) == null || bc . getName ( ) . trim ( ) . equals ( "" ) ) throw new IllegalArgumentException ( "The name of BootstrapContext is invalid: " + bc ) ; if ( ! bootstrapContexts . keySet ( ) . contains ( bc . getName ( ) ) ) { bootstrapContexts . put ( bc . getName ( ) , bc ) ; } } }
Register bootstrap context
115
4
14,841
public void unregisterBootstrapContext ( CloneableBootstrapContext bc ) { if ( bc != null ) { if ( bc . getName ( ) == null || bc . getName ( ) . trim ( ) . equals ( "" ) ) throw new IllegalArgumentException ( "The name of BootstrapContext is invalid: " + bc ) ; if ( bootstrapContexts . keySet ( ) . contains ( bc . getName ( ) ) ) { bootstrapContexts . remove ( bc . getName ( ) ) ; } } }
Unregister boostrap context
113
5
14,842
public void setDefaultBootstrapContext ( CloneableBootstrapContext bc ) { if ( trace ) log . tracef ( "Default BootstrapContext: %s" , bc ) ; String currentName = null ; if ( defaultBootstrapContext != null ) currentName = defaultBootstrapContext . getName ( ) ; defaultBootstrapContext = bc ; if ( bc != null ) { bootstrapContexts . put ( bc . getName ( ) , bc ) ; } else if ( currentName != null ) { bootstrapContexts . remove ( currentName ) ; } }
Set the default bootstrap context
120
6
14,843
public synchronized CloneableBootstrapContext createBootstrapContext ( String id , String name ) { if ( id == null || id . trim ( ) . equals ( "" ) ) throw new IllegalArgumentException ( "The id of BootstrapContext is invalid: " + id ) ; // Check for an active BC if ( activeBootstrapContexts . keySet ( ) . contains ( id ) ) { Integer i = refCountBootstrapContexts . get ( id ) ; refCountBootstrapContexts . put ( id , Integer . valueOf ( i . intValue ( ) + 1 ) ) ; return activeBootstrapContexts . get ( id ) ; } try { // Create a new instance CloneableBootstrapContext template = null ; if ( name != null ) { template = bootstrapContexts . get ( name ) ; } else { template = defaultBootstrapContext ; } if ( template == null ) throw new IllegalArgumentException ( "The BootstrapContext wasn't found: " + name ) ; CloneableBootstrapContext bc = template . clone ( ) ; bc . setId ( id ) ; org . ironjacamar . core . api . workmanager . WorkManager wm = workManagerCoordinator . createWorkManager ( id , bc . getWorkManagerName ( ) ) ; bc . setWorkManager ( wm ) ; activeBootstrapContexts . put ( id , bc ) ; refCountBootstrapContexts . put ( id , Integer . valueOf ( 1 ) ) ; if ( trace ) log . tracef ( "Created BootstrapContext: %s" , bc ) ; return bc ; } catch ( Throwable t ) { throw new IllegalStateException ( "The BootstrapContext couldn't be created: " + name , t ) ; } }
Get a bootstrap context
373
5
14,844
public synchronized void removeBootstrapContext ( String id ) { if ( id == null || id . trim ( ) . equals ( "" ) ) throw new IllegalArgumentException ( "The id of BootstrapContext is invalid: " + id ) ; Integer i = refCountBootstrapContexts . get ( id ) ; if ( i != null ) { int newValue = i . intValue ( ) - 1 ; if ( newValue == 0 ) { CloneableBootstrapContext cbc = activeBootstrapContexts . remove ( id ) ; refCountBootstrapContexts . remove ( id ) ; cbc . shutdown ( ) ; workManagerCoordinator . removeWorkManager ( id ) ; } else { refCountBootstrapContexts . put ( id , Integer . valueOf ( newValue ) ) ; } } }
Remove a bootstrap context
172
5
14,845
public static Janitor createJanitor ( String type ) { if ( type == null || type . equals ( "" ) ) return new MinimalJanitor ( ) ; type = type . toLowerCase ( Locale . US ) ; switch ( type ) { case "minimal" : return new MinimalJanitor ( ) ; case "full" : return new FullJanitor ( ) ; default : { return new MinimalJanitor ( ) ; } } }
Create a janitor
96
4
14,846
static Properties getSystemProperties ( ) { return ( Properties ) AccessController . doPrivileged ( new PrivilegedAction < Object > ( ) { public Object run ( ) { return System . getProperties ( ) ; } } ) ; }
Get the system properties
50
4
14,847
static URLClassLoader createURLCLassLoader ( final URL [ ] urls , final ClassLoader parent ) { return ( URLClassLoader ) AccessController . doPrivileged ( new PrivilegedAction < Object > ( ) { public Object run ( ) { return new URLClassLoader ( urls , parent ) ; } } ) ; }
Create an URLClassLoader
69
5
14,848
private static String readStreamIntoString ( Reader reader ) throws IOException { StringBuilder s = new StringBuilder ( ) ; char a [ ] = new char [ 0x10000 ] ; while ( true ) { int l = reader . read ( a ) ; if ( l == - 1 ) break ; if ( l <= 0 ) throw new IOException ( ) ; s . append ( a , 0 , l ) ; } return s . toString ( ) ; }
Reads the contents of a stream into a string variable .
97
12
14,849
public static FileWriter createSrcFile ( String name , String packageName , String outDir ) throws IOException { String directory = "src" + File . separatorChar + "main" + File . separatorChar + "java" ; return createPackageFile ( name , packageName , directory , outDir ) ; }
Create source file
68
3
14,850
private static FileWriter createPackageFile ( String name , String packageName , String directory , String outDir ) throws IOException { if ( packageName != null && ! packageName . trim ( ) . equals ( "" ) ) { directory = directory + File . separatorChar + packageName . replace ( ' ' , File . separatorChar ) ; } File path = new File ( outDir , directory ) ; if ( ! path . exists ( ) ) { if ( ! path . mkdirs ( ) ) throw new IOException ( "outdir can't be created" ) ; } File file = new File ( path . getAbsolutePath ( ) + File . separatorChar + name ) ; if ( file . exists ( ) ) { if ( ! file . delete ( ) ) throw new IOException ( "there is exist file, please check" ) ; } return new FileWriter ( file ) ; }
Create file in the package
190
5
14,851
public Set < Address > getAddresses ( T physicalAddress ) { Set < Address > result = new HashSet < Address > ( ) ; for ( Entry < Address , T > entry : nodes . entrySet ( ) ) { if ( entry . getValue ( ) == null || entry . getValue ( ) . equals ( physicalAddress ) ) { result . add ( entry . getKey ( ) ) ; } } if ( trace ) log . tracef ( "Addresses: %s" , result ) ; return Collections . unmodifiableSet ( result ) ; }
Get the addresses
118
3
14,852
public void localDeltaDoWorkAccepted ( Address address ) { if ( trace ) log . tracef ( "LOCAL_DELTA_DOWORK_ACCEPTED(%s)" , address ) ; DistributedWorkManager dwm = workManagerCoordinator . resolveDistributedWorkManager ( address ) ; if ( dwm != null ) { Collection < NotificationListener > copy = new ArrayList < NotificationListener > ( dwm . getNotificationListeners ( ) ) ; for ( NotificationListener nl : copy ) { nl . deltaDoWorkAccepted ( ) ; } } }
Local delta doWork accepted
126
5
14,853
private void done ( ) { if ( longThreadPool != null && isLong ) { transport . updateLongRunningFree ( address , longThreadPool . getNumberOfFreeThreads ( ) + 1 ) ; } else { transport . updateShortRunningFree ( address , shortThreadPool . getNumberOfFreeThreads ( ) + 1 ) ; } }
Send the done signal to other nodes We are adding 1 to the result since the thread officially has been released yet but will be shortly
73
26
14,854
private Subject getSubject ( ) { return AccessController . doPrivileged ( new PrivilegedAction < Subject > ( ) { /** * run method */ public Subject run ( ) { try { String domain = recoverSecurityDomain ; if ( domain != null && subjectFactory != null ) { Subject subject = SecurityActions . createSubject ( subjectFactory , domain ) ; Set < PasswordCredential > pcs = SecurityActions . getPasswordCredentials ( subject ) ; if ( ! pcs . isEmpty ( ) ) { for ( PasswordCredential pc : pcs ) { pc . setManagedConnectionFactory ( mcf ) ; } } log . debugf ( "Recovery Subject=%s" , subject ) ; return subject ; } else { log . noCrashRecoverySecurityDomain ( jndiName ) ; } } catch ( Throwable t ) { log . exceptionDuringCrashRecoverySubject ( jndiName , t . getMessage ( ) , t ) ; } return null ; } } ) ; }
This method provide the Subject used for the XA Resource Recovery integration with the XAResourceRecoveryRegistry .
214
24
14,855
@ SuppressWarnings ( "unchecked" ) private ManagedConnection open ( Subject s ) throws ResourceException { log . debugf ( "Open managed connection (%s)" , s ) ; if ( recoverMC == null ) recoverMC = mcf . createManagedConnection ( s , null ) ; if ( plugin == null ) { try { ValidatingManagedConnectionFactory vmcf = ( ValidatingManagedConnectionFactory ) mcf ; Set connectionSet = new HashSet ( 1 ) ; connectionSet . add ( recoverMC ) ; Set invalid = vmcf . getInvalidConnections ( connectionSet ) ; if ( invalid != null && ! invalid . isEmpty ( ) ) { log . debugf ( "Invalid managed connection: %s" , recoverMC ) ; close ( recoverMC ) ; recoverMC = mcf . createManagedConnection ( s , null ) ; } } catch ( ResourceException re ) { log . debugf ( "Exception during invalid check" , re ) ; close ( recoverMC ) ; recoverMC = mcf . createManagedConnection ( s , null ) ; } } return recoverMC ; }
Open a managed connection
236
4
14,856
private void close ( ManagedConnection mc ) { log . debugf ( "Closing managed connection for recovery (%s)" , mc ) ; if ( mc != null ) { try { mc . cleanup ( ) ; } catch ( ResourceException ire ) { log . debugf ( "Error during recovery cleanup" , ire ) ; } } if ( mc != null ) { try { mc . destroy ( ) ; } catch ( ResourceException ire ) { log . debugf ( "Error during recovery destroy" , ire ) ; } } // The managed connection for recovery is now gone recoverMC = null ; }
Close a managed connection
124
4
14,857
private Object openConnection ( ManagedConnection mc , Subject s ) throws ResourceException { if ( plugin == null ) return null ; log . debugf ( "Open connection (%s, %s)" , mc , s ) ; return mc . getConnection ( s , null ) ; }
Open a connection
58
3
14,858
private boolean closeConnection ( Object c ) { if ( plugin == null ) return false ; log . debugf ( "Closing connection for recovery check (%s)" , c ) ; boolean forceClose = false ; if ( c != null ) { try { forceClose = ! plugin . isValid ( c ) ; } catch ( ResourceException re ) { log . debugf ( "Error during recovery plugin isValid()" , re ) ; forceClose = true ; } try { plugin . close ( c ) ; } catch ( ResourceException re ) { log . debugf ( "Error during recovery plugin close()" , re ) ; forceClose = true ; } } log . debugf ( "Force close=%s" , forceClose ) ; return forceClose ; }
Close a connection
159
3
14,859
protected boolean isCommandAvailable ( String command ) throws Throwable { Socket socket = null ; try { socket = new Socket ( host , port ) ; ObjectOutputStream output = new ObjectOutputStream ( socket . getOutputStream ( ) ) ; output . writeUTF ( "getcommand" ) ; output . writeInt ( 1 ) ; output . writeUTF ( command ) ; output . flush ( ) ; ObjectInputStream input = new ObjectInputStream ( socket . getInputStream ( ) ) ; Serializable result = ( Serializable ) input . readObject ( ) ; if ( result == null || ! ( result instanceof Throwable ) ) return true ; return false ; } finally { if ( socket != null ) { try { socket . close ( ) ; } catch ( IOException ioe ) { // Ignore } } } }
Is a command available
170
4
14,860
void registerConnection ( ConnectionManager cm , ConnectionListener cl , Object c ) { if ( cmToCl == null ) cmToCl = new HashMap < ConnectionManager , List < ConnectionListener > > ( ) ; List < ConnectionListener > l = cmToCl . get ( cm ) ; if ( l == null ) l = new ArrayList < ConnectionListener > ( 1 ) ; l . add ( cl ) ; cmToCl . put ( cm , l ) ; if ( clToC == null ) clToC = new HashMap < ConnectionListener , List < Object > > ( ) ; List < Object > connections = clToC . get ( cl ) ; if ( connections == null ) connections = new ArrayList < Object > ( 1 ) ; connections . add ( c ) ; clToC . put ( cl , connections ) ; }
Register a connection
176
3
14,861
boolean unregisterConnection ( ConnectionManager cm , ConnectionListener cl , Object c ) { if ( clToC != null && clToC . get ( cl ) != null ) { List < Object > l = clToC . get ( cl ) ; return l . remove ( c ) ; } return false ; }
Unregister a connection
66
4
14,862
Set < ConnectionManager > getConnectionManagers ( ) { if ( cmToCl == null ) return Collections . unmodifiableSet ( Collections . emptySet ( ) ) ; return Collections . unmodifiableSet ( cmToCl . keySet ( ) ) ; }
Get the connection managers
55
4
14,863
List < ConnectionListener > getConnectionListeners ( ConnectionManager cm ) { if ( cmToCl == null ) return Collections . unmodifiableList ( Collections . emptyList ( ) ) ; List < ConnectionListener > l = cmToCl . get ( cm ) ; if ( l == null ) l = Collections . emptyList ( ) ; return Collections . unmodifiableList ( l ) ; }
Get the connection listeners for a connection manager
82
8
14,864
List < Object > getConnections ( ConnectionListener cl ) { List < Object > l = null ; if ( clToC != null ) l = clToC . get ( cl ) ; if ( l == null ) l = Collections . emptyList ( ) ; return Collections . unmodifiableList ( l ) ; }
Get the connections for a connection listener
67
7
14,865
void switchConnectionListener ( Object c , ConnectionListener from , ConnectionListener to ) { if ( clToC != null && clToC . get ( from ) != null && clToC . get ( to ) != null ) { clToC . get ( from ) . remove ( c ) ; clToC . get ( to ) . add ( c ) ; } }
Switch the connection listener for a connection
78
7
14,866
void removeConnectionListener ( ConnectionManager cm , ConnectionListener cl ) { if ( cmToCl != null && cmToCl . get ( cm ) != null ) { cmToCl . get ( cm ) . remove ( cl ) ; clToC . remove ( cl ) ; } }
Remove a connection listener
59
4
14,867
public synchronized void forceConfigProperties ( List < ConfigProperty > newContents ) { if ( newContents != null ) { this . configProperties = new ArrayList < ConfigProperty > ( newContents ) ; } else { this . configProperties = new ArrayList < ConfigProperty > ( 0 ) ; } }
Force configProperties with new content . This method is thread safe
65
13
14,868
public String getMessage ( ) { String msg = super . getMessage ( ) ; String ec = getErrorCode ( ) ; if ( ( msg == null ) && ( ec == null ) ) { return null ; } if ( ( msg != null ) && ( ec != null ) ) { return ( msg + ", error code: " + ec ) ; } return ( ( msg != null ) ? msg : ( "error code: " + ec ) ) ; }
Returns a detailed message string describing this exception .
96
9
14,869
void writeClassComment ( Definition def , Writer out ) throws IOException { out . write ( "/**\n" ) ; out . write ( " * " + getClassName ( def ) ) ; writeEol ( out ) ; out . write ( " *\n" ) ; out . write ( " * @version $Revision: $\n" ) ; out . write ( " */\n" ) ; }
Output class comment
89
3
14,870
protected void writeSimpleMethodSignature ( Writer out , int indent , String javadoc , String signature ) throws IOException { writeWithIndent ( out , indent , "/**\n" ) ; writeIndent ( out , indent ) ; out . write ( javadoc ) ; writeEol ( out ) ; writeWithIndent ( out , indent , " */\n" ) ; writeIndent ( out , indent ) ; out . write ( signature ) ; }
write a simple method signature
102
5
14,871
protected void writeMethodSignature ( Writer out , int indent , MethodForConnection method ) throws IOException { writeWithIndent ( out , indent , "/**\n" ) ; writeWithIndent ( out , indent , " * " + method . getMethodName ( ) ) ; writeEol ( out ) ; for ( MethodParam param : method . getParams ( ) ) { writeIndent ( out , indent ) ; out . write ( " * @param " + param . getName ( ) + " " + param . getName ( ) ) ; writeEol ( out ) ; } if ( ! method . getReturnType ( ) . equals ( "void" ) ) { writeIndent ( out , indent ) ; out . write ( " * @return " + method . getReturnType ( ) ) ; writeEol ( out ) ; } for ( String ex : method . getExceptionType ( ) ) { writeIndent ( out , indent ) ; out . write ( " * @throws " + ex + " " + ex ) ; writeEol ( out ) ; } writeWithIndent ( out , indent , " */\n" ) ; writeWithIndent ( out , indent , "public " + method . getReturnType ( ) + " " + method . getMethodName ( ) + "(" ) ; int paramSize = method . getParams ( ) . size ( ) ; for ( int i = 0 ; i < paramSize ; i ++ ) { MethodParam param = method . getParams ( ) . get ( i ) ; out . write ( param . getType ( ) ) ; out . write ( " " ) ; out . write ( param . getName ( ) ) ; if ( i + 1 < paramSize ) out . write ( ", " ) ; } out . write ( ")" ) ; int exceptionSize = method . getExceptionType ( ) . size ( ) ; for ( int i = 0 ; i < exceptionSize ; i ++ ) { if ( i == 0 ) out . write ( " throws " ) ; String ex = method . getExceptionType ( ) . get ( i ) ; out . write ( ex ) ; if ( i + 1 < exceptionSize ) out . write ( ", " ) ; } }
Write method signature for given
480
5
14,872
void writeLeftCurlyBracket ( Writer out , int indent ) throws IOException { writeEol ( out ) ; writeWithIndent ( out , indent , "{\n" ) ; }
Output left curly bracket
41
4
14,873
void writeRightCurlyBracket ( Writer out , int indent ) throws IOException { writeEol ( out ) ; writeWithIndent ( out , indent , "}\n" ) ; }
Output right curly bracket
41
4
14,874
void writeDefaultConstructor ( Definition def , Writer out , int indent ) throws IOException { writeWithIndent ( out , indent , "/**\n" ) ; writeWithIndent ( out , indent , " * Default constructor\n" ) ; writeWithIndent ( out , indent , " */\n" ) ; //constructor writeWithIndent ( out , indent , "public " + getClassName ( def ) + "()" ) ; writeLeftCurlyBracket ( out , indent ) ; writeRightCurlyBracket ( out , indent ) ; writeEol ( out ) ; }
Output Default Constructor
129
4
14,875
String upcaseFirst ( String name ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( name . substring ( 0 , 1 ) . toUpperCase ( Locale . ENGLISH ) ) ; sb . append ( name . substring ( 1 ) ) ; return sb . toString ( ) ; }
Upcase first letter
73
4
14,876
public int getInitialSize ( ) { if ( initialSize == null ) return getMinSize ( ) ; if ( initialSize . intValue ( ) > maxSize ) return maxSize ; return initialSize . intValue ( ) ; }
Get initial - pool - size
49
6
14,877
private String dumpQueuedThread ( Thread t ) { StringBuilder sb = new StringBuilder ( ) ; // Header sb = sb . append ( "Queued thread: " ) ; sb = sb . append ( t . getName ( ) ) ; sb = sb . append ( newLine ) ; // Body StackTraceElement [ ] stes = SecurityActions . getStackTrace ( t ) ; if ( stes != null ) { for ( StackTraceElement ste : stes ) { sb = sb . append ( " " ) ; sb = sb . append ( ste . getClassName ( ) ) ; sb = sb . append ( ":" ) ; sb = sb . append ( ste . getMethodName ( ) ) ; sb = sb . append ( ":" ) ; sb = sb . append ( ste . getLineNumber ( ) ) ; sb = sb . append ( newLine ) ; } } return sb . toString ( ) ; }
Dump a thread
222
4
14,878
public synchronized void addEvent ( WorkManagerEvent event ) { if ( trace ) log . tracef ( "addEvent(%s)" , event ) ; List < WorkManagerEvent > e = events . get ( event . getAddress ( ) . getWorkManagerName ( ) ) ; if ( e == null ) { e = new ArrayList < WorkManagerEvent > ( ) ; events . put ( event . getAddress ( ) . getWorkManagerName ( ) , e ) ; } e . add ( event ) ; }
Add an event
109
3
14,879
private ScriptText createScriptText ( int key , BMRule rule ) { StringBuilder builder = new StringBuilder ( ) ; builder . append ( "# BMUnit autogenerated script: " ) . append ( rule . name ( ) ) ; builder . append ( "\nRULE " ) ; builder . append ( rule . name ( ) ) ; if ( rule . isInterface ( ) ) { builder . append ( "\nINTERFACE " ) ; } else { builder . append ( "\nCLASS " ) ; } builder . append ( rule . targetClass ( ) ) ; builder . append ( "\nMETHOD " ) ; builder . append ( rule . targetMethod ( ) ) ; String location = rule . targetLocation ( ) ; if ( location != null && location . length ( ) > 0 ) { builder . append ( "\nAT " ) ; builder . append ( location ) ; } String binding = rule . binding ( ) ; if ( binding != null && binding . length ( ) > 0 ) { builder . append ( "\nBIND " ) ; builder . append ( binding ) ; } String helper = rule . helper ( ) ; if ( helper != null && helper . length ( ) > 0 ) { builder . append ( "\nHELPER " ) ; builder . append ( helper ) ; } builder . append ( "\nIF " ) ; builder . append ( rule . condition ( ) ) ; builder . append ( "\nDO " ) ; builder . append ( rule . action ( ) ) ; builder . append ( "\nENDRULE\n" ) ; return new ScriptText ( "IronJacamarWithByteman" + key , builder . toString ( ) ) ; }
Create a ScriptText instance
354
5
14,880
static Class < ? > [ ] getDeclaredClasses ( final Class < ? > c ) { if ( System . getSecurityManager ( ) == null ) return c . getDeclaredClasses ( ) ; return AccessController . doPrivileged ( new PrivilegedAction < Class < ? > [ ] > ( ) { public Class < ? > [ ] run ( ) { return c . getDeclaredClasses ( ) ; } } ) ; }
Get the declared classes
94
4
14,881
static Field getDeclaredField ( final Class < ? > c , final String name ) throws NoSuchFieldException { if ( System . getSecurityManager ( ) == null ) return c . getDeclaredField ( name ) ; Field result = AccessController . doPrivileged ( new PrivilegedAction < Field > ( ) { public Field run ( ) { try { return c . getDeclaredField ( name ) ; } catch ( NoSuchFieldException e ) { return null ; } } } ) ; if ( result != null ) return result ; throw new NoSuchFieldException ( ) ; }
Get the declared field
123
4
14,882
public String getAsText ( ) { if ( throwable != null ) return throwable . toString ( ) ; if ( result != null ) { try { if ( editor != null ) { editor . setValue ( result ) ; return editor . getAsText ( ) ; } else { return result . toString ( ) ; } } catch ( Exception e ) { return "String representation of " + name + "unavailable" ; } } return null ; }
Get the text representation
96
4
14,883
private void checkTransport ( ) throws WorkException { if ( ! transport . isInitialized ( ) ) { try { transport . initialize ( ) ; initialize ( ) ; } catch ( Throwable t ) { WorkException we = new WorkException ( "Exception during transport initialization" ) ; we . initCause ( t ) ; throw we ; } } }
Check the transport
72
3
14,884
private synchronized void removeDistributedStatistics ( ) { if ( distributedStatistics != null ) { listeners . remove ( ( NotificationListener ) distributedStatistics ) ; distributedStatistics . setTransport ( null ) ; distributedStatistics = null ; } }
Remove distributed statistics
47
3
14,885
Address getLocalAddress ( ) { if ( localAddress == null ) localAddress = new Address ( getId ( ) , getName ( ) , transport != null ? transport . getId ( ) : null ) ; return localAddress ; }
Get local address
49
3
14,886
public void setShortRunningThreadPool ( BlockingExecutor executor ) { if ( trace ) log . trace ( "short running executor:" + ( executor != null ? executor . getClass ( ) : "null" ) ) ; if ( executor != null ) { if ( executor instanceof StatisticsExecutor ) { this . shortRunningExecutor = ( StatisticsExecutor ) executor ; } else { this . shortRunningExecutor = new StatisticsExecutorImpl ( executor ) ; } } }
Set the executor for short running tasks
108
8
14,887
public void setLongRunningThreadPool ( BlockingExecutor executor ) { if ( trace ) log . trace ( "long running executor:" + ( executor != null ? executor . getClass ( ) : "null" ) ) ; if ( executor != null ) { if ( executor instanceof StatisticsExecutor ) { this . longRunningExecutor = ( StatisticsExecutor ) executor ; } else { this . longRunningExecutor = new StatisticsExecutorImpl ( executor ) ; } } }
Set the executor for long running tasks
108
8
14,888
public void doFirstChecks ( Work work , long startTimeout , ExecutionContext execContext ) throws WorkException { if ( isShutdown ( ) ) throw new WorkRejectedException ( bundle . workmanagerShutdown ( ) ) ; if ( work == null ) throw new WorkRejectedException ( bundle . workIsNull ( ) ) ; if ( startTimeout < 0 ) throw new WorkRejectedException ( bundle . startTimeoutIsNegative ( startTimeout ) ) ; checkAndVerifyWork ( work , execContext ) ; }
Do first checks for work starting methods
110
7
14,889
void addWorkWrapper ( WorkWrapper ww ) { synchronized ( activeWorkWrappers ) { activeWorkWrappers . add ( ww ) ; if ( statisticsEnabled ) statistics . setWorkActive ( activeWorkWrappers . size ( ) ) ; } }
Add work wrapper to active set
55
6
14,890
void removeWorkWrapper ( WorkWrapper ww ) { synchronized ( activeWorkWrappers ) { activeWorkWrappers . remove ( ww ) ; if ( statisticsEnabled ) statistics . setWorkActive ( activeWorkWrappers . size ( ) ) ; } }
Remove work wrapper from active set
55
6
14,891
private BlockingExecutor getExecutor ( Work work ) { BlockingExecutor executor = shortRunningExecutor ; if ( longRunningExecutor != null && WorkManagerUtil . isLongRunning ( work ) ) { executor = longRunningExecutor ; } fireHintsComplete ( work ) ; return executor ; }
Get the executor
69
4
14,892
private void fireHintsComplete ( Work work ) { if ( work != null && work instanceof WorkContextProvider ) { WorkContextProvider wcProvider = ( WorkContextProvider ) work ; List < WorkContext > contexts = wcProvider . getWorkContexts ( ) ; if ( contexts != null && ! contexts . isEmpty ( ) ) { Iterator < WorkContext > it = contexts . iterator ( ) ; while ( it . hasNext ( ) ) { WorkContext wc = it . next ( ) ; if ( wc instanceof HintsContext ) { HintsContext hc = ( HintsContext ) wc ; if ( hc instanceof WorkContextLifecycleListener ) { WorkContextLifecycleListener listener = ( WorkContextLifecycleListener ) hc ; listener . contextSetupComplete ( ) ; } } } } } }
Fire complete for HintsContext
179
6
14,893
private void checkAndVerifyWork ( Work work , ExecutionContext executionContext ) throws WorkException { if ( specCompliant ) { verifyWork ( work ) ; } if ( work instanceof WorkContextProvider && executionContext != null ) { //Implements WorkContextProvider and not-null ExecutionContext throw new WorkRejectedException ( bundle . workExecutionContextMustNullImplementsWorkContextProvider ( ) ) ; } }
Check and verify work before submitting .
89
7
14,894
private void verifyWork ( Work work ) throws WorkException { Class < ? extends Work > workClass = work . getClass ( ) ; String className = workClass . getName ( ) ; if ( ! validatedWork . contains ( className ) ) { if ( isWorkMethodSynchronized ( workClass , RUN_METHOD_NAME ) ) throw new WorkException ( bundle . runMethodIsSynchronized ( className ) ) ; if ( isWorkMethodSynchronized ( workClass , RELEASE_METHOD_NAME ) ) throw new WorkException ( bundle . releaseMethodIsSynchronized ( className ) ) ; validatedWork . add ( className ) ; } }
Verify the given work instance .
140
7
14,895
private boolean isWorkMethodSynchronized ( Class < ? extends Work > workClass , String methodName ) { try { Method method = SecurityActions . getMethod ( workClass , methodName , new Class [ 0 ] ) ; if ( Modifier . isSynchronized ( method . getModifiers ( ) ) ) return true ; } catch ( NoSuchMethodException e ) { //Never happens, Work implementation should have these methods } return false ; }
Checks if Work implementation class method is synchronized
95
9
14,896
private void checkWorkCompletionException ( WorkWrapper wrapper ) throws WorkException { if ( wrapper . getWorkException ( ) != null ) { if ( trace ) log . tracef ( "Exception %s for %s" , wrapper . getWorkException ( ) , this ) ; deltaWorkFailed ( ) ; throw wrapper . getWorkException ( ) ; } deltaWorkSuccessful ( ) ; }
Checks work completed status .
84
6
14,897
private void fireWorkContextSetupFailed ( Object workContext , String errorCode , WorkListener workListener , Work work , WorkException exception ) { if ( workListener != null ) { WorkEvent event = new WorkEvent ( this , WorkEvent . WORK_STARTED , work , null ) ; workListener . workStarted ( event ) ; } if ( workContext instanceof WorkContextLifecycleListener ) { WorkContextLifecycleListener listener = ( WorkContextLifecycleListener ) workContext ; listener . contextSetupFailed ( errorCode ) ; } if ( workListener != null ) { WorkEvent event = new WorkEvent ( this , WorkEvent . WORK_COMPLETED , work , exception ) ; workListener . workCompleted ( event ) ; } }
Calls listener with given error code .
160
8
14,898
@ SuppressWarnings ( "unchecked" ) private < T extends WorkContext > Class < T > getSupportedWorkContextClass ( Class < T > adaptorWorkContext ) { for ( Class < ? extends WorkContext > supportedWorkContext : SUPPORTED_WORK_CONTEXT_CLASSES ) { // Assignable or not if ( supportedWorkContext . isAssignableFrom ( adaptorWorkContext ) ) { Class clz = adaptorWorkContext ; while ( clz != null ) { // Supported by the server if ( clz . equals ( supportedWorkContext ) ) { return clz ; } clz = clz . getSuperclass ( ) ; } } } return null ; }
Returns work context class if given work context is supported by server returns null instance otherwise .
148
17
14,899
public < T > T getWorkContext ( Class < T > workContextClass ) { T instance = null ; if ( workContexts != null && workContexts . containsKey ( workContextClass ) ) { instance = workContextClass . cast ( workContexts . get ( workContextClass ) ) ; } return instance ; }
Returns work context instance .
69
5