idx
int64
0
41.2k
question
stringlengths
83
4.15k
target
stringlengths
5
715
14,600
public void exclusiveOr ( Area area ) { Area a = clone ( ) ; a . intersect ( area ) ; add ( area ) ; subtract ( a ) ; }
Computes the exclusive or of this area and the supplied area and sets this area to the result .
14,601
private static double [ ] adjustSize ( double [ ] array , int newSize ) { if ( newSize <= array . length ) { return array ; } double [ ] newArray = new double [ 2 * newSize ] ; System . arraycopy ( array , 0 , newArray , 0 , array . length ) ; return newArray ; }
the method check up the array size and necessarily increases it .
14,602
@ Path ( "/ipAddrInfo" ) public String getIPAddrInfo ( ) throws UnknownHostException { Properties clientProps = getPropeSenderProps ( ) ; StringBuffer buf = new StringBuffer ( ) ; InetAddress localhost = null ; NetworkInterface ni = null ; try { localhost = InetAddress . getLocalHost ( ) ; LOGGER . debug ( "Network Interface name not specified. Using the NI for localhost " + localhost . getHostAddress ( ) ) ; ni = NetworkInterface . getByInetAddress ( localhost ) ; } catch ( UnknownHostException | SocketException e ) { LOGGER . error ( "Error occured dealing with network interface name lookup " , e ) ; } buf . append ( "<p>" ) . append ( "<span style='color: red'> IP Address: </span>" ) . append ( localhost . getHostAddress ( ) ) ; buf . append ( "<span style='color: red'> Host name: </span>" ) . append ( localhost . getCanonicalHostName ( ) ) ; if ( ni == null ) { buf . append ( "<span style='color: red'> Network Interface is NULL </span>" ) ; } else { buf . append ( "<span style='color: red'> Network Interface name: </span>" ) . append ( ni . getDisplayName ( ) ) ; } buf . append ( "</p><p>" ) ; buf . append ( "Sending probes to " + respondToAddresses . size ( ) + " addresses - " ) ; for ( ProbeRespondToAddress rta : respondToAddresses ) { buf . append ( "<span style='color: red'> Probe to: </span>" ) . append ( rta . respondToAddress + ":" + rta . respondToPort ) ; } buf . append ( "</p>" ) ; return buf . toString ( ) ; }
Return the ip info of where the web host lives that supports the browser app .
14,603
@ Path ( "/launchProbe" ) @ Produces ( "application/txt" ) public String launchProbe ( ) throws IOException , UnsupportedPayloadType , ProbeSenderException , TransportException { Properties clientProps = getPropeSenderProps ( ) ; String multicastGroupAddr = clientProps . getProperty ( "multicastGroupAddr" , DEFAULT_MULTICAST_GROUP_ADDR ) ; String multicastPortString = clientProps . getProperty ( "multicastPort" , DEFAULT_MULTICAST_PORT . toString ( ) ) ; String listenerURLPath = clientProps . getProperty ( "listenerProbeResponseURLPath" , DEFAULT_PROBE_RESPONSE_URL_PATH ) ; Integer multicastPort = Integer . parseInt ( multicastPortString ) ; ProbeSender gen ; try { gen = ProbeSenderFactory . createMulticastProbeSender ( multicastGroupAddr , multicastPort ) ; Probe probe = new Probe ( Probe . JSON ) ; for ( ProbeRespondToAddress rta : respondToAddresses ) { probe . addRespondToURL ( "browser" , "http://" + rta . respondToAddress + ":" + rta . respondToPort + listenerURLPath ) ; } gen . sendProbe ( probe ) ; gen . close ( ) ; return "Launched " + respondToAddresses . size ( ) + " probe(s) successfully on " + multicastGroupAddr + ":" + multicastPort ; } catch ( TransportConfigException e ) { return "Launched Failed: " + e . getLocalizedMessage ( ) ; } }
Actually launch a probe .
14,604
@ Path ( "/responses" ) @ Produces ( "application/json" ) public String getResponses ( ) throws UnknownHostException { Properties clientProps = getPropeSenderProps ( ) ; String listenerIPAddress = clientProps . getProperty ( "listenerIPAddress" ) ; String listenerPort = clientProps . getProperty ( "listenerPort" ) ; String listenerReponsesURLPath = clientProps . getProperty ( "listenerReponsesURLPath" , DEFAULT_RESPONSES_URL_PATH ) ; String response = restGetCall ( "http://" + listenerIPAddress + ":" + listenerPort + listenerReponsesURLPath ) ; return response ; }
Returns a list of the responses collected in the listener .
14,605
@ Path ( "/clearCache" ) @ Produces ( "application/json" ) public String clearCache ( ) throws UnknownHostException { Properties clientProps = getPropeSenderProps ( ) ; String listenerIPAddress = clientProps . getProperty ( "listenerIPAddress" ) ; String listenerPort = clientProps . getProperty ( "listenerPort" ) ; String listenerClearCacheURLPath = clientProps . getProperty ( "listenerClearCacheURLPath" , DEFAULT_CLEAR_CACHE_URL_PATH ) ; String response = restGetCall ( "http://" + listenerIPAddress + ":" + listenerPort + listenerClearCacheURLPath ) ; return response ; }
Clears the active response cache .
14,606
public double distance ( Vector3 point ) { double distance = - Float . MAX_VALUE ; for ( Plane plane : _planes ) { distance = Math . max ( distance , plane . distance ( point ) ) ; } return distance ; }
Determines the maximum signed distance of the point from the planes of the frustum . If the distance is less than or equal to zero the point lies inside the frustum .
14,607
public static Class < ? extends Command < ? extends CLIContext > > getCommandClass ( CLIContext context , String commandName ) { return context . getHostApplication ( ) . getCommands ( ) . get ( commandName . toLowerCase ( ) ) ; }
Get a command by name .
14,608
public static < T > DecomposableMatchBuilder0 < List < T > > nil ( ) { List < Matcher < Object > > matchers = Lists . of ( ) ; return new DecomposableMatchBuilder0 < List < T > > ( matchers , new ListConsNilFieldExtractor < > ( ) ) ; }
Matches an empty list .
14,609
public static void print ( ConsoleLevel level , String message ) { if ( level . compareTo ( _level ) <= 0 ) { if ( _printLogLevel ) { level . getStream ( ) . println ( level . name ( ) + ": " + message ) ; } else { level . getStream ( ) . println ( message ) ; } level . getStream ( ) . flush ( ) ; } }
Print the given message at the given level .
14,610
public R getMatch ( ) { for ( Pattern < T , R > pattern : patterns ) { if ( pattern . matches ( value ) ) { return pattern . apply ( value ) ; } } throw new MatchException ( "No match found for " + value ) ; }
Runs through the possible matches and executes the specified action of the first match and returns the result .
14,611
public void seedUsingPcmAudio ( byte [ ] data ) { byte [ ] key = new byte [ 64 ] ; for ( int i = 0 ; i < key . length ; i ++ ) { int x = 0 ; for ( int j = 0 ; j < 4 ; j ++ ) { x = ( x << 2 ) | ( 3 & data [ RandomSource . getInt ( data . length ) ] ) ; } key [ i ] = ( byte ) x ; } seed ( key ) ; initialized = true ; }
Seed the random generator with 2 least significant bits of randomly picked bytes within the provided PCM audio data
14,612
public int getInt ( ) { try { byte [ ] rand = fipsGenerator . getBytes ( 4 ) ; int result = rand [ 0 ] ; for ( int i = 1 ; i < 4 ; i ++ ) { result = ( result << 8 ) | rand [ i ] ; } return result ; } catch ( Throwable ex ) { BBPlatform . getPlatform ( ) . getLogger ( ) . logException ( "RandomGenerator.getInt() Falling back to RandomSource " + ex . getMessage ( ) ) ; return RandomSource . getInt ( ) ; } }
Returns a random integer
14,613
public void getBytes ( byte [ ] buffer ) { try { fipsGenerator . getBytes ( buffer ) ; } catch ( Throwable ex ) { BBPlatform . getPlatform ( ) . getLogger ( ) . logException ( "RandomGenerator.getBytes() Falling back to RandomSource... " + ex . getMessage ( ) ) ; RandomSource . getBytes ( buffer ) ; } }
Generates random bytes filling the given buffer entirely
14,614
protected void checkBuf ( int pointCount , boolean checkMove ) { if ( checkMove && typeSize == 0 ) { throw new IllegalPathStateException ( "First segment must be a SEG_MOVETO" ) ; } if ( typeSize == types . length ) { byte [ ] tmp = new byte [ typeSize + BUFFER_CAPACITY ] ; System . arraycopy ( types , 0 , tmp , 0 , typeSize ) ; types = tmp ; } if ( pointSize + pointCount > points . length ) { float [ ] tmp = new float [ pointSize + Math . max ( BUFFER_CAPACITY * 2 , pointCount ) ] ; System . arraycopy ( points , 0 , tmp , 0 , pointSize ) ; points = tmp ; } }
Checks points and types buffer size to add pointCount points . If necessary realloc buffers to enlarge size .
14,615
protected boolean isInside ( int cross ) { return ( rule == WIND_NON_ZERO ) ? Crossing . isInsideNonZero ( cross ) : Crossing . isInsideEvenOdd ( cross ) ; }
Checks cross count according to path rule to define is it point inside shape or not .
14,616
public static void subQuad ( double [ ] coef , double t0 , boolean left ) { if ( left ) { coef [ 2 ] = ( 1 - t0 ) * coef [ 0 ] + t0 * coef [ 2 ] ; coef [ 3 ] = ( 1 - t0 ) * coef [ 1 ] + t0 * coef [ 3 ] ; } else { coef [ 2 ] = ( 1 - t0 ) * coef [ 2 ] + t0 * coef [ 4 ] ; coef [ 3 ] = ( 1 - t0 ) * coef [ 3 ] + t0 * coef [ 5 ] ; } }
t0 - ?
14,617
private boolean sendResponse ( String respondToURL , String payloadType , ResponseWrapper payload ) { String responseStr = null ; String contentType = null ; boolean success = true ; switch ( payloadType ) { case "XML" : { responseStr = payload . toXML ( ) ; contentType = "application/xml" ; break ; } case "JSON" : { responseStr = payload . toJSON ( ) ; contentType = "application/json" ; break ; } default : responseStr = payload . toJSON ( ) ; } try { HttpPost postRequest = new HttpPost ( respondToURL ) ; StringEntity input = new StringEntity ( responseStr ) ; input . setContentType ( contentType ) ; postRequest . setEntity ( input ) ; LOGGER . debug ( "Sending response" ) ; LOGGER . debug ( "Response payload:" ) ; LOGGER . debug ( responseStr ) ; CloseableHttpResponse httpResponse = httpClient . execute ( postRequest ) ; try { int statusCode = httpResponse . getStatusLine ( ) . getStatusCode ( ) ; if ( statusCode > 300 ) { throw new RuntimeException ( "Failed : HTTP error code : " + httpResponse . getStatusLine ( ) . getStatusCode ( ) ) ; } if ( statusCode != 204 ) { BufferedReader br = new BufferedReader ( new InputStreamReader ( ( httpResponse . getEntity ( ) . getContent ( ) ) ) ) ; LOGGER . debug ( "Successful response from response target - " + respondToURL ) ; String output ; LOGGER . debug ( "Output from Listener .... \n" ) ; while ( ( output = br . readLine ( ) ) != null ) { LOGGER . debug ( output ) ; } br . close ( ) ; } } finally { httpResponse . close ( ) ; } LOGGER . info ( "Successfully handled probeID: " + probe . getProbeId ( ) + " sending response to: " + respondToURL ) ; } catch ( MalformedURLException e ) { success = false ; LOGGER . error ( "MalformedURLException occured for probeID [" + payload . getProbeID ( ) + "]" + "\nThe respondTo URL was a no good. respondTo URL is: " + respondToURL ) ; } catch ( IOException e ) { success = false ; LOGGER . error ( "An IOException occured for probeID [" + payload . getProbeID ( ) + "]" + " - " + e . getLocalizedMessage ( ) ) ; LOGGER . debug ( "Stack trace for IOException for probeID [" + payload . getProbeID ( ) + "]" , e ) ; } catch ( Exception e ) { success = false ; LOGGER . error ( "Some other error occured for probeID [" + payload . getProbeID ( ) + "]" + ". respondTo URL is: " + respondToURL + " - " + e . getLocalizedMessage ( ) ) ; LOGGER . debug ( "Stack trace for probeID [" + payload . getProbeID ( ) + "]" , e ) ; } return success ; }
If the probe yields responses from the handler then send this method will send the responses to the given respondTo addresses .
14,618
public void run ( ) { ResponseWrapper response = null ; LOGGER . info ( "Received probe id: " + probe . getProbeId ( ) ) ; if ( ! isProbeHandled ( probe . getProbeId ( ) ) ) { if ( this . noBrowser && probe . isNaked ( ) ) { LOGGER . warn ( "Responder set to noBrowser mode. Discarding naked probe with id [" + probe . getProbeId ( ) + "]" ) ; } else { for ( ProbeHandlerPlugin handler : handlers ) { response = handler . handleProbeEvent ( probe ) ; if ( ! response . isEmpty ( ) ) { LOGGER . debug ( "Response to probe [" + probe . getProbeId ( ) + "] includes " + response . numberOfServices ( ) ) ; Iterator < RespondToURL > respondToURLs = probe . getRespondToURLs ( ) . iterator ( ) ; if ( probe . getRespondToURLs ( ) . isEmpty ( ) ) LOGGER . warn ( "Processed probe [" + probe . getProbeId ( ) + "] with no respondTo address. That's odd." ) ; if ( respondToURLs . hasNext ( ) ) { RespondToURL respondToURL = respondToURLs . next ( ) ; boolean success = sendResponse ( respondToURL . url , probe . getRespondToPayloadType ( ) , response ) ; if ( ! success ) { LOGGER . warn ( "Issue sending probe [" + probe . getProbeId ( ) + "] response to [" + respondToURL . url + "]" ) ; } } } else { LOGGER . error ( "Response to probe [" + probe . getProbeId ( ) + "] is empty. Not sending empty response." ) ; } } } markProbeAsHandled ( probe . getProbeId ( ) ) ; responder . probeProcessed ( ) ; } else { LOGGER . info ( "Discarding duplicate/handled probe with id: " + probe . getProbeId ( ) ) ; } }
Handle the probe .
14,619
protected static int fixRoots ( float [ ] res , int rc ) { int tc = 0 ; for ( int i = 0 ; i < rc ; i ++ ) { out : { for ( int j = i + 1 ; j < rc ; j ++ ) { if ( isZero ( res [ i ] - res [ j ] ) ) { break out ; } } res [ tc ++ ] = res [ i ] ; } } return tc ; }
Excludes double roots . Roots are double if they lies enough close with each other .
14,620
public static int intersectQuad ( float x1 , float y1 , float cx , float cy , float x2 , float y2 , float rx1 , float ry1 , float rx2 , float ry2 ) { if ( ( rx2 < x1 && rx2 < cx && rx2 < x2 ) || ( rx1 > x1 && rx1 > cx && rx1 > x2 ) || ( ry1 > y1 && ry1 > cy && ry1 > y2 ) ) { return 0 ; } if ( ry2 < y1 && ry2 < cy && ry2 < y2 && rx1 != x1 && rx1 != x2 ) { if ( x1 < x2 ) { return x1 < rx1 && rx1 < x2 ? 1 : 0 ; } return x2 < rx1 && rx1 < x1 ? - 1 : 0 ; } QuadCurve c = new QuadCurve ( x1 , y1 , cx , cy , x2 , y2 ) ; float px1 = rx1 - x1 ; float py1 = ry1 - y1 ; float px2 = rx2 - x1 ; float py2 = ry2 - y1 ; float [ ] res1 = new float [ 3 ] ; float [ ] res2 = new float [ 3 ] ; int rc1 = c . solvePoint ( res1 , px1 ) ; int rc2 = c . solvePoint ( res2 , px2 ) ; if ( rc1 == 0 && rc2 == 0 ) { return 0 ; } float minX = px1 - DELTA ; float maxX = px2 + DELTA ; float [ ] bound = new float [ 28 ] ; int bc = 0 ; bc = c . addBound ( bound , bc , res1 , rc1 , minX , maxX , false , 0 ) ; bc = c . addBound ( bound , bc , res2 , rc2 , minX , maxX , false , 1 ) ; rc2 = c . solveExtreme ( res2 ) ; bc = c . addBound ( bound , bc , res2 , rc2 , minX , maxX , true , 2 ) ; if ( rx1 < x1 && x1 < rx2 ) { bound [ bc ++ ] = 0f ; bound [ bc ++ ] = 0f ; bound [ bc ++ ] = 0f ; bound [ bc ++ ] = 4 ; } if ( rx1 < x2 && x2 < rx2 ) { bound [ bc ++ ] = 1f ; bound [ bc ++ ] = c . ax ; bound [ bc ++ ] = c . ay ; bound [ bc ++ ] = 5 ; } int cross = crossBound ( bound , bc , py1 , py2 ) ; if ( cross != UNKNOWN ) { return cross ; } return c . cross ( res1 , rc1 , py1 , py2 ) ; }
Returns how many times rectangle stripe cross quad curve or the are intersect
14,621
public static int intersectPath ( PathIterator p , float x , float y , float w , float h ) { int cross = 0 ; int count ; float mx , my , cx , cy ; mx = my = cx = cy = 0f ; float [ ] coords = new float [ 6 ] ; float rx1 = x ; float ry1 = y ; float rx2 = x + w ; float ry2 = y + h ; while ( ! p . isDone ( ) ) { count = 0 ; switch ( p . currentSegment ( coords ) ) { case PathIterator . SEG_MOVETO : if ( cx != mx || cy != my ) { count = intersectLine ( cx , cy , mx , my , rx1 , ry1 , rx2 , ry2 ) ; } mx = cx = coords [ 0 ] ; my = cy = coords [ 1 ] ; break ; case PathIterator . SEG_LINETO : count = intersectLine ( cx , cy , cx = coords [ 0 ] , cy = coords [ 1 ] , rx1 , ry1 , rx2 , ry2 ) ; break ; case PathIterator . SEG_QUADTO : count = intersectQuad ( cx , cy , coords [ 0 ] , coords [ 1 ] , cx = coords [ 2 ] , cy = coords [ 3 ] , rx1 , ry1 , rx2 , ry2 ) ; break ; case PathIterator . SEG_CUBICTO : count = intersectCubic ( cx , cy , coords [ 0 ] , coords [ 1 ] , coords [ 2 ] , coords [ 3 ] , cx = coords [ 4 ] , cy = coords [ 5 ] , rx1 , ry1 , rx2 , ry2 ) ; break ; case PathIterator . SEG_CLOSE : if ( cy != my || cx != mx ) { count = intersectLine ( cx , cy , mx , my , rx1 , ry1 , rx2 , ry2 ) ; } cx = mx ; cy = my ; break ; } if ( count == CROSSING ) { return CROSSING ; } cross += count ; p . next ( ) ; } if ( cy != my ) { count = intersectLine ( cx , cy , mx , my , rx1 , ry1 , rx2 , ry2 ) ; if ( count == CROSSING ) { return CROSSING ; } cross += count ; } return cross ; }
Returns how many times rectangle stripe cross path or the are intersect
14,622
public static int intersectShape ( IShape s , float x , float y , float w , float h ) { if ( ! s . bounds ( ) . intersects ( x , y , w , h ) ) { return 0 ; } return intersectPath ( s . pathIterator ( null ) , x , y , w , h ) ; }
Returns how many times rectangle stripe cross shape or the are intersect
14,623
public boolean isExpired ( ) { if ( _service . getTtl ( ) == 0 ) { return false ; } long t = this . cacheStartTime . getTime ( ) ; Date validTime = new Date ( t + ( _service . getTtl ( ) * ONE_MINUTE_IN_MILLIS ) ) ; Date now = new Date ( ) ; return ( now . getTime ( ) > validTime . getTime ( ) ) ; }
Determine if the service record is expired . The service record include a TTL that tells the client how many minutes the client can count on the information in the service record . If the cache times out then those service records that have expired should be expunged from the cache .
14,624
public Matrix4 setToTransform ( IVector3 translation , IQuaternion rotation ) { return setToRotation ( rotation ) . setTranslation ( translation ) ; }
Sets this to a matrix that first rotates then translates .
14,625
public Matrix4 setToTranslation ( IVector3 translation ) { return setToTranslation ( translation . x ( ) , translation . y ( ) , translation . z ( ) ) ; }
Sets this to a translation matrix .
14,626
public Matrix4 setToRotationScale ( IMatrix3 rotScale ) { return set ( rotScale . m00 ( ) , rotScale . m01 ( ) , rotScale . m02 ( ) , 0f , rotScale . m10 ( ) , rotScale . m11 ( ) , rotScale . m12 ( ) , 0f , rotScale . m20 ( ) , rotScale . m21 ( ) , rotScale . m22 ( ) , 0f , 0 , 0 , 0 , 1 ) ; }
Sets this to a rotation plus scale matrix .
14,627
public Matrix4 setToPerspective ( double fovy , double aspect , double near , double far ) { double f = 1f / Math . tan ( fovy / 2f ) , dscale = 1f / ( near - far ) ; return set ( f / aspect , 0f , 0f , 0f , 0f , f , 0f , 0f , 0f , 0f , ( far + near ) * dscale , 2f * far * near * dscale , 0f , 0f , - 1f , 0f ) ; }
Sets this to a perspective projection matrix . The formula comes from the OpenGL documentation for the gluPerspective function .
14,628
public Matrix4 setToFrustum ( double left , double right , double bottom , double top , double near , double far ) { return setToFrustum ( left , right , bottom , top , near , far , Vector3 . UNIT_Z ) ; }
Sets this to a perspective projection matrix . The formula comes from the OpenGL documentation for the glFrustum function .
14,629
public Matrix4 setToFrustum ( double left , double right , double bottom , double top , double near , double far , IVector3 nearFarNormal ) { double rrl = 1f / ( right - left ) ; double rtb = 1f / ( top - bottom ) ; double rnf = 1f / ( near - far ) ; double n2 = 2f * near ; double s = ( far + near ) / ( near * nearFarNormal . z ( ) - far * nearFarNormal . z ( ) ) ; return set ( n2 * rrl , 0f , ( right + left ) * rrl , 0f , 0f , n2 * rtb , ( top + bottom ) * rtb , 0f , s * nearFarNormal . x ( ) , s * nearFarNormal . y ( ) , ( far + near ) * rnf , n2 * far * rnf , 0f , 0f , - 1f , 0f ) ; }
Sets this to a perspective projection matrix .
14,630
public Matrix4 setToOrtho ( double left , double right , double bottom , double top , double near , double far , IVector3 nearFarNormal ) { double rlr = 1f / ( left - right ) ; double rbt = 1f / ( bottom - top ) ; double rnf = 1f / ( near - far ) ; double s = 2f / ( near * nearFarNormal . z ( ) - far * nearFarNormal . z ( ) ) ; return set ( - 2f * rlr , 0f , 0f , ( right + left ) * rlr , 0f , - 2f * rbt , 0f , ( top + bottom ) * rbt , s * nearFarNormal . x ( ) , s * nearFarNormal . y ( ) , 2f * rnf , ( far + near ) * rnf , 0f , 0f , 0f , 1f ) ; }
Sets this to an orthographic projection matrix .
14,631
public static int distanceSq ( int x1 , int y1 , int x2 , int y2 ) { x2 -= x1 ; y2 -= y1 ; return x2 * x2 + y2 * y2 ; }
Returns the squared Euclidian distance between the specified two points .
14,632
public static int distance ( int x1 , int y1 , int x2 , int y2 ) { return ( int ) Math . sqrt ( distanceSq ( x1 , y1 , x2 , y2 ) ) ; }
Returns the Euclidian distance between the specified two points truncated to the nearest integer .
14,633
public static int manhattanDistance ( int x1 , int y1 , int x2 , int y2 ) { return Math . abs ( x2 - x1 ) + Math . abs ( y2 - y1 ) ; }
Returns the Manhattan distance between the specified two points .
14,634
public static double roundNearest ( double v , double target ) { target = Math . abs ( target ) ; if ( v >= 0 ) { return target * Math . floor ( ( v + 0.5f * target ) / target ) ; } else { return target * Math . ceil ( ( v - 0.5f * target ) / target ) ; } }
Rounds a value to the nearest multiple of a target .
14,635
public List < Probe > sendProbe ( Probe probe ) throws ProbeSenderException { List < Probe > actualProbesToSend ; try { actualProbesToSend = splitProbe ( probe ) ; } catch ( MalformedURLException | JAXBException | UnsupportedPayloadType e ) { throw new ProbeSenderException ( "Issue splitting the probe." , e ) ; } for ( Probe probeSegment : actualProbesToSend ) { try { probeTransport . sendProbe ( probeSegment ) ; } catch ( TransportException e ) { e . printStackTrace ( ) ; } } return actualProbesToSend ; }
Send the probe . It will take the provided probe and then disassemble it into a number of smaller probes based on the max payload size of the transport provided .
14,636
private List < Probe > splitProbe ( Probe probe ) throws ProbeSenderException , JAXBException , MalformedURLException , UnsupportedPayloadType { List < Probe > actualProbeList = new ArrayList < Probe > ( ) ; int maxPayloadSize = this . probeTransport . maxPayloadSize ( ) ; LinkedList < ProbeIdEntry > combinedList = probe . getCombinedIdentifierList ( ) ; if ( probe . asXML ( ) . length ( ) < maxPayloadSize ) { actualProbeList . add ( probe ) ; } else { Probe frame = Probe . frameProbeFrom ( probe ) ; Probe splitProbe = new Probe ( frame ) ; int payloadLength = splitProbe . asXML ( ) . length ( ) ; ProbeIdEntry nextId = combinedList . peek ( ) ; if ( payloadLength + nextId . getId ( ) . length ( ) + 40 >= maxPayloadSize ) { throw new ProbeSenderException ( "Basic frame violates maxPayloadSize of transport. Likely due to too many respondTo address." ) ; } while ( ! combinedList . isEmpty ( ) ) { payloadLength = splitProbe . asXML ( ) . length ( ) ; nextId = combinedList . peek ( ) ; if ( payloadLength + nextId . getId ( ) . length ( ) + 40 >= maxPayloadSize ) { actualProbeList . add ( splitProbe ) ; splitProbe = new Probe ( frame ) ; } ProbeIdEntry id = combinedList . pop ( ) ; switch ( id . getType ( ) ) { case "scid" : splitProbe . addServiceContractID ( id . getId ( ) ) ; break ; case "siid" : splitProbe . addServiceInstanceID ( id . getId ( ) ) ; break ; default : break ; } } actualProbeList . add ( splitProbe ) ; } return actualProbeList ; }
This method will take the given probe to send and then chop it up into smaller probes that will fit under the maximum packet size specified by the transport . This is important because Argo wants the UDP packets to not get chopped up by the network routers of at all possible . This makes the overall reliability of the protocol a little higher .
14,637
public String getDescription ( ) { StringBuffer buf = new StringBuffer ( ) ; buf . append ( "ProbeSender for " ) ; buf . append ( probeTransport . toString ( ) ) ; return buf . toString ( ) ; }
Return the description of the ProbeSender .
14,638
public byte [ ] getMyZid ( ) { ZrtpCacheEntry ce = cache . get ( LOCAL_ZID_KEY ) ; if ( ce != null ) { return ce . getData ( ) ; } else { byte [ ] zid = new byte [ 12 ] ; platform . getCrypto ( ) . getRandomGenerator ( ) . getBytes ( zid ) ; cache . put ( LOCAL_ZID_KEY , zid , null ) ; platform . getLogger ( ) . log ( "[ZRTP] created new ZID=" , zid ) ; return zid ; } }
Retrieves this clients cached ZID . If there s no cached ZID i . e . on first run a random ZID is created and stored .
14,639
public void selectEntry ( byte [ ] remoteZID ) { platform . getLogger ( ) . log ( "ZRTPCache: selectEntry(" + platform . getUtils ( ) . byteToHexString ( remoteZID ) + ")" ) ; String zidString = new String ( remoteZID ) ; if ( currentZid != null && currentZid . equals ( zidString ) ) { return ; } currentZid = null ; currentRs1 = null ; currentRs2 = null ; currentTrust = false ; currentNumber = null ; ZrtpCacheEntry ce = cache . get ( zidString ) ; if ( ce == null ) { currentZid = zidString ; return ; } byte [ ] data = ce . getData ( ) ; if ( data . length == 40 || data . length == 72 ) { byte [ ] newData = new byte [ 1 + data . length ] ; newData [ 0 ] = 0 ; System . arraycopy ( data , 0 , newData , 1 , data . length ) ; data = newData ; } if ( data . length != 41 && data . length != 73 ) { platform . getLogger ( ) . logWarning ( "Invalid shared secret cache entry" ) ; currentZid = zidString ; return ; } long expiry = 0 ; for ( int i = 8 ; i != 0 ; ) { expiry = ( expiry << 8 ) + ( data [ -- i ] & 0xffL ) ; } long now = System . currentTimeMillis ( ) ; if ( expiry > now ) { currentTrust = ( data [ 8 ] != 0 ) ; currentRs1 = new byte [ 32 ] ; System . arraycopy ( data , 9 , currentRs1 , 0 , 32 ) ; if ( data . length == 73 ) { currentRs2 = new byte [ 32 ] ; System . arraycopy ( data , 41 , currentRs2 , 0 , 32 ) ; } } currentNumber = ce . getNumber ( ) ; currentZid = zidString ; if ( UPDATE_FOR_CACHE_MISMATCH_SIMULATION ) { if ( currentRs1 != null ) currentRs1 = platform . getCrypto ( ) . getRandomGenerator ( ) . getBytes ( currentRs1 . length ) ; if ( currentRs2 != null ) currentRs2 = platform . getCrypto ( ) . getRandomGenerator ( ) . getBytes ( currentRs2 . length ) ; if ( currentRs1 != null || currentRs2 != null ) { updateEntry ( expiry , currentTrust , currentRs1 , currentRs2 , currentNumber ) ; } UPDATE_FOR_CACHE_MISMATCH_SIMULATION = false ; } currentTrust &= ( platform . getAddressBook ( ) . isInAddressBook ( currentNumber ) ) ; }
Selects a cache entry base on remote ZID
14,640
public void updateEntry ( long expiryTime , boolean trust , byte [ ] retainedSecret , byte [ ] rs2 , String number ) { if ( platform . isVerboseLogging ( ) ) { platform . getLogger ( ) . log ( "ZRTPCache: updateEntry(" + expiryTime + ", " + trust + ", " + platform . getUtils ( ) . byteToHexString ( retainedSecret ) + ", " + platform . getUtils ( ) . byteToHexString ( rs2 ) + "," + number + ")" ) ; } if ( expiryTime == 0 ) { cache . remove ( currentZid ) ; currentTrust = false ; currentRs1 = null ; currentRs2 = null ; currentNumber = null ; } else { byte [ ] data = new byte [ ( rs2 == null ) ? 41 : 73 ] ; for ( int i = 0 ; i != 8 ; ++ i ) { data [ i ] = ( byte ) ( expiryTime & 0xff ) ; expiryTime >>>= 8 ; } data [ 8 ] = ( byte ) ( trust ? 1 : 0 ) ; System . arraycopy ( retainedSecret , 0 , data , 9 , 32 ) ; if ( rs2 != null ) { System . arraycopy ( rs2 , 0 , data , 41 , 32 ) ; } cache . put ( currentZid , data , number ) ; currentTrust = trust ; currentRs1 = retainedSecret ; currentRs2 = rs2 ; currentNumber = number ; } }
Updates the entry for the selected remote ZID .
14,641
public List < String > descriptionsForResponseIDs ( List < String > _ids , boolean payload , boolean pretty ) { List < String > descriptions = new ArrayList < String > ( ) ; for ( ServiceWrapper s : _cache ) { if ( _ids . isEmpty ( ) || _responseIds . contains ( s . getResponseId ( ) ) ) { StringBuffer buf = serviceDesciption ( payload , pretty , s ) ; descriptions . add ( buf . toString ( ) ) ; } } return descriptions ; }
Return the list of description strings for a list of response ids .
14,642
public List < String > descriptionsForProbeIDs ( List < String > _ids , boolean payload , boolean pretty ) { List < String > descriptions = new ArrayList < String > ( ) ; for ( ServiceWrapper s : _cache ) { if ( _ids . isEmpty ( ) || _probeIds . contains ( s . getProbeId ( ) ) ) { StringBuffer buf = serviceDesciption ( payload , pretty , s ) ; descriptions . add ( buf . toString ( ) ) ; } } return descriptions ; }
Return the list of description strings for a list of probe ids .
14,643
public String asJSON ( boolean pretty ) { JSONSerializer ser = new JSONSerializer ( ) ; Gson gson = new Gson ( ) ; Gson prettyJson = new GsonBuilder ( ) . setPrettyPrinting ( ) . create ( ) ; JsonArray cacheArray = new JsonArray ( ) ; String cacheAsString ; for ( ServiceWrapper s : _cache ) { String json = ser . marshalService ( s ) ; JsonObject jsonService = gson . fromJson ( json , JsonObject . class ) ; cacheArray . add ( jsonService ) ; } if ( pretty ) { cacheAsString = prettyJson . toJson ( cacheArray ) ; } else { cacheAsString = gson . toJson ( cacheArray ) ; } return cacheAsString ; }
Return the cache as JSON .
14,644
public void sendProbe ( Probe probe ) throws TransportException { LOGGER . info ( "Sending probe [" + probe . getProbeID ( ) + "] on network inteface [" + networkInterface . getName ( ) + "] at port [" + multicastAddress + ":" + multicastPort + "]" ) ; LOGGER . debug ( "Probe requesting TTL of [" + probe . getHopLimit ( ) + "]" ) ; try { String msg = probe . asXML ( ) ; LOGGER . debug ( "Probe payload (always XML): \n" + msg ) ; byte [ ] msgBytes ; msgBytes = msg . getBytes ( StandardCharsets . UTF_8 ) ; InetAddress group = InetAddress . getByName ( multicastAddress ) ; DatagramPacket packet = new DatagramPacket ( msgBytes , msgBytes . length , group , multicastPort ) ; outboundSocket . setTimeToLive ( probe . getHopLimit ( ) ) ; outboundSocket . send ( packet ) ; LOGGER . debug ( "Probe sent on port [" + multicastAddress + ":" + multicastPort + "]" ) ; } catch ( IOException e ) { throw new TransportException ( "Unable to send probe. Issue sending UDP packets." , e ) ; } catch ( JAXBException e ) { throw new TransportException ( "Unable to send probe because it could not be serialized to XML" , e ) ; } }
Actually send the probe out on the wire .
14,645
public ResponseWrapper unmarshal ( String payload ) throws ResponseParseException { Services xmlServices = parseResponsePayload ( payload ) ; ResponseWrapper response = constructResponseWrapperFromResponse ( xmlServices ) ; return response ; }
Translate the wireline string into an instance of a ResponseWrapper object .
14,646
public ServiceWrapper unmarshalService ( String payload ) throws ResponseParseException { Service xmlService = parseServicePayload ( payload ) ; ServiceWrapper service = constructServiceWrapperFromService ( xmlService ) ; return service ; }
Translate the wireline string to an instance of a ServiceWrapper object .
14,647
public < T > T get ( String key , T defaultValue ) { if ( map . containsKey ( key ) ) { Object value = map . get ( key ) ; return ( T ) ( value instanceof byte [ ] ? unmarshall ( ( byte [ ] ) value ) : value ) ; } return defaultValue ; }
Returns the value of the mapping with the specified key or the given default value .
14,648
public void setRespondToPayloadType ( String respondToPayloadType ) throws UnsupportedPayloadType { if ( respondToPayloadType == null || respondToPayloadType . isEmpty ( ) || ( ! respondToPayloadType . equals ( ProbeWrapper . JSON ) && ! respondToPayloadType . equals ( ProbeWrapper . XML ) ) ) throw new UnsupportedPayloadType ( "Attempting to set payload type to: " + respondToPayloadType + ". Cannot be null or empty and must be " + ProbeWrapper . JSON + " or " + ProbeWrapper . XML ) ; _probe . setRespondToPayloadType ( respondToPayloadType ) ; }
set the payload type for the response from the Responder . It only support XML and JSON .
14,649
public LinkedList < ProbeIdEntry > getCombinedIdentifierList ( ) { LinkedList < ProbeIdEntry > combinedList = new LinkedList < ProbeIdEntry > ( ) ; for ( String id : this . getProbeWrapper ( ) . getServiceContractIDs ( ) ) { combinedList . add ( new ProbeIdEntry ( "scid" , id ) ) ; } for ( String id : this . getProbeWrapper ( ) . getServiceInstanceIDs ( ) ) { combinedList . add ( new ProbeIdEntry ( "siid" , id ) ) ; } return combinedList ; }
Create and return a LinkedList of a combination of both scids and siids . This is a method that is used primarily in the creation of split packets .
14,650
public static boolean checkClientId ( boolean isLegacyAttributeList , String farEndClientID ) { if ( ZRTP . CLIENT_ID_LEGACY . equals ( farEndClientID ) ) return true ; if ( ZRTP . CLIENT_ID_RFC . equals ( farEndClientID ) ) return false ; boolean isPrintable = true ; for ( int i = 0 ; i < farEndClientID . length ( ) ; i ++ ) { int singleChar = farEndClientID . charAt ( i ) ; if ( singleChar < 32 || singleChar >= 127 ) { isPrintable = false ; } } return ! isPrintable && isLegacyAttributeList ; }
Legacy Client send ZRTP . CLIENT_ID_LEGACY or a non - printable ClientId
14,651
public static float pointRectDistanceSq ( IRectangle r , IPoint p ) { Point p2 = closestInteriorPoint ( r , p ) ; return Points . distanceSq ( p . x ( ) , p . y ( ) , p2 . x , p2 . y ) ; }
Returns the squared Euclidean distance between the given point and the nearest point inside the bounds of the given rectangle . If the supplied point is inside the rectangle the distance will be zero .
14,652
public void cacheAll ( ArrayList < ExpiringService > list ) { for ( ExpiringService service : list ) { cache . put ( service . getService ( ) . getId ( ) , service ) ; } }
Put a list of services in the cache .
14,653
public String asJSON ( ) { Gson gson = new Gson ( ) ; clearExpired ( ) ; Cache jsonCache = new Cache ( ) ; for ( ExpiringService svc : cache . values ( ) ) { jsonCache . cache . add ( svc . getService ( ) ) ; } String json = gson . toJson ( jsonCache ) ; return json ; }
Return the JSON string of the response cache . Leverage the Gson nature of the domain wireline classes
14,654
public void addRespondToURL ( String label , String url ) { RespondToURL respondToURL = new RespondToURL ( ) ; respondToURL . label = label ; respondToURL . url = url ; respondToURLs . add ( respondToURL ) ; }
Add a response URL to the probe .
14,655
public String asString ( ) { StringBuffer buf = new StringBuffer ( ) ; buf . append ( " PID: [ " ) . append ( this . id ) . append ( " ]" ) ; ; buf . append ( " CID: [ " ) . append ( this . clientId ) . append ( " ]" ) ; ; buf . append ( " DES: [ " ) . append ( this . desVersion ) . append ( " ]" ) ; ; buf . append ( " SCIDS: [ " ) ; for ( String scid : serviceContractIDs ) { buf . append ( scid ) . append ( " " ) ; } buf . append ( "]" ) ; buf . append ( " SIIDS: [ " ) ; for ( String siid : serviceInstanceIDs ) { buf . append ( siid ) . append ( " " ) ; } buf . append ( "]" ) ; buf . append ( " RESPOND_TO: [ " ) ; for ( RespondToURL rt : respondToURLs ) { buf . append ( rt . label ) . append ( ", " ) . append ( rt . url ) . append ( " " ) ; } buf . append ( "]" ) ; buf . append ( " PAYLOAD_TYPE: [ " ) . append ( respondToPayloadType ) . append ( " ]" ) ; return buf . toString ( ) ; }
This will return the single - line textual representation . This was crafted for the command line client . Your mileage may vary .
14,656
public void setFrame ( XY loc , IDimension size ) { setFrame ( loc . x ( ) , loc . y ( ) , size . width ( ) , size . height ( ) ) ; }
Sets the location and size of the framing rectangle of this shape to the supplied values .
14,657
public void setFrame ( IRectangle r ) { setFrame ( r . x ( ) , r . y ( ) , r . width ( ) , r . height ( ) ) ; }
Sets the location and size of the framing rectangle of this shape to be equal to the supplied rectangle .
14,658
public void setFrameFromDiagonal ( XY p1 , XY p2 ) { setFrameFromDiagonal ( p1 . x ( ) , p1 . y ( ) , p2 . x ( ) , p2 . y ( ) ) ; }
Sets the location and size of the framing rectangle of this shape based on the supplied diagonal line .
14,659
public void setFrameFromCenter ( XY center , XY corner ) { setFrameFromCenter ( center . x ( ) , center . y ( ) , corner . x ( ) , corner . y ( ) ) ; }
Sets the location and size of the framing rectangle of this shape based on the supplied center and corner points .
14,660
public static Point inverseTransform ( double x , double y , double sx , double sy , double rotation , double tx , double ty , Point result ) { x -= tx ; y -= ty ; double sinnega = Math . sin ( - rotation ) , cosnega = Math . cos ( - rotation ) ; double nx = ( x * cosnega - y * sinnega ) ; double ny = ( x * sinnega + y * cosnega ) ; return result . set ( nx / sx , ny / sy ) ; }
Inverse transforms a point as specified storing the result in the point provided .
14,661
public void setServiceList ( ArrayList < ServiceWrapper > services ) { writeLock . lock ( ) ; try { LOGGER . info ( "Updating service list by " + Thread . currentThread ( ) . getName ( ) ) ; this . serviceList = services ; } finally { writeLock . unlock ( ) ; } }
As the Responder is multi - threaded make sure that the access to the services list which might change out if the user changes it is synchronized to make sure nothing weird happens .
14,662
public void initializeWithPropertiesFilename ( String filename ) throws ProbeHandlerConfigException { InputStream is ; if ( ConfigFileProbeHandlerPlugin . class . getResource ( filename ) != null ) { is = ConfigFileProbeHandlerPlugin . class . getResourceAsStream ( filename ) ; } else { try { is = new FileInputStream ( filename ) ; } catch ( FileNotFoundException e ) { throw new ProbeHandlerConfigException ( "Error loading handler config for [" + this . getClass ( ) . getName ( ) + "]" , e ) ; } } try { config . load ( is ) ; } catch ( IOException e ) { throw new ProbeHandlerConfigException ( "Error loading handler config for [" + this . getClass ( ) . getName ( ) + "]" , e ) ; } finally { try { is . close ( ) ; } catch ( IOException e ) { throw new ProbeHandlerConfigException ( "Error closing handler config for {" + this . getClass ( ) . getName ( ) + "]" , e ) ; } } try { configFileScan = new Timer ( ) ; configFileScan . scheduleAtFixedRate ( new ConfigFileMonitorTask ( this ) , 100 , 10000 ) ; } catch ( ConfigurationException e ) { throw new ProbeHandlerConfigException ( "Error initializing monitor task." , e ) ; } }
Initialize the handler .
14,663
private void initializeTransports ( ArrayList < TransportConfig > transportConfigs ) { for ( TransportConfig config : transportConfigs ) { ClientProbeSenders transport = new ClientProbeSenders ( config ) ; try { transport . initialize ( this ) ; _clientSenders . add ( transport ) ; } catch ( TransportConfigException e ) { LOGGER . warn ( "Transport [" + config . getName ( ) + "] failed to initialize." , e ) ; Console . error ( "Unable to initialize the Transport [" + config . getName ( ) + "]. Ignoring." ) ; } } }
Initializes the Transports .
14,664
private void initializeLocalhostNI ( ) { InetAddress localhost ; try { localhost = InetAddress . getLocalHost ( ) ; NetworkInterface ni = NetworkInterface . getByInetAddress ( localhost ) ; if ( ni != null ) getNIList ( ) . add ( ni . getName ( ) ) ; } catch ( UnknownHostException | SocketException e ) { Console . severe ( "Cannot get the Network Interface for localhost" ) ; Console . severe ( e . getMessage ( ) ) ; } }
Sets up the network interface list with at least the localhost NI .
14,665
public List < String > getAvailableNetworkInterfaces ( boolean requiresMulticast ) throws SocketException { Enumeration < NetworkInterface > nis = NetworkInterface . getNetworkInterfaces ( ) ; List < String > multicastNIs = new ArrayList < String > ( ) ; while ( nis . hasMoreElements ( ) ) { NetworkInterface ni = nis . nextElement ( ) ; if ( ni . isUp ( ) && ! ni . isLoopback ( ) ) { if ( requiresMulticast ) { if ( ni . supportsMulticast ( ) ) multicastNIs . add ( ni . getName ( ) ) ; } else { multicastNIs . add ( ni . getName ( ) ) ; } } } return multicastNIs ; }
This gets a list of all the available network interface names .
14,666
public ClientProbeSenders getClientTransportNamed ( String transportName ) { ClientProbeSenders found = null ; for ( ClientProbeSenders t : _clientSenders ) { if ( t . getName ( ) . equalsIgnoreCase ( transportName ) ) { found = t ; break ; } } return found ; }
Returns the client transport specified by given name .
14,667
public static < T extends Case3 < A , B , C > , A , B , C > DecomposableMatchBuilder0 < T > case3 ( Class < T > clazz , MatchesExact < A > a , MatchesExact < B > b , MatchesExact < C > c ) { List < Matcher < Object > > matchers = Lists . of ( ArgumentMatchers . eq ( a . t ) , ArgumentMatchers . eq ( b . t ) , ArgumentMatchers . eq ( c . t ) ) ; return new DecomposableMatchBuilder0 < T > ( matchers , new Case3FieldExtractor < > ( clazz ) ) ; }
Matches a case class of three elements .
14,668
public CommandResult execute ( T context ) { try { return innerExecute ( context ) ; } catch ( Exception e ) { Console . error ( e . getMessage ( ) ) ; return CommandResult . ERROR ; } }
Executes the command . The command line arguments contains all of the key - value pairs and switches but does not include the command name that came from the original arguments .
14,669
public long factMatching ( long n ) { return match ( n ) . when ( caseLong ( 0 ) ) . get ( ( ) -> 1L ) . when ( caseLong ( any ( ) ) ) . get ( i -> i * factMatching ( i - 1 ) ) . getMatch ( ) ; }
An implementation of factorial using motif pattern matching .
14,670
public static IShape createTransformedShape ( Transform t , IShape src ) { if ( src == null ) { return null ; } if ( src instanceof Path ) { return ( ( Path ) src ) . createTransformedShape ( t ) ; } PathIterator path = src . pathIterator ( t ) ; Path dst = new Path ( path . windingRule ( ) ) ; dst . append ( path , false ) ; return dst ; }
Creates and returns a new shape that is the supplied shape transformed by this transform s matrix .
14,671
private static void sort ( double [ ] coords1 , int length1 , double [ ] coords2 , int length2 , int [ ] array ) { int temp ; int length = length1 + length2 ; double x1 , y1 , x2 , y2 ; for ( int i = 1 ; i < length ; i ++ ) { if ( array [ i - 1 ] < length1 ) { x1 = coords1 [ 2 * array [ i - 1 ] ] ; y1 = coords1 [ 2 * array [ i - 1 ] + 1 ] ; } else { x1 = coords2 [ 2 * ( array [ i - 1 ] - length1 ) ] ; y1 = coords2 [ 2 * ( array [ i - 1 ] - length1 ) + 1 ] ; } if ( array [ i ] < length1 ) { x2 = coords1 [ 2 * array [ i ] ] ; y2 = coords1 [ 2 * array [ i ] + 1 ] ; } else { x2 = coords2 [ 2 * ( array [ i ] - length1 ) ] ; y2 = coords2 [ 2 * ( array [ i ] - length1 ) + 1 ] ; } int j = i ; while ( j > 0 && compare ( x1 , y1 , x2 , y2 ) <= 0 ) { temp = array [ j ] ; array [ j ] = array [ j - 1 ] ; array [ j - 1 ] = temp ; j -- ; if ( j > 0 ) { if ( array [ j - 1 ] < length1 ) { x1 = coords1 [ 2 * array [ j - 1 ] ] ; y1 = coords1 [ 2 * array [ j - 1 ] + 1 ] ; } else { x1 = coords2 [ 2 * ( array [ j - 1 ] - length1 ) ] ; y1 = coords2 [ 2 * ( array [ j - 1 ] - length1 ) + 1 ] ; } if ( array [ j ] < length1 ) { x2 = coords1 [ 2 * array [ j ] ] ; y2 = coords1 [ 2 * array [ j ] + 1 ] ; } else { x2 = coords2 [ 2 * ( array [ j ] - length1 ) ] ; y2 = coords2 [ 2 * ( array [ j ] - length1 ) + 1 ] ; } } } } }
the array sorting
14,672
public void setFrameFromDiagonal ( float x1 , float y1 , float x2 , float y2 ) { float rx , ry , rw , rh ; if ( x1 < x2 ) { rx = x1 ; rw = x2 - x1 ; } else { rx = x2 ; rw = x1 - x2 ; } if ( y1 < y2 ) { ry = y1 ; rh = y2 - y1 ; } else { ry = y2 ; rh = y1 - y2 ; } setFrame ( rx , ry , rw , rh ) ; }
Sets the location and size of the framing rectangle of this shape based on the specified diagonal line .
14,673
public void setFrameFromCenter ( float centerX , float centerY , float cornerX , float cornerY ) { float width = Math . abs ( cornerX - centerX ) ; float height = Math . abs ( cornerY - centerY ) ; setFrame ( centerX - width , centerY - height , width * 2 , height * 2 ) ; }
Sets the location and size of the framing rectangle of this shape based on the specified center and corner points .
14,674
@ Path ( "/probeResponse" ) @ Consumes ( "application/json" ) public String handleJSONProbeResponse ( String probeResponseJSON ) { JSONSerializer serializer = new JSONSerializer ( ) ; ResponseWrapper response ; try { response = serializer . unmarshal ( probeResponseJSON ) ; } catch ( ResponseParseException e ) { String errorResponseString = "Incoming Response could not be parsed. Error message is: " + e . getMessage ( ) ; Console . error ( errorResponseString ) ; Console . error ( "Wireline message that could no be parsed is:" ) ; Console . error ( probeResponseJSON ) ; return errorResponseString ; } for ( ServiceWrapper service : response . getServices ( ) ) { service . setResponseID ( response . getResponseID ( ) ) ; service . setProbeID ( response . getProbeID ( ) ) ; cache . cache ( new ExpiringService ( service ) ) ; } String statusString = "Successfully cached " + response . getServices ( ) . size ( ) + " services" ; updateCacheListener ( statusString ) ; return statusString ; }
Inbound JSON responses get processed here .
14,675
public Circle set ( ICircle c ) { return set ( c . x ( ) , c . y ( ) , c . radius ( ) ) ; }
Sets the properties of this circle to be equal to those of the supplied circle .
14,676
public Circle set ( double x , double y , double radius ) { this . x = x ; this . y = y ; this . radius = radius ; return this ; }
Sets the properties of this circle to the supplied values .
14,677
public Matrix4 setToRotation ( float angle , float x , float y , float z ) { float c = FloatMath . cos ( angle ) , s = FloatMath . sin ( angle ) , omc = 1f - c ; float xs = x * s , ys = y * s , zs = z * s , xy = x * y , xz = x * z , yz = y * z ; return set ( x * x * omc + c , xy * omc - zs , xz * omc + ys , 0f , xy * omc + zs , y * y * omc + c , yz * omc - xs , 0f , xz * omc - ys , yz * omc + xs , z * z * omc + c , 0f , 0f , 0f , 0f , 1f ) ; }
Sets this to a rotation matrix . The formula comes from the OpenGL documentation for the glRotatef function .
14,678
public Matrix4 setToReflection ( float x , float y , float z , float w ) { float x2 = - 2f * x , y2 = - 2f * y , z2 = - 2f * z ; float xy2 = x2 * y , xz2 = x2 * z , yz2 = y2 * z ; float x2y2z2 = x * x + y * y + z * z ; return set ( 1f + x2 * x , xy2 , xz2 , x2 * w * x2y2z2 , xy2 , 1f + y2 * y , yz2 , y2 * w * x2y2z2 , xz2 , yz2 , 1f + z2 * z , z2 * w * x2y2z2 , 0f , 0f , 0f , 1f ) ; }
Sets this to a reflection across the specified plane .
14,679
public Matrix4 set ( float [ ] values ) { return set ( values [ 0 ] , values [ 1 ] , values [ 2 ] , values [ 3 ] , values [ 4 ] , values [ 5 ] , values [ 6 ] , values [ 7 ] , values [ 8 ] , values [ 9 ] , values [ 10 ] , values [ 11 ] , values [ 12 ] , values [ 13 ] , values [ 14 ] , values [ 15 ] ) ; }
Copies the elements of a row - major array .
14,680
public void launch ( Object arg ) { ReconnectableMap . INSTANCE . dismiss ( key ) ; out . put ( "restore" , true ) ; out . put ( "arg" , arg ) ; launches . onNext ( arg ) ; }
Launches an observable providing an argument . Dismisses the previous observable instance if it is not completed yet .
14,681
public static < E > List < E > of ( E e1 , E e2 , E e3 , E e4 ) { List < E > list = new ArrayList < > ( ) ; list . add ( e1 ) ; list . add ( e2 ) ; list . add ( e3 ) ; list . add ( e4 ) ; return list ; }
Returns a list of the given elements in order .
14,682
public void run ( ) { LOGGER . debug ( "begin scan for config file changes ..." ) ; try { Date lastModified = new Date ( _xmlConfigFile . lastModified ( ) ) ; if ( _lastTimeRead == null || lastModified . after ( _lastTimeRead ) ) { LOGGER . info ( "loading config file changes ..." ) ; this . loadServiceConfigFile ( ) ; _lastTimeRead = new Date ( ) ; } } catch ( ConfigurationException e ) { e . printStackTrace ( ) ; LOGGER . error ( "Error loading configuation file: " , e ) ; } LOGGER . debug ( "finish scan for config file changes" ) ; }
When the timer goes off look for changes to the specified xml config file . For comparison we are only interested in the last time we read the file . A null value for lastTimeRead means that we never read the file before .
14,683
private void loadServiceConfigFile ( ) throws ConfigurationException { Properties properties = _plugin . getConfiguration ( ) ; Configuration config = ConfigurationConverter . getConfiguration ( properties ) ; String xmlConfigFilename = config . getString ( "xmlConfigFilename" ) ; _config = new ServiceListConfiguration ( xmlConfigFilename ) ; ArrayList < ServiceWrapper > serviceList = _config . getServiceList ( ) ; LOGGER . debug ( "Setting the service list in the plugin" ) ; _plugin . setServiceList ( serviceList ) ; }
actually load the xml configuration file . If anything goes wrong throws an exception . This created a list of service records . When done set the service record list in the plugin . The plugin set function should be synchronized so that it won t squash any concurrent access to the old set of services .
14,684
public void initialize ( ArgoClientContext context ) throws TransportConfigException { transportProps = processPropertiesFile ( config . getPropertiesFilename ( ) ) ; createProbeSenders ( context ) ; }
Initialize the actual ProbeSenders .
14,685
public String getDescription ( ) { StringBuffer buf = new StringBuffer ( ) ; String transportName = config . getName ( ) ; for ( ProbeSender sender : senders ) { buf . append ( transportName ) . append ( " -- " ) . append ( isEnabled ( ) ? "Enabled" : "Disabled" ) . append ( " -- " ) . append ( sender . getDescription ( ) ) ; } return buf . toString ( ) ; }
return the text description of the transport and its associated ProbeSenders .
14,686
public String showConfiguration ( ) { StringBuffer buf = new StringBuffer ( ) ; buf . append ( "\n Client Transport Configuration\n" ) ; buf . append ( " Name ...................... " ) . append ( config . getName ( ) ) . append ( "\n" ) ; buf . append ( " Is Enabled................. " ) . append ( isEnabled ( ) ) . append ( "\n" ) ; buf . append ( " Required Multicast ........ " ) . append ( config . requiresMulticast ( ) ) . append ( "\n" ) ; buf . append ( " Uses NI ................... " ) . append ( config . usesNetworkInterface ( ) ) . append ( "\n" ) ; buf . append ( " Classname ................. " ) . append ( config . getClassname ( ) ) . append ( "\n" ) ; buf . append ( " Properties filename ....... " ) . append ( config . getPropertiesFilename ( ) ) . append ( "\n\n" ) ; buf . append ( " Number of ProbeSenders .... " ) . append ( this . getSenders ( ) . size ( ) ) . append ( "\n" ) ; buf . append ( " ProbeSenders .............. \n" ) ; for ( ProbeSender s : getSenders ( ) ) { buf . append ( " .... " ) . append ( s . getDescription ( ) ) . append ( "\n" ) ; } buf . append ( " -------------------------------\n" ) ; return buf . toString ( ) ; }
Show the configuration for a Client Transport .
14,687
public void close ( ) { for ( ProbeSender sender : getSenders ( ) ) { try { sender . close ( ) ; } catch ( TransportException e ) { LOGGER . warn ( "Issue closing the ProbeSender [" + sender . getDescription ( ) + "]" , e ) ; } } }
This closes any of the underlying resources that a ProbeSender might be using such as a connection to a server somewhere .
14,688
private void createProbeSenders ( ArgoClientContext context ) throws TransportConfigException { senders = new ArrayList < ProbeSender > ( ) ; if ( config . usesNetworkInterface ( ) ) { try { for ( String niName : context . getAvailableNetworkInterfaces ( config . requiresMulticast ( ) ) ) { try { Transport transport = instantiateTransportClass ( config . getClassname ( ) ) ; transport . initialize ( transportProps , niName ) ; ProbeSender sender = new ProbeSender ( transport ) ; senders . add ( sender ) ; } catch ( TransportConfigException e ) { LOGGER . warn ( e . getLocalizedMessage ( ) ) ; } } } catch ( SocketException e ) { throw new TransportConfigException ( "Error getting available network interfaces" , e ) ; } } else { Transport transport = instantiateTransportClass ( config . getClassname ( ) ) ; transport . initialize ( transportProps , "" ) ; ProbeSender sender = new ProbeSender ( transport ) ; senders . add ( sender ) ; } }
Create the actual ProbeSender instances given the configuration information . If the transport depends on Network Interfaces then create a ProbeSender for each NI we can find on this machine .
14,689
protected List < TypeVariableName > getTypeVariables ( TypeName t ) { return match ( t ) . when ( typeOf ( TypeVariableName . class ) ) . get ( v -> { if ( v . bounds . isEmpty ( ) ) { return ImmutableList . of ( v ) ; } else { return Stream . concat ( Stream . of ( v ) , v . bounds . stream ( ) . map ( b -> getTypeVariables ( b ) ) . flatMap ( b -> b . stream ( ) ) ) . collect ( Collectors . toList ( ) ) ; } } ) . when ( typeOf ( ParameterizedTypeName . class ) ) . get ( p -> p . typeArguments . stream ( ) . map ( v -> getTypeVariables ( v ) ) . flatMap ( l -> l . stream ( ) ) . collect ( Collectors . toList ( ) ) ) . orElse ( Collections . emptyList ( ) ) . getMatch ( ) ; }
Returns a list of type variables for a given type .
14,690
protected List < TypeNameWithArity > createTypeArityList ( TypeName t , String extractVariableName , int maxArity ) { TypeName u = match ( t ) . when ( typeOf ( TypeVariableName . class ) ) . get ( x -> ( TypeName ) TypeVariableName . get ( "E" + x . name , x ) ) . orElse ( x -> x ) . getMatch ( ) ; List < TypeNameWithArity > typeArityList = new ArrayList < > ( ) ; typeArityList . add ( TypeNameWithArity . of ( ParameterizedTypeName . get ( MATCH_EXACT , t ) , 0 ) ) ; typeArityList . add ( TypeNameWithArity . of ( ParameterizedTypeName . get ( MATCH_ANY , t ) , 1 ) ) ; IntStream . rangeClosed ( 0 , maxArity ) . forEach ( extractArity -> { TypeName [ ] typeVariables = createTypeVariables ( u , extractVariableName , extractArity ) ; typeArityList . add ( TypeNameWithArity . of ( ParameterizedTypeName . get ( ClassName . get ( getDecomposableBuilderByArity ( extractArity ) ) , typeVariables ) , extractArity ) ) ; } ) ; return typeArityList ; }
Returns a list of pairs of types and arities up to a given max arity .
14,691
protected TypeName [ ] createTypeVariables ( TypeName extractedType , String extractVariableName , int extractArity ) { List < TypeName > typeVariables = new ArrayList < > ( ) ; typeVariables . add ( extractedType ) ; if ( extractArity > 0 ) { typeVariables . addAll ( IntStream . rangeClosed ( 1 , extractArity ) . mapToObj ( j -> TypeVariableName . get ( extractVariableName + j ) ) . collect ( Collectors . toList ( ) ) ) ; } return typeVariables . toArray ( new TypeName [ typeVariables . size ( ) ] ) ; }
Returns an array of type variables for a given type and arity .
14,692
protected static Object [ ] getMatcherStatementArgs ( int matchedCount ) { TypeName matcher = ParameterizedTypeName . get ( ClassName . get ( Matcher . class ) , TypeName . OBJECT ) ; TypeName listOfMatchers = ParameterizedTypeName . get ( ClassName . get ( List . class ) , matcher ) ; TypeName lists = TypeName . get ( Lists . class ) ; TypeName argumentMatchers = TypeName . get ( ArgumentMatchers . class ) ; return Stream . concat ( ImmutableList . of ( listOfMatchers , lists ) . stream ( ) , IntStream . range ( 0 , matchedCount ) . mapToObj ( i -> argumentMatchers ) ) . toArray ( s -> new TypeName [ s ] ) ; }
Returns the statement arguments for the match method matcher statement .
14,693
protected MatchType getMatchType ( TypeName m ) { return match ( m ) . when ( typeOf ( ParameterizedTypeName . class ) ) . get ( t -> { if ( isDecomposableBuilder ( t . rawType ) ) { return MatchType . DECOMPOSE ; } else if ( t . rawType . equals ( MATCH_ANY ) ) { return MatchType . ANY ; } else if ( t . rawType . equals ( MATCH_EXACT ) ) { return MatchType . EXACT ; } else { return MatchType . EXACT ; } } ) . when ( typeOf ( TypeVariableName . class ) ) . get ( t -> MatchType . EXACT ) . orElse ( MatchType . ANY ) . getMatch ( ) ; }
Returns the type of match to use for a given type .
14,694
protected List < TypeName > getExtractedTypes ( TypeName permutationType , TypeName paramType ) { return match ( permutationType ) . when ( typeOf ( ParameterizedTypeName . class ) ) . get ( t -> { if ( isDecomposableBuilder ( t . rawType ) ) { return t . typeArguments . subList ( 1 , t . typeArguments . size ( ) ) ; } else if ( t . rawType . equals ( MATCH_ANY ) ) { return ImmutableList . of ( paramType ) ; } else { return Collections . < TypeName > emptyList ( ) ; } } ) . when ( typeOf ( TypeVariableName . class ) ) . get ( t -> ImmutableList . of ( ) ) . when ( typeOf ( ClassName . class ) ) . get ( t -> ImmutableList . of ( paramType ) ) . orElse ( t -> ImmutableList . of ( t ) ) . getMatch ( ) ; }
Returns the extracted type parameters .
14,695
protected List < TypeName > getReturnStatementArgs ( MatchType matchType , TypeName paramType ) { List < TypeName > extractA ; if ( matchType == MatchType . DECOMPOSE ) { TypeName u = match ( paramType ) . when ( typeOf ( TypeVariableName . class ) ) . get ( x -> ( TypeName ) TypeVariableName . get ( "E" + x . name , x ) ) . orElse ( x -> x ) . getMatch ( ) ; extractA = ImmutableList . of ( u ) ; } else if ( matchType == MatchType . ANY ) { extractA = ImmutableList . of ( paramType ) ; } else { extractA = ImmutableList . of ( ) ; } return extractA ; }
Returns the statement arguments for the match method returns statement .
14,696
public static ProbeSender createMulticastProbeSender ( ) throws ProbeSenderException , TransportConfigException { Transport mcastTransport = new MulticastTransport ( "" ) ; ProbeSender gen = new ProbeSender ( mcastTransport ) ; return gen ; }
Create a Multicast ProbeSender with all the default values . The default values are the default multicast group address and port of the Argo protocol . The Network Interface is the NI associated with the localhost address .
14,697
public static ProbeSender createMulticastProbeSender ( String niName ) throws TransportConfigException { Transport mcastTransport = new MulticastTransport ( niName ) ; ProbeSender gen = new ProbeSender ( mcastTransport ) ; return gen ; }
Create a Multicast ProbeSender specifying the Network Interface to send on .
14,698
public static ProbeSender createSNSProbeSender ( String ak , String sk ) throws ProbeSenderException { Transport snsTransport = new AmazonSNSTransport ( ak , sk ) ; ProbeSender gen = new ProbeSender ( snsTransport ) ; return gen ; }
Create a AmazonSNS transport ProbeSender using the default values .
14,699
private void initializeHTTPClient ( ) { if ( _config . isHTTPSConfigured ( ) ) { try { KeyStore trustKeystore = getClientTruststore ( ) ; SSLContext sslContext = SSLContexts . custom ( ) . loadTrustMaterial ( trustKeystore , new TrustSelfSignedStrategy ( ) ) . build ( ) ; SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory ( sslContext , NoopHostnameVerifier . INSTANCE ) ; Registry < ConnectionSocketFactory > r = RegistryBuilder . < ConnectionSocketFactory > create ( ) . register ( "http" , PlainConnectionSocketFactory . INSTANCE ) . register ( "https" , sslsf ) . build ( ) ; HttpClientConnectionManager cm = new PoolingHttpClientConnectionManager ( r ) ; httpClient = HttpClients . custom ( ) . setConnectionManager ( cm ) . build ( ) ; } catch ( Exception e ) { LOGGER . error ( "Issue creating HTTP client using supplied configuration. Proceeding with default non-SSL client." , e ) ; httpClient = HttpClients . createDefault ( ) ; } } else { httpClient = HttpClients . createDefault ( ) ; } }
Create HTTP Client .