2
0
mirror of https://github.com/esiur/esiur-js.git synced 2025-05-06 20:42:58 +00:00

ConnectionStatus

This commit is contained in:
Esiur Project 2022-08-14 21:45:48 +03:00
parent a74907526c
commit d057f87b76
5 changed files with 48 additions and 20 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "esiur", "name": "esiur",
"version": "2.1.0", "version": "2.1.1",
"description": "Distributed Object Framework", "description": "Distributed Object Framework",
"main": "esiur.js", "main": "esiur.js",
"type": "module", "type": "module",

View File

@ -0,0 +1,6 @@
export default
{
Closed : 0,
Connecting: 1,
Connected: 2
};

View File

@ -80,6 +80,8 @@ import {TransmissionType, TransmissionTypeIdentifier} from '../../Data/Transmiss
import PropertyValue from '../../Data/PropertyValue.js'; import PropertyValue from '../../Data/PropertyValue.js';
import PropertyValueArray from '../../Data/PropertyValueArray.js'; import PropertyValueArray from '../../Data/PropertyValueArray.js';
import { UInt8 } from '../../Data/ExtendedTypes.js';
import ConnectionStatus from './ConnectionStatus.js';
export default class DistributedConnection extends IStore { export default class DistributedConnection extends IStore {
@ -671,8 +673,11 @@ export default class DistributedConnection extends IStore {
{ {
this.ready = true; this.ready = true;
this.status = ConnectionStatus.Connected;
this._openReply?.trigger(true); this._openReply?.trigger(true);
this._openReply = null; this._openReply = null;
this._emit("ready", this); this._emit("ready", this);
this.server?.membership.login(this.session); this.server?.membership.login(this.session);
@ -685,8 +690,11 @@ export default class DistributedConnection extends IStore {
else else
{ {
this.ready = true; this.ready = true;
this.status = ConnectionStatus.Connected;
this._openReply?.trigger(true); this._openReply?.trigger(true);
this._openReply = null; this._openReply = null;
this._emit("ready", this); this._emit("ready", this);
this.server?.membership.login(this.session); this.server?.membership.login(this.session);
} }
@ -772,7 +780,8 @@ export default class DistributedConnection extends IStore {
{ {
this.session.id = authPacket.sessionId; this.session.id = authPacket.sessionId;
this.ready = true; this.ready = true;
this._emit("ready", this); this.status = ConnectionStatus.Connected;
// put it in the warehouse // put it in the warehouse
if (this.instance == null) if (this.instance == null)
@ -1002,6 +1011,8 @@ export default class DistributedConnection extends IStore {
if (this._openReply != null) if (this._openReply != null)
throw new AsyncException(ErrorType.Exception, 0, "Connection in progress"); throw new AsyncException(ErrorType.Exception, 0, "Connection in progress");
this.status = ConnectionStatus.Connecting;
this._openReply = new AsyncReply(); this._openReply = new AsyncReply();
if (hostname != null) if (hostname != null)
@ -1131,6 +1142,8 @@ export default class DistributedConnection extends IStore {
{ {
// clean up // clean up
this.ready = false; this.ready = false;
this.status = ConnectionStatus.Closed;
this.readyToEstablish = false; this.readyToEstablish = false;
clearTimeout(this._keepAliveTimer); clearTimeout(this._keepAliveTimer);
@ -3166,4 +3179,11 @@ export default class DistributedConnection extends IStore {
this._lastKeepAliveReceived = now; this._lastKeepAliveReceived = now;
} }
static get template() {
return {
namespace: "Esiur",
properties: [["status", UInt8]]
};
}
} }

View File

@ -1,35 +1,37 @@
import Warehouse from "../Resource/Warehouse.js"; import Warehouse from "../Resource/Warehouse.js";
export default class ResourceProxy export default class ResourceProxy {
{
static cache = {}; static cache = {};
static getProxy(type) static getProxy(type) {
{ let template = Warehouse.getTemplateByType(type);
var template = Warehouse.getTemplateByType(type); let className = type.prototype.constructor.name;
var className = type.prototype.constructor.name; let classUrl = "esiur://" + template.className.replace('.', '/');
if (template.namespace != null) {
className = template.namespace + "_" + className;
}
if (ResourceProxy.cache[className]) if (ResourceProxy.cache[className])
return ResourceProxy.cache[className]; return ResourceProxy.cache[className];
var code = `return (class E_${className} extends b { constructor() {super();} `; var code = `return ( class E_${className} extends b { constructor() {super();} `;
// generate class // generate class
for(var i = 0; i < template.properties.length; i++) for (var i = 0; i < template.properties.length; i++) {
{
let pt = template.properties[i]; let pt = template.properties[i];
let desc = Object.getOwnPropertyDescriptor(type.prototype, pt.name); let desc = Object.getOwnPropertyDescriptor(type.prototype, pt.name);
if (desc) if (desc) {
{ code += `\r\n set ${pt.name}(v) { \r\n super.${pt.name} = v; \r\n if (this.instance) this.instance.emitModification(this.instance.template.properties[${i}], v); } \r\n get ${pt.name}() { \r\n return super.${pt.name};}`;
code += `\r\n set ${pt.name}(v) { \r\n if (this.instance) this.instance.emitModification(this.instance.template.properties[${i}], v); \r\n super.${pt.name} = v; } \r\n get ${pt.name}() { \r\n return super.${pt.name};}`;
} }
else else {
{ code += `\r\n set ${pt.name}(v) { \r\n super._${pt.name} = v; \r\n if (this.instance) this.instance.emitModification(this.instance.template.properties[${i}], v); } \r\n get ${pt.name}() { \r\n return this._${pt.name};}`;
code += `\r\n set ${pt.name}(v) { \r\n if (this.instance) this.instance.emitModification(this.instance.template.properties[${i}], v); \r\n this._${pt.name} = v; } \r\n get ${pt.name}() { \r\n return this._${pt.name};}`;
} }
} }
var func = new Function("b", code + "})"); debugger;
var func = new Function("b", `//# sourceURL=${classUrl} \r\n ${code}});`);
var proxyType = func.call(type /* this */, type); var proxyType = func.call(type /* this */, type);

View File

@ -155,9 +155,9 @@ export default class Instance extends IEventHandler
this.modificationDates[pt.index] = now; this.modificationDates[pt.index] = now;
if (pt.recordable) if (pt.recordable)
this.store.record(resource, pt.name, value, this.ages[pt.index], now); this.store?.record(resource, pt.name, value, this.ages[pt.index], now);
else else
this.store.modify(resource, pt.name, value, this.ages[pt.index], now); this.store?.modify(resource, pt.name, value, this.ages[pt.index], now);
let pmInfo = new PropertyModificationInfo(resource, pt, value, this.instanceAge); let pmInfo = new PropertyModificationInfo(resource, pt, value, this.instanceAge);