idx
int64
0
165k
question
stringlengths
73
5.81k
target
stringlengths
5
918
144,800
public static < A , B , Z > Function2 < A , B , Z > lift ( Func2 < A , B , Z > f ) { return bridge . lift ( f ) ; }
Lift a Java Func2 to a Scala Function2
144,801
public static < A , B , C , Z > Function3 < A , B , C , Z > lift ( Func3 < A , B , C , Z > f ) { return bridge . lift ( f ) ; }
Lift a Java Func3 to a Scala Function3
144,802
public static < A , B , C , D , Z > Function4 < A , B , C , D , Z > lift ( Func4 < A , B , C , D , Z > f ) { return bridge . lift ( f ) ; }
Lift a Java Func4 to a Scala Function4
144,803
public static < Z > Function0 < Z > lift ( Callable < Z > f ) { return bridge . lift ( f ) ; }
Lift a Java Callable to a Scala Function0
144,804
public static CssSel sel ( String selector , String value ) { return j . sel ( selector , value ) ; }
Create a Css Selector Transform
144,805
public static < T > Vendor < T > vendor ( Func0 < T > f ) { return j . vendor ( f ) ; }
Create a Vendor from a Func0
144,806
public static < T > Vendor < T > vendor ( Callable < T > f ) { return j . vendor ( f ) ; }
Create a Vendor from a Callable
144,807
public static < T > SessionVar < T > vendSessionVar ( T defValue ) { return ( new VarsJBridge ( ) ) . vendSessionVar ( defValue , new Exception ( ) ) ; }
Vend a SessionVar with the default value
144,808
public static < T > SessionVar < T > vendSessionVar ( Callable < T > defFunc ) { return ( new VarsJBridge ( ) ) . vendSessionVar ( defFunc , new Exception ( ) ) ; }
Vend a SessionVar with the function to create the default value
144,809
protected < T1 > void dispatchCommand ( final BiConsumer < P , T1 > action , final T1 routable1 ) { routingFor ( routable1 ) . routees ( ) . forEach ( routee -> routee . receiveCommand ( action , routable1 ) ) ; }
DISPATCHING - COMMANDS
144,810
public ResultT first ( ) { final CoreRemoteMongoCursor < ResultT > cursor = iterator ( ) ; if ( ! cursor . hasNext ( ) ) { return null ; } return cursor . next ( ) ; }
Helper to return the first item in the iterator or null .
144,811
public < U > CoreRemoteMongoIterable < U > map ( final Function < ResultT , U > mapper ) { return new CoreRemoteMappingIterable < > ( this , mapper ) ; }
Maps this iterable from the source document type to the target document type .
144,812
public < A extends Collection < ? super ResultT > > A into ( final A target ) { forEach ( new Block < ResultT > ( ) { public void apply ( final ResultT t ) { target . add ( t ) ; } } ) ; return target ; }
Iterates over all the documents adding each to the given target .
144,813
public AwsServiceClient withCodecRegistry ( final CodecRegistry codecRegistry ) { return new AwsServiceClientImpl ( proxy . withCodecRegistry ( codecRegistry ) , dispatcher ) ; }
Create a new AwsServiceClient instance with a different codec registry .
144,814
public void callFunction ( final String name , final List < ? > args , final Long requestTimeout ) { this . functionService . callFunction ( name , args , requestTimeout ) ; }
Calls the specified Stitch function .
144,815
public < T > T callFunction ( final String name , final List < ? > args , final Long requestTimeout , final Class < T > resultClass , final CodecRegistry codecRegistry ) { return this . functionService . withCodecRegistry ( codecRegistry ) . callFunction ( name , args , requestTimeout , resultClass ) ; }
Calls the specified Stitch function and decodes the response into an instance of the specified type . The response will be decoded using the codec registry given .
144,816
public void start ( ) { instanceLock . writeLock ( ) . lock ( ) ; try { for ( final Map . Entry < MongoNamespace , NamespaceChangeStreamListener > streamerEntry : nsStreamers . entrySet ( ) ) { streamerEntry . getValue ( ) . start ( ) ; } } finally { instanceLock . writeLock ( ) . unlock ( ) ; } }
Starts all streams .
144,817
public void stop ( ) { instanceLock . writeLock ( ) . lock ( ) ; try { for ( final NamespaceChangeStreamListener streamer : nsStreamers . values ( ) ) { streamer . stop ( ) ; } } finally { instanceLock . writeLock ( ) . unlock ( ) ; } }
Stops all streams .
144,818
public void addNamespace ( final MongoNamespace namespace ) { this . instanceLock . writeLock ( ) . lock ( ) ; try { if ( this . nsStreamers . containsKey ( namespace ) ) { return ; } final NamespaceChangeStreamListener streamer = new NamespaceChangeStreamListener ( namespace , instanceConfig . getNamespaceConfig ( nam...
Requests that the given namespace be started listening to for change events .
144,819
public void removeNamespace ( final MongoNamespace namespace ) { this . instanceLock . writeLock ( ) . lock ( ) ; try { if ( ! this . nsStreamers . containsKey ( namespace ) ) { return ; } final NamespaceChangeStreamListener streamer = this . nsStreamers . get ( namespace ) ; streamer . stop ( ) ; this . nsStreamers . ...
Requests that the given namespace stopped being listened to for change events .
144,820
public Map < BsonValue , ChangeEvent < BsonDocument > > getEventsForNamespace ( final MongoNamespace namespace ) { this . instanceLock . readLock ( ) . lock ( ) ; final NamespaceChangeStreamListener streamer ; try { streamer = nsStreamers . get ( namespace ) ; } finally { this . instanceLock . readLock ( ) . unlock ( )...
Returns the latest change events for a given namespace .
144,821
public ChangeEvent < BsonDocument > getUnprocessedEventForDocumentId ( final MongoNamespace namespace , final BsonValue documentId ) { this . instanceLock . readLock ( ) . lock ( ) ; final NamespaceChangeStreamListener streamer ; try { streamer = nsStreamers . get ( namespace ) ; } finally { this . instanceLock . readL...
If there is an unprocessed change event for a particular document ID fetch it from the appropriate namespace change stream listener and remove it . By reading the event here we are assuming it will be processed by the consumer .
144,822
void setPaused ( final boolean isPaused ) { docLock . writeLock ( ) . lock ( ) ; try { docsColl . updateOne ( getDocFilter ( namespace , documentId ) , new BsonDocument ( "$set" , new BsonDocument ( ConfigCodec . Fields . IS_PAUSED , new BsonBoolean ( isPaused ) ) ) ) ; this . isPaused = isPaused ; } catch ( IllegalSta...
A document that is paused no longer has remote updates applied to it . Any local updates to this document cause it to be thawed . An example of pausing a document is when a conflict is being resolved for that document and the handler throws an exception .
144,823
public void setSomePendingWritesAndSave ( final long atTime , final ChangeEvent < BsonDocument > changeEvent ) { docLock . writeLock ( ) . lock ( ) ; try { if ( isPaused ) { setPaused ( false ) ; setStale ( true ) ; } this . lastUncommittedChangeEvent = coalesceChangeEvents ( this . lastUncommittedChangeEvent , changeE...
Sets that there are some pending writes that occurred at a time for an associated locally emitted change event . This variant maintains the last version set .
144,824
private static ChangeEvent < BsonDocument > coalesceChangeEvents ( final ChangeEvent < BsonDocument > lastUncommittedChangeEvent , final ChangeEvent < BsonDocument > newestChangeEvent ) { if ( lastUncommittedChangeEvent == null ) { return newestChangeEvent ; } switch ( lastUncommittedChangeEvent . getOperationType ( ) ...
Possibly coalesces the newest change event to match the user s original intent . For example an unsynchronized insert and update is still an insert .
144,825
static DocumentVersionInfo getRemoteVersionInfo ( final BsonDocument remoteDocument ) { final BsonDocument version = getDocumentVersionDoc ( remoteDocument ) ; return new DocumentVersionInfo ( version , remoteDocument != null ? BsonUtils . getDocumentId ( remoteDocument ) : null ) ; }
Returns the current version info for a provided remote document .
144,826
static BsonDocument getFreshVersionDocument ( ) { final BsonDocument versionDoc = new BsonDocument ( ) ; versionDoc . append ( Fields . SYNC_PROTOCOL_VERSION_FIELD , new BsonInt32 ( 1 ) ) ; versionDoc . append ( Fields . INSTANCE_ID_FIELD , new BsonString ( UUID . randomUUID ( ) . toString ( ) ) ) ; versionDoc . append...
Returns a BSON version document representing a new version with a new instance ID and version counter of zero .
144,827
static BsonDocument getDocumentVersionDoc ( final BsonDocument document ) { if ( document == null || ! document . containsKey ( DOCUMENT_VERSION_FIELD ) ) { return null ; } return document . getDocument ( DOCUMENT_VERSION_FIELD , null ) ; }
Returns the version document of the given document if any ; returns null otherwise .
144,828
static BsonDocument getVersionedFilter ( final BsonValue documentId , final BsonValue version ) { final BsonDocument filter = new BsonDocument ( "_id" , documentId ) ; if ( version == null ) { filter . put ( DOCUMENT_VERSION_FIELD , new BsonDocument ( "$exists" , BsonBoolean . FALSE ) ) ; } else { filter . put ( DOCUME...
Returns a query filter for the given document _id and version . The version is allowed to be null . The query will match only if there is either no version on the document in the database in question if we have no reference of the version or if the version matches the database s version .
144,829
BsonDocument getNextVersion ( ) { if ( ! this . hasVersion ( ) || this . getVersionDoc ( ) == null ) { return getFreshVersionDocument ( ) ; } final BsonDocument nextVersion = BsonUtils . copyOfDocument ( this . getVersionDoc ( ) ) ; nextVersion . put ( Fields . VERSION_COUNTER_FIELD , new BsonInt64 ( this . getVersion ...
Given a DocumentVersionInfo returns a BSON document representing the next version . This means and incremented version count for a non - empty version or a fresh version document for an empty version .
144,830
public RemoteMongoCollection < Document > getCollection ( final String collectionName ) { return new RemoteMongoCollectionImpl < > ( proxy . getCollection ( collectionName ) , dispatcher ) ; }
Gets a collection .
144,831
static < T > StitchEvent < T > fromEvent ( final Event event , final Decoder < T > decoder ) { return new StitchEvent < > ( event . getEventName ( ) , event . getData ( ) , decoder ) ; }
Convert a SSE to a Stitch SSE
144,832
protected final Event processEvent ( ) throws IOException { while ( true ) { String line ; try { line = readLine ( ) ; } catch ( final EOFException ex ) { if ( doneOnce ) { throw ex ; } doneOnce = true ; line = "" ; } if ( line . isEmpty ( ) ) { if ( dataBuffer . length ( ) == 0 ) { eventName = "" ; continue ; } final ...
Process the next event in a given stream .
144,833
private static String handleRichError ( final Response response , final String body ) { if ( ! response . getHeaders ( ) . containsKey ( Headers . CONTENT_TYPE ) || ! response . getHeaders ( ) . get ( Headers . CONTENT_TYPE ) . equals ( ContentTypes . APPLICATION_JSON ) ) { return body ; } final Document doc ; try { do...
Private helper method which decodes the Stitch error from the body of an HTTP Response object . If the error is successfully decoded this function will throw the error for the end user to eventually consume . If the error cannot be decoded this is likely not an error from the Stitch server and this function will return...
144,834
public static void initialize ( final Context context ) { if ( ! initialized . compareAndSet ( false , true ) ) { return ; } applicationContext = context . getApplicationContext ( ) ; final String packageName = applicationContext . getPackageName ( ) ; localAppName = packageName ; final PackageManager manager = applica...
Initializes the Stitch SDK so that app clients can be created .
144,835
public static StitchAppClient getAppClient ( final String clientAppId ) { ensureInitialized ( ) ; synchronized ( Stitch . class ) { if ( ! appClients . containsKey ( clientAppId ) ) { throw new IllegalStateException ( String . format ( "client for app '%s' has not yet been initialized" , clientAppId ) ) ; } return appC...
Gets an app client by its client app id if it has been initialized ; throws if none can be found .
144,836
public void start ( ) { nsLock . writeLock ( ) . lock ( ) ; try { if ( runnerThread != null ) { return ; } runnerThread = new Thread ( new NamespaceChangeStreamRunner ( new WeakReference < > ( this ) , networkMonitor , logger ) ) ; runnerThread . start ( ) ; } finally { nsLock . writeLock ( ) . unlock ( ) ; } }
Opens the stream in a background thread .
144,837
public void stop ( ) { if ( runnerThread == null ) { return ; } runnerThread . interrupt ( ) ; nsLock . writeLock ( ) . lock ( ) ; try { if ( runnerThread == null ) { return ; } this . cancel ( ) ; this . close ( ) ; while ( runnerThread . isAlive ( ) ) { runnerThread . interrupt ( ) ; try { runnerThread . join ( 1000 ...
Stops the background stream thread .
144,838
boolean openStream ( ) throws InterruptedException , IOException { logger . info ( "stream START" ) ; final boolean isOpen ; final Set < BsonValue > idsToWatch = nsConfig . getSynchronizedDocumentIds ( ) ; if ( ! networkMonitor . isConnected ( ) ) { logger . info ( "stream END - Network disconnected" ) ; return false ;...
Open the event stream
144,839
@ SuppressWarnings ( "unchecked" ) public Map < BsonValue , ChangeEvent < BsonDocument > > getEvents ( ) { nsLock . readLock ( ) . lock ( ) ; final Map < BsonValue , ChangeEvent < BsonDocument > > events ; try { events = new HashMap < > ( this . events ) ; } finally { nsLock . readLock ( ) . unlock ( ) ; } nsLock . wri...
Returns the latest change events and clears them from the change stream listener .
144,840
public ChangeEvent < BsonDocument > getUnprocessedEventForDocumentId ( final BsonValue documentId ) { final ChangeEvent < BsonDocument > event ; nsLock . readLock ( ) . lock ( ) ; try { event = this . events . get ( documentId ) ; } finally { nsLock . readLock ( ) . unlock ( ) ; } nsLock . writeLock ( ) . lock ( ) ; tr...
If there is an unprocessed change event for a particular document ID fetch it from the change stream listener and remove it . By reading the event here we are assuming it will be processed by the consumer .
144,841
public static long hash ( final BsonDocument doc ) { if ( doc == null ) { return 0L ; } final byte [ ] docBytes = toBytes ( doc ) ; long hashValue = FNV_64BIT_OFFSET_BASIS ; for ( int offset = 0 ; offset < docBytes . length ; offset ++ ) { hashValue ^= ( 0xFF & docBytes [ offset ] ) ; hashValue *= FNV_64BIT_PRIME ; } r...
Implementation of FNV - 1a hash algorithm .
144,842
public static boolean deleteDatabase ( final StitchAppClientInfo appInfo , final String serviceName , final EmbeddedMongoClientFactory clientFactory , final String userId ) { final String dataDir = appInfo . getDataDirectory ( ) ; if ( dataDir == null ) { throw new IllegalArgumentException ( "StitchAppClient not config...
Delete a database for a given path and userId .
144,843
public Task < Long > count ( ) { return dispatcher . dispatchTask ( new Callable < Long > ( ) { public Long call ( ) { return proxy . count ( ) ; } } ) ; }
Counts the number of documents in the collection .
144,844
public Task < RemoteInsertOneResult > insertOne ( final DocumentT document ) { return dispatcher . dispatchTask ( new Callable < RemoteInsertOneResult > ( ) { public RemoteInsertOneResult call ( ) { return proxy . insertOne ( document ) ; } } ) ; }
Inserts the provided document . If the document is missing an identifier the client should generate one .
144,845
public Task < Void > registerWithEmail ( final String email , final String password ) { return dispatcher . dispatchTask ( new Callable < Void > ( ) { public Void call ( ) { registerWithEmailInternal ( email , password ) ; return null ; } } ) ; }
Registers a new user with the given email and password .
144,846
public Task < Void > confirmUser ( final String token , final String tokenId ) { return dispatcher . dispatchTask ( new Callable < Void > ( ) { public Void call ( ) { confirmUserInternal ( token , tokenId ) ; return null ; } } ) ; }
Confirms a user with the given token and token id .
144,847
public Task < Void > resendConfirmationEmail ( final String email ) { return dispatcher . dispatchTask ( new Callable < Void > ( ) { public Void call ( ) { resendConfirmationEmailInternal ( email ) ; return null ; } } ) ; }
Resend the confirmation for a user to the given email .
144,848
public Task < Void > sendResetPasswordEmail ( final String email ) { return dispatcher . dispatchTask ( new Callable < Void > ( ) { public Void call ( ) { sendResetPasswordEmailInternal ( email ) ; return null ; } } ) ; }
Sends a user a password reset email for the given email .
144,849
public boolean commit ( ) { final CoreRemoteMongoCollection < DocumentT > collection = getCollection ( ) ; final List < WriteModel < DocumentT > > writeModels = getBulkWriteModels ( ) ; boolean success = true ; for ( final WriteModel < DocumentT > write : writeModels ) { if ( write instanceof ReplaceOneModel ) { final ...
Commits the writes to the remote collection .
144,850
public Response doRequest ( final StitchRequest stitchReq ) { initAppMetadata ( clientAppId ) ; return super . doRequestUrl ( stitchReq , getHostname ( ) ) ; }
Performs a request against a Stitch app server determined by the deployment model of the underlying app . Throws a Stitch specific exception if the request fails .
144,851
public EventStream doStreamRequest ( final StitchRequest stitchReq ) { initAppMetadata ( clientAppId ) ; return super . doStreamRequestUrl ( stitchReq , getHostname ( ) ) ; }
Performs a streaming request against a Stitch app server determined by the deployment model of the underlying app . Throws a Stitch specific exception if the request fails .
144,852
public BsonDocument toUpdateDocument ( ) { final List < BsonElement > unsets = new ArrayList < > ( ) ; for ( final String removedField : this . removedFields ) { unsets . add ( new BsonElement ( removedField , new BsonBoolean ( true ) ) ) ; } final BsonDocument updateDocument = new BsonDocument ( ) ; if ( this . update...
Convert this update description to an update document .
144,853
public BsonDocument toBsonDocument ( ) { final BsonDocument updateDescDoc = new BsonDocument ( ) ; updateDescDoc . put ( Fields . UPDATED_FIELDS_FIELD , this . getUpdatedFields ( ) ) ; final BsonArray removedFields = new BsonArray ( ) ; for ( final String field : this . getRemovedFields ( ) ) { removedFields . add ( ne...
Converts this update description to its document representation as it would appear in a MongoDB Change Event .
144,854
public static UpdateDescription fromBsonDocument ( final BsonDocument document ) { keyPresent ( Fields . UPDATED_FIELDS_FIELD , document ) ; keyPresent ( Fields . REMOVED_FIELDS_FIELD , document ) ; final BsonArray removedFieldsArr = document . getArray ( Fields . REMOVED_FIELDS_FIELD ) ; final Set < String > removedFi...
Converts an update description BSON document from a MongoDB Change Event into an UpdateDescription object .
144,855
public UpdateDescription merge ( final UpdateDescription otherDescription ) { if ( otherDescription != null ) { for ( final Map . Entry < String , BsonValue > entry : this . updatedFields . entrySet ( ) ) { if ( otherDescription . removedFields . contains ( entry . getKey ( ) ) ) { this . updatedFields . remove ( entry...
Unilaterally merge an update description into this update description .
144,856
@ SuppressWarnings ( "unchecked" ) public Stream < ChangeEvent < DocumentT > > watch ( final BsonValue ... ids ) throws InterruptedException , IOException { return operations . watch ( new HashSet < > ( Arrays . asList ( ids ) ) , false , documentClass ) . execute ( service ) ; }
Watches specified IDs in a collection .
144,857
public Task < Void > updateSyncFrequency ( final SyncFrequency syncFrequency ) { return this . dispatcher . dispatchTask ( new Callable < Void > ( ) { public Void call ( ) throws Exception { SyncImpl . this . proxy . updateSyncFrequency ( syncFrequency ) ; return null ; } } ) ; }
Sets the SyncFrequency on this collection .
144,858
public void emitEvent ( final NamespaceSynchronizationConfig nsConfig , final ChangeEvent < BsonDocument > event ) { listenersLock . lock ( ) ; try { if ( nsConfig . getNamespaceListenerConfig ( ) == null ) { return ; } final NamespaceListenerConfig namespaceListener = nsConfig . getNamespaceListenerConfig ( ) ; eventD...
Emits a change event for the given document id .
144,859
static ChangeEvent < BsonDocument > changeEventForLocalInsert ( final MongoNamespace namespace , final BsonDocument document , final boolean writePending ) { final BsonValue docId = BsonUtils . getDocumentId ( document ) ; return new ChangeEvent < > ( new BsonDocument ( ) , OperationType . INSERT , document , namespace...
Generates a change event for a local insert of the given document in the given namespace .
144,860
static ChangeEvent < BsonDocument > changeEventForLocalUpdate ( final MongoNamespace namespace , final BsonValue documentId , final UpdateDescription update , final BsonDocument fullDocumentAfterUpdate , final boolean writePending ) { return new ChangeEvent < > ( new BsonDocument ( ) , OperationType . UPDATE , fullDocu...
Generates a change event for a local update of a document in the given namespace referring to the given document _id .
144,861
static ChangeEvent < BsonDocument > changeEventForLocalReplace ( final MongoNamespace namespace , final BsonValue documentId , final BsonDocument document , final boolean writePending ) { return new ChangeEvent < > ( new BsonDocument ( ) , OperationType . REPLACE , document , namespace , new BsonDocument ( "_id" , docu...
Generates a change event for a local replacement of a document in the given namespace referring to the given document _id .
144,862
static ChangeEvent < BsonDocument > changeEventForLocalDelete ( final MongoNamespace namespace , final BsonValue documentId , final boolean writePending ) { return new ChangeEvent < > ( new BsonDocument ( ) , OperationType . DELETE , null , namespace , new BsonDocument ( "_id" , documentId ) , null , writePending ) ; }
Generates a change event for a local deletion of a document in the given namespace referring to the given document _id .
144,863
public static < T > void notNull ( final String name , final T value ) { if ( value == null ) { throw new IllegalArgumentException ( name + " can not be null" ) ; } }
Throw IllegalArgumentException if the value is null .
144,864
public static void keyPresent ( final String key , final Map < String , ? > map ) { if ( ! map . containsKey ( key ) ) { throw new IllegalStateException ( String . format ( "expected %s to be present" , key ) ) ; } }
Throw IllegalStateException if key is not present in map .
144,865
public static BsonDocument copyOfDocument ( final BsonDocument document ) { final BsonDocument newDocument = new BsonDocument ( ) ; for ( final Map . Entry < String , BsonValue > kv : document . entrySet ( ) ) { newDocument . put ( kv . getKey ( ) , kv . getValue ( ) ) ; } return newDocument ; }
Returns a copy of the given document .
144,866
public static < T > ConflictHandler < T > localWins ( ) { return new ConflictHandler < T > ( ) { public T resolveConflict ( final BsonValue documentId , final ChangeEvent < T > localEvent , final ChangeEvent < T > remoteEvent ) { return localEvent . getFullDocument ( ) ; } } ; }
The local event will decide the next state of the document in question .
144,867
public static boolean isTodoItem ( final Document todoItemDoc ) { return todoItemDoc . containsKey ( ID_KEY ) && todoItemDoc . containsKey ( TASK_KEY ) && todoItemDoc . containsKey ( CHECKED_KEY ) ; }
Returns if a MongoDB document is a todo item .
144,868
void recover ( ) { final List < NamespaceSynchronizationConfig > nsConfigs = new ArrayList < > ( ) ; for ( final MongoNamespace ns : this . syncConfig . getSynchronizedNamespaces ( ) ) { nsConfigs . add ( this . syncConfig . getNamespaceConfig ( ns ) ) ; } for ( final NamespaceSynchronizationConfig nsConfig : nsConfigs...
Recovers the state of synchronization in case a system failure happened . The goal is to revert to a known good state .
144,869
private void recoverNamespace ( final NamespaceSynchronizationConfig nsConfig ) { final MongoCollection < BsonDocument > undoCollection = getUndoCollection ( nsConfig . getNamespace ( ) ) ; final MongoCollection < BsonDocument > localCollection = getLocalCollection ( nsConfig . getNamespace ( ) ) ; final List < BsonDoc...
Recovers the state of synchronization for a namespace in case a system failure happened . The goal is to revert the namespace to a known good state . This method itself is resilient to failures since it doesn t delete any documents from the undo collection until the collection is in the desired state with respect to th...
144,870
public void wipeInMemorySettings ( ) { this . waitUntilInitialized ( ) ; syncLock . lock ( ) ; try { this . instanceChangeStreamListener . stop ( ) ; if ( instancesColl . find ( ) . first ( ) == null ) { throw new IllegalStateException ( "expected to find instance configuration" ) ; } this . syncConfig = new InstanceSy...
Reloads the synchronization config . This wipes all in - memory synchronization settings .
144,871
public void start ( ) { syncLock . lock ( ) ; try { if ( ! this . isConfigured ) { return ; } instanceChangeStreamListener . stop ( ) ; if ( listenersEnabled ) { instanceChangeStreamListener . start ( ) ; } if ( syncThread == null ) { syncThread = new Thread ( new DataSynchronizerRunner ( new WeakReference < > ( this )...
Starts data synchronization in a background thread .
144,872
public void stop ( ) { syncLock . lock ( ) ; try { if ( syncThread == null ) { return ; } instanceChangeStreamListener . stop ( ) ; syncThread . interrupt ( ) ; try { syncThread . join ( ) ; } catch ( final InterruptedException e ) { return ; } syncThread = null ; isRunning = false ; } finally { syncLock . unlock ( ) ;...
Stops the background data synchronization thread .
144,873
public void close ( ) { this . waitUntilInitialized ( ) ; this . ongoingOperationsGroup . blockAndWait ( ) ; syncLock . lock ( ) ; try { if ( this . networkMonitor != null ) { this . networkMonitor . removeNetworkStateListener ( this ) ; } this . dispatcher . close ( ) ; stop ( ) ; this . localClient . close ( ) ; } fi...
Stops the background data synchronization thread and releases the local client .
144,874
public boolean doSyncPass ( ) { if ( ! this . isConfigured || ! syncLock . tryLock ( ) ) { return false ; } try { if ( logicalT == Long . MAX_VALUE ) { if ( logger . isInfoEnabled ( ) ) { logger . info ( "reached max logical time; resetting back to 0" ) ; } logicalT = 0 ; } logicalT ++ ; if ( logger . isInfoEnabled ( )...
Performs a single synchronization pass in both the local and remote directions ; the order of which does not matter . If switching the order produces different results after one pass then there is a bug .
144,875
private LocalSyncWriteModelContainer resolveConflict ( final NamespaceSynchronizationConfig nsConfig , final CoreDocumentSynchronizationConfig docConfig , final ChangeEvent < BsonDocument > remoteEvent ) { return resolveConflict ( nsConfig , docConfig , docConfig . getLastUncommittedChangeEvent ( ) , remoteEvent ) ; }
Resolves a conflict between a synchronized document s local and remote state . The resolution will result in either the document being desynchronized or being replaced with some resolved state based on the conflict resolver specified for the document . Uses the last uncommitted local event as the local state .
144,876
@ SuppressWarnings ( "unchecked" ) private static Object resolveConflictWithResolver ( final ConflictHandler conflictResolver , final BsonValue documentId , final ChangeEvent localEvent , final ChangeEvent remoteEvent ) { return conflictResolver . resolveConflict ( documentId , localEvent , remoteEvent ) ; }
Returns the resolution of resolving the conflict between a local and remote event using the given conflict resolver .
144,877
public void addWatcher ( final MongoNamespace namespace , final Callback < ChangeEvent < BsonDocument > , Object > watcher ) { instanceChangeStreamListener . addWatcher ( namespace , watcher ) ; }
Queues up a callback to be removed and invoked on the next change event .
144,878
public Set < CoreDocumentSynchronizationConfig > getSynchronizedDocuments ( final MongoNamespace namespace ) { this . waitUntilInitialized ( ) ; try { ongoingOperationsGroup . enter ( ) ; return this . syncConfig . getSynchronizedDocuments ( namespace ) ; } finally { ongoingOperationsGroup . exit ( ) ; } }
Returns the set of synchronized documents in a namespace .
144,879
public Set < BsonValue > getPausedDocumentIds ( final MongoNamespace namespace ) { this . waitUntilInitialized ( ) ; try { ongoingOperationsGroup . enter ( ) ; final Set < BsonValue > pausedDocumentIds = new HashSet < > ( ) ; for ( final CoreDocumentSynchronizationConfig config : this . syncConfig . getSynchronizedDocu...
Return the set of synchronized document _ids in a namespace that have been paused due to an irrecoverable error .
144,880
boolean resumeSyncForDocument ( final MongoNamespace namespace , final BsonValue documentId ) { if ( namespace == null || documentId == null ) { return false ; } final NamespaceSynchronizationConfig namespaceSynchronizationConfig ; final CoreDocumentSynchronizationConfig config ; if ( ( namespaceSynchronizationConfig =...
A document that is paused no longer has remote updates applied to it . Any local updates to this document cause it to be resumed . An example of pausing a document is when a conflict is being resolved for that document and the handler throws an exception .
144,881
void insertOne ( final MongoNamespace namespace , final BsonDocument document ) { this . waitUntilInitialized ( ) ; try { ongoingOperationsGroup . enter ( ) ; final BsonDocument docForStorage = sanitizeDocument ( document ) ; final NamespaceSynchronizationConfig nsConfig = this . syncConfig . getNamespaceConfig ( names...
Inserts a single document locally and being to synchronize it based on its _id . Inserting a document with the same _id twice will result in a duplicate key exception .
144,882
DeleteResult deleteMany ( final MongoNamespace namespace , final Bson filter ) { this . waitUntilInitialized ( ) ; try { ongoingOperationsGroup . enter ( ) ; final List < ChangeEvent < BsonDocument > > eventsToEmit = new ArrayList < > ( ) ; final DeleteResult result ; final NamespaceSynchronizationConfig nsConfig = thi...
Removes all documents from the collection that match the given query filter . If no documents match the collection is not modified .
144,883
MongoCollection < BsonDocument > getUndoCollection ( final MongoNamespace namespace ) { return localClient . getDatabase ( String . format ( "sync_undo_%s" , namespace . getDatabaseName ( ) ) ) . getCollection ( namespace . getCollectionName ( ) , BsonDocument . class ) . withCodecRegistry ( MongoClientSettings . getDe...
Returns the undo collection representing the given namespace for recording documents that may need to be reverted after a system failure .
144,884
private < T > MongoCollection < T > getLocalCollection ( final MongoNamespace namespace , final Class < T > resultClass , final CodecRegistry codecRegistry ) { return localClient . getDatabase ( String . format ( "sync_user_%s" , namespace . getDatabaseName ( ) ) ) . getCollection ( namespace . getCollectionName ( ) , ...
Returns the local collection representing the given namespace .
144,885
MongoCollection < BsonDocument > getLocalCollection ( final MongoNamespace namespace ) { return getLocalCollection ( namespace , BsonDocument . class , MongoClientSettings . getDefaultCodecRegistry ( ) ) ; }
Returns the local collection representing the given namespace for raw document operations .
144,886
private < T > CoreRemoteMongoCollection < T > getRemoteCollection ( final MongoNamespace namespace , final Class < T > resultClass ) { return remoteClient . getDatabase ( namespace . getDatabaseName ( ) ) . getCollection ( namespace . getCollectionName ( ) , resultClass ) ; }
Returns the remote collection representing the given namespace .
144,887
static BsonDocument sanitizeDocument ( final BsonDocument document ) { if ( document == null ) { return null ; } if ( document . containsKey ( DOCUMENT_VERSION_FIELD ) ) { final BsonDocument clonedDoc = document . clone ( ) ; clonedDoc . remove ( DOCUMENT_VERSION_FIELD ) ; return clonedDoc ; } return document ; }
Given a BSON document remove any forbidden fields and return the document . If no changes are made the original document reference is returned . If changes are made a cloned copy of the document with the changes will be returned .
144,888
private static BsonDocument withNewVersion ( final BsonDocument document , final BsonDocument newVersion ) { final BsonDocument newDocument = BsonUtils . copyOfDocument ( document ) ; newDocument . put ( DOCUMENT_VERSION_FIELD , newVersion ) ; return newDocument ; }
Adds and returns a document with a new version to the given document .
144,889
public static void clearallLocalDBs ( ) { for ( final Map . Entry < MongoClient , Boolean > entry : localInstances . entrySet ( ) ) { for ( final String dbName : entry . getKey ( ) . listDatabaseNames ( ) ) { entry . getKey ( ) . getDatabase ( dbName ) . drop ( ) ; } } }
Helper function that drops all local databases for every client .
144,890
public StitchObjectMapper withCodecRegistry ( final CodecRegistry codecRegistry ) { final CodecRegistry newReg = CodecRegistries . fromRegistries ( BsonUtils . DEFAULT_CODEC_REGISTRY , codecRegistry ) ; return new StitchObjectMapper ( this , newReg ) ; }
Applies the given codec registry to be used alongside the default codec registry .
144,891
public StitchEvent < T > nextEvent ( ) throws IOException { final Event nextEvent = eventStream . nextEvent ( ) ; if ( nextEvent == null ) { return null ; } return StitchEvent . fromEvent ( nextEvent , this . decoder ) ; }
Fetch the next event from a given stream
144,892
public StitchUserT getUser ( ) { authLock . readLock ( ) . lock ( ) ; try { return activeUser ; } finally { authLock . readLock ( ) . unlock ( ) ; } }
Returns the active logged in user .
144,893
private synchronized Response doAuthenticatedRequest ( final StitchAuthRequest stitchReq , final AuthInfo authInfo ) { try { return requestClient . doRequest ( prepareAuthRequest ( stitchReq , authInfo ) ) ; } catch ( final StitchServiceException ex ) { return handleAuthFailure ( ex , stitchReq ) ; } }
Internal method which performs the authenticated request by preparing the auth request with the provided auth info and request .
144,894
private void tryRefreshAccessToken ( final Long reqStartedAt ) { authLock . writeLock ( ) . lock ( ) ; try { if ( ! isLoggedIn ( ) ) { throw new StitchClientException ( StitchClientErrorCode . LOGGED_OUT_DURING_REQUEST ) ; } try { final Jwt jwt = Jwt . fromEncoded ( getAuthInfo ( ) . getAccessToken ( ) ) ; if ( jwt . g...
prevent too many refreshes happening one after the other .
144,895
private StitchUserT doLogin ( final StitchCredential credential , final boolean asLinkRequest ) { final Response response = doLoginRequest ( credential , asLinkRequest ) ; final StitchUserT previousUser = activeUser ; final StitchUserT user = processLoginResponse ( credential , response , asLinkRequest ) ; if ( asLinkR...
callers of doLogin should be serialized before calling in .
144,896
private static Interval parseStartExtended ( CharSequence startStr , CharSequence endStr ) { Instant start = Instant . parse ( startStr ) ; if ( endStr . length ( ) > 0 ) { char c = endStr . charAt ( 0 ) ; if ( c == 'P' || c == 'p' ) { PeriodDuration amount = PeriodDuration . parse ( endStr ) ; long move = start . isBe...
handle case where Instant is outside the bounds of OffsetDateTime
144,897
private static Interval parseEndDateTime ( Instant start , ZoneOffset offset , CharSequence endStr ) { try { TemporalAccessor temporal = DateTimeFormatter . ISO_DATE_TIME . parseBest ( endStr , OffsetDateTime :: from , LocalDateTime :: from ) ; if ( temporal instanceof OffsetDateTime ) { OffsetDateTime odt = ( OffsetDa...
parse when there are two date - times
144,898
public AccountingDate date ( int prolepticYear , int month , int dayOfMonth ) { return AccountingDate . of ( this , prolepticYear , month , dayOfMonth ) ; }
Obtains a local date in Accounting calendar system from the proleptic - year month - of - year and day - of - month fields .
144,899
public AccountingDate dateYearDay ( Era era , int yearOfEra , int dayOfYear ) { return dateYearDay ( prolepticYear ( era , yearOfEra ) , dayOfYear ) ; }
Obtains a local date in Accounting calendar system from the era year - of - era and day - of - year fields .