-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor StorageCommunicationEndpointProvider to return StorageCommun…
…icationEndpoint per StoreInfo (#6614) This patch moves the StoreInfo argument from the getStorageEndpointProvider() call to the getStorageEndpoint() call, which means that a single StorageEndpointProvider can be used for a set of StorageProxies. Eventually this single StorageEndpointProvider will become a separate StorageEndpointManager, rather than being a responsibility of Stores directly. This will allow the same manager to be used in both direct communication mode and in hosted (via PEC) mode. A short-term consequence is that both StoreInfo and an ActiveStore are passed into the StorageProxy constructor (the ActiveStore is currently still the StorageEndpointProvider and StoreInfo is needed to get the endpoint). This duplication will be resolved in a subsequent patch (the ActiveStore argument will become a StorageEndpoint instead, vended by a StorageEndpointManager which will have responsibility for creating ActiveStores on demand). ________________________________________________________________________________________________ next steps: - DirectStorageEndpointManager should implement StorageCommunicationEndpointProvider, and ActiveStore StorageCommunicationEndpoint instead. Closes #6614 PiperOrigin-RevId: 347933211
- Loading branch information
1 parent
d7f7b04
commit 638a50a
Showing
17 changed files
with
133 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
|
||
/** | ||
* @license | ||
* Copyright (c) 2020 Google Inc. All rights reserved. | ||
* This code may only be used under the BSD style license found at | ||
* http://polymer.github.io/LICENSE.txt | ||
* Code distributed by Google as part of this project is also | ||
* subject to an additional IP rights grant found at | ||
* http://polymer.github.io/PATENTS.txt | ||
*/ | ||
|
||
import {StorageCommunicationEndpoint, ProxyMessage, ProxyCallback, StorageCommunicationEndpointProvider} from './store-interface.js'; | ||
import {CRDTTypeRecord} from '../../crdt/lib-crdt.js'; | ||
import {ActiveStore} from './active-store.js'; | ||
import {ChannelConstructor} from '../channel-constructor.js'; | ||
import {PropagatedException} from '../arc-exceptions.js'; | ||
import {noAwait} from '../../utils/lib-utils.js'; | ||
|
||
export class DirectStorageEndpoint<T extends CRDTTypeRecord> implements StorageCommunicationEndpoint<T> { | ||
private id = 0; | ||
|
||
constructor(private readonly store: ActiveStore<T>) {} | ||
|
||
get storeInfo() { return this.store.storeInfo; } | ||
|
||
async onProxyMessage(message: ProxyMessage<T>): Promise<void> { | ||
message.id = this.id!; | ||
noAwait(this.store.onProxyMessage(message)); | ||
} | ||
|
||
setCallback(callback: ProxyCallback<T>) { | ||
this.id = this.store.on(callback); | ||
} | ||
reportExceptionInHost(exception: PropagatedException): void { | ||
this.store.reportExceptionInHost(exception); | ||
} | ||
|
||
getChannelConstructor(): ChannelConstructor { | ||
const store = this.store; | ||
// TODO(shans): implement so that we can use references outside of the PEC. | ||
return { | ||
generateID() { | ||
return null; | ||
}, | ||
idGenerator: null, | ||
getStorageProxyMuxer() { | ||
throw new Error('References not yet supported outside of the PEC'); | ||
}, | ||
reportExceptionInHost(exception: PropagatedException): void { | ||
store.reportExceptionInHost(exception); | ||
} | ||
}; | ||
} | ||
async idle(): Promise<void> { return this.store.idle(); } | ||
async close(): Promise<void> { | ||
if (this.id) { | ||
return this.store.off(this.id); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.