idx int64 0 41.2k | question stringlengths 74 4.21k | target stringlengths 5 888 |
|---|---|---|
8,300 | public static void postTaskSuccess ( final TaskCompletionListener completionListener ) { new Handler ( Looper . getMainLooper ( ) ) . post ( new Runnable ( ) { public void run ( ) { if ( null != completionListener ) { completionListener . onSuccess ( ) ; } } } ) ; } | A helper function to post success to a TaskCompletionListener on the UI thread |
8,301 | public static void postTaskError ( final TaskCompletionListener completionListener , final String errorMessage ) { new Handler ( Looper . getMainLooper ( ) ) . post ( new Runnable ( ) { public void run ( ) { if ( null != completionListener ) { completionListener . onError ( errorMessage ) ; } } } ) ; } | A helper function to post an error message to a TaskCompletionListener on the UI thread |
8,302 | public static String makeGUID ( ) { String uuid = "" ; String chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ; int rnd = 0 ; int r ; for ( int i = 0 ; i < GUID_STRING_LENGTH ; i += 1 ) { if ( i == 8 || i == 13 || i == 18 || i == 23 ) { uuid = uuid + "-" ; } else if ( i == 14 ) { uuid = uuid + "4" ; } else { if ( rnd <= 0x02 ) { rnd = ( int ) ( 0x2000000 + Math . round ( java . lang . Math . random ( ) * 0x1000000 ) ) ; } r = rnd & 0xf ; rnd = rnd >> 4 ; if ( i == 19 ) { uuid = uuid + chars . charAt ( ( r & 0x3 ) | 0x8 ) ; } else { uuid = uuid + chars . charAt ( r ) ; } } } return uuid ; } | Create a globally unique identifier for naming instances |
8,303 | public void unregisterPushServices ( TaskCompletionListener completionListener ) { RespokeClient activeInstance = null ; for ( RespokeClient eachInstance : instances ) { if ( eachInstance . isConnected ( ) ) { activeInstance = eachInstance ; break ; } } if ( null != activeInstance ) { activeInstance . unregisterFromPushServices ( completionListener ) ; } else { postTaskError ( completionListener , "There is no active client to unregister" ) ; } } | Unregister this device from the Respoke push notification service and stop any future notifications until it is re - registered |
8,304 | public void clientConnected ( RespokeClient client ) { if ( null != pushToken ) { registerPushServices ( ) ; } if ( ! factoryStaticInitialized ) { PeerConnectionFactory . initializeAndroidGlobals ( context , true , true , true , VideoRendererGui . getEGLContext ( ) ) ; factoryStaticInitialized = true ; } } | Notify the shared SDK instance that the specified client has connected . This is for internal use only and should never be called by your client application . |
8,305 | private void registerPushServices ( ) { RespokeClient activeInstance = null ; for ( RespokeClient eachInstance : instances ) { if ( eachInstance . isConnected ( ) ) { activeInstance = eachInstance ; } } if ( null != activeInstance ) { activeInstance . registerPushServicesWithToken ( pushToken ) ; } } | Attempt to register push services for this device |
8,306 | public static JiraRestClient connect ( URL jiraUrl , String username , String password ) throws IOException { return new AsynchronousJiraRestClientFactory ( ) . createWithBasicHttpAuthentication ( URI . create ( jiraUrl . toExternalForm ( ) ) , username , password ) ; } | Connects to the JIRA server . |
8,307 | public < T extends Serializable > T get ( Object key , T defaultValue ) { throw new UnsupportedOperationException ( "DeltaMap must only be read in bulk." ) ; } | - If we clear this map the type changes to REPLACE and all elements are cleared |
8,308 | public void update ( ) { final long time = System . currentTimeMillis ( ) ; elapsedTime += time - lastUpdateTime ; lastUpdateTime = time ; frameCount ++ ; if ( elapsedTime >= 1000 ) { tps = frameCount ; frameCount = 0 ; elapsedTime = 0 ; } } | Updates the TPS . |
8,309 | public InternalContext createSubContext ( VariantIndexer [ ] indexers , InternalContext localContext , int varSize ) { Object [ ] [ ] myParentScopes = this . parentScopes ; Object [ ] [ ] scopes ; if ( myParentScopes == null ) { scopes = new Object [ ] [ ] { this . vars } ; } else { scopes = new Object [ myParentScopes . length + 1 ] [ ] ; scopes [ 0 ] = this . vars ; System . arraycopy ( myParentScopes , 0 , scopes , 1 , myParentScopes . length ) ; } InternalContext newContext = new InternalContext ( template , localContext . out , Vars . EMPTY , indexers , varSize , scopes ) ; newContext . localContext = localContext ; return newContext ; } | Create a sub context . |
8,310 | public Object resetReturnLoop ( ) { Object result = this . loopType == LoopInfo . RETURN ? this . returned : VOID ; resetLoop ( ) ; return result ; } | Unmark loops at the end of functions . |
8,311 | public < T > Object getBeanProperty ( final T bean , final Object property ) { if ( bean != null ) { @ SuppressWarnings ( "unchecked" ) GetResolver < T > resolver = this . getters . unsafeGet ( bean . getClass ( ) ) ; if ( resolver != null ) { return resolver . get ( bean , property ) ; } } return this . resolverManager . get ( bean , property ) ; } | Get a bean s property . |
8,312 | public < T > void setBeanProperty ( final T bean , final Object property , final Object value ) { if ( bean != null ) { @ SuppressWarnings ( "unchecked" ) SetResolver < T > resolver = this . setters . unsafeGet ( bean . getClass ( ) ) ; if ( resolver != null ) { resolver . set ( bean , property , value ) ; return ; } } this . resolverManager . set ( bean , property , value ) ; } | Set a bean s property . |
8,313 | public void execute ( CinchContext cinchContext , SparkConf sparkConf ) { JavaSparkContext sparkContext = new JavaSparkContext ( sparkConf ) ; execute ( sparkContext , cinchContext ) ; } | Execute cinch job with context . |
8,314 | private void put ( String section , String key , String value , boolean append ) { if ( key == null ) { return ; } if ( section == null ) { put ( key , value , append ) ; return ; } put ( key . isEmpty ( ) ? section : section + '.' + key , value , append ) ; } | Adds accumulated value to key and current section . |
8,315 | public void forEachConst ( BiConsumer < String , Object > action ) { Objects . requireNonNull ( action ) ; this . constVars . forEach ( action ) ; } | Performs the given action for each const vars until all have been processed or the action throws an exception . |
8,316 | public void forEachGlobal ( BiConsumer < String , Object > action ) { Objects . requireNonNull ( action ) ; this . globalVars . forEach ( action ) ; } | Performs the given action for each global vars until all have been processed or the action throws an exception . |
8,317 | private void sendMessage ( org . isoblue . isobus . Message message ) { if ( mChatService . getState ( ) != BluetoothService . STATE_CONNECTED ) { Toast . makeText ( this , R . string . not_connected , Toast . LENGTH_SHORT ) . show ( ) ; return ; } mChatService . write ( message ) ; mOutStringBuffer . setLength ( 0 ) ; } | Sends a message . |
8,318 | static void setHost ( String scheme , String host , int port ) { BASE_URL = scheme + "://" + host + ":" + port + "/" + VERSION + "/" ; } | Override the server location . |
8,319 | public String performPostRequest ( String requestString , String data ) throws IOException { HttpPost request = new HttpPost ( getBaseUrl ( ) + requestString ) ; String json = null ; CloseableHttpClient httpClient = HttpClients . createDefault ( ) ; if ( proxies . size ( ) > 0 ) { Proxy myProxy = proxies . get ( 0 ) ; HttpHost proxy = myProxy . getHttpHost ( ) ; RequestConfig config = RequestConfig . custom ( ) . setProxy ( proxy ) . setSocketTimeout ( myProxy . getProxySocketTimeout ( ) ) . setConnectTimeout ( myProxy . getProxyConnectTimeout ( ) ) . setConnectionRequestTimeout ( myProxy . getProxyConnectionRequestTimeout ( ) ) . setProxyPreferredAuthSchemes ( Arrays . asList ( AuthSchemes . BASIC ) ) . build ( ) ; request . setConfig ( config ) ; } try { logger . debug ( "------------------------------------------------" ) ; logger . debug ( "OSS Index POST: " + getBaseUrl ( ) + requestString ) ; logger . debug ( data ) ; logger . debug ( "------------------------------------------------" ) ; request . setEntity ( new StringEntity ( data ) ) ; CloseableHttpResponse response = httpClient . execute ( request ) ; int code = response . getStatusLine ( ) . getStatusCode ( ) ; if ( code < 200 || code > 299 ) { throw new ConnectException ( response . getStatusLine ( ) . getReasonPhrase ( ) + " (" + code + ")" ) ; } json = EntityUtils . toString ( response . getEntity ( ) , "UTF-8" ) ; } catch ( ParseException e ) { throw new IOException ( e ) ; } finally { httpClient . close ( ) ; } return json ; } | Perform the request with the given URL and JSON data . |
8,320 | protected String performGetRequest ( String requestString ) throws IOException { HttpGet request = new HttpGet ( getBaseUrl ( ) + requestString ) ; if ( USER != null && ! USER . isEmpty ( ) ) { request . setHeader ( "Authorization" , USER + ":" + TOKEN ) ; } String json = null ; CloseableHttpClient httpClient = HttpClients . createDefault ( ) ; try { logger . debug ( "------------------------------------------------" ) ; logger . debug ( "OSS Index GET: " + getBaseUrl ( ) + requestString ) ; logger . debug ( "------------------------------------------------" ) ; CloseableHttpResponse response = httpClient . execute ( request ) ; int code = response . getStatusLine ( ) . getStatusCode ( ) ; if ( code < 200 || code > 299 ) { throw new ConnectException ( response . getStatusLine ( ) . getReasonPhrase ( ) + " (" + code + ")" ) ; } json = EntityUtils . toString ( response . getEntity ( ) , "UTF-8" ) ; } catch ( ParseException e ) { throw new IOException ( e ) ; } finally { httpClient . close ( ) ; } return json ; } | Perform a get request |
8,321 | public String concat ( final String parent , final String name ) { return parent != null ? FileNameUtil . concat ( FileNameUtil . getPath ( parent ) , name ) : name ; } | get child template name by parent template name and relative name . |
8,322 | protected String getRealPath ( final String name ) { return this . root != null ? this . root . concat ( name ) : name . substring ( 1 ) ; } | get real path from name . |
8,323 | public String normalize ( String name ) { if ( name == null ) { return null ; } if ( name . isEmpty ( ) ) { return "/" ; } if ( name . charAt ( 0 ) != '/' && name . charAt ( 0 ) != '\\' ) { name = "/" . concat ( name ) ; } name = FileNameUtil . normalize ( name ) ; if ( name == null ) { return null ; } if ( ! this . appendLostSuffix || name . endsWith ( this . suffix ) || name . charAt ( name . length ( ) - 1 ) == '/' ) { return name ; } else { for ( String item : this . assistantSuffixs ) { if ( name . endsWith ( item ) ) { return name ; } } return name . concat ( this . suffix ) ; } } | normalize a template s name . |
8,324 | public final int get ( int i ) { if ( fullWidth ) { return array . get ( i ) ; } return unPack ( array . get ( getIndex ( i ) ) , getSubIndex ( i ) ) ; } | Gets an element from the array at a given index |
8,325 | public int [ ] getPacked ( ) { int length = this . array . length ( ) ; int [ ] packed = new int [ length ] ; for ( int i = 0 ; i < length ; i ++ ) { packed [ i ] = this . array . get ( i ) ; } return packed ; } | Gets a packed version of this array . Tearing may occur if the array is updated during this method call . |
8,326 | @ SuppressWarnings ( "unchecked" ) public < T > T get ( final Class < T > type ) { T bean = ( T ) components . get ( type ) ; if ( bean != null ) { return bean ; } return ( T ) get ( type . getName ( ) ) ; } | Get component or bean by type . |
8,327 | public Object get ( final String name ) { Object bean = this . beans . get ( name ) ; if ( bean != null ) { return bean ; } return resolveBeanIfAbsent ( name ) ; } | Get bean by name . |
8,328 | private synchronized void setState ( int state ) { mState = state ; mHandler . obtainMessage ( ISOBlueDemo . MESSAGE_STATE_CHANGE , state , - 1 ) . sendToTarget ( ) ; } | Set the current state of the chat connection |
8,329 | public synchronized void connect ( BluetoothDevice device , boolean past ) throws IOException , InterruptedException { if ( mState == STATE_CONNECTING ) { if ( mConnectThread != null ) { mConnectThread . cancel ( ) ; mConnectThread = null ; } } if ( mEngConnectedThread != null ) { mEngConnectedThread . cancel ( ) ; mEngConnectedThread = null ; } if ( mImpConnectedThread != null ) { mImpConnectedThread . cancel ( ) ; mImpConnectedThread = null ; } mPast = past ; try { mConnectThread = new ConnectThread ( device ) ; mConnectThread . start ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; connectionFailed ( ) ; setState ( STATE_NONE ) ; } setState ( STATE_CONNECTING ) ; } | Start the ConnectThread to initiate a connection to a remote device . |
8,330 | public void write ( org . isoblue . isobus . Message out ) { ConnectedThread r ; synchronized ( this ) { if ( mState != STATE_CONNECTED ) return ; r = mEngConnectedThread ; } r . write ( out ) ; } | Write to the ConnectedThread in an unsynchronized manner |
8,331 | private void connectionFailed ( ) { Message msg = mHandler . obtainMessage ( ISOBlueDemo . MESSAGE_TOAST ) ; Bundle bundle = new Bundle ( ) ; bundle . putString ( ISOBlueDemo . TOAST , "Unable to connect device" ) ; msg . setData ( bundle ) ; mHandler . sendMessage ( msg ) ; BluetoothService . this . start ( ) ; } | Indicate that the connection attempt failed and notify the UI Activity . |
8,332 | public void onCreate ( Bundle savedInstanceState ) { setContentView ( R . layout . about ) ; TextView tv = ( TextView ) findViewById ( R . id . legal_text ) ; tv . setText ( readRawTextFile ( R . raw . legal ) ) ; tv = ( TextView ) findViewById ( R . id . info_text ) ; tv . setText ( Html . fromHtml ( readRawTextFile ( R . raw . info ) ) ) ; tv . setLinkTextColor ( Color . WHITE ) ; Linkify . addLinks ( tv , Linkify . ALL ) ; } | This is the standard Android on create method that gets called when the activity initialized . |
8,333 | public static < A , B > boolean equalsAny ( A object , B ... objects ) { for ( B o : objects ) { if ( bothNullOrEqual ( o , object ) ) { return true ; } } return false ; } | Checks if the object equals one of the other objects given |
8,334 | public static boolean bothNullOrEqual ( Object a , Object b ) { return ( a == null || b == null ) ? ( a == b ) : a . equals ( b ) ; } | Checks if object a and b are both null or are equal |
8,335 | protected void verifySadRequest ( SignatureActivationDataContext sadRequest , ProfileRequestContext < ? , ? > context ) throws ExternalAutenticationErrorCodeException { final AuthnRequest authnRequest = this . getAuthnRequest ( context ) ; if ( authnRequest == null ) { log . error ( "No AuthnRequest available [{}]" , this . getLogString ( context ) ) ; throw new ExternalAutenticationErrorCodeException ( AuthnEventIds . INVALID_AUTHN_CTX , "Missing AuthnRequest" ) ; } final SADRequest r = sadRequest . getSadRequest ( ) ; if ( r . getRequestedVersion ( ) != null && ! supportedSadVersions . contains ( r . getRequestedVersion ( ) ) ) { final String msg = String . format ( "Requested SAD version (%s) is not supported by the IdP" , r . getRequestedVersion ( ) ) ; log . info ( "{} [{}]" , msg , this . getLogString ( context ) ) ; throw new ExternalAutenticationErrorCodeException ( ExtAuthnEventIds . BAD_SAD_REQUEST , msg ) ; } if ( ! StringUtils . hasText ( r . getRequesterID ( ) ) ) { final String msg = "RequesterID is not present in the SADRequest - invalid" ; log . info ( "{} [{}]" , msg , this . getLogString ( context ) ) ; throw new ExternalAutenticationErrorCodeException ( ExtAuthnEventIds . BAD_SAD_REQUEST , msg ) ; } final String issuer = authnRequest . getIssuer ( ) . getValue ( ) ; if ( ! r . getRequesterID ( ) . equals ( issuer ) ) { final String msg = String . format ( "Invalid RequestID of SADRequest (%s) - Issuer of AuthnRequest is '%s'" , r . getRequesterID ( ) , issuer ) ; log . info ( "{} [{}]" , msg , this . getLogString ( context ) ) ; throw new ExternalAutenticationErrorCodeException ( ExtAuthnEventIds . BAD_SAD_REQUEST , msg ) ; } if ( ! StringUtils . hasText ( r . getSignRequestID ( ) ) ) { final String msg = "SignRequestID is not present in the SADRequest - invalid" ; log . info ( "{} [{}]" , msg , this . getLogString ( context ) ) ; throw new ExternalAutenticationErrorCodeException ( ExtAuthnEventIds . BAD_SAD_REQUEST , msg ) ; } if ( r . getDocCount ( ) == null ) { final String msg = "DocCount is not present in the SADRequest - invalid" ; log . info ( "{} [{}]" , msg , this . getLogString ( context ) ) ; throw new ExternalAutenticationErrorCodeException ( ExtAuthnEventIds . BAD_SAD_REQUEST , msg ) ; } if ( ! StringUtils . hasText ( r . getID ( ) ) ) { final String msg = "ID attribute is not present in the SADRequest - invalid" ; log . info ( "{} [{}]" , msg , this . getLogString ( context ) ) ; throw new ExternalAutenticationErrorCodeException ( ExtAuthnEventIds . BAD_SAD_REQUEST , msg ) ; } } | Verifies a received SAD request . |
8,336 | protected boolean isSignMessageURI ( String uri ) { LoaEnum loa = LoaEnum . parse ( uri ) ; return ( loa != null && loa . isSignatureMessageUri ( ) ) ; } | Predicate that tells if the supplied URI is a URI indicating sign message display . |
8,337 | public void connect ( String endpointID , String appID , boolean shouldReconnect , final Object initialPresence , Context context , final ConnectCompletionListener completionListener ) { if ( ( endpointID != null ) && ( appID != null ) && ( endpointID . length ( ) > 0 ) && ( appID . length ( ) > 0 ) ) { connectionInProgress = true ; reconnect = shouldReconnect ; applicationID = appID ; appContext = context ; APIGetToken request = new APIGetToken ( context , baseURL ) { public void transactionComplete ( ) { super . transactionComplete ( ) ; if ( success ) { connect ( this . token , initialPresence , appContext , new ConnectCompletionListener ( ) { public void onError ( final String errorMessage ) { connectionInProgress = false ; postConnectError ( completionListener , errorMessage ) ; } } ) ; } else { connectionInProgress = false ; postConnectError ( completionListener , this . errorMessage ) ; } } } ; request . appID = appID ; request . endpointID = endpointID ; request . go ( ) ; } else { postConnectError ( completionListener , "AppID and endpointID must be specified" ) ; } } | Connect to the Respoke infrastructure and authenticate in development mode using the specified endpoint ID and app ID . Attempt to obtain an authentication token automatically from the Respoke infrastructure . |
8,338 | public void connect ( String tokenID , final Object initialPresence , Context context , final ConnectCompletionListener completionListener ) { if ( ( tokenID != null ) && ( tokenID . length ( ) > 0 ) ) { connectionInProgress = true ; appContext = context ; APIDoOpen request = new APIDoOpen ( context , baseURL ) { public void transactionComplete ( ) { super . transactionComplete ( ) ; if ( success ) { presence = initialPresence ; signalingChannel = new RespokeSignalingChannel ( appToken , RespokeClient . this , baseURL , appContext ) ; signalingChannel . authenticate ( ) ; } else { connectionInProgress = false ; postConnectError ( completionListener , this . errorMessage ) ; } } } ; request . tokenID = tokenID ; request . go ( ) ; } else { postConnectError ( completionListener , "TokenID must be specified" ) ; } } | Connect to the Respoke infrastructure and authenticate with the specified brokered auth token ID . |
8,339 | public void joinGroups ( final ArrayList < String > groupIDList , final JoinGroupCompletionListener completionListener ) { if ( isConnected ( ) ) { if ( ( groupIDList != null ) && ( groupIDList . size ( ) > 0 ) ) { String urlEndpoint = "/v1/groups" ; JSONArray groupList = new JSONArray ( groupIDList ) ; JSONObject data = new JSONObject ( ) ; try { data . put ( "groups" , groupList ) ; signalingChannel . sendRESTMessage ( "post" , urlEndpoint , data , new RespokeSignalingChannel . RESTListener ( ) { public void onSuccess ( Object response ) { final ArrayList < RespokeGroup > newGroupList = new ArrayList < RespokeGroup > ( ) ; for ( String eachGroupID : groupIDList ) { RespokeGroup newGroup = new RespokeGroup ( eachGroupID , signalingChannel , RespokeClient . this ) ; groups . put ( eachGroupID , newGroup ) ; newGroupList . add ( newGroup ) ; } new Handler ( Looper . getMainLooper ( ) ) . post ( new Runnable ( ) { public void run ( ) { if ( null != completionListener ) { completionListener . onSuccess ( newGroupList ) ; } } } ) ; } public void onError ( final String errorMessage ) { postJoinGroupMembersError ( completionListener , errorMessage ) ; } } ) ; } catch ( JSONException e ) { postJoinGroupMembersError ( completionListener , "Error encoding group list to json" ) ; } } else { postJoinGroupMembersError ( completionListener , "At least one group must be specified" ) ; } } else { postJoinGroupMembersError ( completionListener , "Can't complete request when not connected. Please reconnect!" ) ; } } | Join a list of Groups and begin keeping track of them . |
8,340 | public RespokeConnection getConnection ( String connectionID , String endpointID , boolean skipCreate ) { RespokeConnection connection = null ; if ( null != connectionID ) { RespokeEndpoint endpoint = getEndpoint ( endpointID , skipCreate ) ; if ( null != endpoint ) { for ( RespokeConnection eachConnection : endpoint . connections ) { if ( eachConnection . connectionID . equals ( connectionID ) ) { connection = eachConnection ; break ; } } if ( ( null == connection ) && ( ! skipCreate ) ) { connection = new RespokeConnection ( connectionID , endpoint ) ; endpoint . connections . add ( connection ) ; } } } return connection ; } | Find a Connection by id and return it . In most cases if we don t find it we will create it . This is useful in the case of dynamic endpoints where groups are not in use . Set skipCreate = true to return null if the Connection is not already known . |
8,341 | public RespokeCall joinConference ( RespokeCall . Listener callListener , Context context , String conferenceID ) { RespokeCall call = null ; if ( ( null != signalingChannel ) && ( signalingChannel . connected ) ) { call = new RespokeCall ( signalingChannel , conferenceID , "conference" ) ; call . setListener ( callListener ) ; call . startCall ( context , null , true ) ; } return call ; } | Initiate a call to a conference . |
8,342 | public RespokeEndpoint getEndpoint ( String endpointIDToFind , boolean skipCreate ) { RespokeEndpoint endpoint = null ; if ( null != endpointIDToFind ) { for ( RespokeEndpoint eachEndpoint : knownEndpoints ) { if ( eachEndpoint . getEndpointID ( ) . equals ( endpointIDToFind ) ) { endpoint = eachEndpoint ; break ; } } if ( ( null == endpoint ) && ( ! skipCreate ) ) { endpoint = new RespokeEndpoint ( signalingChannel , endpointIDToFind , this ) ; knownEndpoints . add ( endpoint ) ; } if ( null != endpoint ) { queuePresenceRegistration ( endpoint . getEndpointID ( ) ) ; } } return endpoint ; } | Find an endpoint by id and return it . In most cases if we don t find it we will create it . This is useful in the case of dynamic endpoints where groups are not in use . Set skipCreate = true to return null if the Endpoint is not already known . |
8,343 | public RespokeGroup getGroup ( String groupIDToFind ) { RespokeGroup group = null ; if ( null != groupIDToFind ) { group = groups . get ( groupIDToFind ) ; } return group ; } | Returns the group with the specified ID |
8,344 | public void getGroupHistories ( final List < String > groupIds , final Integer maxMessages , final GroupHistoriesCompletionListener completionListener ) { if ( ! isConnected ( ) ) { getGroupHistoriesError ( completionListener , "Can't complete request when not connected, " + "Please reconnect!" ) ; return ; } if ( ( maxMessages == null ) || ( maxMessages < 1 ) ) { getGroupHistoriesError ( completionListener , "maxMessages must be at least 1" ) ; return ; } if ( ( groupIds == null ) || ( groupIds . size ( ) == 0 ) ) { getGroupHistoriesError ( completionListener , "At least 1 group must be specified" ) ; return ; } JSONObject body = new JSONObject ( ) ; try { body . put ( "limit" , maxMessages . toString ( ) ) ; JSONArray groupIdParams = new JSONArray ( groupIds ) ; body . put ( "groupIds" , groupIdParams ) ; } catch ( JSONException e ) { getGroupHistoriesError ( completionListener , "Error forming JSON body to send." ) ; return ; } String urlEndpoint = "/v1/group-history-search" ; signalingChannel . sendRESTMessage ( "post" , urlEndpoint , body , new RespokeSignalingChannel . RESTListener ( ) { public void onSuccess ( Object response ) { if ( ! ( response instanceof JSONObject ) ) { getGroupHistoriesError ( completionListener , "Invalid response from server" ) ; return ; } final JSONObject json = ( JSONObject ) response ; final HashMap < String , List < RespokeGroupMessage > > results = new HashMap < > ( ) ; for ( Iterator < String > keys = json . keys ( ) ; keys . hasNext ( ) ; ) { final String key = keys . next ( ) ; try { final JSONArray jsonMessages = json . getJSONArray ( key ) ; final ArrayList < RespokeGroupMessage > messageList = new ArrayList < > ( jsonMessages . length ( ) ) ; for ( int i = 0 ; i < jsonMessages . length ( ) ; i ++ ) { final JSONObject jsonMessage = jsonMessages . getJSONObject ( i ) ; final RespokeGroupMessage message = buildGroupMessage ( jsonMessage ) ; messageList . add ( message ) ; } results . put ( key , messageList ) ; } catch ( JSONException e ) { getGroupHistoriesError ( completionListener , "Error parsing JSON response" ) ; return ; } } new Handler ( Looper . getMainLooper ( ) ) . post ( new Runnable ( ) { public void run ( ) { if ( completionListener != null ) { completionListener . onSuccess ( results ) ; } } } ) ; } public void onError ( final String errorMessage ) { getGroupHistoriesError ( completionListener , errorMessage ) ; } } ) ; } | Retrieve the history of messages that have been persisted for 1 or more groups . Only those messages that have been marked to be persisted when sent will show up in the history . |
8,345 | public void setConversationsRead ( final List < RespokeConversationReadStatus > updates , final Respoke . TaskCompletionListener completionListener ) { if ( ! isConnected ( ) ) { Respoke . postTaskError ( completionListener , "Can't complete request when not connected, " + "Please reconnect!" ) ; return ; } if ( ( updates == null ) || ( updates . size ( ) == 0 ) ) { Respoke . postTaskError ( completionListener , "At least 1 conversation must be specified" ) ; return ; } JSONObject body = new JSONObject ( ) ; JSONArray groupsJsonArray = new JSONArray ( ) ; try { for ( RespokeConversationReadStatus status : updates ) { JSONObject jsonStatus = new JSONObject ( ) ; jsonStatus . put ( "groupId" , status . groupId ) ; jsonStatus . put ( "timestamp" , status . timestamp . toString ( ) ) ; groupsJsonArray . put ( jsonStatus ) ; } body . put ( "groups" , groupsJsonArray ) ; } catch ( JSONException e ) { Respoke . postTaskError ( completionListener , "Error forming JSON body to send." ) ; return ; } String urlEndpoint = "/v1/endpoints/" + localEndpointID + "/conversations" ; signalingChannel . sendRESTMessage ( "put" , urlEndpoint , body , new RespokeSignalingChannel . RESTListener ( ) { public void onSuccess ( Object response ) { new Handler ( Looper . getMainLooper ( ) ) . post ( new Runnable ( ) { public void run ( ) { if ( completionListener != null ) { completionListener . onSuccess ( ) ; } } } ) ; } public void onError ( final String errorMessage ) { Respoke . postTaskError ( completionListener , errorMessage ) ; } } ) ; } | Mark messages in a conversation as having been read up to the given timestamp |
8,346 | public void getGroupHistory ( final String groupId , final Integer maxMessages , final GroupHistoryCompletionListener completionListener ) { getGroupHistory ( groupId , maxMessages , null , completionListener ) ; } | Retrieve the history of messages that have been persisted for a specific group . Only those messages that have been marked to be persisted when sent will show up in the history . To retrieve messages further back in the history than right now use the other method signature that allows before to be specified . |
8,347 | public void getGroupHistory ( final String groupId , final Integer maxMessages , final Date before , final GroupHistoryCompletionListener completionListener ) { if ( ! isConnected ( ) ) { getGroupHistoryError ( completionListener , "Can't complete request when not connected, " + "Please reconnect!" ) ; return ; } if ( ( maxMessages == null ) || ( maxMessages < 1 ) ) { getGroupHistoryError ( completionListener , "maxMessages must be at least 1" ) ; return ; } if ( ( groupId == null ) || groupId . length ( ) == 0 ) { getGroupHistoryError ( completionListener , "groupId cannot be blank" ) ; return ; } Uri . Builder builder = new Uri . Builder ( ) ; builder . appendQueryParameter ( "limit" , maxMessages . toString ( ) ) ; if ( before != null ) { builder . appendQueryParameter ( "before" , Long . toString ( before . getTime ( ) ) ) ; } String urlEndpoint = String . format ( "/v1/groups/%s/history%s" , groupId , builder . build ( ) . toString ( ) ) ; signalingChannel . sendRESTMessage ( "get" , urlEndpoint , null , new RespokeSignalingChannel . RESTListener ( ) { public void onSuccess ( Object response ) { if ( ! ( response instanceof JSONArray ) ) { getGroupHistoryError ( completionListener , "Invalid response from server" ) ; return ; } final JSONArray json = ( JSONArray ) response ; final ArrayList < RespokeGroupMessage > results = new ArrayList < > ( json . length ( ) ) ; try { for ( int i = 0 ; i < json . length ( ) ; i ++ ) { final JSONObject jsonMessage = json . getJSONObject ( i ) ; final RespokeGroupMessage message = buildGroupMessage ( jsonMessage ) ; results . add ( message ) ; } } catch ( JSONException e ) { getGroupHistoryError ( completionListener , "Error parsing JSON response" ) ; return ; } new Handler ( Looper . getMainLooper ( ) ) . post ( new Runnable ( ) { public void run ( ) { if ( completionListener != null ) { completionListener . onSuccess ( results ) ; } } } ) ; } public void onError ( final String errorMessage ) { getGroupHistoryError ( completionListener , errorMessage ) ; } } ) ; } | Retrieve the history of messages that have been persisted for a specific group . Only those messages that have been marked to be persisted when sent will show up in the history . |
8,348 | public void setPresence ( Object newPresence , final Respoke . TaskCompletionListener completionListener ) { if ( isConnected ( ) ) { Object presenceToSet = newPresence ; if ( null == presenceToSet ) { presenceToSet = "available" ; } JSONObject typeData = new JSONObject ( ) ; JSONObject data = new JSONObject ( ) ; try { typeData . put ( "type" , presenceToSet ) ; data . put ( "presence" , typeData ) ; final Object finalPresence = presenceToSet ; signalingChannel . sendRESTMessage ( "post" , "/v1/presence" , data , new RespokeSignalingChannel . RESTListener ( ) { public void onSuccess ( Object response ) { presence = finalPresence ; Respoke . postTaskSuccess ( completionListener ) ; } public void onError ( final String errorMessage ) { Respoke . postTaskError ( completionListener , errorMessage ) ; } } ) ; } catch ( JSONException e ) { Respoke . postTaskError ( completionListener , "Error encoding presence to json" ) ; } } else { Respoke . postTaskError ( completionListener , "Can't complete request when not connected. Please reconnect!" ) ; } } | Set the presence on the client session |
8,349 | public void registerPushServicesWithToken ( final String token ) { String httpURI ; String httpMethod ; JSONObject data = new JSONObject ( ) ; try { data . put ( "token" , token ) ; data . put ( "service" , "google" ) ; SharedPreferences prefs = appContext . getSharedPreferences ( appContext . getPackageName ( ) , Context . MODE_PRIVATE ) ; if ( null != prefs ) { String lastKnownPushToken = prefs . getString ( PROPERTY_LAST_VALID_PUSH_TOKEN , "notAvailable" ) ; String lastKnownPushTokenID = prefs . getString ( PROPERTY_LAST_VALID_PUSH_TOKEN_ID , "notAvailable" ) ; if ( ( null == lastKnownPushTokenID ) || ( lastKnownPushTokenID . equals ( "notAvailable" ) ) ) { httpURI = String . format ( "/v1/connections/%s/push-token" , localConnectionID ) ; httpMethod = "post" ; createOrUpdatePushServiceToken ( token , httpURI , httpMethod , data , prefs ) ; } else if ( ! lastKnownPushToken . equals ( "notAvailable" ) && ! lastKnownPushToken . equals ( token ) ) { httpURI = String . format ( "/v1/connections/%s/push-token/%s" , localConnectionID , lastKnownPushTokenID ) ; httpMethod = "put" ; createOrUpdatePushServiceToken ( token , httpURI , httpMethod , data , prefs ) ; } } } catch ( JSONException e ) { Log . d ( "" , "Invalid JSON format for token" ) ; } } | Register the client to receive push notifications when the socket is not active |
8,350 | public void unregisterFromPushServices ( final Respoke . TaskCompletionListener completionListener ) { if ( isConnected ( ) ) { SharedPreferences prefs = appContext . getSharedPreferences ( appContext . getPackageName ( ) , Context . MODE_PRIVATE ) ; if ( null != prefs ) { String lastKnownPushTokenID = prefs . getString ( PROPERTY_LAST_VALID_PUSH_TOKEN_ID , "notAvailable" ) ; if ( ( null != lastKnownPushTokenID ) && ! lastKnownPushTokenID . equals ( "notAvailable" ) ) { String httpURI = String . format ( "/v1/connections/%s/push-token/%s" , localConnectionID , lastKnownPushTokenID ) ; signalingChannel . sendRESTMessage ( "delete" , httpURI , null , new RespokeSignalingChannel . RESTListener ( ) { public void onSuccess ( Object response ) { SharedPreferences prefs = appContext . getSharedPreferences ( appContext . getPackageName ( ) , Context . MODE_PRIVATE ) ; SharedPreferences . Editor editor = prefs . edit ( ) ; editor . remove ( PROPERTY_LAST_VALID_PUSH_TOKEN_ID ) ; editor . apply ( ) ; Respoke . postTaskSuccess ( completionListener ) ; } public void onError ( String errorMessage ) { Respoke . postTaskError ( completionListener , "Error unregistering push service token: " + errorMessage ) ; } } ) ; } else { Respoke . postTaskSuccess ( completionListener ) ; } } else { Respoke . postTaskError ( completionListener , "Unable to access shared preferences to look for push token" ) ; } } else { Respoke . postTaskError ( completionListener , "Can't complete request when not connected. Please reconnect!" ) ; } } | Unregister this client from the push service so that no more notifications will be received for this endpoint ID |
8,351 | private void postConnectError ( final ConnectCompletionListener completionListener , final String errorMessage ) { new Handler ( Looper . getMainLooper ( ) ) . post ( new Runnable ( ) { public void run ( ) { if ( null != completionListener ) { completionListener . onError ( errorMessage ) ; } } } ) ; } | A convenience method for posting errors to a ConnectCompletionListener |
8,352 | private void postJoinGroupMembersError ( final JoinGroupCompletionListener completionListener , final String errorMessage ) { new Handler ( Looper . getMainLooper ( ) ) . post ( new Runnable ( ) { public void run ( ) { if ( null != completionListener ) { completionListener . onError ( errorMessage ) ; } } } ) ; } | A convenience method for posting errors to a JoinGroupCompletionListener |
8,353 | private void performReconnect ( ) { if ( null != applicationID ) { reconnectCount ++ ; new java . util . Timer ( ) . schedule ( new java . util . TimerTask ( ) { public void run ( ) { actuallyReconnect ( ) ; } } , RECONNECT_INTERVAL * ( reconnectCount - 1 ) ) ; } } | Attempt to reconnect the client after a small delay |
8,354 | private void actuallyReconnect ( ) { if ( ( ( null == signalingChannel ) || ! signalingChannel . connected ) && reconnect ) { if ( connectionInProgress ) { performReconnect ( ) ; } else { Log . d ( TAG , "Trying to reconnect..." ) ; connect ( localEndpointID , applicationID , reconnect , presence , appContext , new ConnectCompletionListener ( ) { public void onError ( final String errorMessage ) { new Handler ( Looper . getMainLooper ( ) ) . post ( new Runnable ( ) { public void run ( ) { Listener listener = listenerReference . get ( ) ; if ( null != listener ) { listener . onError ( RespokeClient . this , errorMessage ) ; } } } ) ; performReconnect ( ) ; } } ) ; } } } | Attempt to reconnect the client if it is not already trying in another thread |
8,355 | private RespokeGroupMessage buildGroupMessage ( JSONObject source ) throws JSONException { if ( source == null ) { throw new IllegalArgumentException ( "source cannot be null" ) ; } final JSONObject header = source . getJSONObject ( "header" ) ; final String endpointID = header . getString ( "from" ) ; final RespokeEndpoint endpoint = getEndpoint ( endpointID , false ) ; final String groupID = header . getString ( "channel" ) ; RespokeGroup group = getGroup ( groupID ) ; if ( group == null ) { group = new RespokeGroup ( groupID , signalingChannel , this , false ) ; groups . put ( groupID , group ) ; } final String message = source . getString ( "message" ) ; final Date timestamp ; if ( ! header . isNull ( "timestamp" ) ) { timestamp = new Date ( header . getLong ( "timestamp" ) ) ; } else { timestamp = new Date ( ) ; } return new RespokeGroupMessage ( message , group , endpoint , timestamp ) ; } | Build a group message from a JSON object . The format of the JSON object would be the format that comes over the wire from Respoke when receiving a pubsub message . This same format is used when retrieving message history . |
8,356 | public void setListener ( Listener listener ) { if ( null != listener ) { listenerReference = new WeakReference < Listener > ( listener ) ; } else { listenerReference = null ; } } | Set a receiver for the Listener interface |
8,357 | public void accept ( Context context ) { if ( null != callReference ) { RespokeCall call = callReference . get ( ) ; if ( null != call ) { call . directConnectionDidAccept ( context ) ; } } } | Accept the direct connection and start the process of obtaining media . |
8,358 | public void sendMessage ( String message , final Respoke . TaskCompletionListener completionListener ) { if ( isActive ( ) ) { JSONObject jsonMessage = new JSONObject ( ) ; try { jsonMessage . put ( "message" , message ) ; byte [ ] rawMessage = jsonMessage . toString ( ) . getBytes ( Charset . forName ( "UTF-8" ) ) ; ByteBuffer directData = ByteBuffer . allocateDirect ( rawMessage . length ) ; directData . put ( rawMessage ) ; directData . flip ( ) ; DataChannel . Buffer data = new DataChannel . Buffer ( directData , false ) ; if ( dataChannel . send ( data ) ) { Respoke . postTaskSuccess ( completionListener ) ; } else { Respoke . postTaskError ( completionListener , "Error sending message" ) ; } } catch ( JSONException e ) { Respoke . postTaskError ( completionListener , "Unable to encode message to JSON" ) ; } } else { Respoke . postTaskError ( completionListener , "DataChannel not in an open state" ) ; } } | Send a message to the remote client through the direct connection . |
8,359 | public void createDataChannel ( ) { if ( null != callReference ) { RespokeCall call = callReference . get ( ) ; if ( null != call ) { PeerConnection peerConnection = call . getPeerConnection ( ) ; dataChannel = peerConnection . createDataChannel ( "respokeDataChannel" , new DataChannel . Init ( ) ) ; dataChannel . registerObserver ( this ) ; } } } | Establish a new direct connection instance with the peer connection for the call . This is used internally to the SDK and should not be called directly by your client application . |
8,360 | public void peerConnectionDidOpenDataChannel ( DataChannel newDataChannel ) { if ( null != dataChannel ) { dataChannel . unregisterObserver ( ) ; } else { new Handler ( Looper . getMainLooper ( ) ) . post ( new Runnable ( ) { public void run ( ) { if ( null != listenerReference ) { Listener listener = listenerReference . get ( ) ; if ( null != listener ) { listener . onStart ( RespokeDirectConnection . this ) ; } } } } ) ; } dataChannel = newDataChannel ; newDataChannel . registerObserver ( this ) ; } | Notify the direct connection instance that the peer connection has opened the specified data channel |
8,361 | public void onStateChange ( ) { switch ( dataChannel . state ( ) ) { case CONNECTING : break ; case OPEN : { if ( null != callReference ) { RespokeCall call = callReference . get ( ) ; if ( null != call ) { call . directConnectionDidOpen ( this ) ; } } new Handler ( Looper . getMainLooper ( ) ) . post ( new Runnable ( ) { public void run ( ) { if ( null != listenerReference ) { Listener listener = listenerReference . get ( ) ; if ( null != listener ) { listener . onOpen ( RespokeDirectConnection . this ) ; } } } } ) ; } break ; case CLOSING : break ; case CLOSED : { if ( null != callReference ) { RespokeCall call = callReference . get ( ) ; if ( null != call ) { call . directConnectionDidClose ( this ) ; } } new Handler ( Looper . getMainLooper ( ) ) . post ( new Runnable ( ) { public void run ( ) { if ( null != listenerReference ) { Listener listener = listenerReference . get ( ) ; if ( null != listener ) { listener . onClose ( RespokeDirectConnection . this ) ; } } } } ) ; } break ; } } | org . webrtc . DataChannel . Observer methods |
8,362 | public void set ( int [ ] initial ) { resizeLock . lock ( ) ; try { if ( initial . length != length ) { throw new IllegalArgumentException ( "Array length mismatch, expected " + length + ", got " + initial . length ) ; } int unique = AtomicShortIntArray . getUnique ( initial ) ; int allowedPalette = AtomicShortIntPaletteBackingArray . getAllowedPalette ( length ) ; if ( unique == 1 ) { store . set ( new AtomicShortIntUniformBackingArray ( length , initial [ 0 ] ) ) ; } else if ( unique > allowedPalette ) { store . set ( new AtomicShortIntDirectBackingArray ( length , initial ) ) ; } else { store . set ( new AtomicShortIntPaletteBackingArray ( length , unique , initial ) ) ; } } finally { resizeLock . unlock ( ) ; } } | Sets the array equal to the given array . The array should be the same length as this array |
8,363 | public void uncompressedSet ( int [ ] initial ) { resizeLock . lock ( ) ; try { if ( initial . length != length ) { throw new IllegalArgumentException ( "Array length mismatch, expected " + length + ", got " + initial . length ) ; } store . set ( new AtomicShortIntDirectBackingArray ( length , initial ) ) ; } finally { resizeLock . unlock ( ) ; } } | Sets the array equal to the given array without automatically compressing the data . The array should be the same length as this array |
8,364 | public void set ( int [ ] palette , int blockArrayWidth , int [ ] variableWidthBlockArray ) { resizeLock . lock ( ) ; try { if ( palette . length == 0 ) { store . set ( new AtomicShortIntDirectBackingArray ( length , variableWidthBlockArray ) ) ; } else if ( palette . length == 1 ) { store . set ( new AtomicShortIntUniformBackingArray ( length , palette [ 0 ] ) ) ; } else { store . set ( new AtomicShortIntPaletteBackingArray ( length , palette , blockArrayWidth , variableWidthBlockArray ) ) ; } } finally { resizeLock . unlock ( ) ; } } | Sets the array equal to the given palette based array . The main array should be the same length as this array |
8,365 | public void compress ( ) { resizeLock . lock ( ) ; try { AtomicShortIntBackingArray s = store . get ( ) ; if ( s instanceof AtomicShortIntUniformBackingArray ) { return ; } int unique = s . getUnique ( ) ; if ( AtomicShortIntPaletteBackingArray . roundUpWidth ( unique - 1 ) >= s . width ( ) ) { return ; } if ( unique > AtomicShortIntPaletteBackingArray . getAllowedPalette ( s . length ( ) ) ) { return ; } if ( unique == 1 ) { store . set ( new AtomicShortIntUniformBackingArray ( s ) ) ; } else { store . set ( new AtomicShortIntPaletteBackingArray ( s , length , true , false , unique ) ) ; } } finally { resizeLock . unlock ( ) ; } } | Attempts to compress the array |
8,366 | public void getMembers ( final GetGroupMembersCompletionListener completionListener ) { if ( isJoined ( ) ) { if ( ( null != groupID ) && ( groupID . length ( ) > 0 ) ) { String urlEndpoint = "/v1/channels/" + groupID + "/subscribers/" ; signalingChannel . sendRESTMessage ( "get" , urlEndpoint , null , new RespokeSignalingChannel . RESTListener ( ) { public void onSuccess ( Object response ) { JSONArray responseArray = null ; if ( response != null ) { if ( response instanceof JSONArray ) { responseArray = ( JSONArray ) response ; } else if ( response instanceof String ) { try { responseArray = new JSONArray ( ( String ) response ) ; } catch ( JSONException e ) { } } } if ( null != responseArray ) { final ArrayList < RespokeConnection > nameList = new ArrayList < RespokeConnection > ( ) ; RespokeClient client = clientReference . get ( ) ; if ( null != client ) { for ( int ii = 0 ; ii < responseArray . length ( ) ; ii ++ ) { try { JSONObject eachEntry = ( JSONObject ) responseArray . get ( ii ) ; String newEndpointID = eachEntry . getString ( "endpointId" ) ; String newConnectionID = eachEntry . getString ( "connectionId" ) ; if ( ! newEndpointID . equals ( client . getEndpointID ( ) ) ) { RespokeConnection connection = client . getConnection ( newConnectionID , newEndpointID , false ) ; if ( null != connection ) { nameList . add ( connection ) ; } } } catch ( JSONException e ) { } } } members . clear ( ) ; members . addAll ( nameList ) ; new Handler ( Looper . getMainLooper ( ) ) . post ( new Runnable ( ) { public void run ( ) { if ( null != completionListener ) { completionListener . onSuccess ( nameList ) ; } } } ) ; } else { postGetGroupMembersError ( completionListener , "Invalid response from server" ) ; } } public void onError ( final String errorMessage ) { postGetGroupMembersError ( completionListener , errorMessage ) ; } } ) ; } else { postGetGroupMembersError ( completionListener , "Group name must be specified" ) ; } } else { postGetGroupMembersError ( completionListener , "Not a member of this group anymore." ) ; } } | Get an array containing the members of the group . |
8,367 | public void join ( final Respoke . TaskCompletionListener completionListener ) { if ( ! isConnected ( ) ) { Respoke . postTaskError ( completionListener , "Can't complete request when not connected. " + "Please reconnect!" ) ; return ; } if ( ( groupID == null ) || ( groupID . length ( ) == 0 ) ) { Respoke . postTaskError ( completionListener , "Group name must be specified" ) ; return ; } String urlEndpoint = String . format ( "/v1/groups/%s" , groupID ) ; signalingChannel . sendRESTMessage ( "post" , urlEndpoint , null , new RespokeSignalingChannel . RESTListener ( ) { public void onSuccess ( Object response ) { joined = true ; Respoke . postTaskSuccess ( completionListener ) ; } public void onError ( final String errorMessage ) { Respoke . postTaskError ( completionListener , errorMessage ) ; } } ) ; } | Join this group |
8,368 | public void leave ( final Respoke . TaskCompletionListener completionListener ) { if ( isJoined ( ) ) { if ( ( null != groupID ) && ( groupID . length ( ) > 0 ) ) { String urlEndpoint = "/v1/groups" ; JSONArray groupList = new JSONArray ( ) ; groupList . put ( groupID ) ; JSONObject data = new JSONObject ( ) ; try { data . put ( "groups" , groupList ) ; signalingChannel . sendRESTMessage ( "delete" , urlEndpoint , data , new RespokeSignalingChannel . RESTListener ( ) { public void onSuccess ( Object response ) { joined = false ; Respoke . postTaskSuccess ( completionListener ) ; } public void onError ( final String errorMessage ) { Respoke . postTaskError ( completionListener , errorMessage ) ; } } ) ; } catch ( JSONException e ) { Respoke . postTaskError ( completionListener , "Error encoding group list to json" ) ; } } else { Respoke . postTaskError ( completionListener , "Group name must be specified" ) ; } } else { Respoke . postTaskError ( completionListener , "Not a member of this group anymore." ) ; } } | Leave this group |
8,369 | public void sendMessage ( String message , boolean push , boolean persist , final Respoke . TaskCompletionListener completionListener ) { if ( isJoined ( ) ) { if ( ( null != groupID ) && ( groupID . length ( ) > 0 ) ) { RespokeClient client = clientReference . get ( ) ; if ( null != client ) { JSONObject data = new JSONObject ( ) ; try { data . put ( "endpointId" , client . getEndpointID ( ) ) ; data . put ( "message" , message ) ; data . put ( "push" , push ) ; data . put ( "persist" , persist ) ; } catch ( JSONException e ) { Respoke . postTaskError ( completionListener , "Unable to encode message" ) ; return ; } String urlEndpoint = "/v1/channels/" + groupID + "/publish/" ; signalingChannel . sendRESTMessage ( "post" , urlEndpoint , data , new RespokeSignalingChannel . RESTListener ( ) { public void onSuccess ( Object response ) { Respoke . postTaskSuccess ( completionListener ) ; } public void onError ( final String errorMessage ) { Respoke . postTaskError ( completionListener , errorMessage ) ; } } ) ; } else { Respoke . postTaskError ( completionListener , "There was an internal error processing this request." ) ; } } else { Respoke . postTaskError ( completionListener , "Group name must be specified" ) ; } } else { Respoke . postTaskError ( completionListener , "Not a member of this group anymore." ) ; } } | Send a message to the entire group . |
8,370 | public void connectionDidJoin ( final RespokeConnection connection ) { members . add ( connection ) ; new Handler ( Looper . getMainLooper ( ) ) . post ( new Runnable ( ) { public void run ( ) { Listener listener = listenerReference . get ( ) ; if ( null != listener ) { listener . onJoin ( connection , RespokeGroup . this ) ; } } } ) ; } | Notify the group that a connection has joined . This is used internally to the SDK and should not be called directly by your client application . |
8,371 | public void connectionDidLeave ( final RespokeConnection connection ) { members . remove ( connection ) ; new Handler ( Looper . getMainLooper ( ) ) . post ( new Runnable ( ) { public void run ( ) { Listener listener = listenerReference . get ( ) ; if ( null != listener ) { listener . onLeave ( connection , RespokeGroup . this ) ; } } } ) ; } | Notify the group that a connection has left . This is used internally to the SDK and should not be called directly by your client application . |
8,372 | private void postGetGroupMembersError ( final GetGroupMembersCompletionListener completionListener , final String errorMessage ) { new Handler ( Looper . getMainLooper ( ) ) . post ( new Runnable ( ) { public void run ( ) { if ( null != completionListener ) { completionListener . onError ( errorMessage ) ; } } } ) ; } | A convenience method for posting errors to a GetGroupMembersCompletionListener |
8,373 | public HttpEntity < byte [ ] > getMetadata ( HttpServletRequest request , @ RequestHeader ( name = "Accept" , required = false ) String acceptHeader ) { logger . debug ( "Request to download metadata from {}" , request . getRemoteAddr ( ) ) ; try { if ( this . metadataContainer . updateRequired ( true ) ) { logger . debug ( "Metadata needs to be updated ..." ) ; this . metadataContainer . update ( true ) ; logger . debug ( "Metadata was updated and signed" ) ; } else { logger . debug ( "Metadata is up-to-date, using cached metadata" ) ; } Element dom = this . metadataContainer . marshall ( ) ; ByteArrayOutputStream stream = new ByteArrayOutputStream ( ) ; SerializeSupport . writeNode ( dom , stream ) ; HttpHeaders header = new HttpHeaders ( ) ; if ( acceptHeader != null && ! acceptHeader . contains ( APPLICATION_SAML_METADATA ) ) { header . setContentType ( MediaType . APPLICATION_XML ) ; } else { header . setContentType ( MediaType . valueOf ( APPLICATION_SAML_METADATA ) ) ; } byte [ ] documentBody = stream . toByteArray ( ) ; header . setContentLength ( documentBody . length ) ; return new HttpEntity < byte [ ] > ( documentBody , header ) ; } catch ( SignatureException | MarshallingException e ) { logger . error ( "Failed to return valid metadata" , e ) ; return new ResponseEntity < byte [ ] > ( HttpStatus . INTERNAL_SERVER_ERROR ) ; } } | Returns the metadata for the entity . |
8,374 | public void execute ( StreamingCinchContext cinchContext , SparkConf sparkConf ) { JavaStreamingContext streamingContext = new JavaStreamingContext ( sparkConf , new Duration ( durationInMillis ) ) ; defineJob ( streamingContext , cinchContext ) ; streamingContext . start ( ) ; streamingContext . awaitTermination ( ) ; } | Execute cinch job with context and spark conf . |
8,375 | public Context merge ( final Map < String , Object > vars ) { return merge ( Vars . of ( vars ) ) ; } | Merge this template and discard outputs . |
8,376 | public Context debug ( final Vars vars , final Out out , final BreakpointListener listener ) { try { return Parser . parse ( this , listener ) . execute ( this , out , vars ) ; } catch ( Exception e ) { throw completeException ( e ) ; } } | Debug this template . |
8,377 | protected void setAuthenticatingAuthority ( Assertion assertion , Assertion proxiedAssertion ) { if ( proxiedAssertion . getIssuer ( ) == null || proxiedAssertion . getIssuer ( ) . getValue ( ) == null ) { log . warn ( "No issuer element found in proxied assertion" ) ; return ; } if ( assertion . getAuthnStatements ( ) . isEmpty ( ) ) { log . warn ( "No AuthnStatement available is assertion to update - will not process" ) ; return ; } AuthnStatement authnStatement = assertion . getAuthnStatements ( ) . get ( 0 ) ; if ( authnStatement . getAuthnContext ( ) == null ) { log . warn ( "No AuthnContext found in assertion to update - will not process" ) ; } final XMLObjectBuilderFactory bf = XMLObjectProviderRegistrySupport . getBuilderFactory ( ) ; SAMLObjectBuilder < AuthenticatingAuthority > aaBuilder = ( SAMLObjectBuilder < AuthenticatingAuthority > ) bf . < AuthenticatingAuthority > getBuilderOrThrow ( AuthenticatingAuthority . DEFAULT_ELEMENT_NAME ) ; AuthenticatingAuthority aa = aaBuilder . buildObject ( ) ; aa . setURI ( proxiedAssertion . getIssuer ( ) . getValue ( ) ) ; authnStatement . getAuthnContext ( ) . getAuthenticatingAuthorities ( ) . add ( aa ) ; log . info ( "Updated Assertion with AuthenticatingAuthority ({})" , aa . getURI ( ) ) ; } | Assigns the AuthenticatingAuthority element holding the issuer of the proxied assertion . |
8,378 | public void update ( Matrix4f projection , Matrix4f view ) { final float [ ] clip = projection . mul ( view ) . toArray ( true ) ; frustum [ 0 ] [ 0 ] = clip [ 3 ] - clip [ 0 ] ; frustum [ 0 ] [ 1 ] = clip [ 7 ] - clip [ 4 ] ; frustum [ 0 ] [ 2 ] = clip [ 11 ] - clip [ 8 ] ; frustum [ 0 ] [ 3 ] = clip [ 15 ] - clip [ 12 ] ; frustum [ 1 ] [ 0 ] = clip [ 3 ] + clip [ 0 ] ; frustum [ 1 ] [ 1 ] = clip [ 7 ] + clip [ 4 ] ; frustum [ 1 ] [ 2 ] = clip [ 11 ] + clip [ 8 ] ; frustum [ 1 ] [ 3 ] = clip [ 15 ] + clip [ 12 ] ; frustum [ 2 ] [ 0 ] = clip [ 3 ] + clip [ 1 ] ; frustum [ 2 ] [ 1 ] = clip [ 7 ] + clip [ 5 ] ; frustum [ 2 ] [ 2 ] = clip [ 11 ] + clip [ 9 ] ; frustum [ 2 ] [ 3 ] = clip [ 15 ] + clip [ 13 ] ; frustum [ 3 ] [ 0 ] = clip [ 3 ] - clip [ 1 ] ; frustum [ 3 ] [ 1 ] = clip [ 7 ] - clip [ 5 ] ; frustum [ 3 ] [ 2 ] = clip [ 11 ] - clip [ 9 ] ; frustum [ 3 ] [ 3 ] = clip [ 15 ] - clip [ 13 ] ; frustum [ 4 ] [ 0 ] = clip [ 3 ] - clip [ 2 ] ; frustum [ 4 ] [ 1 ] = clip [ 7 ] - clip [ 6 ] ; frustum [ 4 ] [ 2 ] = clip [ 11 ] - clip [ 10 ] ; frustum [ 4 ] [ 3 ] = clip [ 15 ] - clip [ 14 ] ; frustum [ 5 ] [ 0 ] = clip [ 3 ] + clip [ 2 ] ; frustum [ 5 ] [ 1 ] = clip [ 7 ] + clip [ 6 ] ; frustum [ 5 ] [ 2 ] = clip [ 11 ] + clip [ 10 ] ; frustum [ 5 ] [ 3 ] = clip [ 15 ] + clip [ 14 ] ; final Vector4f nPos = view . invert ( ) . getColumn ( 3 ) ; position = nPos . div ( nPos . getW ( ) ) . toVector3 ( ) ; vertices = null ; farPlane = - 1 ; nearPlane = - 1 ; } | Updates the frustum to match the view and projection matrix . |
8,379 | public float getNearPlane ( ) { if ( nearPlane == - 1 ) { final Vector3f nearPos = vertices [ 0 ] . add ( vertices [ 2 ] ) . add ( vertices [ 4 ] ) . add ( vertices [ 6 ] ) . div ( 4 ) ; nearPlane = nearPos . sub ( position ) . length ( ) ; } return nearPlane ; } | Returns the near plane distance of the frustum . |
8,380 | public float getFarPlane ( ) { if ( farPlane == - 1 ) { final Vector3f farPos = vertices [ 1 ] . add ( vertices [ 3 ] ) . add ( vertices [ 5 ] ) . add ( vertices [ 7 ] ) . div ( 4 ) ; farPlane = farPos . sub ( position ) . length ( ) ; } return farPlane ; } | Returns the far plane distance of the frustum . |
8,381 | private float distance ( int i , float x , float y , float z ) { return frustum [ i ] [ 0 ] * x + frustum [ i ] [ 1 ] * y + frustum [ i ] [ 2 ] * z + frustum [ i ] [ 3 ] ; } | Compute the distance between a point and the given plane . |
8,382 | protected Locale getLocale ( RequestContext context ) { return this . locale != null ? this . locale : context . getExternalContext ( ) . getLocale ( ) ; } | Returns the locale to use when resolving messages . |
8,383 | private static < A extends Annotation > A getParameterAnnotation ( Method method , int index , Class < A > annotationClass ) { for ( Annotation a : method . getParameterAnnotations ( ) [ index ] ) { if ( annotationClass . isInstance ( a ) ) { return annotationClass . cast ( a ) ; } } return null ; } | Find an annotation for a parameter on a method . |
8,384 | private static < A extends Annotation > A getAnnotation ( AnnotatedElement element , Class < A > annotationClass ) { return ( element != null ) ? element . getAnnotation ( annotationClass ) : null ; } | Null safe annotation checker |
8,385 | public byte [ ] serialize ( ) { try { ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ; ObjectOutputStream oos = new ObjectOutputStream ( out ) ; oos . writeObject ( map ) ; return out . toByteArray ( ) ; } catch ( IOException ex ) { throw new IllegalStateException ( "Unable to compress SerializableMap" ) ; } } | This serializes only the data as opposed to the whole object . |
8,386 | @ SuppressWarnings ( "unchecked" ) public void deserialize ( byte [ ] serializedData , boolean wipe ) throws IOException { if ( wipe ) { map . clear ( ) ; } InputStream in = new ByteArrayInputStream ( serializedData ) ; ObjectInputStream ois = new ClassResolverObjectInputStream ( in ) ; try { for ( Map . Entry < String , ? extends Serializable > e : ( ( Map < String , ? extends Serializable > ) ois . readObject ( ) ) . entrySet ( ) ) { if ( e . getValue ( ) instanceof Map && map . get ( e . getKey ( ) ) instanceof Map ) { ( ( Map ) map . get ( e . getKey ( ) ) ) . putAll ( ( Map ) e . getValue ( ) ) ; } else { put ( e . getKey ( ) , e . getValue ( ) ) ; } } } catch ( ClassNotFoundException ex ) { throw new IllegalStateException ( "Unable to decompress SerializableHashMap" , ex ) ; } } | This deserializes only the data as opposed to the whole object . |
8,387 | public boolean becomePublisher ( ) { if ( publisherThreadID . get ( ) != - 1 ) { return false ; } publisherThreadID . set ( Thread . currentThread ( ) . getId ( ) ) ; return true ; } | Attempts to make the thread the publisher returning true if the attempt succeeded . This is only possible if there s no publisher . |
8,388 | public void unsubscribe ( ) { final long id = Thread . currentThread ( ) . getId ( ) ; queues . remove ( id ) ; if ( subscriberIdentifiers != null ) { for ( Iterator < Entry < Object , Long > > iterator = subscriberIdentifiers . entrySet ( ) . iterator ( ) ; iterator . hasNext ( ) ; ) { if ( id == iterator . next ( ) . getValue ( ) ) { iterator . remove ( ) ; break ; } } } } | Unsubscribes the thread from the queue . |
8,389 | public boolean addAll ( Collection < ? extends T > c , Object identifier ) { checkNotNullArgument ( c ) ; if ( isPublisherThread ( ) ) { boolean changed = false ; if ( identifier != null ) { final Long id = subscriberIdentifiers . get ( identifier ) ; checkNotNullIdentifier ( id ) ; changed = queues . get ( id ) . addAll ( c ) ; } else { for ( Queue < T > queue : queues . values ( ) ) { if ( queue . addAll ( c ) ) { changed = true ; } } } return changed ; } return getCurrentThreadQueue ( ) . addAll ( c ) ; } | Adds a collection of objects to the queue targeting only the subscriber identified by the provided identifier object unless said object is null . The added objects will only be visible to the subscriber . |
8,390 | public final boolean isValid ( HttpServletRequest req , String token ) { String storedToken = getStoredToken ( req ) ; if ( storedToken == null ) return false ; return storedToken . equals ( token ) ; } | Tests given token against stored one . |
8,391 | protected void store ( HttpServletRequest req , HttpServletResponse resp , String token ) { HttpSession session = req . getSession ( ) ; session . setAttribute ( ATR_SESSION_TOKEN , token ) ; } | Associates a token with an user . Default implementation stores the token into user session . |
8,392 | protected String getStoredToken ( HttpServletRequest req ) { HttpSession session = req . getSession ( false ) ; if ( session == null ) return null ; return ( String ) session . getAttribute ( ATR_SESSION_TOKEN ) ; } | Returns the token previously associated with given request . Default implementation retrieves the token from user session . |
8,393 | public void spec ( String name , Runnable body ) { context . spec ( name , new GroovyClosure ( body ) ) ; } | Declares a child spec . |
8,394 | public QueryableIndex cache ( String dataSource , Iterable < InputRow > loader , IncrementalIndexSchema indexSchema ) throws IOException { IncrementalIndex < ? > incIndex = new OnheapIncrementalIndex ( indexSchema , true , Integer . MAX_VALUE ) ; for ( InputRow row : loader ) { incIndex . add ( row ) ; } String tmpDir = System . getProperty ( "druid.segment.dir" ) ; if ( tmpDir == null ) { tmpDir = System . getProperty ( "java.io.tmpdir" ) + File . separator + "druid-tmp-index-" ; } File tmpIndexDir = new File ( tmpDir + loader . hashCode ( ) ) ; IndexIO indexIO = new IndexIO ( new DefaultObjectMapper ( ) , new ColumnConfig ( ) { public int columnCacheSizeBytes ( ) { return 0 ; } } ) ; if ( OSCheck . isWindows ( ) ) { new SlowIndexMerger ( new DefaultObjectMapper ( ) , indexIO ) . persist ( incIndex , tmpIndexDir , new IndexSpec ( ) ) ; } else { new IndexMerger ( new DefaultObjectMapper ( ) , indexIO ) . persist ( incIndex , tmpIndexDir , new IndexSpec ( ) ) ; } this . indexMap . put ( dataSource , indexIO . loadIndex ( tmpIndexDir ) ) ; return this . indexMap . get ( dataSource ) ; } | Builds and caches a QueryableIndex from an Iterable by building persisting and reloading an IncrementalIndex |
8,395 | public static boolean startsWithIgnoreCase ( String input , String prefix ) { if ( input == null || prefix == null || prefix . length ( ) > input . length ( ) ) { return false ; } else { final char [ ] inputCharArray = input . toCharArray ( ) ; final char [ ] prefixCharArray = prefix . toCharArray ( ) ; for ( int i = 0 ; i < prefixCharArray . length ; i ++ ) { if ( ! equalsIgnoreCase ( prefixCharArray [ i ] , inputCharArray [ i ] ) ) { return false ; } } return true ; } } | Tests if this string starts with the specified prefix ignoring case |
8,396 | public static < T extends Named > Collection < T > matchName ( Collection < T > values , String name ) { List < T > result = new ArrayList < > ( ) ; for ( T value : values ) { if ( value == null ) { continue ; } if ( startsWithIgnoreCase ( value . getName ( ) , name ) ) { result . add ( value ) ; } } return result ; } | Matches a named class using a name |
8,397 | public static String toNamedString ( Object object , Object ... components ) { StringBuilder b = new StringBuilder ( components . length * 5 + 2 ) ; if ( object != null ) { b . append ( object . getClass ( ) . getSimpleName ( ) ) . append ( ' ' ) ; } b . append ( '{' ) ; for ( int i = 0 ; i < components . length ; i ++ ) { if ( i != 0 ) { b . append ( ", " ) ; } b . append ( components [ i ] ) ; } b . append ( '}' ) ; return b . toString ( ) ; } | Wraps all components in between brackets delimited by - signs appending the class name in front of it . |
8,398 | public String getAttributeID ( String name ) { Map < String , String > m = this . getMapping ( ) ; return m != null ? m . get ( name ) : null ; } | Returns the Shibboleth attribute ID that corresponds to the supplied SAML2 attribute name . |
8,399 | protected void initializeServices ( ProfileRequestContext < ? , ? > profileRequestContext ) throws ExternalAutenticationErrorCodeException { this . authnContextService . initializeContext ( profileRequestContext ) ; this . signSupportService . initializeContext ( profileRequestContext ) ; } | Initializes the services for the controller . Subclasses should override this method to initialize their own services . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.