1- import { Hash , HashedObject , HashedSet , Literal , LiteralUtils , MutationOp } from 'data/model' ;
1+ import { Hash , HashedObject , HashedSet , Literal , LiteralUtils , MutableObject , MutationOp } from 'data/model' ;
22import { AgentPod } from 'mesh/service/AgentPod' ;
33import { Store } from 'storage/store' ;
44import { Logger , LogLevel } from 'util/logging' ;
@@ -27,7 +27,8 @@ class HeaderBasedSyncAgent extends PeeringAgentBase implements StateSyncAgent {
2727
2828 static MaxRequestsPerRemote = 2 ;
2929
30- mutableObj : Hash ;
30+ mutableObj : MutableObject ;
31+ mutableObjHash : Hash ;
3132 acceptedMutationOpClasses : string [ ] ;
3233 stateOpFilter ?: StateFilter ;
3334
@@ -50,10 +51,11 @@ class HeaderBasedSyncAgent extends PeeringAgentBase implements StateSyncAgent {
5051 controlLog : Logger ;
5152 messageLog : Logger ;
5253
53- constructor ( peerGroupAgent : PeerGroupAgent , mutableObj : Hash , resources : Resources , acceptedMutationOpClasses : string [ ] , stateOpFilter ?: StateFilter ) {
54+ constructor ( peerGroupAgent : PeerGroupAgent , mutableObj : MutableObject , resources : Resources , acceptedMutationOpClasses : string [ ] , stateOpFilter ?: StateFilter ) {
5455 super ( peerGroupAgent ) ;
5556
56- this . mutableObj = mutableObj ;
57+ this . mutableObj = mutableObj ;
58+ this . mutableObjHash = mutableObj . hash ( ) ;
5759 this . acceptedMutationOpClasses = acceptedMutationOpClasses ;
5860 this . stateOpFilter = stateOpFilter ;
5961
@@ -75,7 +77,7 @@ class HeaderBasedSyncAgent extends PeeringAgentBase implements StateSyncAgent {
7577
7678
7779 getAgentId ( ) : string {
78- return HeaderBasedSyncAgent . syncAgentIdFor ( this . mutableObj , this . peerGroupAgent . peerGroupId ) ;
80+ return HeaderBasedSyncAgent . syncAgentIdFor ( this . mutableObjHash , this . peerGroupAgent . peerGroupId ) ;
7981 }
8082
8183 ready ( pod : AgentPod ) : void {
@@ -111,7 +113,7 @@ class HeaderBasedSyncAgent extends PeeringAgentBase implements StateSyncAgent {
111113
112114 let isNew = false ;
113115
114- if ( state instanceof HeaderBasedState && state . mutableObj === this . mutableObj ) {
116+ if ( state instanceof HeaderBasedState && state . mutableObj === this . mutableObjHash ) {
115117
116118
117119
@@ -174,18 +176,18 @@ class HeaderBasedSyncAgent extends PeeringAgentBase implements StateSyncAgent {
174176 // Monitoring local state for changes:
175177
176178 watchStoreForOps ( ) {
177- this . store . watchReferences ( 'targetObject' , this . mutableObj , this . opCallback ) ;
179+ this . store . watchReferences ( 'targetObject' , this . mutableObjHash , this . opCallback ) ;
178180 }
179181
180182 unwatchStoreForOps ( ) {
181- this . store . removeReferencesWatch ( 'targetObject' , this . mutableObj , this . opCallback ) ;
183+ this . store . removeReferencesWatch ( 'targetObject' , this . mutableObjHash , this . opCallback ) ;
182184 }
183185
184186 async opCallback ( opHash : Hash ) : Promise < void > {
185187
186188 if ( this . terminated ) return ;
187189
188- this . controlLog . trace ( 'Op ' + opHash + ' found for object ' + this . mutableObj + ' in peer ' + this . peerGroupAgent . getLocalPeer ( ) . endpoint ) ;
190+ this . controlLog . trace ( 'Op ' + opHash + ' found for object ' + this . mutableObjHash + ' in peer ' + this . peerGroupAgent . getLocalPeer ( ) . endpoint ) ;
189191
190192 let op = await this . store . load ( opHash ) as MutationOp ;
191193 if ( this . shouldAcceptMutationOp ( op ) ) {
@@ -202,7 +204,7 @@ class HeaderBasedSyncAgent extends PeeringAgentBase implements StateSyncAgent {
202204 const fields = LiteralUtils . getFields ( literal ) ;
203205 const className = LiteralUtils . getClassName ( literal ) ;
204206
205- if ( fields [ 'targetObject' ] !== undefined && fields [ 'targetObject' ] . _hash === this . mutableObj &&
207+ if ( fields [ 'targetObject' ] !== undefined && fields [ 'targetObject' ] . _hash === this . mutableObjHash &&
206208 this . acceptedMutationOpClasses . indexOf ( className ) >= 0 ) {
207209
208210 valid = true ;
@@ -229,7 +231,7 @@ class HeaderBasedSyncAgent extends PeeringAgentBase implements StateSyncAgent {
229231 }*/
230232
231233 private async loadStateFromStore ( ) : Promise < HeaderBasedState > {
232- let terminalOpsInfo = await this . store . loadTerminalOpsForMutable ( this . mutableObj ) ;
234+ let terminalOpsInfo = await this . store . loadTerminalOpsForMutable ( this . mutableObjHash ) ;
233235
234236 if ( terminalOpsInfo === undefined ) {
235237 terminalOpsInfo = { terminalOps : [ ] } ;
@@ -244,7 +246,7 @@ class HeaderBasedSyncAgent extends PeeringAgentBase implements StateSyncAgent {
244246
245247 terminalOpHeaders . push ( terminalOpHeader as OpHeader )
246248 }
247- const state = HeaderBasedState . create ( this . mutableObj , terminalOpHeaders ) ;
249+ const state = HeaderBasedState . create ( this . mutableObjHash , terminalOpHeaders ) ;
248250
249251 if ( this . stateOpFilter === undefined ) {
250252 return state ;
@@ -257,7 +259,7 @@ class HeaderBasedSyncAgent extends PeeringAgentBase implements StateSyncAgent {
257259 const stateHash = state . hash ( ) ;
258260
259261 if ( this . stateHash === undefined || this . stateHash !== stateHash ) {
260- HeaderBasedSyncAgent . controlLog . trace ( 'Found new state ' + stateHash + ' for ' + this . mutableObj + ' in ' + this . peerGroupAgent . getLocalPeer ( ) . endpoint ) ;
262+ HeaderBasedSyncAgent . controlLog . trace ( 'Found new state ' + stateHash + ' for ' + this . mutableObjHash + ' in ' + this . peerGroupAgent . getLocalPeer ( ) . endpoint ) ;
261263 this . state = state ;
262264 this . stateHash = stateHash ;
263265 this . stateOpHeadersByOpHash = new Map ( ) ;
@@ -278,17 +280,17 @@ class HeaderBasedSyncAgent extends PeeringAgentBase implements StateSyncAgent {
278280
279281 private shouldAcceptMutationOp ( op : MutationOp ) : boolean {
280282
281- return this . mutableObj === op . targetObject ?. hash ( ) &&
283+ return this . mutableObjHash === op . targetObject ?. hash ( ) &&
282284 this . acceptedMutationOpClasses . indexOf ( op . getClassName ( ) ) >= 0 ;
283285 }
284286
285287 async lastStoredOpsDescription ( limit = 25 ) {
286288
287- const load = await this . store . loadByReference ( 'targetObject' , this . mutableObj , { order : 'desc' , limit : limit } ) ;
289+ const load = await this . store . loadByReference ( 'targetObject' , this . mutableObjHash , { order : 'desc' , limit : limit } ) ;
288290
289291 const last = load . objects . length === limit ? 'last ' : '' ;
290292
291- let contents = 'Showing ' + last + load . objects . length + ' ops in store for ' + this . mutableObj + '\n' ;
293+ let contents = 'Showing ' + last + load . objects . length + ' ops in store for ' + this . mutableObjHash + '\n' ;
292294
293295 let idx = 0 ;
294296 for ( const op of load . objects ) {
0 commit comments