idx
int64
0
41.2k
question
stringlengths
74
4.04k
target
stringlengths
7
750
29,000
protected boolean sendLeaveReqToCoord ( final Address coord ) { if ( coord == null ) { log . warn ( "%s: cannot send LEAVE request to null coord" , gms . getLocalAddress ( ) ) ; return false ; } Promise < Address > leave_promise = gms . getLeavePromise ( ) ; gms . setLeaving ( true ) ; log . trace ( "%s: sending LEAVE request to %s" , gms . local_addr , coord ) ; long start = System . currentTimeMillis ( ) ; sendLeaveMessage ( coord , gms . local_addr ) ; Address sender = leave_promise . getResult ( gms . leave_timeout ) ; if ( ! Objects . equals ( coord , sender ) ) return false ; long time = System . currentTimeMillis ( ) - start ; if ( sender != null ) log . trace ( "%s: got LEAVE response from %s in %d ms" , gms . local_addr , coord , time ) ; else log . trace ( "%s: timed out waiting for LEAVE response from %s (after %d ms)" , gms . local_addr , coord , time ) ; return true ; }
Sends a leave request to coord and blocks until a leave response has been received or the leave timeout has elapsed
29,001
public static boolean isBinaryCompatible ( short ver ) { if ( version == ver ) return true ; short tmp_major = ( short ) ( ( ver & MAJOR_MASK ) >> MAJOR_SHIFT ) ; short tmp_minor = ( short ) ( ( ver & MINOR_MASK ) >> MINOR_SHIFT ) ; return major == tmp_major && minor == tmp_minor ; }
Checks whether ver is binary compatible with the current version . The rule for binary compatibility is that the major and minor versions have to match whereas micro versions can differ .
29,002
public void connect ( String group , Address addr , String logical_name , PhysicalAddress phys_addr ) throws Exception { synchronized ( this ) { _doConnect ( ) ; } try { writeRequest ( new GossipData ( GossipType . REGISTER , group , addr , logical_name , phys_addr ) ) ; } catch ( Exception ex ) { throw new Exception ( String . format ( "connection to %s failed: %s" , group , ex ) ) ; } }
Registers mbr with the GossipRouter under the given group with the given logical name and physical address . Establishes a connection to the GossipRouter and sends a CONNECT message .
29,003
public int compareTo ( Address o ) { int h1 , h2 , rc ; if ( this == o ) return 0 ; if ( ! ( o instanceof IpAddress ) ) throw new ClassCastException ( "comparison between different classes: the other object is " + ( o != null ? o . getClass ( ) : o ) ) ; IpAddress other = ( IpAddress ) o ; if ( ip_addr == null ) if ( other . ip_addr == null ) return port < other . port ? - 1 : ( port > other . port ? 1 : 0 ) ; else return - 1 ; h1 = ip_addr . hashCode ( ) ; h2 = other . ip_addr . hashCode ( ) ; rc = h1 < h2 ? - 1 : h1 > h2 ? 1 : 0 ; return rc != 0 ? rc : port < other . port ? - 1 : ( port > other . port ? 1 : 0 ) ; }
implements the java . lang . Comparable interface
29,004
public Membership add ( Collection < Address > v ) { if ( v != null ) v . forEach ( this :: add ) ; return this ; }
Adds a list of members to this membership
29,005
public Membership remove ( Address old_member ) { if ( old_member != null ) { synchronized ( members ) { members . remove ( old_member ) ; } } return this ; }
Removes an member from the membership . If this member doesn t exist no action will be performed on the existing membership
29,006
public Membership remove ( Collection < Address > v ) { if ( v != null ) { synchronized ( members ) { members . removeAll ( v ) ; } } return this ; }
Removes all the members contained in v from this membership
29,007
public Membership merge ( Collection < Address > new_mems , Collection < Address > suspects ) { remove ( suspects ) ; return add ( new_mems ) ; }
Merges membership with the new members and removes suspects . The Merge method will remove all the suspects and add in the new members . It will do it in the order 1 . Remove suspects 2 . Add new members the order is very important to notice .
29,008
public boolean contains ( Address member ) { if ( member == null ) return false ; synchronized ( members ) { return members . contains ( member ) ; } }
Returns true if the provided member belongs to this membership
29,009
public Set getChildrenNames ( String fqn ) { Node n = findNode ( fqn ) ; Map m ; if ( n == null ) return null ; m = n . getChildren ( ) ; if ( m != null ) return m . keySet ( ) ; else return null ; }
Returns all children of a given node
29,010
public boolean containsKeys ( Collection < K > keys ) { for ( K key : keys ) if ( ! map . containsKey ( key ) ) return false ; return true ; }
Returns true if all of the keys in keys are present . Returns false if one or more of the keys are absent
29,011
public Set < V > nonRemovedValues ( ) { return map . values ( ) . stream ( ) . filter ( entry -> ! entry . removable ) . map ( entry -> entry . val ) . collect ( Collectors . toSet ( ) ) ; }
Adds all value which have not been marked as removable to the returned set
29,012
public void removeMarkedElements ( boolean force ) { long curr_time = System . nanoTime ( ) ; for ( Iterator < Map . Entry < K , Entry < V > > > it = map . entrySet ( ) . iterator ( ) ; it . hasNext ( ) ; ) { Map . Entry < K , Entry < V > > entry = it . next ( ) ; Entry < V > tmp = entry . getValue ( ) ; if ( tmp == null ) continue ; if ( tmp . removable && ( force || ( curr_time - tmp . timestamp ) >= max_age ) ) { it . remove ( ) ; } } }
Removes elements marked as removable
29,013
public void setResult ( T result ) { lock . lock ( ) ; try { if ( Objects . equals ( expected_result , result ) ) super . setResult ( result ) ; } finally { lock . unlock ( ) ; } }
Sets the result only if expected_result matches result
29,014
protected static String sanitize ( final String name ) { String retval = name ; retval = retval . replace ( '/' , '-' ) ; retval = retval . replace ( '\\' , '-' ) ; return retval ; }
Sanitizes bucket and folder names according to AWS guidelines
29,015
public Map < Thread , Runnable > getCurrentRunningTasks ( ) { Map < Thread , Runnable > map = new HashMap < > ( ) ; for ( Entry < Thread , Holder < Runnable > > entry : _runnables . entrySet ( ) ) { map . put ( entry . getKey ( ) , entry . getValue ( ) . value ) ; } return map ; }
Returns a copy of the runners being used with the runner and what threads . If a thread is not currently running a task it will return with a null value . This map is a copy and can be modified if necessary without causing issues .
29,016
public boolean add ( T obj ) { if ( obj == null ) return false ; while ( size ( ) >= max_capacity && size ( ) > 0 ) { poll ( ) ; } return super . add ( obj ) ; }
Adds an element at the tail . Removes an object from the head if capacity is exceeded
29,017
protected static FORK getFORK ( JChannel ch , ProtocolStack . Position position , Class < ? extends Protocol > neighbor , boolean create_fork_if_absent ) throws Exception { ProtocolStack stack = ch . getProtocolStack ( ) ; FORK fork = stack . findProtocol ( FORK . class ) ; if ( fork == null ) { if ( ! create_fork_if_absent ) throw new IllegalArgumentException ( "FORK not found in main stack" ) ; fork = new FORK ( ) ; fork . setProtocolStack ( stack ) ; stack . insertProtocol ( fork , position , neighbor ) ; } return fork ; }
Creates a new FORK protocol or returns the existing one or throws an exception . Never returns null .
29,018
protected void copyFields ( ) { for ( Field field : copied_fields ) { Object value = Util . getField ( field , main_channel ) ; Util . setField ( field , this , value ) ; } }
Copies state from main - channel to this fork - channel
29,019
protected Map < String , Map < String , Object > > dumpAttrsSelectedProtocol ( String protocol_name , List < String > attrs ) { return ch . dumpStats ( protocol_name , attrs ) ; }
Dumps attributes and their values of a given protocol .
29,020
protected void handleOperation ( Map < String , String > map , String operation ) throws Exception { int index = operation . indexOf ( '.' ) ; if ( index == - 1 ) throw new IllegalArgumentException ( "operation " + operation + " is missing the protocol name" ) ; String prot_name = operation . substring ( 0 , index ) ; Protocol prot = ch . getProtocolStack ( ) . findProtocol ( prot_name ) ; if ( prot == null ) { log . error ( "protocol %s not found" , prot_name ) ; return ; } int args_index = operation . indexOf ( '[' ) ; String method_name ; if ( args_index != - 1 ) method_name = operation . substring ( index + 1 , args_index ) . trim ( ) ; else method_name = operation . substring ( index + 1 ) . trim ( ) ; String [ ] args = null ; if ( args_index != - 1 ) { int end_index = operation . indexOf ( ']' ) ; if ( end_index == - 1 ) throw new IllegalArgumentException ( "] not found" ) ; List < String > str_args = Util . parseCommaDelimitedStrings ( operation . substring ( args_index + 1 , end_index ) ) ; Object [ ] strings = str_args . toArray ( ) ; args = new String [ strings . length ] ; for ( int i = 0 ; i < strings . length ; i ++ ) args [ i ] = ( String ) strings [ i ] ; } Method method = findMethod ( prot , method_name , args ) ; MethodCall call = new MethodCall ( method ) ; Object [ ] converted_args = null ; if ( args != null ) { converted_args = new Object [ args . length ] ; Class < ? > [ ] types = method . getParameterTypes ( ) ; for ( int i = 0 ; i < args . length ; i ++ ) converted_args [ i ] = Util . convert ( args [ i ] , types [ i ] ) ; } Object retval = call . invoke ( prot , converted_args ) ; if ( retval != null ) map . put ( prot_name + "." + method_name , retval . toString ( ) ) ; }
Invokes an operation and puts the return value into map
29,021
public void send ( Message msg ) throws Exception { num_senders . incrementAndGet ( ) ; long size = msg . size ( ) ; lock . lock ( ) ; try { if ( count + size >= transport . getMaxBundleSize ( ) ) sendBundledMessages ( ) ; addMessage ( msg , size ) ; if ( num_senders . decrementAndGet ( ) == 0 ) sendBundledMessages ( ) ; } finally { lock . unlock ( ) ; } }
current senders adding msgs to the bundler
29,022
public int getNumDeliverable ( ) { NumDeliverable visitor = new NumDeliverable ( ) ; lock . lock ( ) ; try { forEach ( hd + 1 , hr , visitor ) ; return visitor . getResult ( ) ; } finally { lock . unlock ( ) ; } }
Returns the number of messages that can be delivered
29,023
public boolean add ( final List < LongTuple < T > > list , boolean remove_added_elements ) { return add ( list , remove_added_elements , null ) ; }
Adds elements from list to the table removes elements from list that were not added to the table
29,024
public boolean add ( final List < LongTuple < T > > list , boolean remove_added_elements , T const_value ) { if ( list == null || list . isEmpty ( ) ) return false ; boolean added = false ; long highest_seqno = findHighestSeqno ( list ) ; lock . lock ( ) ; try { if ( highest_seqno != - 1 && computeRow ( highest_seqno ) >= matrix . length ) resize ( highest_seqno ) ; for ( Iterator < LongTuple < T > > it = list . iterator ( ) ; it . hasNext ( ) ; ) { LongTuple < T > tuple = it . next ( ) ; long seqno = tuple . getVal1 ( ) ; T element = const_value != null ? const_value : tuple . getVal2 ( ) ; if ( _add ( seqno , element , false , null ) ) added = true ; else if ( remove_added_elements ) it . remove ( ) ; } return added ; } finally { lock . unlock ( ) ; } }
Adds elements from the list to the table
29,025
public T get ( long seqno ) { lock . lock ( ) ; try { if ( seqno - low <= 0 || seqno - hr > 0 ) return null ; int row_index = computeRow ( seqno ) ; if ( row_index < 0 || row_index >= matrix . length ) return null ; T [ ] row = matrix [ row_index ] ; if ( row == null ) return null ; int index = computeIndex ( seqno ) ; return index >= 0 ? row [ index ] : null ; } finally { lock . unlock ( ) ; } }
Returns an element at seqno
29,026
public T _get ( long seqno ) { lock . lock ( ) ; try { int row_index = computeRow ( seqno ) ; if ( row_index < 0 || row_index >= matrix . length ) return null ; T [ ] row = matrix [ row_index ] ; if ( row == null ) return null ; int index = computeIndex ( seqno ) ; return index >= 0 ? row [ index ] : null ; } finally { lock . unlock ( ) ; } }
To be used only for testing ; doesn t do any index or sanity checks
29,027
public T remove ( boolean nullify ) { lock . lock ( ) ; try { int row_index = computeRow ( hd + 1 ) ; if ( row_index < 0 || row_index >= matrix . length ) return null ; T [ ] row = matrix [ row_index ] ; if ( row == null ) return null ; int index = computeIndex ( hd + 1 ) ; if ( index < 0 ) return null ; T existing_element = row [ index ] ; if ( existing_element != null ) { hd ++ ; size = Math . max ( size - 1 , 0 ) ; if ( nullify ) { row [ index ] = null ; if ( hd - low > 0 ) low = hd ; } } return existing_element ; } finally { lock . unlock ( ) ; } }
Removes the next non - null element and nulls the index if nullify = true
29,028
public < R > R removeMany ( boolean nullify , int max_results , Predicate < T > filter , Supplier < R > result_creator , BiConsumer < R , T > accumulator ) { lock . lock ( ) ; try { Remover < R > remover = new Remover < > ( nullify , max_results , filter , result_creator , accumulator ) ; forEach ( hd + 1 , hr , remover ) ; return remover . getResult ( ) ; } finally { lock . unlock ( ) ; } }
Removes elements from the table and adds them to the result created by result_creator . Between 0 and max_results elements are removed . If no elements were removed processing will be set to true while the table lock is held .
29,029
protected long findHighestSeqno ( List < LongTuple < T > > list ) { long seqno = - 1 ; for ( LongTuple < T > tuple : list ) { long val = tuple . getVal1 ( ) ; if ( val - seqno > 0 ) seqno = val ; } return seqno ; }
list must not be null or empty
29,030
public SeqnoList getMissing ( int max_msgs ) { lock . lock ( ) ; try { if ( size == 0 ) return null ; long start_seqno = getHighestDeliverable ( ) + 1 ; int capacity = ( int ) ( hr - start_seqno ) ; int max_size = max_msgs > 0 ? Math . min ( max_msgs , capacity ) : capacity ; if ( max_size <= 0 ) return null ; Missing missing = new Missing ( start_seqno , max_size ) ; long to = max_size > 0 ? Math . min ( start_seqno + max_size - 1 , hr - 1 ) : hr - 1 ; forEach ( start_seqno , to , missing ) ; return missing . getMissingElements ( ) ; } finally { lock . unlock ( ) ; } }
Returns a list of missing messages
29,031
public String dump ( ) { lock . lock ( ) ; try { return stream ( low , hr ) . filter ( Objects :: nonNull ) . map ( Object :: toString ) . collect ( Collectors . joining ( ", " ) ) ; } finally { lock . unlock ( ) ; } }
Dumps the seqnos in the table as a list
29,032
@ GuardedBy ( "lock" ) protected T [ ] getRow ( int index ) { T [ ] row = matrix [ index ] ; if ( row == null ) { row = ( T [ ] ) new Object [ elements_per_row ] ; matrix [ index ] = row ; } return row ; }
Returns a row . Creates a new row and inserts it at index if the row at index doesn t exist
29,033
protected Tuple < SecretKey , byte [ ] > getSecretKeyFromAbove ( ) { return ( Tuple < SecretKey , byte [ ] > ) up_prot . up ( new Event ( Event . GET_SECRET_KEY ) ) ; }
Fetches the secret key from a protocol above us
29,034
protected void setSecretKeyAbove ( Tuple < SecretKey , byte [ ] > key ) { up_prot . up ( new Event ( Event . SET_SECRET_KEY , key ) ) ; }
Sets the secret key in a protocol above us
29,035
public static ProtocolStackConfigurator getStackConfigurator ( File file ) throws Exception { checkJAXPAvailability ( ) ; InputStream input = getConfigStream ( file ) ; return XmlConfigurator . getInstance ( input ) ; }
Returns a protocol stack configurator based on the XML configuration provided by the specified File .
29,036
public static ProtocolStackConfigurator getStackConfigurator ( URL url ) throws Exception { checkForNullConfiguration ( url ) ; checkJAXPAvailability ( ) ; return XmlConfigurator . getInstance ( url ) ; }
Returns a protocol stack configurator based on the XML configuration provided at the specified URL .
29,037
public static ProtocolStackConfigurator getStackConfigurator ( Element element ) throws Exception { checkForNullConfiguration ( element ) ; return XmlConfigurator . getInstance ( element ) ; }
Returns a protocol stack configurator based on the XML configuration provided by the specified XML element .
29,038
public static ProtocolStackConfigurator getStackConfigurator ( String properties ) throws Exception { if ( properties == null ) properties = Global . DEFAULT_PROTOCOL_STACK ; XmlConfigurator configurator = null ; checkForNullConfiguration ( properties ) ; configurator = getXmlConfigurator ( properties ) ; if ( configurator != null ) return configurator ; throw new IllegalStateException ( String . format ( "configuration %s not found or invalid" , properties ) ) ; }
Returns a protocol stack configurator based on the provided properties string .
29,039
public static InputStream getConfigStream ( String properties ) throws IOException { InputStream configStream = null ; try { configStream = new FileInputStream ( properties ) ; } catch ( FileNotFoundException | AccessControlException fnfe ) { } if ( configStream == null ) { try { configStream = new URL ( properties ) . openStream ( ) ; } catch ( MalformedURLException mre ) { } } if ( configStream == null && properties . endsWith ( "xml" ) ) configStream = Util . getResourceAsStream ( properties , ConfiguratorFactory . class ) ; return configStream ; }
Returns a JGroups XML configuration InputStream based on the provided properties string .
29,040
static void checkJAXPAvailability ( ) { try { XmlConfigurator . class . getName ( ) ; } catch ( NoClassDefFoundError error ) { Error tmp = new NoClassDefFoundError ( JAXP_MISSING_ERROR_MSG ) ; tmp . initCause ( error ) ; throw tmp ; } }
Checks the availability of the JAXP classes on the classpath .
29,041
public T getValue ( Object key ) { Rsp < T > rsp = get ( key ) ; return rsp != null ? rsp . getValue ( ) : null ; }
Returns the value associated with address key
29,042
public T getFirst ( ) { Optional < Rsp < T > > retval = values ( ) . stream ( ) . filter ( rsp -> rsp . getValue ( ) != null ) . findFirst ( ) ; return retval . isPresent ( ) ? retval . get ( ) . getValue ( ) : null ; }
Returns the first value in the response set . This is random but we try to return a non - null value first
29,043
public List < T > getResults ( ) { return values ( ) . stream ( ) . filter ( rsp -> rsp . wasReceived ( ) && rsp . getValue ( ) != null ) . collect ( ( ) -> new ArrayList < > ( size ( ) ) , ( list , rsp ) -> list . add ( rsp . getValue ( ) ) , ( l , r ) -> { } ) ; }
Returns the results from non - suspected members that are not null .
29,044
public void renameThread ( String base_name , Thread thread , String addr , String cluster_name ) { String thread_name = getThreadName ( base_name , thread , addr , cluster_name ) ; if ( thread_name != null ) thread . setName ( thread_name ) ; }
Names a thread according to base_name cluster name and local address . If includeClusterName and includeLocalAddress are null but cluster_name is set then we assume we have a shared transport and name the thread shared = clusterName . In the latter case clusterName points to the singleton_name of TP .
29,045
public RingBuffer < T > put ( T element ) throws InterruptedException { if ( element == null ) return this ; lock . lock ( ) ; try { while ( count == buf . length ) not_full . await ( ) ; buf [ wi ] = element ; if ( ++ wi == buf . length ) wi = 0 ; count ++ ; not_empty . signal ( ) ; return this ; } finally { lock . unlock ( ) ; } }
Tries to add a new element at the current write index and advances the write index . If the write index is at the same position as the read index this will block until the read index is advanced .
29,046
public int drainTo ( T [ ] c ) { int num = Math . min ( count , c . length ) ; if ( num == 0 ) return num ; int read_index = ri ; for ( int i = 0 ; i < num ; i ++ ) { int real_index = realIndex ( read_index + i ) ; c [ i ] = ( buf [ real_index ] ) ; buf [ real_index ] = null ; } publishReadIndex ( num ) ; return num ; }
Removes messages and adds them to c .
29,047
public int waitForMessages ( int num_spins , final BiConsumer < Integer , Integer > wait_strategy ) throws InterruptedException { for ( int i = 0 ; i < num_spins && count == 0 ; i ++ ) { if ( wait_strategy != null ) wait_strategy . accept ( i , num_spins ) ; else Thread . yield ( ) ; } if ( count == 0 ) _waitForMessages ( ) ; return count ; }
Blocks until messages are available
29,048
public ByteBuffer readLengthAndData ( SocketChannel ch ) throws Exception { if ( bufs [ 0 ] . hasRemaining ( ) && ch . read ( bufs [ 0 ] ) < 0 ) throw new EOFException ( ) ; if ( bufs [ 0 ] . hasRemaining ( ) ) return null ; int len = bufs [ 0 ] . getInt ( 0 ) ; if ( bufs [ 1 ] == null || len > bufs [ 1 ] . capacity ( ) ) bufs [ 1 ] = ByteBuffer . allocate ( len ) ; bufs [ 1 ] . limit ( len ) ; if ( bufs [ 1 ] . hasRemaining ( ) && ch . read ( bufs [ 1 ] ) < 0 ) throw new EOFException ( ) ; if ( bufs [ 1 ] . hasRemaining ( ) ) return null ; try { return ( ByteBuffer ) bufs [ 1 ] . duplicate ( ) . flip ( ) ; } finally { bufs [ 0 ] . clear ( ) ; bufs [ 1 ] . clear ( ) ; } }
Reads length and then length bytes into the data buffer which is grown if needed .
29,049
public Buffers copy ( ) { for ( int i = Math . max ( position , next_to_copy ) ; i < limit ; i ++ ) { this . bufs [ i ] = copyBuffer ( this . bufs [ i ] ) ; next_to_copy = ( short ) ( i + 1 ) ; } return this ; }
Copies the data that has not yet been written and moves last_copied . Typically done after an unsuccessful write if copying is required . This is typically needed if the output buffer is reused . Note that direct buffers will be converted to heap - based buffers
29,050
public static ByteBuffer copyBuffer ( final ByteBuffer buf ) { if ( buf == null ) return null ; int offset = buf . hasArray ( ) ? buf . arrayOffset ( ) + buf . position ( ) : buf . position ( ) , len = buf . remaining ( ) ; byte [ ] tmp = new byte [ len ] ; if ( ! buf . isDirect ( ) ) System . arraycopy ( buf . array ( ) , offset , tmp , 0 , len ) ; else { for ( int i = 0 ; i < len ; i ++ ) tmp [ i ] = buf . get ( i + offset ) ; } return ByteBuffer . wrap ( tmp ) ; }
Copies a ByteBuffer by copying and wrapping the underlying array of a heap - based buffer . Direct buffers are converted to heap - based buffers
29,051
@ GuardedBy ( "lock" ) protected void sendBundledMessages ( ) { for ( Map . Entry < Address , List < Message > > entry : msgs . entrySet ( ) ) { List < Message > list = entry . getValue ( ) ; if ( list . isEmpty ( ) ) continue ; output . position ( 0 ) ; if ( list . size ( ) == 1 ) sendSingleMessage ( list . get ( 0 ) ) ; else { Address dst = entry . getKey ( ) ; sendMessageList ( dst , list . get ( 0 ) . getSrc ( ) , list ) ; if ( transport . statsEnabled ( ) ) transport . incrBatchesSent ( 1 ) ; } } clearMessages ( ) ; count = 0 ; }
Sends all messages in the map . Messages for the same destination are bundled into a message list . The map will be cleared when done .
29,052
public V get ( K key ) { if ( l1_cache != null ) { V val = l1_cache . get ( key ) ; if ( val != null ) { if ( log . isTraceEnabled ( ) ) log . trace ( "returned value " + val + " for " + key + " from L1 cache" ) ; return val ; } } Cache . Value < Value < V > > val = l2_cache . getEntry ( key ) ; Value < V > tmp ; if ( val != null ) { tmp = val . getValue ( ) ; if ( tmp != null ) { V real_value = tmp . getVal ( ) ; if ( real_value != null && l1_cache != null && val . getTimeout ( ) >= 0 ) l1_cache . put ( key , real_value , val . getTimeout ( ) ) ; return tmp . getVal ( ) ; } } try { RspList < Object > rsps = disp . callRemoteMethods ( null , new MethodCall ( GET , key ) , new RequestOptions ( ResponseMode . GET_ALL , call_timeout ) ) ; for ( Rsp rsp : rsps . values ( ) ) { Object obj = rsp . getValue ( ) ; if ( obj == null || obj instanceof Throwable ) continue ; val = ( Cache . Value < Value < V > > ) rsp . getValue ( ) ; if ( val != null ) { tmp = val . getValue ( ) ; if ( tmp != null ) { V real_value = tmp . getVal ( ) ; if ( real_value != null && l1_cache != null && val . getTimeout ( ) >= 0 ) l1_cache . put ( key , real_value , val . getTimeout ( ) ) ; return real_value ; } } } return null ; } catch ( Throwable t ) { if ( log . isWarnEnabled ( ) ) log . warn ( "get() failed" , t ) ; return null ; } }
Returns the value associated with key
29,053
public void remove ( K key , boolean synchronous ) { try { disp . callRemoteMethods ( null , new MethodCall ( REMOVE , key ) , new RequestOptions ( synchronous ? ResponseMode . GET_ALL : ResponseMode . GET_NONE , call_timeout ) ) ; if ( l1_cache != null ) l1_cache . remove ( key ) ; } catch ( Throwable t ) { if ( log . isWarnEnabled ( ) ) log . warn ( "remove() failed" , t ) ; } }
Removes key in all nodes in the cluster both from their local hashmaps and L1 caches
29,054
public void clear ( ) { Set < K > keys = new HashSet < > ( l2_cache . getInternalMap ( ) . keySet ( ) ) ; mcastClear ( keys , false ) ; }
Removes all keys and values in the L2 and L1 caches
29,055
protected boolean installViewIfValidJoinRsp ( final Promise < JoinRsp > join_promise , boolean block_for_rsp ) { boolean success = false ; JoinRsp rsp = null ; try { if ( join_promise . hasResult ( ) ) rsp = join_promise . getResult ( 1 , true ) ; else if ( block_for_rsp ) rsp = join_promise . getResult ( gms . join_timeout , true ) ; return success = rsp != null && isJoinResponseValid ( rsp ) && installView ( rsp . getView ( ) , rsp . getDigest ( ) ) ; } finally { if ( success ) gms . sendViewAck ( rsp . getView ( ) . getCreator ( ) ) ; } }
go through discovery and JOIN - REQ again in a next iteration
29,056
private static List < Address > getCoords ( Iterable < PingData > mbrs ) { if ( mbrs == null ) return null ; List < Address > coords = null ; for ( PingData mbr : mbrs ) { if ( mbr . isCoord ( ) ) { if ( coords == null ) coords = new ArrayList < > ( ) ; if ( ! coords . contains ( mbr . getAddress ( ) ) ) coords . add ( mbr . getAddress ( ) ) ; } } return coords ; }
Returns all members whose PingData is flagged as coordinator
29,057
public static Protocol createProtocol ( String prot_spec , ProtocolStack stack ) throws Exception { ProtocolConfiguration config ; Protocol prot ; if ( prot_spec == null ) throw new Exception ( "Configurator.createProtocol(): prot_spec is null" ) ; config = new ProtocolConfiguration ( prot_spec ) ; prot = createLayer ( stack , config ) ; prot . init ( ) ; return prot ; }
Creates a new protocol given the protocol specification . Initializes the properties and starts the up and down handler threads .
29,058
public static Protocol connectProtocols ( List < Protocol > protocol_list ) throws Exception { Protocol current_layer = null , next_layer = null ; for ( int i = 0 ; i < protocol_list . size ( ) ; i ++ ) { current_layer = protocol_list . get ( i ) ; if ( i + 1 >= protocol_list . size ( ) ) break ; next_layer = protocol_list . get ( i + 1 ) ; next_layer . setDownProtocol ( current_layer ) ; current_layer . setUpProtocol ( next_layer ) ; } sanityCheck ( protocol_list ) ; return current_layer ; }
Creates a protocol stack by iterating through the protocol list and connecting adjacent layers . The list starts with the topmost layer and has the bottommost layer at the tail .
29,059
public static List < Protocol > createProtocols ( List < ProtocolConfiguration > protocol_configs , final ProtocolStack stack ) throws Exception { List < Protocol > retval = new LinkedList < > ( ) ; for ( int i = 0 ; i < protocol_configs . size ( ) ; i ++ ) { ProtocolConfiguration protocol_config = protocol_configs . get ( i ) ; Protocol layer = createLayer ( stack , protocol_config ) ; if ( layer == null ) return null ; retval . add ( layer ) ; } return retval ; }
Takes vector of ProtocolConfigurations iterates through it creates Protocol for each ProtocolConfiguration and returns all Protocols in a list .
29,060
public static void sanityCheck ( List < Protocol > protocols ) throws Exception { Set < Short > ids = new HashSet < > ( ) ; for ( Protocol protocol : protocols ) { short id = protocol . getId ( ) ; if ( id > 0 && ! ids . add ( id ) ) throw new Exception ( "Protocol ID " + id + " (name=" + protocol . getName ( ) + ") is duplicate; protocol IDs have to be unique" ) ; } for ( Protocol protocol : protocols ) { List < Integer > required_down_services = protocol . requiredDownServices ( ) ; List < Integer > required_up_services = protocol . requiredUpServices ( ) ; if ( required_down_services != null && ! required_down_services . isEmpty ( ) ) { List < Integer > tmp = new ArrayList < > ( required_down_services ) ; removeProvidedUpServices ( protocol , tmp ) ; if ( ! tmp . isEmpty ( ) ) throw new Exception ( "events " + printEvents ( tmp ) + " are required by " + protocol . getName ( ) + ", but not provided by any of the protocols below it" ) ; } if ( required_up_services != null && ! required_up_services . isEmpty ( ) ) { List < Integer > tmp = new ArrayList < > ( required_up_services ) ; removeProvidedDownServices ( protocol , tmp ) ; if ( ! tmp . isEmpty ( ) ) throw new Exception ( "events " + printEvents ( tmp ) + " are required by " + protocol . getName ( ) + ", but not provided by any of the protocols above it" ) ; } } }
Throws an exception if sanity check fails . Possible sanity check is uniqueness of all protocol names
29,061
protected static void removeProvidedUpServices ( Protocol protocol , List < Integer > events ) { if ( protocol == null || events == null ) return ; for ( Protocol prot = protocol . getDownProtocol ( ) ; prot != null && ! events . isEmpty ( ) ; prot = prot . getDownProtocol ( ) ) { List < Integer > provided_up_services = prot . providedUpServices ( ) ; if ( provided_up_services != null && ! provided_up_services . isEmpty ( ) ) events . removeAll ( provided_up_services ) ; } }
Removes all events provided by the protocol below protocol from events
29,062
protected static void removeProvidedDownServices ( Protocol protocol , List < Integer > events ) { if ( protocol == null || events == null ) return ; for ( Protocol prot = protocol . getUpProtocol ( ) ; prot != null && ! events . isEmpty ( ) ; prot = prot . getUpProtocol ( ) ) { List < Integer > provided_down_services = prot . providedDownServices ( ) ; if ( provided_down_services != null && ! provided_down_services . isEmpty ( ) ) events . removeAll ( provided_down_services ) ; } }
Removes all events provided by the protocol above protocol from events
29,063
public static Collection < InetAddress > getAddresses ( Map < String , Map < String , InetAddressInfo > > inetAddressMap ) throws Exception { Set < InetAddress > addrs = new HashSet < > ( ) ; for ( Map . Entry < String , Map < String , InetAddressInfo > > inetAddressMapEntry : inetAddressMap . entrySet ( ) ) { Map < String , InetAddressInfo > protocolInetAddressMap = inetAddressMapEntry . getValue ( ) ; for ( Map . Entry < String , InetAddressInfo > protocolInetAddressMapEntry : protocolInetAddressMap . entrySet ( ) ) { InetAddressInfo inetAddressInfo = protocolInetAddressMapEntry . getValue ( ) ; List < InetAddress > addresses = inetAddressInfo . getInetAddresses ( ) ; for ( InetAddress address : addresses ) { if ( address == null ) throw new RuntimeException ( "failed converting address info to IP address: " + inetAddressInfo ) ; addrs . add ( address ) ; } } } return addrs ; }
Returns all inet addresses found
29,064
public static void ensureValidBindAddresses ( List < Protocol > protocols ) throws Exception { for ( Protocol protocol : protocols ) { String protocolName = protocol . getName ( ) ; Field [ ] fields = Util . getAllDeclaredFieldsWithAnnotations ( protocol . getClass ( ) , LocalAddress . class ) ; for ( int i = 0 ; i < fields . length ; i ++ ) { Object val = getValueFromProtocol ( protocol , fields [ i ] ) ; if ( val == null ) continue ; if ( ! ( val instanceof InetAddress ) ) throw new Exception ( "field " + protocolName + "." + fields [ i ] . getName ( ) + " is not an InetAddress" ) ; Util . checkIfValidAddress ( ( InetAddress ) val , protocolName ) ; } } }
Makes sure that all fields annotated with
29,065
static void addPropertyToDependencyList ( List < AccessibleObject > orderedList , Map < String , AccessibleObject > props , Stack < AccessibleObject > stack , AccessibleObject obj ) { if ( orderedList . contains ( obj ) ) return ; if ( stack . search ( obj ) > 0 ) { throw new RuntimeException ( "Deadlock in @Property dependency processing" ) ; } stack . push ( obj ) ; Property annotation = obj . getAnnotation ( Property . class ) ; String dependsClause = annotation . dependsUpon ( ) ; StringTokenizer st = new StringTokenizer ( dependsClause , "," ) ; while ( st . hasMoreTokens ( ) ) { String token = st . nextToken ( ) . trim ( ) ; AccessibleObject dep = props . get ( token ) ; addPropertyToDependencyList ( orderedList , props , stack , dep ) ; } stack . pop ( ) ; orderedList . add ( obj ) ; }
DFS of dependency graph formed by Property annotations and dependsUpon parameter This is used to create a list of Properties in dependency order
29,066
public int length ( ) { if ( keys == null ) return 0 ; int retval = 0 ; for ( byte [ ] key : keys ) if ( key != null ) retval ++ ; return retval ; }
The number of non - null keys
29,067
protected void resize ( int new_length ) { if ( keys == null ) { keys = new byte [ Math . min ( new_length , 0xff ) ] [ ] ; values = new byte [ Math . min ( new_length , 0xff ) ] [ ] ; return ; } if ( new_length > 0xff ) { if ( keys . length < 0xff ) new_length = 0xff ; else throw new ArrayIndexOutOfBoundsException ( "the hashmap cannot exceed " + 0xff + " entries" ) ; } keys = Arrays . copyOf ( keys , new_length ) ; values = Arrays . copyOf ( values , new_length ) ; }
Resizes the arrays
29,068
public static Map < String , List < ProtocolConfiguration > > parse ( InputStream input ) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory . newInstance ( ) ; factory . setValidating ( false ) ; DocumentBuilder builder = factory . newDocumentBuilder ( ) ; Document document = builder . parse ( input ) ; Element root = document . getDocumentElement ( ) ; return parse ( root ) ; }
Parses the input and returns a map of fork - stack IDs and lists of ProtocolConfigurations
29,069
public static void writeInt ( int num , ByteBuffer buf ) { if ( num == 0 ) { buf . put ( ( byte ) 0 ) ; return ; } final byte bytes_needed = bytesRequiredFor ( num ) ; buf . put ( bytes_needed ) ; for ( int i = 0 ; i < bytes_needed ; i ++ ) buf . put ( getByteAt ( num , i ) ) ; }
Writes an int to a ByteBuffer
29,070
public static void writeInt ( int num , DataOutput out ) throws IOException { if ( num == 0 ) { out . write ( 0 ) ; return ; } final byte bytes_needed = bytesRequiredFor ( num ) ; out . write ( bytes_needed ) ; for ( int i = 0 ; i < bytes_needed ; i ++ ) out . write ( getByteAt ( num , i ) ) ; }
Writes an int to an output stream
29,071
public static int readInt ( ByteBuffer buf ) { byte len = buf . get ( ) ; if ( len == 0 ) return 0 ; return makeInt ( buf , len ) ; }
Reads an int from a buffer .
29,072
public static int readInt ( DataInput in ) throws IOException { byte len = in . readByte ( ) ; if ( len == 0 ) return 0 ; return makeInt ( in , len ) ; }
Reads an int from an input stream
29,073
public static long readLong ( ByteBuffer buf ) { byte len = buf . get ( ) ; if ( len == 0 ) return 0 ; return makeLong ( buf , len ) ; }
Reads a long from a buffer .
29,074
public static void writeFloat ( float num , DataOutput out ) throws IOException { writeInt ( Float . floatToIntBits ( num ) , out ) ; }
Writes a float to an output stream
29,075
public static void writeDouble ( double num , DataOutput out ) throws IOException { writeLong ( Double . doubleToLongBits ( num ) , out ) ; }
Writes a double to an output stream
29,076
public static int size ( AsciiString str ) { return str == null ? Global . SHORT_SIZE : Global . SHORT_SIZE + str . length ( ) ; }
Measures the number of bytes required to encode an AsciiSring .
29,077
protected void removeAndDispatchNonBundledMessages ( MessageBatch oob_batch ) { if ( oob_batch == null ) return ; AsciiString tmp = oob_batch . clusterName ( ) ; byte [ ] cname = tmp != null ? tmp . chars ( ) : null ; for ( Iterator < Message > it = oob_batch . iterator ( ) ; it . hasNext ( ) ; ) { Message msg = it . next ( ) ; if ( msg . isFlagSet ( Message . Flag . DONT_BUNDLE ) && msg . isFlagSet ( Message . Flag . OOB ) ) { boolean internal = msg . isFlagSet ( Message . Flag . INTERNAL ) ; it . remove ( ) ; if ( tp . statsEnabled ( ) ) tp . getMessageStats ( ) . incrNumOOBMsgsReceived ( 1 ) ; tp . submitToThreadPool ( new SingleMessageHandlerWithClusterName ( msg , cname ) , internal ) ; } } }
Removes messages with flags DONT_BUNDLE and OOB set and executes them in the oob or internal thread pool . JGRP - 1737
29,078
public void waitFor ( Condition condition ) { boolean intr = false ; lock . lock ( ) ; try { while ( ! condition . isMet ( ) ) { try { cond . await ( ) ; } catch ( InterruptedException e ) { intr = true ; } } } finally { lock . unlock ( ) ; if ( intr ) Thread . currentThread ( ) . interrupt ( ) ; } }
Blocks until condition is true .
29,079
public boolean waitFor ( Condition condition , long timeout , TimeUnit unit ) { boolean intr = false ; final long timeout_ns = TimeUnit . NANOSECONDS . convert ( timeout , unit ) ; lock . lock ( ) ; try { for ( long wait_time = timeout_ns , start = System . nanoTime ( ) ; wait_time > 0 && ! condition . isMet ( ) ; ) { try { wait_time = cond . awaitNanos ( wait_time ) ; } catch ( InterruptedException e ) { wait_time = timeout_ns - ( System . nanoTime ( ) - start ) ; intr = true ; } } return condition . isMet ( ) ; } finally { lock . unlock ( ) ; if ( intr ) Thread . currentThread ( ) . interrupt ( ) ; } }
Blocks until condition is true or the time elapsed
29,080
void deliverSingleDestinationMessage ( Message msg , MessageID messageID ) { synchronized ( deliverySet ) { long sequenceNumber = sequenceNumberManager . get ( ) ; MessageInfo messageInfo = new MessageInfo ( messageID , msg , sequenceNumber ) ; messageInfo . updateAndMarkReadyToDeliver ( sequenceNumber ) ; deliverySet . add ( messageInfo ) ; notifyIfNeeded ( ) ; } }
delivers a message that has only as destination member this node
29,081
public List < Message > getNextMessagesToDeliver ( ) throws InterruptedException { LinkedList < Message > toDeliver = new LinkedList < > ( ) ; synchronized ( deliverySet ) { while ( deliverySet . isEmpty ( ) || ! deliverySet . first ( ) . isReadyToDeliver ( ) ) { deliverySet . wait ( ) ; } Iterator < MessageInfo > iterator = deliverySet . iterator ( ) ; while ( iterator . hasNext ( ) ) { MessageInfo messageInfo = iterator . next ( ) ; if ( messageInfo . isReadyToDeliver ( ) ) { toDeliver . add ( messageInfo . getMessage ( ) ) ; iterator . remove ( ) ; } else { break ; } } } return toDeliver ; }
see the interface javadoc
29,082
public boolean containsMember ( Address mbr ) { if ( mbr == null || members == null ) return false ; for ( Address member : members ) if ( Objects . equals ( member , mbr ) ) return true ; return false ; }
Returns true if this view contains a certain member
29,083
public boolean containsMembers ( Address ... mbrs ) { if ( mbrs == null || members == null ) return false ; for ( Address mbr : mbrs ) { if ( ! containsMember ( mbr ) ) return false ; } return true ; }
Returns true if all mbrs are elements of this view false otherwise
29,084
public static List < Address > leftMembers ( View one , View two ) { if ( one == null || two == null ) return null ; List < Address > retval = new ArrayList < > ( one . getMembers ( ) ) ; retval . removeAll ( two . getMembers ( ) ) ; return retval ; }
Returns a list of members which left from view one to two
29,085
public static Address [ ] [ ] diff ( final View from , final View to ) { if ( to == null ) throw new IllegalArgumentException ( "the second view cannot be null" ) ; if ( from == to ) return new Address [ ] [ ] { { } , { } } ; if ( from == null ) { Address [ ] joined = new Address [ to . size ( ) ] ; int index = 0 ; for ( Address addr : to . getMembers ( ) ) joined [ index ++ ] = addr ; return new Address [ ] [ ] { joined , { } } ; } Address [ ] joined = null , left = null ; int num_joiners = 0 , num_left = 0 ; for ( Address addr : to ) if ( ! from . containsMember ( addr ) ) num_joiners ++ ; if ( num_joiners > 0 ) { joined = new Address [ num_joiners ] ; int index = 0 ; for ( Address addr : to ) if ( ! from . containsMember ( addr ) ) joined [ index ++ ] = addr ; } for ( Address addr : from ) if ( ! to . containsMember ( addr ) ) num_left ++ ; if ( num_left > 0 ) { left = new Address [ num_left ] ; int index = 0 ; for ( Address addr : from ) if ( ! to . containsMember ( addr ) ) left [ index ++ ] = addr ; } return new Address [ ] [ ] { joined != null ? joined : new Address [ ] { } , left != null ? left : new Address [ ] { } } ; }
Returns the difference between 2 views from and to . It is assumed that view from is logically prior to view to .
29,086
public static boolean sameViews ( View ... views ) { ViewId first_view_id = views [ 0 ] . getViewId ( ) ; return Stream . of ( views ) . allMatch ( v -> v . getViewId ( ) . equals ( first_view_id ) ) ; }
Returns true if all views are the same . Uses the view IDs for comparison
29,087
public byte [ ] getBuffer ( ) { if ( buf == null ) return null ; if ( offset == 0 && length == buf . length ) return buf ; else { byte [ ] retval = new byte [ length ] ; System . arraycopy ( buf , offset , retval , 0 , length ) ; return retval ; } }
Returns a copy of the buffer if offset and length are used otherwise a reference .
29,088
public Message setFlag ( Flag ... flags ) { if ( flags != null ) { short tmp = this . flags ; for ( Flag flag : flags ) { if ( flag != null ) tmp |= flag . value ( ) ; } this . flags = tmp ; } return this ; }
Sets a number of flags in a message
29,089
public Message clearFlag ( Flag ... flags ) { if ( flags != null ) { short tmp = this . flags ; for ( Flag flag : flags ) if ( flag != null ) tmp &= ~ flag . value ( ) ; this . flags = tmp ; } return this ; }
Clears a number of flags in a message
29,090
public Message putHeader ( short id , Header hdr ) { if ( id < 0 ) throw new IllegalArgumentException ( "An ID of " + id + " is invalid" ) ; if ( hdr != null ) hdr . setProtId ( id ) ; synchronized ( this ) { Header [ ] resized_array = Headers . putHeader ( this . headers , id , hdr , true ) ; if ( resized_array != null ) this . headers = resized_array ; } return this ; }
Puts a header given an ID into the hashmap . Overwrites potential existing entry .
29,091
public < T extends Header > T getHeader ( short ... ids ) { if ( ids == null || ids . length == 0 ) return null ; return Headers . getHeader ( this . headers , ids ) ; }
Returns a header for a range of IDs or null if not found
29,092
public Message copy ( boolean copy_buffer , short starting_id , short ... copy_only_ids ) { Message retval = copy ( copy_buffer , false ) ; for ( Map . Entry < Short , Header > entry : getHeaders ( ) . entrySet ( ) ) { short id = entry . getKey ( ) ; if ( id >= starting_id || Util . containsId ( id , copy_only_ids ) ) retval . putHeader ( id , entry . getValue ( ) ) ; } return retval ; }
Copies a message . Copies only headers with IDs > = starting_id or IDs which are in the copy_only_ids list
29,093
public void writeTo ( DataOutput out ) throws IOException { byte leading = 0 ; if ( dest != null ) leading = Util . setFlag ( leading , DEST_SET ) ; if ( sender != null ) leading = Util . setFlag ( leading , SRC_SET ) ; if ( buf != null ) leading = Util . setFlag ( leading , BUF_SET ) ; out . write ( leading ) ; out . writeShort ( flags ) ; if ( dest != null ) Util . writeAddress ( dest , out ) ; if ( sender != null ) Util . writeAddress ( sender , out ) ; Header [ ] hdrs = this . headers ; int size = Headers . size ( hdrs ) ; out . writeShort ( size ) ; if ( size > 0 ) { for ( Header hdr : hdrs ) { if ( hdr == null ) break ; out . writeShort ( hdr . getProtId ( ) ) ; writeHeader ( hdr , out ) ; } } if ( buf != null ) { out . writeInt ( length ) ; out . write ( buf , offset , length ) ; } }
Writes the message to the output stream
29,094
public void writeToNoAddrs ( Address src , DataOutput out , short ... excluded_headers ) throws IOException { byte leading = 0 ; boolean write_src_addr = src == null || sender != null && ! sender . equals ( src ) ; if ( write_src_addr ) leading = Util . setFlag ( leading , SRC_SET ) ; if ( buf != null ) leading = Util . setFlag ( leading , BUF_SET ) ; out . write ( leading ) ; out . writeShort ( flags ) ; if ( write_src_addr ) Util . writeAddress ( sender , out ) ; Header [ ] hdrs = this . headers ; int size = Headers . size ( hdrs , excluded_headers ) ; out . writeShort ( size ) ; if ( size > 0 ) { for ( Header hdr : hdrs ) { if ( hdr == null ) break ; short id = hdr . getProtId ( ) ; if ( Util . containsId ( id , excluded_headers ) ) continue ; out . writeShort ( id ) ; writeHeader ( hdr , out ) ; } } if ( buf != null ) { out . writeInt ( length ) ; out . write ( buf , offset , length ) ; } }
Writes the message to the output stream but excludes the dest and src addresses unless the src address given as argument is different from the message s src address
29,095
public void readFrom ( DataInput in ) throws IOException , ClassNotFoundException { byte leading = in . readByte ( ) ; flags = in . readShort ( ) ; if ( Util . isFlagSet ( leading , DEST_SET ) ) dest = Util . readAddress ( in ) ; if ( Util . isFlagSet ( leading , SRC_SET ) ) sender = Util . readAddress ( in ) ; int len = in . readShort ( ) ; this . headers = createHeaders ( len ) ; for ( int i = 0 ; i < len ; i ++ ) { short id = in . readShort ( ) ; Header hdr = readHeader ( in ) . setProtId ( id ) ; this . headers [ i ] = hdr ; } if ( Util . isFlagSet ( leading , BUF_SET ) ) { len = in . readInt ( ) ; buf = new byte [ len ] ; in . readFully ( buf , 0 , len ) ; length = len ; } }
Reads the message s contents from an input stream
29,096
public void forEach ( Consumer < RouterStub > action ) { stubs . stream ( ) . filter ( RouterStub :: isConnected ) . forEach ( action :: accept ) ; }
Applies action to all RouterStubs that are connected
29,097
public void forAny ( Consumer < RouterStub > action ) { while ( ! stubs . isEmpty ( ) ) { RouterStub stub = Util . pickRandomElement ( stubs ) ; if ( stub != null && stub . isConnected ( ) ) { action . accept ( stub ) ; return ; } } }
Applies action to a randomly picked RouterStub that s connected
29,098
public Element < T > get ( ) { int starting_index = ( ( int ) ( Math . random ( ) * pool . length ) ) & ( pool . length - 1 ) ; for ( int i = 0 ; i < locks . length ; i ++ ) { int index = ( starting_index + i ) & ( pool . length - 1 ) ; Lock lock = locks [ index ] ; if ( lock . tryLock ( ) ) { if ( pool [ index ] != null ) return new Element < > ( pool [ index ] , lock ) ; return new Element < > ( pool [ index ] = creator . get ( ) , lock ) ; } } return new Element < > ( creator . get ( ) , null ) ; }
Gets the next available resource for which the lock can be acquired and returns it and its associated lock which needs to be released when the caller is done using the resource . If no resource in the pool can be locked returns a newly created resource and a null lock . This means that no lock was acquired and thus doesn t need to be released .
29,099
protected static String toLowerCase ( String input ) { if ( Character . isUpperCase ( input . charAt ( 0 ) ) ) return input . substring ( 0 , 1 ) . toLowerCase ( ) + input . substring ( 1 ) ; return input ; }
Returns a string with the first letter being lowercase