idx
int64
0
165k
question
stringlengths
73
4.15k
target
stringlengths
5
918
len_question
int64
21
890
len_target
int64
3
255
140,000
private void getFields ( ArrayList < JField > fieldList ) { for ( JField field : getDeclaredFields ( ) ) { if ( ! fieldList . contains ( field ) ) fieldList . add ( field ) ; } if ( getSuperClass ( ) != null ) { for ( JField field : getSuperClass ( ) . getFields ( ) ) { if ( ! fieldList . contains ( field ) ) fieldList . add ( field ) ; } } }
Returns all the fields
103
4
140,001
private void lazyLoad ( ) { if ( _major > 0 ) return ; try { if ( _url == null ) throw new IllegalStateException ( ) ; try ( InputStream is = _url . openStream ( ) ) { //ReadStream rs = VfsOld.openRead(is); _major = 1 ; ByteCodeParser parser = new ByteCodeParser ( ) ; parser . setClassLoader ( _loader ) ; parser . setJavaClass ( this ) ; parser . parse ( is ) ; } } catch ( RuntimeException e ) { throw e ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } }
Lazily load the class .
134
7
140,002
public void write ( OutputStream os ) throws IOException { ByteCodeWriter out = new ByteCodeWriter ( os , this ) ; out . writeInt ( MAGIC ) ; out . writeShort ( _minor ) ; out . writeShort ( _major ) ; _constantPool . write ( out ) ; out . writeShort ( _accessFlags ) ; out . writeClass ( _thisClass ) ; out . writeClass ( _superClass ) ; out . writeShort ( _interfaces . size ( ) ) ; for ( int i = 0 ; i < _interfaces . size ( ) ; i ++ ) { String className = _interfaces . get ( i ) ; out . writeClass ( className ) ; } out . writeShort ( _fields . size ( ) ) ; for ( int i = 0 ; i < _fields . size ( ) ; i ++ ) { JavaField field = _fields . get ( i ) ; field . write ( out ) ; } out . writeShort ( _methods . size ( ) ) ; for ( int i = 0 ; i < _methods . size ( ) ; i ++ ) { JavaMethod method = _methods . get ( i ) ; method . write ( out ) ; } out . writeShort ( _attributes . size ( ) ) ; for ( int i = 0 ; i < _attributes . size ( ) ; i ++ ) { Attribute attr = _attributes . get ( i ) ; attr . write ( out ) ; } }
Writes the class to the output .
321
8
140,003
public final I getInvocation ( Object protocolKey ) { I invocation = null ; // XXX: see if can remove this LruCache < Object , I > invocationCache = _invocationCache ; if ( invocationCache != null ) { invocation = invocationCache . get ( protocolKey ) ; } if ( invocation == null ) { return null ; } else if ( invocation . isModified ( ) ) { return null ; } else { return invocation ; } }
Returns the cached invocation .
95
5
140,004
public I buildInvocation ( Object protocolKey , I invocation ) throws ConfigException { Objects . requireNonNull ( invocation ) ; invocation = buildInvocation ( invocation ) ; // XXX: see if can remove this, and rely on the invocation cache existing LruCache < Object , I > invocationCache = _invocationCache ; if ( invocationCache != null ) { I oldInvocation ; oldInvocation = invocationCache . get ( protocolKey ) ; // server/10r2 if ( oldInvocation != null && ! oldInvocation . isModified ( ) ) { return oldInvocation ; } if ( invocation . getURLLength ( ) < _maxURLLength ) { invocationCache . put ( protocolKey , invocation ) ; } } return invocation ; }
Builds the invocation saving its value keyed by the protocol key .
160
14
140,005
public void clearCache ( ) { // XXX: see if can remove this, and rely on the invocation cache existing LruCache < Object , I > invocationCache = _invocationCache ; if ( invocationCache != null ) { invocationCache . clear ( ) ; } }
Clears the invocation cache .
56
6
140,006
public ArrayList < I > getInvocations ( ) { LruCache < Object , I > invocationCache = _invocationCache ; ArrayList < I > invocationList = new ArrayList <> ( ) ; synchronized ( invocationCache ) { Iterator < I > iter ; iter = invocationCache . values ( ) ; while ( iter . hasNext ( ) ) { invocationList . add ( iter . next ( ) ) ; } } return invocationList ; }
Returns the invocations .
96
5
140,007
private void loadManifest ( ) { if ( _isManifestRead ) return ; synchronized ( this ) { if ( _isManifestRead ) return ; try { _manifest = _jarPath . getManifest ( ) ; if ( _manifest == null ) return ; Attributes attr = _manifest . getMainAttributes ( ) ; if ( attr != null ) addManifestPackage ( "" , attr ) ; Map < String , Attributes > entries = _manifest . getEntries ( ) ; for ( Map . Entry < String , Attributes > entry : entries . entrySet ( ) ) { String pkg = entry . getKey ( ) ; attr = entry . getValue ( ) ; if ( attr == null ) continue ; addManifestPackage ( pkg , attr ) ; } } catch ( IOException e ) { log . log ( Level . WARNING , e . toString ( ) , e ) ; } finally { _isManifestRead = true ; } } }
Reads the jar s manifest .
212
7
140,008
private void addManifestPackage ( String name , Attributes attr ) { // only add packages if ( ! name . endsWith ( "/" ) && ! name . equals ( "" ) ) return ; String specTitle = attr . getValue ( "Specification-Title" ) ; String specVersion = attr . getValue ( "Specification-Version" ) ; String specVendor = attr . getValue ( "Specification-Vendor" ) ; String implTitle = attr . getValue ( "Implementation-Title" ) ; String implVersion = attr . getValue ( "Implementation-Version" ) ; String implVendor = attr . getValue ( "Implementation-Vendor" ) ; // If all none, then it isn't a package entry if ( specTitle == null && specVersion == null && specVendor != null && implTitle == null && implVersion == null && implVendor != null ) return ; ClassPackage pkg = new ClassPackage ( name ) ; pkg . setSpecificationTitle ( specTitle ) ; pkg . setSpecificationVersion ( specVersion ) ; pkg . setSpecificationVendor ( specVendor ) ; pkg . setImplementationTitle ( implTitle ) ; pkg . setImplementationVersion ( implVersion ) ; pkg . setImplementationVendor ( implVendor ) ; _packages . add ( pkg ) ; }
Adds package information from the manifest .
299
7
140,009
public void validate ( ) throws ConfigException { loadManifest ( ) ; if ( _manifest != null ) validateManifest ( _jarPath . getContainer ( ) . getURL ( ) , _manifest ) ; }
Validates the jar .
47
5
140,010
public static void validateManifest ( String manifestName , Manifest manifest ) throws ConfigException { Attributes attr = manifest . getMainAttributes ( ) ; if ( attr == null ) return ; String extList = attr . getValue ( "Extension-List" ) ; if ( extList == null ) return ; Pattern pattern = Pattern . compile ( "[, \t]+" ) ; String [ ] split = pattern . split ( extList ) ; for ( int i = 0 ; i < split . length ; i ++ ) { String ext = split [ i ] ; String name = attr . getValue ( ext + "-Extension-Name" ) ; if ( name == null ) continue ; Package pkg = Package . getPackage ( name ) ; if ( pkg == null ) { log . warning ( L . l ( "package {0} is missing. {1} requires package {0}." , name , manifestName ) ) ; continue ; } String version = attr . getValue ( ext + "-Specification-Version" ) ; if ( version == null ) continue ; if ( pkg . getSpecificationVersion ( ) == null || pkg . getSpecificationVersion ( ) . equals ( "" ) ) { log . warning ( L . l ( "installed {0} is not compatible with version `{1}'. {2} requires version {1}." , name , version , manifestName ) ) ; } else if ( ! pkg . isCompatibleWith ( version ) ) { log . warning ( L . l ( "installed {0} is not compatible with version `{1}'. {2} requires version {1}." , name , version , manifestName ) ) ; } } }
Validates the manifest .
363
5
140,011
public CodeSource getCodeSource ( String path ) { try { PathImpl jarPath = _jarPath . lookup ( path ) ; Certificate [ ] certificates = jarPath . getCertificates ( ) ; URL url = new URL ( _jarPath . getContainer ( ) . getURL ( ) ) ; return new CodeSource ( url , certificates ) ; } catch ( Exception e ) { log . log ( Level . WARNING , e . toString ( ) , e ) ; return null ; } }
Returns the code source .
103
5
140,012
public GuaranteeTermEvaluationResult evaluate ( IAgreement agreement , IGuaranteeTerm term , List < IMonitoringMetric > metrics , Date now ) { /* * throws NullPointerException if not property initialized */ checkInitialized ( ) ; logger . debug ( "evaluate(agreement={}, term={}, now={})" , agreement . getAgreementId ( ) , term . getKpiName ( ) , now ) ; final List < IViolation > violations = serviceLevelEval . evaluate ( agreement , term , metrics , now ) ; logger . debug ( "Found " + violations . size ( ) + " violations" ) ; final List < ? extends ICompensation > compensations = businessEval . evaluate ( agreement , term , violations , now ) ; logger . debug ( "Found " + compensations . size ( ) + " compensations" ) ; GuaranteeTermEvaluationResult result = new GuaranteeTermEvaluationResult ( violations , compensations ) ; return result ; }
Evaluate violations and penalties for a given guarantee term and a list of metrics .
214
17
140,013
@ Override public int read ( byte [ ] buf , int offset , int len ) throws IOException { int available = _available ; // The chunk still has more data left if ( available > 0 ) { len = Math . min ( len , available ) ; len = _next . read ( buf , offset , len ) ; if ( len > 0 ) { _available -= len ; } } // The chunk is done, so read the next chunk else if ( available == 0 ) { _available = readChunkLength ( ) ; // the new chunk has data if ( _available > 0 ) { len = Math . min ( len , _available ) ; len = _next . read ( buf , offset , len ) ; if ( len > 0 ) _available -= len ; } // the new chunk is the last else { _available = - 1 ; len = - 1 ; } } else { len = - 1 ; } return len ; }
Reads more data from the input stream .
197
9
140,014
private int readChunkLength ( ) throws IOException { int length = 0 ; int ch ; ReadStream is = _next ; // skip whitespace for ( ch = is . read ( ) ; ch == ' ' || ch == ' ' || ch == ' ' || ch == ' ' ; ch = is . read ( ) ) { } // XXX: This doesn't properly handle the case when when the browser // sends headers at the end of the data. See the HTTP/1.1 spec. for ( ; ch > 0 && ch != ' ' && ch != ' ' ; ch = is . read ( ) ) { if ( ' ' <= ch && ch <= ' ' ) length = 16 * length + ch - ' ' ; else if ( ' ' <= ch && ch <= ' ' ) length = 16 * length + ch - ' ' + 10 ; else if ( ' ' <= ch && ch <= ' ' ) length = 16 * length + ch - ' ' + 10 ; else if ( ch == ' ' || ch == ' ' ) { //if (dbg.canWrite()) // dbg.println("unexpected chunk whitespace."); } else { StringBuilder sb = new StringBuilder ( ) ; sb . append ( ( char ) ch ) ; for ( int ch1 = is . read ( ) ; ch1 >= 0 && ch1 != ' ' && ch1 != ' ' ; ch1 = is . read ( ) ) { sb . append ( ( char ) ch1 ) ; } throw new IOException ( "HTTP/1.1 protocol error: bad chunk at" + " '" + sb + "'" + " 0x" + Integer . toHexString ( ch ) + " length=" + length ) ; } } if ( ch == ' ' ) ch = is . read ( ) ; return length ; }
Reads the next chunk length from the input stream .
390
11
140,015
private String getSlaUrl ( String envSlaUrl , UriInfo uriInfo ) { String baseUrl = uriInfo . getBaseUri ( ) . toString ( ) ; if ( envSlaUrl == null ) { envSlaUrl = "" ; } String result = ( "" . equals ( envSlaUrl ) ) ? baseUrl : envSlaUrl ; logger . debug ( "getSlaUrl(env={}, supplied={}) = {}" , envSlaUrl , baseUrl , result ) ; return result ; }
Returns base url of the sla core .
116
9
140,016
private String getMetricsBaseUrl ( String suppliedBaseUrl , String envBaseUrl ) { String result = ( "" . equals ( suppliedBaseUrl ) ) ? envBaseUrl : suppliedBaseUrl ; logger . debug ( "getMetricsBaseUrl(env={}, supplied={}) = {}" , envBaseUrl , suppliedBaseUrl , result ) ; return result ; }
Return base url of the metrics endpoint of the Monitoring Platform .
77
12
140,017
public int read ( byte [ ] buffer , int offset , int length ) throws IOException { return _stream . read ( buffer , offset , length ) ; }
Reads a buffer to the underlying stream .
33
9
140,018
@ Override public PathImpl getParent ( ) { if ( _pathname . length ( ) <= 1 ) return lookup ( "/" ) ; int length = _pathname . length ( ) ; int lastSlash = _pathname . lastIndexOf ( ' ' ) ; if ( lastSlash < 1 ) return lookup ( "/" ) ; if ( lastSlash == length - 1 ) { lastSlash = _pathname . lastIndexOf ( ' ' , length - 2 ) ; if ( lastSlash < 1 ) return lookup ( "/" ) ; } return lookup ( _pathname . substring ( 0 , lastSlash ) ) ; }
Return the parent Path
139
4
140,019
static protected String normalizePath ( String oldPath , String newPath , int offset , char separatorChar ) { CharBuffer cb = new CharBuffer ( ) ; normalizePath ( cb , oldPath , newPath , offset , separatorChar ) ; return cb . toString ( ) ; }
wrapper for the real normalize path routine to use CharBuffer .
65
13
140,020
static protected void normalizePath ( CharBuffer cb , String oldPath , String newPath , int offset , char separatorChar ) { cb . clear ( ) ; cb . append ( oldPath ) ; if ( cb . length ( ) == 0 || cb . lastChar ( ) != ' ' ) cb . append ( ' ' ) ; int length = newPath . length ( ) ; int i = offset ; while ( i < length ) { char ch = newPath . charAt ( i ) ; char ch2 ; switch ( ch ) { default : if ( ch != separatorChar ) { cb . append ( ch ) ; i ++ ; break ; } // the separator character falls through to be treated as '/' case ' ' : // "//" -> "/" if ( cb . lastChar ( ) != ' ' ) cb . append ( ' ' ) ; i ++ ; break ; case ' ' : if ( cb . lastChar ( ) != ' ' ) { cb . append ( ' ' ) ; i ++ ; break ; } // "/." -> "" if ( i + 1 >= length ) { i += 2 ; break ; } switch ( newPath . charAt ( i + 1 ) ) { default : if ( newPath . charAt ( i + 1 ) != separatorChar ) { cb . append ( ' ' ) ; i ++ ; break ; } // the separator falls through to be treated as '/' // "/./" -> "/" case ' ' : i += 2 ; break ; // "foo/.." -> "" case ' ' : if ( ( i + 2 >= length || ( ch2 = newPath . charAt ( i + 2 ) ) == ' ' || ch2 == separatorChar ) && cb . lastChar ( ) == ' ' ) { int segment = cb . lastIndexOf ( ' ' , cb . length ( ) - 2 ) ; if ( segment == - 1 ) { cb . clear ( ) ; cb . append ( ' ' ) ; } else cb . length ( segment + 1 ) ; i += 3 ; } else { cb . append ( ' ' ) ; i ++ ; } break ; } } } // strip trailing "/" /* if (cb.length() > 1 && cb.getLastChar() == '/') cb.setLength(cb.length() - 1); */ }
Normalizes a filesystemPath path .
511
7
140,021
public String getFullPath ( ) { if ( _root == this || _root == null ) return getPath ( ) ; String rootPath = _root . getFullPath ( ) ; String path = getPath ( ) ; if ( rootPath . length ( ) <= 1 ) return path ; else if ( path . length ( ) <= 1 ) return rootPath ; else return rootPath + path ; }
For chrooted filesystems return the real system path .
84
12
140,022
public Class < ? > getClass ( int index ) { Object value = _values [ index - 1 ] ; if ( value == null ) { return null ; } else { return value . getClass ( ) ; } }
Returns the class of the column .
46
7
140,023
public String getString ( int index ) { Object value = _values [ index - 1 ] ; if ( value != null ) { return value . toString ( ) ; } else { return null ; } }
Returns the column as a String .
43
7
140,024
public long getLong ( int index ) { Object value = _values [ index - 1 ] ; if ( value instanceof Long ) { return ( Long ) value ; } else if ( value instanceof Integer ) { return ( Integer ) value ; } else { return Long . valueOf ( value . toString ( ) ) ; } }
Returns the column as a long .
69
7
140,025
public double getDouble ( int index ) { Object value = _values [ index - 1 ] ; if ( value instanceof Double ) { return ( Double ) value ; } else if ( value instanceof Float ) { return ( Float ) value ; } else if ( value instanceof Number ) { return ( Double ) ( ( Number ) value ) ; } else { return Double . valueOf ( value . toString ( ) ) ; } }
Returns the column as a double .
90
7
140,026
public boolean getBoolean ( int index ) { Object value = _values [ index - 1 ] ; if ( value instanceof Boolean ) { return ( Boolean ) value ; } else { return Boolean . valueOf ( value . toString ( ) ) ; } }
Returns the column as a boolean .
54
7
140,027
@ InService ( SegmentServiceImpl . class ) public Page writeCheckpoint ( TableKelp table , OutSegment sOut , long oldSequence , int saveLength , int tail , int saveSequence ) throws IOException { return null ; }
Called by the segment writing service to write the page to the stream .
54
15
140,028
public String getJavaCreateString ( ) { StringBuilder sb = new StringBuilder ( ) ; sb . append ( "new com.caucho.v5.make.DependencyList()" ) ; for ( int i = 0 ; i < _dependencyList . size ( ) ; i ++ ) { sb . append ( ".add(" ) ; sb . append ( _dependencyList . get ( i ) . getJavaCreateString ( ) ) ; sb . append ( ")" ) ; } return sb . toString ( ) ; }
Returns a string to recreate the dependency .
121
8
140,029
protected void initRequest ( ) { _hostHeader = null ; _xForwardedHostHeader = null ; _expect100Continue = false ; _cookies . clear ( ) ; _contentLengthIn = - 1 ; _hasReadStream = false ; _readEncoding = null ; //_request = request; //_requestFacade = getHttp().createFacade(this); _startTime = - 1 ; _expireTime = - 1 ; _isUpgrade = false ; _statusCode = 200 ; _statusMessage = "OK" ; _headerKeysOut . clear ( ) ; _headerValuesOut . clear ( ) ; _contentTypeOut = null ; _contentEncodingOut = null ; _contentLengthOut = - 1 ; _footerKeys . clear ( ) ; _footerValues . clear ( ) ; out ( ) . start ( ) ; _isHeaderWritten = false ; _isClosed = false ; //_serverHeader = http().serverHeader(); _isKeepalive = true ; }
Prepare the Request object for a new request .
216
10
140,030
public void clientDisconnect ( ) { try { OutHttpApp responseStream = _responseStream ; if ( responseStream != null ) { responseStream . close ( ) ; } } catch ( Exception e ) { log . log ( Level . FINER , e . toString ( ) , e ) ; } ConnectionTcp conn = connTcp ( ) ; if ( conn != null ) { conn . clientDisconnect ( ) ; } killKeepalive ( "client disconnect" ) ; }
Called when the client has disconnected
102
7
140,031
public int getServerPort ( ) { String host = null ; CharSequence rawHost ; if ( ( rawHost = getHost ( ) ) != null ) { int length = rawHost . length ( ) ; int i ; for ( i = length - 1 ; i >= 0 ; i -- ) { if ( rawHost . charAt ( i ) == ' ' ) { int port = 0 ; for ( i ++ ; i < length ; i ++ ) { char ch = rawHost . charAt ( i ) ; if ( ' ' <= ch && ch <= ' ' ) { port = 10 * port + ch - ' ' ; } } return port ; } } // server/0521 vs server/052o // because of proxies, need to use the host header, // not the actual port return isSecure ( ) ? 443 : 80 ; } if ( host == null ) { return connTcp ( ) . portLocal ( ) ; } int p1 = host . lastIndexOf ( ' ' ) ; if ( p1 < 0 ) return isSecure ( ) ? 443 : 80 ; else { int length = host . length ( ) ; int port = 0 ; for ( int i = p1 + 1 ; i < length ; i ++ ) { char ch = host . charAt ( i ) ; if ( ' ' <= ch && ch <= ' ' ) { port = 10 * port + ch - ' ' ; } } return port ; } }
Returns the server s port .
304
6
140,032
public CharSegment getHeaderBuffer ( String name ) { String value = header ( name ) ; if ( value != null ) return new CharBuffer ( value ) ; else return null ; }
Fills the result with the header values as CharSegment values . Most implementations will implement this directly .
39
21
140,033
protected boolean addHeaderInt ( char [ ] keyBuf , int keyOff , int keyLen , CharSegment value ) { if ( keyLen < 4 ) { return true ; } int key1 = keyBuf [ keyOff ] | 0x20 | ( keyLen << 8 ) ; switch ( key1 ) { case CONNECTION_KEY : if ( match ( keyBuf , keyOff , keyLen , CONNECTION ) ) { char [ ] valueBuffer = value . buffer ( ) ; int valueOffset = value . offset ( ) ; int valueLength = value . length ( ) ; int end = valueOffset + valueLength ; boolean isKeepalive = false ; while ( valueOffset < end ) { char ch = Character . toLowerCase ( valueBuffer [ valueOffset ] ) ; if ( ch == ' ' && match ( valueBuffer , valueOffset , KEEPALIVE . length , KEEPALIVE ) ) { isKeepalive = true ; valueOffset += KEEPALIVE . length ; } else if ( ch == ' ' && match ( valueBuffer , valueOffset , UPGRADE . length , UPGRADE ) ) { _isUpgrade = true ; valueOffset += UPGRADE . length ; } while ( valueOffset < end && valueBuffer [ valueOffset ++ ] != ' ' ) { } if ( valueBuffer [ valueOffset ] == ' ' ) { valueOffset ++ ; } } _isKeepalive = isKeepalive ; return true ; } case COOKIE_KEY : if ( match ( keyBuf , keyOff , keyLen , COOKIE ) ) { fillCookie ( _cookies , value ) ; } return true ; case CONTENT_LENGTH_KEY : if ( match ( keyBuf , keyOff , keyLen , CONTENT_LENGTH ) ) { contentLengthIn ( value ) ; } return true ; case EXPECT_KEY : if ( match ( keyBuf , keyOff , keyLen , EXPECT ) ) { if ( match ( value . buffer ( ) , value . offset ( ) , value . length ( ) , CONTINUE_100 ) ) { _expect100Continue = true ; return false ; } } return true ; case HOST_KEY : if ( match ( keyBuf , keyOff , keyLen , HOST ) ) { _hostHeader = value ; } return true ; case TRANSFER_ENCODING_KEY : if ( match ( keyBuf , keyOff , keyLen , TRANSFER_ENCODING ) ) { _isChunkedIn = true ; } return true ; case X_FORWARDED_HOST_KEY : if ( match ( keyBuf , keyOff , keyLen , X_FORWARDED_HOST ) ) { _xForwardedHostHeader = value ; } return true ; default : return true ; } }
Adds the header checking for known values .
608
8
140,034
private boolean match ( char [ ] a , int aOff , int aLength , char [ ] b ) { int bLength = b . length ; if ( aLength != bLength ) return false ; for ( int i = aLength - 1 ; i >= 0 ; i -- ) { char chA = a [ aOff + i ] ; char chB = b [ i ] ; if ( chA != chB && chA + ' ' - ' ' != chB ) { return false ; } } return true ; }
Matches case insensitively with the second normalized to lower case .
111
13
140,035
public Enumeration < String > getHeaders ( String name ) { String value = header ( name ) ; if ( value == null ) { return Collections . emptyEnumeration ( ) ; } ArrayList < String > list = new ArrayList < String > ( ) ; list . add ( value ) ; return Collections . enumeration ( list ) ; }
Returns an enumeration of the headers for the named attribute .
74
12
140,036
public void getHeaderBuffers ( String name , ArrayList < CharSegment > resultList ) { String value = header ( name ) ; if ( value != null ) resultList . add ( new CharBuffer ( value ) ) ; }
Fills the result with a list of the header values as CharSegment values . Most implementations will implement this directly .
49
24
140,037
public int getIntHeader ( String key ) { CharSegment value = getHeaderBuffer ( key ) ; if ( value == null ) return - 1 ; int len = value . length ( ) ; if ( len == 0 ) throw new NumberFormatException ( value . toString ( ) ) ; int iValue = 0 ; int i = 0 ; int ch = value . charAt ( i ) ; int sign = 1 ; if ( ch == ' ' ) { if ( i + 1 < len ) ch = value . charAt ( ++ i ) ; else throw new NumberFormatException ( value . toString ( ) ) ; } else if ( ch == ' ' ) { sign = - 1 ; if ( i + 1 < len ) ch = value . charAt ( ++ i ) ; else throw new NumberFormatException ( value . toString ( ) ) ; } for ( ; i < len && ( ch = value . charAt ( i ) ) >= ' ' && ch <= ' ' ; i ++ ) iValue = 10 * iValue + ch - ' ' ; if ( i < len ) throw new NumberFormatException ( value . toString ( ) ) ; return sign * iValue ; }
Returns the named header converted to an integer .
250
9
140,038
public String encoding ( ) { if ( _readEncoding != null ) return _readEncoding ; CharSegment value = getHeaderBuffer ( "Content-Type" ) ; if ( value == null ) return null ; int i = value . indexOf ( "charset" ) ; if ( i < 0 ) return null ; int len = value . length ( ) ; for ( i += 7 ; i < len && Character . isWhitespace ( value . charAt ( i ) ) ; i ++ ) { } if ( i >= len || value . charAt ( i ) != ' ' ) return null ; for ( i ++ ; i < len && Character . isWhitespace ( value . charAt ( i ) ) ; i ++ ) { } if ( i >= len ) return null ; char end = value . charAt ( i ) ; if ( end == ' ' ) { int tail ; for ( tail = ++ i ; tail < len ; tail ++ ) { if ( value . charAt ( tail ) == end ) break ; } _readEncoding = Encoding . getMimeName ( value . substring ( i , tail ) ) ; return _readEncoding ; } int tail ; for ( tail = i ; tail < len ; tail ++ ) { if ( Character . isWhitespace ( value . charAt ( tail ) ) || value . charAt ( tail ) == ' ' ) break ; } _readEncoding = Encoding . getMimeName ( value . substring ( i , tail ) ) ; return _readEncoding ; }
Returns the character encoding of a post .
332
8
140,039
CookieWeb [ ] fillCookies ( ) { int size = _cookies . size ( ) ; if ( size > 0 ) { CookieWeb [ ] cookiesIn = new WebCookie [ size ] ; for ( int i = size - 1 ; i >= 0 ; i -- ) { cookiesIn [ i ] = _cookies . get ( i ) ; } return cookiesIn ; } else { return NULL_COOKIES ; } }
Parses cookie information from the cookie headers .
93
10
140,040
private void finishRequest ( ) throws IOException { try { cleanup ( ) ; } catch ( Exception e ) { log . log ( Level . WARNING , e . toString ( ) , e ) ; } finally { //_requestFacade = null; } }
Cleans up at the end of the request
54
9
140,041
public final OutHttpApp out ( ) { OutHttpApp stream = _responseStream ; if ( stream == null ) { stream = createOut ( ) ; _responseStream = stream ; } return stream ; }
Gets the response stream .
43
6
140,042
public boolean containsHeaderOut ( String name ) { ArrayList < String > headerKeys = _headerKeysOut ; int size = headerKeys . size ( ) ; for ( int i = 0 ; i < size ; i ++ ) { String oldKey = headerKeys . get ( i ) ; if ( oldKey . equalsIgnoreCase ( name ) ) { return true ; } } if ( name . equalsIgnoreCase ( "content-type" ) ) { return _contentTypeOut != null ; } if ( name . equalsIgnoreCase ( "content-length" ) ) { return _contentLengthOut >= 0 ; } return false ; }
Returns true if the response already contains the named header .
135
11
140,043
public String headerOut ( String name ) { ArrayList < String > keys = _headerKeysOut ; int headerSize = keys . size ( ) ; for ( int i = 0 ; i < headerSize ; i ++ ) { String oldKey = keys . get ( i ) ; if ( oldKey . equalsIgnoreCase ( name ) ) { return ( String ) _headerValuesOut . get ( i ) ; } } /* if (name.equalsIgnoreCase("content-type")) { throw new UnsupportedOperationException(); //return request().getContentType(); } */ if ( name . equalsIgnoreCase ( "content-length" ) ) { return _contentLengthOut >= 0 ? String . valueOf ( _contentLengthOut ) : null ; } if ( name . equalsIgnoreCase ( "content-type" ) ) { return _contentTypeOut ; } return null ; }
Returns the value of an already set output header .
188
10
140,044
public void addHeaderOutImpl ( String key , String value ) { if ( headerOutSpecial ( key , value ) ) { return ; } ArrayList < String > keys = _headerKeysOut ; ArrayList < String > values = _headerValuesOut ; int size = keys . size ( ) ; // webapp/1k32 for ( int i = 0 ; i < size ; i ++ ) { if ( keys . get ( i ) . equals ( key ) && values . get ( i ) . equals ( value ) ) { return ; } } keys . add ( key ) ; values . add ( value ) ; }
Adds a new header . If an old header with that name exists both headers are output .
130
18
140,045
private boolean headerOutSpecial ( String key , String value ) { int length = key . length ( ) ; if ( length == 0 ) { return false ; } int ch = key . charAt ( 0 ) ; if ( ' ' <= ch && ch <= ' ' ) { ch += ' ' - ' ' ; } int code = ( length << 8 ) + ch ; switch ( code ) { case 0x0d00 + ' ' : if ( CACHE_CONTROL . matchesIgnoreCase ( key ) ) { // server/13d9, server/13dg if ( value . startsWith ( "max-age" ) ) { } else if ( value . startsWith ( "s-maxage" ) ) { } else if ( value . equals ( "x-anonymous" ) ) { } else { //request().setCacheControl(true); if ( true ) throw new UnsupportedOperationException ( ) ; } } return false ; case 0x0a00 + ' ' : if ( CONNECTION_CB . matchesIgnoreCase ( key ) ) { if ( "close" . equalsIgnoreCase ( value ) ) killKeepalive ( "client connection: close" ) ; return true ; } else { return false ; } case 0x0c00 + ' ' : if ( CONTENT_TYPE_CB . matchesIgnoreCase ( key ) ) { headerOutContentType ( value ) ; return true ; } else { return false ; } case 0x0e00 + ' ' : if ( CONTENT_LENGTH_CB . matchesIgnoreCase ( key ) ) { // server/05a8 // php/164v _contentLengthOut = parseLong ( value ) ; return true ; } else { return false ; } case 0x0400 + ' ' : if ( DATE . matchesIgnoreCase ( key ) ) { return true ; } else { return false ; } case 0x0600 + ' ' : if ( SERVER . matchesIgnoreCase ( key ) ) { _serverHeader = value ; return true ; } else { return false ; } default : return false ; } }
Special processing for a special value .
453
7
140,046
public void setFooter ( String key , String value ) { Objects . requireNonNull ( value ) ; int i = 0 ; boolean hasFooter = false ; for ( i = _footerKeys . size ( ) - 1 ; i >= 0 ; i -- ) { String oldKey = _footerKeys . get ( i ) ; if ( oldKey . equalsIgnoreCase ( key ) ) { if ( hasFooter ) { _footerKeys . remove ( i ) ; _footerValues . remove ( i ) ; } else { hasFooter = true ; _footerValues . set ( i , value ) ; } } } if ( ! hasFooter ) { _footerKeys . add ( key ) ; _footerValues . add ( value ) ; } }
Sets a footer replacing an already - existing footer
166
12
140,047
public void addFooter ( String key , String value ) { if ( headerOutSpecial ( key , value ) ) { return ; } _footerKeys . add ( key ) ; _footerValues . add ( value ) ; }
Adds a new footer . If an old footer with that name exists both footers are output .
49
21
140,048
public final boolean isOutCommitted ( ) { OutHttpApp stream = out ( ) ; if ( stream . isCommitted ( ) ) { return true ; } // server/05a7 if ( _contentLengthOut > 0 && _contentLengthOut <= stream . contentLength ( ) ) { return true ; } return false ; }
Returns true if some data has been sent to the browser .
70
12
140,049
public long contentLengthSent ( ) { OutHttpApp stream = _responseStream ; // stream can be null for duplex (websocket) if ( stream != null ) { return stream . contentLength ( ) ; } else { return Math . max ( _contentLengthOut , 0 ) ; } }
Returns the number of bytes sent to the output .
63
10
140,050
private boolean enableKeepalive ( PollController conn , boolean isNew ) throws IOException { if ( _selectMax <= _connectionCount . get ( ) ) { throw new IllegalStateException ( this + " keepalive overflow " + _connectionCount + " max=" + _selectMax ) ; /* conn.requestDestroy(); return false; */ } JniSocketImpl socket = ( JniSocketImpl ) conn . getSocket ( ) ; if ( socket == null ) { throw new IllegalStateException ( this + " socket empty for " + conn ) ; } int nativeFd = socket . getNativeFd ( ) ; if ( nativeFd < 0 ) { throw new IllegalStateException ( this + " attempted keepalive with closed file descriptor fd=" + nativeFd + "\n " + socket + "\n " + conn ) ; } else if ( _connections . length ( ) <= nativeFd ) { throw new IllegalStateException ( this + " select overflow for file descriptor fd=" + nativeFd + " " + conn ) ; } if ( ! _lifecycle . isActive ( ) ) { throw new IllegalStateException ( "inactive keepalive" ) ; } if ( isNew ) { setMaxConnection ( nativeFd ) ; _connections . set ( nativeFd , conn ) ; _connectionCount . incrementAndGet ( ) ; } int result = addNative ( _fd , nativeFd , isNew ) ; // result < 0 would likely be a disconnect return result == 0 ; }
Enables keepalive and checks to see if data is available .
324
14
140,051
private void runSelectTask ( ) { if ( _lifecycle . isActive ( ) || _lifecycle . isAfterStopping ( ) ) { log . warning ( this + " cannot start because an instance is active" ) ; return ; } initNative ( _fd ) ; synchronized ( _thread ) { _thread . notify ( ) ; } if ( ! _lifecycle . toActive ( ) ) { log . warning ( this + " invalid starting state" ) ; return ; } runImpl ( ) ; }
Running process accepting connections .
107
5
140,052
@ SuppressWarnings ( "unchecked" ) private void initTypesMapping ( ) { if ( mapping == null ) { throw new IllegalStateException ( "Mapping does contain any information in " + "DeployerTypesResolver " + this ) ; } if ( mapping . containsKey ( NODE_TYPES_MAPPING_SECTION ) ) { log . debug ( "Mapping contains NodeTypes mapping" ) ; nodeTypesMapping = ( Map < String , String > ) mapping . get ( NODE_TYPES_MAPPING_SECTION ) ; } if ( mapping . containsKey ( RELATIONSHIP_TYPES_MAPPING_SECTION ) ) { log . debug ( "Mapping contains NodeTypes mapping" ) ; relationshipTypesMapping = ( Map < String , String > ) mapping . get ( RELATIONSHIP_TYPES_MAPPING_SECTION ) ; } if ( mapping . containsKey ( NODE_TYPES_DEFINITIONS ) ) { log . debug ( "Mapping contains NodeTypes description" ) ; nodeTypesDefinitions = ( Map < String , Object > ) mapping . get ( NODE_TYPES_DEFINITIONS ) ; } if ( mapping . containsKey ( POLICY_TYPES_MAPPING_SECTION ) ) { log . debug ( "Mapping contains Policy mapping" ) ; policyTypesMapping = ( Map < String , String > ) mapping . get ( POLICY_TYPES_MAPPING_SECTION ) ; } }
Initialize the different types mapping .
336
7
140,053
@ Override public int addressRemote ( byte [ ] buffer , int offset , int length ) { return _socket . getRemoteAddress ( buffer , offset , length ) ; }
Adds from the socket s remote address .
36
8
140,054
@ Override public void requestWake ( ) { try { _state = _state . toWake ( ) ; requestLoop ( ) ; } catch ( Exception e ) { log . log ( Level . WARNING , e . toString ( ) , e ) ; } /* if (_stateRef.get().toWake(_stateRef)) { offer(getConnectionTask()); } */ }
Wake a connection .
81
5
140,055
private StateConnection processPoll ( ) throws IOException { PortTcp port = _port ; if ( port . isClosed ( ) ) { return StateConnection . DESTROY ; } if ( readStream ( ) . available ( ) > 0 ) { return StateConnection . ACTIVE ; } long timeout = _idleTimeout ; _idleStartTime = CurrentTime . currentTime ( ) ; _idleExpireTime = _idleStartTime + timeout ; // _state = _state.toKeepalive(this); PollTcpManagerBase pollManager = port . pollManager ( ) ; // use poll manager if available if ( pollManager == null ) { port ( ) . stats ( ) . addLifetimeKeepaliveCount ( ) ; return threadPoll ( timeout ) ; } if ( ! _pollHandle . isKeepaliveStarted ( ) ) { ServiceRef . flushOutbox ( ) ; if ( _port . keepaliveThreadRead ( readStream ( ) , _idleTimeout ) > 0 ) { return StateConnection . ACTIVE ; } else if ( _idleExpireTime <= CurrentTime . currentTime ( ) ) { return StateConnection . TIMEOUT ; } } /* if (! _state.toPollRequested(_stateRef)) { return _stateRef.get().getNextState(); } // _state = _state.toKeepaliveSelect(); * */ // keepalive to select manager succeeds switch ( pollManager . startPoll ( _pollHandle ) ) { case START : { if ( log . isLoggable ( Level . FINEST ) ) { log . finest ( dbgId ( ) + "keepalive (poll)" ) ; } port ( ) . stats ( ) . addLifetimeKeepaliveCount ( ) ; port ( ) . stats ( ) . addLifetimeKeepalivePollCount ( ) ; return StateConnection . POLL ; } case DATA : { if ( log . isLoggable ( Level . FINEST ) ) { log . finest ( "keepalive data available (poll) [" + dbgId ( ) + "]" ) ; } //_state = _state.toWake(); //System.out.println("DATA: " + _state); /* if (_stateRef.get().toPollSleep(_stateRef)) { throw new IllegalStateException(); } */ return StateConnection . ACTIVE ; } case CLOSED : { if ( log . isLoggable ( Level . FINEST ) ) { log . finest ( dbgId ( ) + " keepalive close (poll)" ) ; } //_state = _state.toWake(); /* if (_stateRef.get().toPollSleep(_stateRef)) { throw new IllegalStateException(); } */ return StateConnection . CLOSE_READ_A ; } default : throw new IllegalStateException ( ) ; } }
Starts a keepalive either returning available data or returning false to close the loop
610
17
140,056
private void initSocket ( ) throws IOException { _idleTimeout = _port . getKeepaliveTimeout ( ) ; _port . ssl ( _socket ) ; writeStream ( ) . init ( _socket . stream ( ) ) ; // ReadStream cannot use getWriteStream or auto-flush // because of duplex mode // ReadStream is = getReadStream(); _readStream . init ( _socket . stream ( ) ) ; if ( log . isLoggable ( Level . FINEST ) ) { log . finest ( dbgId ( ) + "starting connection " + this + ", total=" + _port . getConnectionCount ( ) ) ; } }
Initialize the socket for a new connection
141
8
140,057
private void destroy ( ) { if ( log . isLoggable ( Level . FINEST ) ) { log . finest ( this + " destroying connection" ) ; } try { _socket . forceShutdown ( ) ; } catch ( Throwable e ) { } try { closeConnection ( ) ; } catch ( Throwable e ) { log . log ( Level . FINER , e . toString ( ) , e ) ; } // XXX: _port . removeConnection ( this ) ; }
Destroy kills the connection and drops it from the connection pool .
103
12
140,058
private boolean isCacheValid ( ) { long now = CurrentTime . currentTime ( ) ; if ( ( now - _lastTime < 100 ) && ! CurrentTime . isTest ( ) ) return true ; long oldLastModified = _lastModified ; long oldLength = _length ; long newLastModified = getBacking ( ) . getLastModified ( ) ; long newLength = getBacking ( ) . length ( ) ; _lastTime = now ; if ( newLastModified == oldLastModified && newLength == oldLength ) { _lastTime = now ; return true ; } else { _changeSequence . incrementAndGet ( ) ; // If the file has changed, close the old file clearCache ( ) ; _zipEntryCache . clear ( ) ; _lastModified = newLastModified ; _length = newLength ; _lastTime = now ; return false ; } }
Returns the last modified time for the path .
194
9
140,059
@ Override public void setContextLoader ( ClassLoader loader ) { if ( loader != null ) _loaderRef = new WeakReference < ClassLoader > ( loader ) ; else _loaderRef = null ; }
Sets the class loader .
43
6
140,060
public static JClassLoaderWrapper create ( ClassLoader loader ) { JClassLoaderWrapper jLoader = _localClassLoader . getLevel ( loader ) ; if ( jLoader == null ) { jLoader = new JClassLoaderWrapper ( loader ) ; _localClassLoader . set ( jLoader , loader ) ; } return jLoader ; }
Creates the class loader with the context class loader .
73
11
140,061
private ByExpressionBuilder parseBy ( ) { ByExpressionBuilder by = new ByExpressionBuilder ( ) ; int x = _parseIndex ; Token token = scanToken ( ) ; if ( token == null ) throw new IllegalStateException ( L . l ( "expected field name at {0} in {1}" , x , _method . getName ( ) ) ) ; do { switch ( token ) { case IDENTIFIER : { StringBuilder sb = new StringBuilder ( ) ; sb . append ( _lexeme ) ; while ( peekToken ( ) == Token . IDENTIFIER ) { token = scanToken ( ) ; sb . append ( _lexeme ) ; } String term = fieldTerm ( sb . toString ( ) ) ; by . addField ( term ) ; break ; } case AND : { by . addAnd ( ) ; break ; } case EQ : case NE : case LT : case LE : case GT : case GE : by . term ( token ) ; break ; case GREATER : { if ( peekToken ( ) == Token . THAN ) { scanToken ( ) ; by . term ( Token . GT ) ; } else if ( peekToken ( ) == Token . EQ ) { scanToken ( ) ; by . term ( Token . GE ) ; } else { by . term ( Token . GT ) ; } break ; } case LESS : { if ( peekToken ( ) == Token . THAN ) { scanToken ( ) ; by . term ( Token . LT ) ; } else if ( peekToken ( ) == Token . EQ ) { scanToken ( ) ; by . term ( Token . LE ) ; } else { by . term ( Token . LT ) ; } break ; } case NOT : { if ( peekToken ( ) == Token . EQ ) { scanToken ( ) ; by . term ( Token . NE ) ; } else { by . term ( Token . NE ) ; } break ; } case OR : { by . addOr ( ) ; break ; } default : { throw new IllegalStateException ( _method . getName ( ) ) ; } } } while ( ( token = scanToken ( ) ) != Token . EOF ) ; return by ; }
Parse the by expression in the method name .
469
10
140,062
public static boolean isCaseInsensitive ( ) { Boolean value = _caseInsensitive . get ( ) ; if ( value == null ) { return _isCaseInsensitive ; } else return value . booleanValue ( ) ; }
Returns true if the local environment is case sensitive .
47
10
140,063
@ Override public void validate ( ) throws ConfigException { for ( int i = 0 ; i < _jarList . size ( ) ; i ++ ) { _jarList . get ( i ) . validate ( ) ; } }
Validates the loader .
48
5
140,064
@ Override public void getResources ( Vector < URL > vector , String name ) { if ( _pathMap != null ) { String cleanName = name ; if ( cleanName . endsWith ( "/" ) ) cleanName = cleanName . substring ( 0 , cleanName . length ( ) - 1 ) ; JarMap . JarList jarEntryList = _pathMap . get ( cleanName ) ; for ( ; jarEntryList != null ; jarEntryList = jarEntryList . getNext ( ) ) { JarEntry jarEntry = jarEntryList . getEntry ( ) ; PathImpl path = jarEntry . getJarPath ( ) ; path = path . lookup ( name ) ; try { URL url = new URL ( path . getURL ( ) ) ; if ( ! vector . contains ( url ) ) vector . add ( url ) ; } catch ( Exception e ) { log . log ( Level . WARNING , e . toString ( ) , e ) ; } } } else { for ( int i = 0 ; i < _jarList . size ( ) ; i ++ ) { JarEntry jarEntry = _jarList . get ( i ) ; PathImpl path = jarEntry . getJarPath ( ) ; path = path . lookup ( name ) ; if ( path . exists ( ) ) { try { URL url = new URL ( path . getURL ( ) ) ; if ( ! vector . contains ( url ) ) vector . add ( url ) ; } catch ( Exception e ) { log . log ( Level . WARNING , e . toString ( ) , e ) ; } } } } }
Adds resources to the enumeration .
336
7
140,065
@ Override public PathImpl getPath ( String pathName ) { if ( _pathMap != null ) { String cleanPathName = pathName ; if ( cleanPathName . endsWith ( "/" ) ) cleanPathName = cleanPathName . substring ( 0 , cleanPathName . length ( ) - 1 ) ; JarMap . JarList jarEntryList = _pathMap . get ( cleanPathName ) ; if ( jarEntryList != null ) { return jarEntryList . getEntry ( ) . getJarPath ( ) . lookup ( pathName ) ; } } else { for ( int i = 0 ; i < _jarList . size ( ) ; i ++ ) { JarEntry jarEntry = _jarList . get ( i ) ; PathImpl path = jarEntry . getJarPath ( ) ; PathImpl filePath = path . lookup ( pathName ) ; if ( filePath . exists ( ) ) return filePath ; } } return null ; }
Find a given path somewhere in the classpath
203
9
140,066
protected void clearJars ( ) { synchronized ( this ) { ArrayList < JarEntry > jars = new ArrayList < JarEntry > ( _jarList ) ; _jarList . clear ( ) ; if ( _pathMap != null ) _pathMap . clear ( ) ; for ( int i = 0 ; i < jars . size ( ) ; i ++ ) { JarEntry jarEntry = jars . get ( i ) ; JarPath jarPath = jarEntry . getJarPath ( ) ; jarPath . closeJar ( ) ; } } }
Closes the jars .
114
5
140,067
public final double sampleSigma ( int n ) { synchronized ( _lock ) { long count = _count . get ( ) ; long lastCount = _lastStdCount ; _lastStdCount = count ; double sum = _sum . get ( ) ; double lastSum = _lastStdSum ; _lastStdSum = sum ; double sumSquare = _sumSquare ; _sumSquare = 0 ; if ( count == lastCount ) return 0 ; double avg = ( sum - lastSum ) / ( count - lastCount ) ; double part = ( count - lastCount ) * sumSquare - sum * sum ; if ( part < 0 ) part = 0 ; double std = Math . sqrt ( part ) / ( count - lastCount ) ; return _scale * ( avg + n * std ) ; } }
Return the probe s next 2 - sigma
173
9
140,068
public static int getInt ( String strValue ) { int value = 0 ; if ( StringUtils . isNotBlank ( strValue ) ) { Matcher m = Pattern . compile ( "^(\\d+)(?:\\w+|%)?$" ) . matcher ( strValue ) ; if ( m . find ( ) ) { value = Integer . parseInt ( m . group ( 1 ) ) ; } } return value ; }
get int value of string
95
5
140,069
boolean isKeepaliveAllowed ( long connectionStartTime ) { if ( ! _lifecycle . isActive ( ) ) { return false ; } else if ( connectionStartTime + _keepaliveTimeMax < CurrentTime . currentTime ( ) ) { return false ; } else if ( _keepaliveMax <= _keepaliveAllocateCount . get ( ) ) { return false ; } /* else if (_connThreadPool.isThreadMax() && _connThreadPool.isIdleLow() && ! isKeepaliveAsyncEnabled()) { return false; } */ else { return true ; } }
Allocates a keepalive for the connection .
130
11
140,070
int keepaliveThreadRead ( ReadStream is , long timeoutConn ) throws IOException { if ( isClosed ( ) ) { return - 1 ; } int available = is . availableBuffer ( ) ; if ( available > 0 ) { return available ; } long timeout = Math . min ( getKeepaliveTimeout ( ) , getSocketTimeout ( ) ) ; if ( timeoutConn > 0 ) { timeout = Math . min ( timeout , timeoutConn ) ; } // server/2l02 int keepaliveThreadCount = _keepaliveThreadCount . incrementAndGet ( ) ; // boolean isSelectManager = getServer().isSelectManagerEnabled(); try { int result ; if ( isKeepaliveAsyncEnabled ( ) && _pollManager != null ) { timeout = Math . min ( timeout , getBlockingTimeoutForPoll ( ) ) ; if ( keepaliveThreadCount > 32 ) { // throttle the thread keepalive when heavily loaded to save threads if ( isAsyncThrottle ( ) ) { // when async throttle is active move the thread to async // immediately return 0 ; } else { timeout = Math . min ( timeout , 100 ) ; } } } /* if (timeout < 0) timeout = 0; */ if ( timeout <= 0 ) { return 0 ; } _keepaliveThreadMeter . start ( ) ; try { /* if (false && _keepaliveThreadCount.get() < 32) { // benchmark perf with memcache result = is.fillWithTimeout(-1); } */ result = is . fillWithTimeout ( timeout ) ; } finally { _keepaliveThreadMeter . end ( ) ; } if ( isClosed ( ) ) { return - 1 ; } return result ; } catch ( IOException e ) { if ( isClosed ( ) ) { log . log ( Level . FINEST , e . toString ( ) , e ) ; return - 1 ; } throw e ; } finally { _keepaliveThreadCount . decrementAndGet ( ) ; } }
Reads data from a keepalive connection
426
9
140,071
@ Friend ( ConnectionTcp . class ) void freeConnection ( ConnectionTcp conn ) { if ( removeConnection ( conn ) ) { _idleConn . free ( conn ) ; } else if ( isActive ( ) ) { // Thread.dumpStack(); System . out . println ( "Possible Double Close: " + this + " " + conn ) ; } //_connThreadPool.wake(); }
Closes the stats for the connection .
86
8
140,072
public void init ( String dc_sync_period , String resources_keep_alive_period , String manager_ip , String manager_port ) { if ( registryInitialized ) throw new RuntimeException ( "Registry was already initialized" ) ; if ( dc_sync_period != null ) { CONFIG_SYNC_PERIOD = Integer . parseInt ( dc_sync_period ) ; } if ( resources_keep_alive_period != null ) { KEEP_ALIVE = Integer . parseInt ( resources_keep_alive_period ) ; } // Build metrics providedMetrics = buildProvidedMetrics ( ) ; // Build the DCAgent dcAgent = new DCAgent ( new ManagerAPI ( manager_ip , Integer . parseInt ( manager_port ) ) ) ; // Add observers of metrics to the DCAgent for ( Metric metric : providedMetrics ) { logger . debug ( "Added metric {} as observer of dcagent" , metric . getMonitoredMetric ( ) ) ; dcAgent . addObserver ( metric ) ; } // Build the DCDescriptor DCDescriptor dcDescriptor = new DCDescriptor ( ) ; dcDescriptor . addMonitoredResources ( getProvidedMetrics ( ) , getResources ( ) ) ; dcDescriptor . addResources ( getResources ( ) ) ; dcDescriptor . setConfigSyncPeriod ( CONFIG_SYNC_PERIOD != null ? CONFIG_SYNC_PERIOD : DEFAULT_CONFIG_SYNC_PERIOD ) ; dcDescriptor . setKeepAlive ( KEEP_ALIVE != null ? KEEP_ALIVE : ( DEFAULT_CONFIG_SYNC_PERIOD + 15 ) ) ; dcAgent . setDCDescriptor ( dcDescriptor ) ; registryInitialized = true ; }
This method is used to initialized the collecting of each metric . It initializes a DCAgent with the manager_ip and manager_port parameters in order to communicate with Tower 4Clouds . It then build a DCDescriptor with the list of all the provided metrics and the set of monitored resources for each provided metric . It then start the DCAgent which enact the collecting of each metric and communicate to Tower 4Clouds the set of monitored resources for each provided metric .
395
95
140,073
public static void addResource ( String type , String id , String url ) { //add the new resource to the list of the managed resources logger . info ( "Adding the following new resource to the Data Collector Descriptor: {}, {}" , type , id ) ; try { resources . put ( new InternalComponent ( type , id ) , new URL ( url ) ) ; } catch ( MalformedURLException e ) { logger . error ( e . getMessage ( ) , e . getCause ( ) ) ; } logger . info ( "Currently managed resources..." ) ; for ( Resource r : _INSTANCE . getResources ( ) ) { logger . info ( r . getType ( ) + " " + r . getId ( ) + "\n" ) ; } // re-Build the DCDescriptor DCDescriptor dcDescriptor = new DCDescriptor ( ) ; dcDescriptor . addMonitoredResources ( _INSTANCE . getProvidedMetrics ( ) , _INSTANCE . getResources ( ) ) ; dcDescriptor . addResources ( _INSTANCE . getResources ( ) ) ; dcDescriptor . setConfigSyncPeriod ( CONFIG_SYNC_PERIOD != null ? CONFIG_SYNC_PERIOD : DEFAULT_CONFIG_SYNC_PERIOD ) ; dcDescriptor . setKeepAlive ( KEEP_ALIVE != null ? KEEP_ALIVE : ( DEFAULT_CONFIG_SYNC_PERIOD + 15 ) ) ; logger . info ( "Setting the new DCDescriptor..." ) ; _INSTANCE . dcAgent . setDCDescriptor ( dcDescriptor ) ; //re-start the monitoring _INSTANCE . monitoringStarted = false ; startMonitoring ( ) ; }
This method allow to add a new monitored resource to the Registry .
384
13
140,074
static Throwable cause ( Throwable e ) { while ( e . getCause ( ) != null && ( e instanceof InstantiationException || e instanceof InvocationTargetException || e . getClass ( ) . equals ( RuntimeExceptionConfig . class ) ) ) { e = e . getCause ( ) ; } return e ; }
Unwraps noise from the exception trace .
69
9
140,075
@ Override public void alarm ( DeployService2Impl < I > deploy , Result < I > result ) { LifecycleState state = deploy . getState ( ) ; if ( ! state . isActive ( ) ) { result . ok ( deploy . get ( ) ) ; } else if ( deploy . isModifiedNow ( ) ) { // baratine/801g deploy . logModified ( deploy . getLog ( ) ) ; deploy . restartImpl ( result ) ; } else { result . ok ( deploy . get ( ) ) ; } }
Restart if the controller is active .
116
8
140,076
String parseLine ( CharCursor is , LineMap lineMap ) throws IOException { int ch = is . read ( ) ; _buf . clear ( ) ; String filename = null ; int line = 0 ; // Take 3: match /.*:\d+:/ _token . clear ( ) ; line : for ( ; ch != is . DONE ; ch = is . read ( ) ) { while ( ch == ' ' ) { line = 0 ; for ( ch = is . read ( ) ; ch >= ' ' && ch <= ' ' ; ch = is . read ( ) ) line = 10 * line + ch - ' ' ; if ( ch == ' ' && line > 0 ) { filename = _token . toString ( ) ; break line ; } else { _token . append ( ' ' ) ; if ( line > 0 ) _token . append ( line ) ; } } if ( ch != is . DONE ) _token . append ( ( char ) ch ) ; } if ( filename == null ) return null ; int column = 0 ; // skip added junk like jikes extra "emacs" style columns for ( ; ch != is . DONE && ch != ' ' ; ch = is . read ( ) ) { } for ( ; ch == ' ' ; ch = is . read ( ) ) { } // now gather the message _buf . clear ( ) ; for ( ; ch != is . DONE ; ch = is . read ( ) ) _buf . append ( ( char ) ch ) ; String message = _buf . toString ( ) ; if ( lineMap != null ) return lineMap . convertError ( filename , line , 0 , message ) ; else return filename + ":" + line + ": " + message ; }
Scans errors .
370
4
140,077
public static long generate ( long crc , long value ) { crc = next ( crc , ( byte ) ( value >> 56 ) ) ; crc = next ( crc , ( byte ) ( value >> 48 ) ) ; crc = next ( crc , ( byte ) ( value >> 40 ) ) ; crc = next ( crc , ( byte ) ( value >> 32 ) ) ; crc = next ( crc , ( byte ) ( value >> 24 ) ) ; crc = next ( crc , ( byte ) ( value >> 16 ) ) ; crc = next ( crc , ( byte ) ( value >> 8 ) ) ; crc = next ( crc , ( byte ) ( value >> 0 ) ) ; return crc ; }
Calculates CRC from a long
162
7
140,078
@ Override public String toObjectExpr ( String columnName ) { if ( _value == null ) { return "null" ; } else if ( _value instanceof String ) { return "'" + _value + "'" ; } else { return String . valueOf ( _value ) ; } }
Object expr support .
64
4
140,079
public int copyTo ( byte [ ] buffer , int rowOffset , int blobTail ) { byte [ ] blockBuffer = _block . getBuffer ( ) ; System . arraycopy ( blockBuffer , _rowOffset , buffer , rowOffset , _length ) ; return _row . copyBlobs ( blockBuffer , _rowOffset , buffer , rowOffset , blobTail ) ; }
Copies the row and its inline blobs to the target buffer .
81
14
140,080
@ Override public PathImpl schemeWalk ( String userPath , Map < String , Object > newAttributes , String newPath , int offset ) { return getWrappedPath ( ) . schemeWalk ( userPath , newAttributes , newPath , offset ) ; }
Path - specific lookup . Path implementations will override this .
54
11
140,081
final void executorTimeout ( ExecutorThrottle executor , long timeout ) { _executor = executor ; _activeSlowExpireTime = CurrentTime . getCurrentTimeActual ( ) + timeout ; }
Sets timeouts .
46
5
140,082
@ Override public void run ( ) { try { _launcher . onChildIdleBegin ( ) ; _launcher . onChildThreadLaunchBegin ( ) ; _pool . addThread ( this ) ; runTasks ( ) ; } catch ( Throwable e ) { log . log ( Level . WARNING , e . toString ( ) , e ) ; } finally { _pool . removeThread ( this ) ; _launcher . onChildIdleEnd ( ) ; _launcher . onChildThreadLaunchEnd ( ) ; } }
The main thread execution method .
114
6
140,083
private void runTasks ( ) { ClassLoader systemClassLoader = ClassLoader . getSystemClassLoader ( ) ; ThreadPoolBase pool = _pool ; Thread thread = this ; Outbox outbox = outbox ( ) ; boolean isWake = false ; setName ( _name ) ; while ( ! _isClose ) { RunnableItem taskItem = pool . poll ( isWake ) ; isWake = false ; if ( taskItem != null ) { try { _launcher . onChildIdleEnd ( ) ; outbox . open ( ) ; do { // if the task is available, run it in the proper context thread . setContextClassLoader ( taskItem . getClassLoader ( ) ) ; taskItem . getTask ( ) . run ( ) ; outbox . flushAndExecuteAll ( ) ; } while ( ( taskItem = pool . poll ( false ) ) != null ) ; } catch ( Throwable e ) { log . log ( Level . WARNING , e . toString ( ) , e ) ; } finally { try { outbox . close ( ) ; } catch ( Throwable e ) { e . printStackTrace ( ) ; } _launcher . onChildIdleBegin ( ) ; thread . setContextClassLoader ( systemClassLoader ) ; if ( ! thread . getName ( ) . equals ( _name ) ) { setName ( _name ) ; } } } else if ( _launcher . isIdleExpire ( ) ) { return ; } else if ( park ( ) ) { //thread.onWakeThread(); isWake = true ; } else { return ; } } }
Main thread loop .
349
4
140,084
private static long addDigest ( long digest , long v ) { digest = Crc64 . generate ( digest , ( byte ) ( v >> 24 ) ) ; digest = Crc64 . generate ( digest , ( byte ) ( v >> 16 ) ) ; digest = Crc64 . generate ( digest , ( byte ) ( v >> 8 ) ) ; digest = Crc64 . generate ( digest , ( byte ) v ) ; return digest ; }
Adds the int to the digest .
94
7
140,085
private int compareView ( ViewRef < ? > viewA , ViewRef < ? > viewB , Class < ? > type ) { int cmp = viewB . priority ( ) - viewA . priority ( ) ; if ( cmp != 0 ) { return cmp ; } cmp = typeDepth ( viewA . type ( ) , type ) - typeDepth ( viewB . type ( ) , type ) ; if ( cmp != 0 ) { return cmp ; } // equivalent views are sorted by name to ensure consistency String nameA = viewA . resolver ( ) . getClass ( ) . getName ( ) ; String nameB = viewB . resolver ( ) . getClass ( ) . getName ( ) ; return nameA . compareTo ( nameB ) ; }
sort views .
167
3
140,086
private int typeDepth ( Class < ? > match , Class < ? > actual ) { if ( actual == null ) { return Integer . MAX_VALUE / 2 ; } if ( match . equals ( Object . class ) ) { return Integer . MAX_VALUE / 4 ; } if ( match . equals ( actual ) ) { return 0 ; } int cost = 1 + typeDepth ( match , actual . getSuperclass ( ) ) ; for ( Class < ? > iface : actual . getInterfaces ( ) ) { cost = Math . min ( cost , 1 + typeDepth ( match , iface ) ) ; } return cost ; }
count of how closely the source matches the target .
133
10
140,087
public final void configure ( Object bean ) { Objects . requireNonNull ( bean ) ; Thread thread = Thread . currentThread ( ) ; ClassLoader loader = thread . getContextClassLoader ( ) ; /* ContextConfig oldContext = ContextConfig.getCurrent(); try { ContextConfig.setCurrent(new ContextConfig(new Config())); ConfigType<?> type = TypeFactoryConfig.getType(bean); configure(bean, type); } finally { ContextConfig.setCurrent(oldContext); } */ }
Configures a bean with a configuration file .
105
9
140,088
final public void configureImpl ( Object bean ) // , ConfigType<?> type) throws ConfigException { Objects . requireNonNull ( bean ) ; //Objects.requireNonNull(type); try { //type.beforeConfigure(bean); // ioc/23e7 InjectContext env = InjectContextImpl . CONTEXT ; injectTop ( bean , env ) ; //type.init(bean); } finally { //type.afterConfigure(bean); } }
Configures the object .
100
5
140,089
public boolean add ( String srcFilename , int srcLine , int dstLine ) { return add ( srcFilename , srcLine , dstLine , false ) ; }
Adds a new line map entry .
33
7
140,090
public void addLine ( int startLine , String sourceFile , int repeatCount , int outputLine , int outputIncrement ) { _lines . add ( new Line ( startLine , sourceFile , repeatCount , outputLine , outputIncrement ) ) ; }
Adds a line from the smap
54
7
140,091
public String convertError ( String filename , int line , int column , String message ) { String srcFilename = null ; int destLine = 0 ; int srcLine = 0 ; for ( int i = 0 ; i < _lines . size ( ) ; i ++ ) { Line map = _lines . get ( i ) ; if ( filename != null && ! filename . endsWith ( _dstFilename ) ) { } else if ( map . _dstLine <= line && line <= map . getLastDestinationLine ( ) ) { srcFilename = map . _srcFilename ; srcLine = map . getSourceLine ( line ) ; } } if ( srcFilename != null ) return srcFilename + ":" + srcLine + ": " + message ; else return filename + ":" + line + ": " + message ; }
Converts an error in the generated file to a CompileError based on the source .
174
18
140,092
private void convertError ( CharBuffer buf , int line ) { String srcFilename = null ; int destLine = 0 ; int srcLine = 0 ; int srcTailLine = Integer . MAX_VALUE ; for ( int i = 0 ; i < _lines . size ( ) ; i ++ ) { Line map = ( Line ) _lines . get ( i ) ; if ( map . _dstLine <= line && line <= map . getLastDestinationLine ( ) ) { srcFilename = map . _srcFilename ; destLine = map . _dstLine ; srcLine = map . getSourceLine ( line ) ; break ; } } if ( srcFilename != null ) { } else if ( _lines . size ( ) > 0 ) srcFilename = ( ( Line ) _lines . get ( 0 ) ) . _srcFilename ; else srcFilename = "" ; buf . append ( srcFilename ) ; if ( line >= 0 ) { buf . append ( ":" ) ; buf . append ( srcLine + ( line - destLine ) ) ; } }
Maps a destination line to an error location .
223
9
140,093
public void copyFrom ( Invocation invocation ) { _classLoader = invocation . _classLoader ; _rawHost = invocation . _rawHost ; _rawURI = invocation . _rawURI ; _hostName = invocation . _hostName ; _port = invocation . _port ; _uri = invocation . _uri ; _depend = invocation . _depend ; _queryString = invocation . _queryString ; }
Copies from the invocation .
85
6
140,094
final public void print ( long v ) { Writer out = this . out ; if ( out == null ) return ; if ( v == 0x8000000000000000 L ) { print ( "-9223372036854775808" ) ; return ; } try { if ( v < 0 ) { out . write ( ' ' ) ; v = - v ; } else if ( v == 0 ) { out . write ( ' ' ) ; return ; } int j = 31 ; while ( v > 0 ) { _tempCharBuffer [ -- j ] = ( char ) ( ( v % 10 ) + ' ' ) ; v /= 10 ; } out . write ( _tempCharBuffer , j , 31 - j ) ; } catch ( IOException e ) { log . log ( Level . FINE , e . toString ( ) , e ) ; } }
Prints a long .
182
5
140,095
final public void println ( long v ) { Writer out = this . out ; if ( out == null ) return ; print ( v ) ; try { out . write ( _newline , 0 , _newline . length ) ; } catch ( IOException e ) { log . log ( Level . FINE , e . toString ( ) , e ) ; } }
Prints a long followed by a newline .
77
10
140,096
public void exportCode ( JavaClass source , JavaClass target ) throws Exception { ExportAnalyzer analyzer = new ExportAnalyzer ( source , target ) ; CodeEnhancer visitor = new CodeEnhancer ( source , this ) ; visitor . analyze ( analyzer , false ) ; visitor . update ( ) ; }
Exports code .
64
4
140,097
@ Override protected void fillChunkHeader ( TempBuffer tBuf , int length ) { if ( length == 0 ) throw new IllegalStateException ( ) ; byte [ ] buffer = tBuf . buffer ( ) ; buffer [ 0 ] = ( byte ) ' ' ; buffer [ 1 ] = ( byte ) ' ' ; buffer [ 2 ] = hexDigit ( length >> 12 ) ; buffer [ 3 ] = hexDigit ( length >> 8 ) ; buffer [ 4 ] = hexDigit ( length >> 4 ) ; buffer [ 5 ] = hexDigit ( length ) ; buffer [ 6 ] = ( byte ) ' ' ; buffer [ 7 ] = ( byte ) ' ' ; }
Fills the chunk header .
146
6
140,098
public static < T > Key < T > of ( Type type , Class < ? extends Annotation > [ ] annTypes ) { return new Key <> ( type , annTypes ) ; }
Builds Key from Type and annotation types
40
8
140,099
public static < T > Key < T > of ( Class < T > type , Class < ? extends Annotation > annType ) { Objects . requireNonNull ( type ) ; Objects . requireNonNull ( annType ) ; return new Key <> ( type , new Class [ ] { annType } ) ; }
Builds Key from Class and annotation type
66
8