2
0
mirror of https://github.com/esiur/esiur-js.git synced 2026-04-03 21:48:21 +00:00
This commit is contained in:
2021-03-10 01:25:20 +03:00
parent ca2b89540a
commit a08519bde8
55 changed files with 4190 additions and 6679 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -31,6 +31,10 @@ import AsyncReply from '../../Core/AsyncReply.js';
import Codec from '../../Data/Codec.js';
import Structure from '../../Data/Structure.js';
import IIPPacketAction from '../Packets//IIPPacketAction.js';
import EventTemplate from '../../Resource/Template/EventTemplate.js';
import AsyncException from '../../Core/AsyncException.js';
import ExceptionCode from '../../Core//ExceptionCode.js';
import ErrorType from '../../Core/ErrorType.js';
export default class DistributedResource extends IResource
{
@@ -166,6 +170,32 @@ export default class DistributedResource extends IResource
return true;
}
listen(event)
{
let et = event instanceof EventTemplate ? event : this.instance.template.getEventTemplateByName(event);
if (et == null)
return new AsyncReply().triggerError(new AsyncException(ErrorType.Management, ExceptionCode.MethodNotFound, ""));
if (!et.listenable)
return new AsyncReply().triggerError(new AsyncException(ErrorType.Management, ExceptionCode.NotListenable, ""));
return this._p.connection.sendListenRequest(this._p.instanceId, et.index);
}
unlisten(event)
{
let et = event instanceof EventTemplate ? event : this.instance.template.getEventTemplateByName(event);
if (et == null)
return new AsyncReply().triggerError(new AsyncException(ErrorType.Management, ExceptionCode.MethodNotFound, ""));
if (!et.listenable)
return new AsyncReply().triggerError(new AsyncException(ErrorType.Management, ExceptionCode.NotListenable, ""));
return this._p.connection.sendUnlistenRequest(this._p.instanceId, et.index);
}
_emitEventByIndex(index, args)
{
var et = this.instance.template.getEventTemplateByIndex(index);
@@ -225,7 +255,7 @@ export default class DistributedResource extends IResource
{
if (!this._p.attached)
{
console.log("What ?");
console.log("Resource not attached.");
return;
}

View File

@@ -0,0 +1,81 @@
/*
* Copyright (c) 2017-2021 Ahmed Kh. Zamil
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
/**
* Created by Ahmed Zamil on 03/05/2021.
*/
"use strict";
import IResource from '../../Resource/IResource.js';
import AsyncReply from '../../Core/AsyncReply.js';
import Codec from '../../Data/Codec.js';
import Structure from '../../Data/Structure.js';
import IIPPacketAction from '../Packets//IIPPacketAction.js';
import EventTemplate from '../../Resource/Template/EventTemplate.js';
import AsyncException from '../../Core/AsyncException.js';
import ExceptionCode from '../../Core//ExceptionCode.js';
import ErrorType from '../../Core/ErrorType.js';
import DistributedConnection from './DistributedConnection.js';
export default class DistributedServer extends IResource
{
destroy()
{
this.connections = [];
this.destroyed = true;
this._emit("destroy", this);
}
trigger(type)
{
return new AsyncReply(true);
}
get membership() {
return this.instance.attributes.get("membership");
}
get entryPoint() {
return this.instance.attributes.get("entryPoint");
}
constructor()
{
super();
this.connections = [];
}
add() {
let self = this;
let con = new DistributedConnection(this);
con.on("close", () => self.remove(con));
this.connections.push(con);
return con;
}
remove(connection){
let i = this.connections.indexOf(connection);
if (i > -1)
this.connections.splice(i, 1);
}
}

View File

@@ -0,0 +1,8 @@
import IResource from "../../Resource/IResource";
export default class EntryPoint extends IResource
{
query(path, sender) {}
create() {}
}