2
0
mirror of https://github.com/esiur/esiur-js.git synced 2025-05-07 12:52:58 +00:00

Deadlock prevention

This commit is contained in:
Ahmed Zamil 2022-03-31 12:08:31 +03:00
parent fa76cf99a6
commit 0db7f6c1e4
7 changed files with 160 additions and 154 deletions

View File

@ -46,7 +46,7 @@
users.append(el); users.append(el);
if (!silent) if (!silent)
appendMessage({usr, msg: "joined the room", date: new Date()}); appendMessage(new Map([['usr', usr], ['msg', "joined the room"], ['date', new Date()]]));
} }
function removeUser(usr){ function removeUser(usr){
@ -57,7 +57,7 @@
break; break;
} }
appendMessage({usr, msg: "left the room", date: new Date()}); appendMessage(new Map([['usr', usr], ['msg', "left the room"], ['date', new Date()]]));
} }
function updateTitle() function updateTitle()

View File

@ -147,7 +147,7 @@ export default class Codec {
/// <returns>Value</returns> /// <returns>Value</returns>
static parse( static parse(
data, offset, connection, data, offset, connection,
dataType = null) { requestSequence, dataType = null) {
let len = 0; let len = 0;
@ -164,18 +164,18 @@ export default class Codec {
return new CodecParseResults( return new CodecParseResults(
len, len,
Codec.fixedParsers[dataType.exponent][dataType.index]( Codec.fixedParsers[dataType.exponent][dataType.index](
data, dataType.offset, dataType.contentLength, connection)); data, dataType.offset, dataType.contentLength, connection, requestSequence));
} else if (dataType.classType == TransmissionTypeClass.Dynamic) { } else if (dataType.classType == TransmissionTypeClass.Dynamic) {
return new CodecParseResults( return new CodecParseResults(
len, len,
Codec.dynamicParsers[dataType.index]( Codec.dynamicParsers[dataType.index](
data, dataType.offset, dataType.contentLength, connection)); data, dataType.offset, dataType.contentLength, connection, requestSequence));
} else //if (tt.Class == TransmissionTypeClass.Typed) } else //if (tt.Class == TransmissionTypeClass.Typed)
{ {
return new CodecParseResults( return new CodecParseResults(
len, len,
Codec.typedParsers[dataType.index]( Codec.typedParsers[dataType.index](
data, dataType.offset, dataType.contentLength, connection)); data, dataType.offset, dataType.contentLength, connection, requestSequence));
} }
} }

View File

@ -14,6 +14,9 @@ import PropertyValueArray from './PropertyValueArray.js';
import PropertyValue from './PropertyValue.js'; import PropertyValue from './PropertyValue.js';
import Record from './Record.js'; import Record from './Record.js';
import { UInt64, Int64 } from '../Data/ExtendedTypes.js'; import { UInt64, Int64 } from '../Data/ExtendedTypes.js';
import AsyncException from '../Core/AsyncException.js';
import ExceptionCode from '../Core/ExceptionCode.js';
import ErrorType from '../Core/ErrorType.js';
export class PropertyValueParserResults { export class PropertyValueParserResults {
//final int size; //final int size;
@ -26,135 +29,135 @@ export class PropertyValueParserResults {
} }
export default class DataDeserializer { export default class DataDeserializer {
static nullParser(data, offset, length, connection) { static nullParser(data, offset, length, connection, requestSequence) {
return new AsyncReply(null); return new AsyncReply(null);
} }
static booleanTrueParser( static booleanTrueParser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
return new AsyncReply(true); return new AsyncReply(true);
} }
static booleanFalseParser( static booleanFalseParser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
return new AsyncReply(false); return new AsyncReply(false);
} }
static notModifiedParser( static notModifiedParser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
return new AsyncReply(NotModified()); return new AsyncReply(NotModified());
} }
static byteParser( static byteParser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
return new AsyncReply(data[offset]); return new AsyncReply(data[offset]);
} }
static sByteParser( static sByteParser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
return new AsyncReply( return new AsyncReply(
data[offset] > 127 ? data[offset] - 256 : data[offset]); data[offset] > 127 ? data[offset] - 256 : data[offset]);
} }
static char16Parser( static char16Parser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
return new AsyncReply(data.getChar(offset)); return new AsyncReply(data.getChar(offset));
} }
static char8Parser( static char8Parser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
return new AsyncReply(String.fromCharCode(data[offset])); return new AsyncReply(String.fromCharCode(data[offset]));
} }
static int16Parser( static int16Parser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
return new AsyncReply(data.getInt16(offset)); return new AsyncReply(data.getInt16(offset));
} }
static uInt16Parser( static uInt16Parser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
return new AsyncReply(data.getUint16(offset)); return new AsyncReply(data.getUint16(offset));
} }
static int32Parser( static int32Parser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
return new AsyncReply(data.getInt32(offset)); return new AsyncReply(data.getInt32(offset));
} }
static uInt32Parser( static uInt32Parser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
return new AsyncReply(data.getUint32(offset)); return new AsyncReply(data.getUint32(offset));
} }
static float32Parser( static float32Parser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
return new AsyncReply(data.getFloat32(offset)); return new AsyncReply(data.getFloat32(offset));
} }
static float64Parser( static float64Parser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
return new AsyncReply(data.getFloat64(offset)); return new AsyncReply(data.getFloat64(offset));
} }
static float128Parser( static float128Parser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
// @TODO // @TODO
return new AsyncReply(data.getFloat64(offset)); return new AsyncReply(data.getFloat64(offset));
} }
static int128Parser( static int128Parser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
// @TODO // @TODO
return new AsyncReply(data.getInt64(offset)); return new AsyncReply(data.getInt64(offset));
} }
static uInt128Parser( static uInt128Parser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
return new AsyncReply(data.getUint64(offset)); return new AsyncReply(data.getUint64(offset));
} }
static int64Parser( static int64Parser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
return new AsyncReply(new Int64(data.getInt64(offset))); return new AsyncReply(new Int64(data.getInt64(offset)));
} }
static uInt64Parser( static uInt64Parser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
return new AsyncReply(new UInt64(data.getUint64(offset))); return new AsyncReply(new UInt64(data.getUint64(offset)));
} }
static dateTimeParser( static dateTimeParser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
return new AsyncReply(data.getDateTime(offset)); return new AsyncReply(data.getDateTime(offset));
} }
static resourceParser( static resourceParser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
if (connection != null) { if (connection != null) {
var id = data.getUint32(offset); var id = data.getUint32(offset, requestSequence);
return connection.fetch(id); return connection.fetch(id);
} }
throw Error("Can't parse resource with no connection"); throw Error("Can't parse resource with no connection");
} }
static localResourceParser( static localResourceParser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
var id = data.getUint32(offset); var id = data.getUint32(offset);
return Warehouse.getById(id); return Warehouse.getById(id);
} }
static rawDataParser( static rawDataParser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
return new AsyncReply(data.clip(offset, length)); return new AsyncReply(data.clip(offset, length));
} }
static stringParser( static stringParser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
return new AsyncReply(data.getString(offset, length)); return new AsyncReply(data.getString(offset, length));
} }
static recordParser( static recordParser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
var reply = new AsyncReply(); var reply = new AsyncReply();
var classId = data.getGuid(offset); var classId = data.getGuid(offset);
@ -163,8 +166,8 @@ export default class DataDeserializer {
var template = Warehouse.getTemplateByClassId(classId, TemplateType.Record); var template = Warehouse.getTemplateByClassId(classId, TemplateType.Record);
if (template != null) { var initRecord = (template) => {
DataDeserializer.listParser(data, offset, length, connection).then((ar) => { DataDeserializer.listParser(data, offset, length, connection, requestSequence).then((ar) => {
let record; let record;
if (template.definedType != null) { if (template.definedType != null) {
@ -178,27 +181,25 @@ export default class DataDeserializer {
reply.trigger(record); reply.trigger(record);
}); });
};
if (template != null) {
initRecord(template);
} else { } else {
if (connection == null) if (connection == null)
throw Error("Can't parse record with no connection"); throw Error("Can't parse record with no connection");
connection.getTemplate(classId).then((tmp) => { connection.getTemplate(classId).then((tmp) => {
if (tmp == null) if (tmp == null)
reply.triggerError(new Error("Couldn't fetch record template.")); {
reply.triggerError(new AsyncException(
DataDeserializer.listParser(data, offset, length, connection).then((ar) => { ErrorType.Management,
ExceptionCode.TemplateNotFound.index,
var record = new Record(); "Template not found for record."));
} else {
//var kv = new Map(); initRecord(tmp);
}
for (var i = 0; i < tmp.properties.length; i++)
record[tmp.properties[i].name] = ar[i];
//record.deserialize(kv);
reply.trigger(record);
});
}).error((x) => reply.triggerError(x)); }).error((x) => reply.triggerError(x));
} }
@ -206,11 +207,11 @@ export default class DataDeserializer {
} }
static constantParser( static constantParser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
throw Error("NotImplementedException"); throw Error("NotImplementedException");
} }
static enumParser(data, offset, length, connection) { static enumParser(data, offset, length, connection, requestSequence) {
var classId = data.getGuid(offset); var classId = data.getGuid(offset);
offset += 16; offset += 16;
var index = data[offset++]; var index = data[offset++];
@ -254,11 +255,11 @@ export default class DataDeserializer {
} }
static recordListParser( static recordListParser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
var rt = new AsyncBag(); var rt = new AsyncBag();
while (length > 0) { while (length > 0) {
var parsed = Codec.parse(data, offset, connection); var parsed = Codec.parse(data, offset, connection, requestSequence);
rt.add(parsed.reply); rt.add(parsed.reply);
@ -274,11 +275,11 @@ export default class DataDeserializer {
} }
static resourceListParser( static resourceListParser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
var rt = new AsyncBag(); var rt = new AsyncBag();
while (length > 0) { while (length > 0) {
var parsed = Codec.parse(data, offset, connection); var parsed = Codec.parse(data, offset, connection, requestSequence);
rt.add(parsed.reply); rt.add(parsed.reply);
@ -294,11 +295,11 @@ export default class DataDeserializer {
} }
static listParser( static listParser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
var rt = new AsyncBag(); var rt = new AsyncBag();
while (length > 0) { while (length > 0) {
var parsed = Codec.parse(data, offset, connection); var parsed = Codec.parse(data, offset, connection, requestSequence);
rt.add(parsed.reply); rt.add(parsed.reply);
@ -314,7 +315,7 @@ export default class DataDeserializer {
} }
static typedMapParser( static typedMapParser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
// get key type // get key type
var keyRep = RepresentationType.parse(data, offset); var keyRep = RepresentationType.parse(data, offset);
offset += keyRep.size; offset += keyRep.size;
@ -332,7 +333,7 @@ export default class DataDeserializer {
var results = new AsyncBag(); var results = new AsyncBag();
while (length > 0) { while (length > 0) {
var parsed = Codec.parse(data, offset, connection); var parsed = Codec.parse(data, offset, connection, requestSequence);
results.add(parsed.reply); results.add(parsed.reply);
@ -356,7 +357,7 @@ export default class DataDeserializer {
} }
static tupleParser( static tupleParser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
var results = new AsyncBag(); var results = new AsyncBag();
@ -368,7 +369,7 @@ export default class DataDeserializer {
var types = []; var types = [];
for (var i = 0; i < tupleSize; i++) { for (var i = 0; i < tupleSize; i++) {
var rep = RepresentationType.parse(data, offset); var rep = RepresentationType.parse(data, offset, requestSequence);
if (rep.type != null) if (rep.type != null)
types.push(rep.type.getRuntimeType() ?? Object); types.push(rep.type.getRuntimeType() ?? Object);
offset += rep.size; offset += rep.size;
@ -376,7 +377,7 @@ export default class DataDeserializer {
} }
while (length > 0) { while (length > 0) {
var parsed = Codec.parse(data, offset, connection); var parsed = Codec.parse(data, offset, connection, requestSequence);
results.add(parsed.reply); results.add(parsed.reply);
@ -397,7 +398,7 @@ export default class DataDeserializer {
} }
static typedListParser( static typedListParser(
data, offset, length, connection) { data, offset, length, connection, requestSequence) {
var rt = new AsyncBag(); var rt = new AsyncBag();
// get the type // get the type
@ -411,7 +412,7 @@ export default class DataDeserializer {
rt.arrayType = runtimeType; rt.arrayType = runtimeType;
while (length > 0) { while (length > 0) {
var parsed = Codec.parse(data, offset, connection); var parsed = Codec.parse(data, offset, connection, requestSequence);
rt.add(parsed.reply); rt.add(parsed.reply);
@ -430,11 +431,11 @@ export default class DataDeserializer {
data, data,
offset, offset,
length, length,
connection) //, bool ageIncluded = true) connection, requestSequence) //, bool ageIncluded = true)
{ {
var rt = new AsyncBag(); var rt = new AsyncBag();
DataDeserializer.listParser(data, offset, length, connection).then((x) => { DataDeserializer.listParser(data, offset, length, connection, requestSequence).then((x) => {
var pvs = new PropertyValueArray(); var pvs = new PropertyValueArray();
for (var i = 0; i < x.length; i += 3) for (var i = 0; i < x.length; i += 3)
@ -447,7 +448,7 @@ export default class DataDeserializer {
} }
static propertyValueParser(data, offset, static propertyValueParser(data, offset,
connection) //, bool ageIncluded = true) connection, requestSequence) //, bool ageIncluded = true)
{ {
let reply = new AsyncReply(); let reply = new AsyncReply();
@ -457,7 +458,7 @@ export default class DataDeserializer {
let date = data.getDateTime(offset); let date = data.getDateTime(offset);
offset += 8; offset += 8;
let parsed = Codec.parse(data, offset, connection); let parsed = Codec.parse(data, offset, connection, requestSequence);
parsed.reply.then((value) => { parsed.reply.then((value) => {
reply.trigger(new PropertyValue(value, age, date)); reply.trigger(new PropertyValue(value, age, date));
@ -468,7 +469,7 @@ export default class DataDeserializer {
static static
historyParser(data, offset, length, resource, historyParser(data, offset, length, resource,
connection) { connection, requestSequence) {
throw new Error("Not implemented"); throw new Error("Not implemented");
// @TODO // @TODO
// var list = new KeyList<PropertyTemplate, List<PropertyValue>>(); // var list = new KeyList<PropertyTemplate, List<PropertyValue>>();

View File

@ -949,7 +949,7 @@ export default class DistributedConnection extends IStore {
for (var i = 0; i < this.resources.keys.length; i++) { for (var i = 0; i < this.resources.keys.length; i++) {
var index = this.resources.keys[i]; var index = this.resources.keys[i];
bag.add(this.fetch(index)); bag.add(this.fetch(index, null));
} }
bag.seal(); bag.seal();
@ -1367,7 +1367,7 @@ export default class DistributedConnection extends IStore {
this.requests.remove(callbackId); this.requests.remove(callbackId);
Codec.parse(data, 0, this, dataType).reply.then(function (rt) { Codec.parse(data, 0, this, null, dataType).reply.then(function (rt) {
req.trigger(rt); req.trigger(rt);
}); });
} }
@ -1391,7 +1391,7 @@ export default class DistributedConnection extends IStore {
IIPReportChunk(callbackId, dataType, data) { IIPReportChunk(callbackId, dataType, data) {
var req = this.requests.item(callbackId); var req = this.requests.item(callbackId);
if (req != null) { if (req != null) {
Codec.parse(data, 0, this, dataType).reply.then(function (x) { Codec.parse(data, 0, this, null, dataType).reply.then(function (x) {
req.triggerChunk(x); req.triggerChunk(x);
}); });
} }
@ -1413,7 +1413,7 @@ export default class DistributedConnection extends IStore {
let self = this; let self = this;
this.fetch(resourceId).then(function (r) { this.fetch(resourceId, null).then(function (r) {
let pt = r.instance.template.getPropertyTemplateByIndex(index); let pt = r.instance.template.getPropertyTemplateByIndex(index);
@ -1424,7 +1424,7 @@ export default class DistributedConnection extends IStore {
let item = new AsyncReply(); let item = new AsyncReply();
self.queue.add(item); self.queue.add(item);
Codec.parse(data, 0, self, dataType).reply.then(function (args) { Codec.parse(data, 0, self, null, dataType).reply.then(function (args) {
item.trigger(new DistributedResourceQueueItem(r, DistributedResourceQueueItemType.Propery, args, index)); item.trigger(new DistributedResourceQueueItem(r, DistributedResourceQueueItemType.Propery, args, index));
}).error(function (ex) { }).error(function (ex) {
self.queue.remove(item); self.queue.remove(item);
@ -1437,7 +1437,7 @@ export default class DistributedConnection extends IStore {
IIPEventEventOccurred(resourceId, index, dataType, data) { IIPEventEventOccurred(resourceId, index, dataType, data) {
var self = this; var self = this;
this.fetch(resourceId).then(function (r) { this.fetch(resourceId, null).then(function (r) {
let et = r.instance.template.getEventTemplateByIndex(index); let et = r.instance.template.getEventTemplateByIndex(index);
if (et == null) if (et == null)
@ -1448,7 +1448,7 @@ export default class DistributedConnection extends IStore {
self.queue.add(item); self.queue.add(item);
// Codec.parseVarArray(content, 0, content.length, self).then(function (args) { // Codec.parseVarArray(content, 0, content.length, self).then(function (args) {
Codec.parse(data, 0, self, dataType).reply.then(function (args) { Codec.parse(data, 0, self, null, dataType).reply.then(function (args) {
item.trigger(new DistributedResourceQueueItem(r, DistributedResourceQueueItemType.Event, args, index)); item.trigger(new DistributedResourceQueueItem(r, DistributedResourceQueueItemType.Event, args, index));
}).error(function (ex) { }).error(function (ex) {
@ -1461,8 +1461,8 @@ export default class DistributedConnection extends IStore {
IIPEventChildAdded(resourceId, childId) { IIPEventChildAdded(resourceId, childId) {
var self = this; var self = this;
this.fetch(resourceId).then(function (parent) { this.fetch(resourceId, null).then(function (parent) {
self.fetch(childId).then(function (child) { self.fetch(childId, null).then(function (child) {
parent.instance.children.add(child); parent.instance.children.add(child);
}); });
}); });
@ -1471,15 +1471,15 @@ export default class DistributedConnection extends IStore {
IIPEventChildRemoved(resourceId, childId) { IIPEventChildRemoved(resourceId, childId) {
var self = this; var self = this;
this.fetch(resourceId).then(function (parent) { this.fetch(resourceId, null).then(function (parent) {
self.fetch(childId).then(function (child) { self.fetch(childId, null).then(function (child) {
parent.instance.children.remove(child); parent.instance.children.remove(child);
}); });
}); });
} }
IIPEventRenamed(resourceId, name) { IIPEventRenamed(resourceId, name) {
this.fetch(resourceId).then(function (resource) { this.fetch(resourceId, null).then(function (resource) {
resource.instance.attributes.set("name", name); resource.instance.attributes.set("name", name);
}); });
} }
@ -1488,7 +1488,7 @@ export default class DistributedConnection extends IStore {
IIPEventAttributesUpdated(resourceId, attributes) { IIPEventAttributesUpdated(resourceId, attributes) {
var self = this; var self = this;
this.fetch(resourceId).then(function (resource) { this.fetch(resourceId, null).then(function (resource) {
var attrs = attributes.getStringArray(0, attributes.length); var attrs = attributes.getStringArray(0, attributes.length);
self.getAttributes(resource, attrs).then(function (s) { self.getAttributes(resource, attrs).then(function (s) {
@ -1691,14 +1691,14 @@ export default class DistributedConnection extends IStore {
return; return;
} }
DataDeserializer.listParser(content, offset, cl, self).then(function (parameters) { DataDeserializer.listParser(content, offset, cl, self, null).then(function (parameters) {
offset += cl; offset += cl;
cl = content.getUint32(offset); cl = content.getUint32(offset);
DataDeserializer.typedMapParser(content, offset, cl, self).then(function (attributes) { DataDeserializer.typedMapParser(content, offset, cl, self, null).then(function (attributes) {
offset += cl; offset += cl;
cl = content.length - offset; cl = content.length - offset;
DataDeserializer.typedMapParser(content, offset, cl, self).then(function (values) { DataDeserializer.typedMapParser(content, offset, cl, self, null).then(function (values) {
var resource = new (Function.prototype.bind.apply(type, values)); var resource = new (Function.prototype.bind.apply(type, values));
@ -1849,7 +1849,7 @@ export default class DistributedConnection extends IStore {
return; return;
} }
Codec.parse(data, 0, self, dataType).reply.then(function (args) { Codec.parse(data, 0, self, null, dataType).reply.then(function (args) {
if (r instanceof DistributedResource) { if (r instanceof DistributedResource) {
var rt = r._invoke(index, args); var rt = r._invoke(index, args);
if (rt != null) { if (rt != null) {
@ -2121,7 +2121,7 @@ export default class DistributedConnection extends IStore {
var pt = r.instance.template.getPropertyTemplateByIndex(index); var pt = r.instance.template.getPropertyTemplateByIndex(index);
if (pt != null) { if (pt != null) {
Codec.parse(data, 0, self, dataType).reply.then(function (value) { Codec.parse(data, 0, self, null, dataType).reply.then(function (value) {
if (r instanceof DistributedResource) { if (r instanceof DistributedResource) {
// propagation // propagation
r._set(index, value).then(function (x) { r._set(index, value).then(function (x) {
@ -2225,7 +2225,7 @@ export default class DistributedConnection extends IStore {
this.sendRequest(IIPPacketAction.CreateResource).addUint8Array(pkt.ToArray()).done().then(function (args) { this.sendRequest(IIPPacketAction.CreateResource).addUint8Array(pkt.ToArray()).done().then(function (args) {
var rid = args[0]; var rid = args[0];
self.fetch(rid).then(function (r) { self.fetch(rid, null).then(function (r) {
reply.trigger(r); reply.trigger(r);
}); });
}); });
@ -2248,7 +2248,7 @@ export default class DistributedConnection extends IStore {
let dataType = ar[0]; let dataType = ar[0];
let data = ar[1]; let data = ar[1];
Codec.parse(data, 0, self, dataType).reply.then((resources) => { Codec.parse(data, 0, self, null, dataType).reply.then((resources) => {
reply.trigger((resources)) reply.trigger((resources))
} }
).error((ex) => reply.triggerError(ex)); ).error((ex) => reply.triggerError(ex));
@ -2377,15 +2377,13 @@ export default class DistributedConnection extends IStore {
} }
// Get a resource from the other end // Get a resource from the other end
fetch(id) { fetch(id, requestSequence) {
let resource = this.resources.item(id); let resource = this.resources.item(id);
let request = this.resourceRequests.item(id); let request = this.resourceRequests.item(id);
if (request != null) { if (request != null) {
if (resource != null && (requestSequence?.contains(id) ?? false))
if (resource != null)
// dig for dead locks // or not
return new AsyncReply(resource); return new AsyncReply(resource);
else else
return request; return request;
@ -2398,6 +2396,9 @@ export default class DistributedConnection extends IStore {
this.resourceRequests.set(id, reply); this.resourceRequests.set(id, reply);
var newSequence =
requestSequence != null ? [...requestSequence, id] : [id];
var self = this; var self = this;
this.sendRequest(IIPPacketAction.AttachResource) this.sendRequest(IIPPacketAction.AttachResource)
@ -2405,11 +2406,19 @@ export default class DistributedConnection extends IStore {
.done() .done()
.then(function (rt) { .then(function (rt) {
if (rt == null) {
reply.triggerError(new AsyncException(ErrorType.Management,
ExceptionCode.ResourceNotFound, "Null response"));
return;
}
var dr; var dr;
let classId = rt[0];
let template = null;
if (resource == null) if (resource == null)
{ {
var template = Warehouse.getTemplateByClassId(rt[0], TemplateType.Wrapper); template = Warehouse.getTemplateByClassId(classId, TemplateType.Wrapper);
if (template?.definedType != null) if (template?.definedType != null)
dr = new template.getDependencies(self, id, rt[1], rt[2]); dr = new template.getDependencies(self, id, rt[1], rt[2]);
else else
@ -2423,61 +2432,52 @@ export default class DistributedConnection extends IStore {
let transmissionType = rt[3] ; let transmissionType = rt[3] ;
let content = rt[4] ; let content = rt[4] ;
self.getTemplate(rt[0]).then(function (tmp) { let initResource = (ok) => {
Codec.parse(content, 0, self, newSequence, transmissionType)
.reply
.then((ar) => {
var pvs = new PropertyValueArray();
// ClassId, ResourceAge, ResourceLink, Content for (var i = 0; i < ar.length; i += 3)
if (resource == null)
{
let wp = Warehouse.put(id.toString(), dr, self, null, tmp).then(function(ok){
Codec.parse(content, 0, self, transmissionType)
.reply
.then((ar) => {
var pvs = new PropertyValueArray();
for (var i = 0; i < ar.length; i += 3)
pvs.push(new PropertyValue( pvs.push(new PropertyValue(
ar[i + 2], ar[i], ar[i + 1])); ar[i + 2], ar[i], ar[i + 1]));
dr._attach(pvs);
self.resourceRequests.remove(id);
reply.trigger(dr);
})
.error((ex) => reply.triggerError(ex));
});
wp.error(function(ex){
reply.triggerError(ex);
});
}
else
{
Codec.parse(content, 0, self, transmissionType)
.reply
.then((ar) => {
//print("attached");
if (results != null) {
var pvs = new PropertyValueArray();
for (var i = 0; i < ar.length; i += 3)
pvs.push(new PropertyValue(
ar[i + 2], ar[i], ar[i + 1]));
dr._attach(pvs);
}
self.resourceRequests.remove(id);
reply.trigger(dr);
}).error(function(ex) { reply.triggerError(ex)});
} dr._attach(pvs);
}).error(function(ex){
reply.triggerError(ex); self.resourceRequests.remove(id);
}); reply.trigger(dr);
})
.error((ex) => reply.triggerError(ex));
};
if (template == null)
{
self.getTemplate(rt[0]).then(function (tmp) {
// ClassId, ResourceAge, ResourceLink, Content
if (resource == null) {
Warehouse.put(id.toString(), dr, self, null, tmp).then(function(ok){
initResource(ok);
}).error(function(ex){
reply.triggerError(ex);
});
}
else
{
initResource(ok);
}
}).error(function(ex){
reply.triggerError(ex);
});
} else {
if (resource == null) {
Warehouse.put(id.toString(), dr, this, null, template)
.then(initResource)
.error((ex) => reply.triggerError(ex));
} else {
initResource(resource);
}
}
}).error(function(ex){ }).error(function(ex){
reply.triggerError(ex); reply.triggerError(ex);
}); });
@ -2500,7 +2500,7 @@ export default class DistributedConnection extends IStore {
.addDateTime(fromDate).addDateTime(toDate) .addDateTime(fromDate).addDateTime(toDate)
.done() .done()
.then(function (rt) { .then(function (rt) {
Codec.parseHistory(rt[0], 0, rt[0].length, resource, self).then(function (history) { Codec.historyParser(rt[0], 0, rt[0].length, resource, self, null).then(function (history) {
reply.trigger(history); reply.trigger(history);
}); });
}); });
@ -2721,7 +2721,8 @@ export default class DistributedConnection extends IStore {
return; return;
} }
DataDeserializer.typedListParser(attributes, 0, attributes.length, this).then(function (attrs) { DataDeserializer.typedListParser(attributes, 0, attributes.length, this, null)
.then(function (attrs) {
if (r.instance.setAttributes(attrs, clearAttributes)) if (r.instance.setAttributes(attrs, clearAttributes))
self.sendReply(clearAttributes ? IIPPacketAction.ClearAllAttributes : IIPPacketAction.ClearAttributes, self.sendReply(clearAttributes ? IIPPacketAction.ClearAllAttributes : IIPPacketAction.ClearAttributes,
callback) callback)
@ -2751,7 +2752,7 @@ export default class DistributedConnection extends IStore {
let dataType = ar[0]; let dataType = ar[0];
let data = ar[1]; let data = ar[1];
Codec.parse(data, 0, self, dataType).reply.then((resources) => { Codec.parse(data, 0, self, null, dataType).reply.then((resources) => {
rt.trigger(resources); rt.trigger(resources);
}) })
.error((ex) => rt.triggerError(ex)); .error((ex) => rt.triggerError(ex));
@ -2775,7 +2776,7 @@ export default class DistributedConnection extends IStore {
let dataType = ar[0] ; let dataType = ar[0] ;
let data = ar[1]; let data = ar[1];
Codec.parse(data, 0, self, dataType).reply.then((resources) => { Codec.parse(data, 0, self, null, dataType).reply.then((resources) => {
rt.trigger(resources); rt.trigger(resources);
}) })
.error((ex) => rt.triggerError(ex)); .error((ex) => rt.triggerError(ex));
@ -2846,7 +2847,7 @@ export default class DistributedConnection extends IStore {
let dataType = ar[0]; let dataType = ar[0];
let data = ar[1]; let data = ar[1];
Codec.parse(data, 0, self, dataType).reply.then((st) => { Codec.parse(data, 0, self, null, dataType).reply.then((st) => {
resource.instance?.setAttributes(st); resource.instance?.setAttributes(st);
rt.trigger(st); rt.trigger(st);
}) })
@ -2867,7 +2868,7 @@ export default class DistributedConnection extends IStore {
let dataType = ar[0] ; let dataType = ar[0] ;
let data = ar[1] ; let data = ar[1] ;
Codec.parse(data, 0, self, dataType).reply Codec.parse(data, 0, self, null, dataType).reply
.then((st) => { .then((st) => {
resource.instance?.setAttributes(st); resource.instance?.setAttributes(st);

View File

@ -7,7 +7,7 @@ export default class PropertyModificationInfo {
return this.propertyTemplate.name; return this.propertyTemplate.name;
} }
PropertyModificationInfo( constructor(
resource, propertyTemplate, value, age) { resource, propertyTemplate, value, age) {
this.resource = resource; this.resource = resource;
this.propertyTemplate = propertyTemplate; this.propertyTemplate = propertyTemplate;

View File

@ -545,7 +545,7 @@ export default class TypeTemplate {
offset += dt.size; offset += dt.size;
let parsed = Codec.parse(data, offset, null); let parsed = Codec.parse(data, offset, null, null);
offset += parsed.size; offset += parsed.size;

View File

@ -47,7 +47,9 @@ import { Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64, Float32, Floa
import Record from '../Data/Record.js'; import Record from '../Data/Record.js';
import TypedMap from '../Data/TypedMap.js'; import TypedMap from '../Data/TypedMap.js';
import {RepresentationType, RepresentationTypeIdentifier} from '../Data/RepresentationType.js'; import {RepresentationType, RepresentationTypeIdentifier} from '../Data/RepresentationType.js';
import FactoryEntry from './FactoryEntry.js'; './FactoryEntry.js'; import FactoryEntry from './FactoryEntry.js';
import IEnum from '../Data/IEnum.js';
export class WH extends IEventHandler export class WH extends IEventHandler
{ {
constructor() constructor()
@ -328,6 +330,8 @@ export class WH extends IEventHandler
templateType = TemplateType.Resource; templateType = TemplateType.Resource;
else if (type.prototype instanceof IRecord) else if (type.prototype instanceof IRecord)
templateType = TemplateType.Record; templateType = TemplateType.Record;
else if (type.prototype instanceof IEnum)
templateType = TemplateType.Enum;
else else
return null; return null;