Skip to content

Commit

Permalink
more map proxy methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafaiman committed Apr 24, 2016
1 parent 48353b8 commit ad0e755
Show file tree
Hide file tree
Showing 6 changed files with 276 additions and 51 deletions.
20 changes: 14 additions & 6 deletions src/IMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,29 @@ export interface IMap<K, V> extends DistributedObject {
putIfAbsent(key: K, value: V, ttl?: number): Q.Promise<V>;

/**
* Same as {@link #put} except it does not call underlyinh MapStore.
* Same as {@link #put} except it does not call underlying MapStore.
* @param key
* @param value
* @param ttl
*/
putTransient(key: K, value: V, ttl?: number): Q.Promise<V>;
putTransient(key: K, value: V, ttl?: number): Q.Promise<void>;

/**
* Replaces value of the key if only it was associated with some value before.
* Replaces value of the key if only it was associated to oldValue.
* @param key
* @param value
* @param oldValue if specified, this method replaces value of the key only if it was equal to oldValue before.
* @return old value associated to key.
* @param oldValue
* @return {true} if the value was replaced.
*/
replace(key: K, value: V, oldValue?: V): Q.Promise<V>;
replaceIfSame(key: K, oldValue: V, newValue: V): Q.Promise<boolean>;

/**
* Replaces value of given key with newValue.
* @param key
* @param newValue
* @return previous value
*/
replace(key: K, newValue: V): Q.Promise<V>;

/**
* Similar to {@link #put} except it does not return the old value.
Expand Down
7 changes: 3 additions & 4 deletions src/codec/MapKeySetCodec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* tslint:disable */
import ClientMessage = require('../ClientMessage');
import ImmutableLazyDataList = require('./ImmutableLazyDataList');
import {BitsUtil} from '../BitsUtil';
import Address = require('../Address');
import {AddressCodec} from './AddressCodec';
Expand Down Expand Up @@ -39,12 +38,12 @@ export class MapKeySetCodec {
var parameters:any = {'response': null};
var responseSize = clientMessage.readInt32();
var response:any = [];
for (var responseIndex = 0; responseIndex <= responseSize; responseIndex++) {
for (var responseIndex = 0; responseIndex < responseSize; responseIndex++) {
var responseItem:Data;
responseItem = toObjectFunction(clientMessage.readData());
responseItem = clientMessage.readData();
response.push(responseItem)
}
parameters['response'] = new ImmutableLazyDataList(response, toObjectFunction);
parameters['response'] = response;
return parameters;

}
Expand Down
8 changes: 4 additions & 4 deletions src/codec/MapValuesCodec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* tslint:disable */
import ClientMessage = require('../ClientMessage');
import ImmutableLazyDataList = require('./ImmutableLazyDataList');
import {BitsUtil} from '../BitsUtil';
import Address = require('../Address');
import {AddressCodec} from './AddressCodec';
import {MemberCodec} from './MemberCodec';
import {Data} from '../serialization/Data';
import {EntryViewCodec} from './EntryViewCodec';
import DistributedObjectInfoCodec = require('./DistributedObjectInfoCodec');
import {MapMessageType} from './MapMessageType';

var REQUEST_TYPE = MapMessageType.MAP_VALUES;
Expand Down Expand Up @@ -39,12 +39,12 @@ export class MapValuesCodec {
var parameters:any = {'response': null};
var responseSize = clientMessage.readInt32();
var response:any = [];
for (var responseIndex = 0; responseIndex <= responseSize; responseIndex++) {
for (var responseIndex = 0; responseIndex < responseSize; responseIndex++) {
var responseItem:Data;
responseItem = toObjectFunction(clientMessage.readData());
responseItem = clientMessage.readData();
response.push(responseItem)
}
parameters['response'] = new ImmutableLazyDataList(response, toObjectFunction);
parameters['response'] = response;
return parameters;

}
Expand Down
95 changes: 73 additions & 22 deletions src/proxy/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ import defer = Q.defer;
import {MapDeleteCodec} from '../codec/MapDeleteCodec';
import {MapEntrySetCodec} from '../codec/MapEntrySetCodec';
import {MapEvictCodec} from '../codec/MapEvictCodec';
import {MapEvictAllCodec} from '../codec/MapEvictAllCodec';
import {MapFlushCodec} from '../codec/MapFlushCodec';
import {MapLockCodec} from '../codec/MapLockCodec';
import {MapIsLockedCodec} from '../codec/MapIsLockedCodec';
import {MapUnlockCodec} from '../codec/MapUnlockCodec';
import {MapForceUnlockCodec} from '../codec/MapForceUnlockCodec';
import {MapKeySetCodec} from '../codec/MapKeySetCodec';
import {MapLoadAllCodec} from '../codec/MapLoadAllCodec';
import {MapPutIfAbsentCodec} from '../codec/MapPutIfAbsentCodec';
import {MapPutTransientCodec} from '../codec/MapPutTransientCodec';
import {MapReplaceCodec} from '../codec/MapReplaceCodec';
import {MapReplaceIfSameCodec} from '../codec/MapReplaceIfSameCodec';
import {MapSetCodec} from '../codec/MapSetCodec';
import {MapValuesCodec} from '../codec/MapValuesCodec';
export class Map<K, V> extends BaseProxy implements IMap<K, V> {
containsKey(key: K): Q.Promise<boolean> {
var keyData = this.toData(key);
Expand Down Expand Up @@ -114,58 +128,95 @@ export class Map<K, V> extends BaseProxy implements IMap<K, V> {

evict(key: K) : Q.Promise<boolean> {
var keyData = this.toData(key);
return this.encodeInvokeOnKey(MapEvictCodec, keyData, keyData, 0);
return this.encodeInvokeOnKey<boolean>(MapEvictCodec, keyData, keyData, 0);
}

evictAll(): Q.Promise<void> {
return null;
return this.encodeInvokeOnRandomTarget<void>(MapEvictAllCodec);
}

flush(): Q.Promise<void> {
return null;
return this.encodeInvokeOnRandomTarget<void>(MapFlushCodec);
}

forceUnlock(key: K): Q.Promise<void> {
return null;
lock(key: K, ttl: number = -1): Q.Promise<void> {
var keyData = this.toData(key);
return this.encodeInvokeOnKey<void>(MapLockCodec, keyData, keyData, 0, ttl);
}

isLocked(key: K): Q.Promise<boolean> {
return null;
var keyData = this.toData(key);
return this.encodeInvokeOnKey<boolean>(MapIsLockedCodec, keyData, keyData);
}

lock(key: K, ttl?: number): Q.Promise<void> {
return null;
unlock(key: K): Q.Promise<void> {
var keyData = this.toData(key);
return this.encodeInvokeOnKey<void>(MapUnlockCodec, keyData, keyData, 0);
}

forceUnlock(key: K): Q.Promise<void> {
var keyData = this.toData(key);
return this.encodeInvokeOnKey<void>(MapForceUnlockCodec, keyData, keyData);
}

keySet(): Q.Promise<K[]> {
return null;
var deserializedSet: K[] = [];
var toObject = this.toObject.bind(this);
return this.encodeInvokeOnRandomTarget<K[]>(MapKeySetCodec).then(function(entrySet) {
entrySet.forEach(function(entry) {
deserializedSet.push(toObject(entry));
});
return deserializedSet;
});
}

loadAll(keys?: K[], replaceExistingValues?: boolean): Q.Promise<void> {
return null;
loadAll(keys: K[] = null, replaceExistingValues: boolean = true): Q.Promise<void> {
if (keys == null) {
return this.encodeInvokeOnRandomTarget<void>(MapLoadAllCodec, replaceExistingValues);
} else {
//TODO MapLoadGivenKeysCodec
}
}

putIfAbsent(key: K, value: V, ttl?: number): Q.Promise<V> {
return null;
putIfAbsent(key: K, value: V, ttl: number = -1): Q.Promise<V> {
var keyData = this.toData(key);
var valueData = this.toData(value);
return this.encodeInvokeOnKey<V>(MapPutIfAbsentCodec, keyData, keyData, valueData, 0, ttl);
}

putTransient(key: K, value: V, ttl?: number): Q.Promise<V> {
return null;
putTransient(key: K, value: V, ttl: number = -1): Q.Promise<void> {
var keyData = this.toData(key);
var valueData = this.toData(value);
return this.encodeInvokeOnKey<void>(MapPutTransientCodec, keyData, keyData, valueData, 0, ttl);
}

replace(key: K, value: V, oldValue?: V): Q.Promise<V> {
return null;
replace(key: K, newValue: V): Q.Promise<V> {
var keyData = this.toData(key);
var newValueData = this.toData(newValue);
return this.encodeInvokeOnKey<V>(MapReplaceCodec, keyData, keyData, newValueData, 0);
}

set(key: K, value: V, ttl?: number): Q.Promise<void> {
return null;
replaceIfSame(key: K, oldValue: V, newValue: V): Q.Promise<boolean> {
var keyData = this.toData(key);
var newValueData = this.toData(newValue);
var oldValueData = this.toData(oldValue);
return this.encodeInvokeOnKey<boolean>(MapReplaceIfSameCodec, keyData, keyData, oldValueData, newValueData, 0);
}

unlock(key: K): Q.Promise<void> {
return null;
set(key: K, value: V, ttl: number = -1): Q.Promise<void> {
var keyData = this.toData(key);
var valueData = this.toData(value);
return this.encodeInvokeOnKey<void>(MapSetCodec, keyData, keyData, valueData, 0, ttl);
}

values(): Q.Promise<V[]> {
return null;
var values: V[] = [];
var toObject = this.toObject.bind(this);
return this.encodeInvokeOnRandomTarget<V[]>(MapValuesCodec).then(function(valuesData) {
valuesData.forEach(function(valueData) {
values.push(toObject(valueData));
});
return values;
});
}
}
Loading

0 comments on commit ad0e755

Please sign in to comment.