-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### 2.6.0 - Update `HamokEmitter` to have metaData property bind to subscriber peers per events. * Add Subscriptions to `HamokEmitter` to track the subscribers of an event. * Add `HamokEmitterStats` to track the number of events emitted and received by the emitter. - Simplifying discovery and joining methods in `Hamok`.
- Loading branch information
1 parent
79e5fc5
commit 1d3aa2f
Showing
30 changed files
with
1,337 additions
and
487 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ purgatory/ | |
node_modules | ||
lib/ | ||
package-lock.json | ||
# yarn.lock | ||
# yarn.lock | ||
_mything.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
|
||
|
||
import { Hamok, setHamokLogLevel } from 'hamok'; | ||
import * as pino from 'pino'; | ||
import { HamokMessageHub } from './utils/HamokMessageHub'; | ||
|
||
const logger = pino.pino({ | ||
name: 'common-join-example-2', | ||
level: 'debug', | ||
}); | ||
|
||
export async function run() { | ||
|
||
const servers = new Map<string, Hamok>(); | ||
const messageHub = new HamokMessageHub(); | ||
const addServer = (server: Hamok) => { | ||
const leaderChangedListener = () => { | ||
logger.debug('Server %s, State: %s remotePeers: %s', server.localPeerId, server.raft.state.stateName, [...server.remotePeerIds].join(', ')); | ||
} | ||
server.once('close', () => { | ||
servers.delete(server.localPeerId); | ||
messageHub.remove(server); | ||
server.off('leader-changed', leaderChangedListener); | ||
}) | ||
servers.set(server.localPeerId, server); | ||
messageHub.add(server); | ||
server.on('leader-changed', leaderChangedListener); | ||
} | ||
addServer(new Hamok()); | ||
addServer(new Hamok()); | ||
addServer(new Hamok()); | ||
|
||
await Promise.all([...servers.values()].map(server => server.join())); | ||
|
||
|
||
|
||
for (let i = 0; i < 10; ++i) { | ||
const newServer = new Hamok(); | ||
const oldServer = servers.values().next().value; | ||
addServer(newServer); | ||
// by having the communication channel we assume we can inquery remote endpoints | ||
|
||
|
||
const timer = setInterval(() => { | ||
const messages: string[] = []; | ||
for (const server of servers.values()) { | ||
messages.push(`server (${server.localPeerId}, state: ${server.state}) remotePeers are ${[...server.remotePeerIds].join(', ')}`); | ||
} | ||
logger.debug('iteration: %d\n, %s', i, messages.join('\n')); | ||
}, 1000) | ||
|
||
|
||
await newServer.join(); | ||
|
||
const messages: string[] = []; | ||
for (const server of servers.values()) { | ||
messages.push(`server (${server.localPeerId}, state: ${server.state}) remotePeers are ${[...server.remotePeerIds].join(', ')}`); | ||
} | ||
logger.debug('iteration: %d\n, %s', i, messages.join('\n')); | ||
|
||
oldServer.close(); | ||
|
||
clearInterval(timer); | ||
} | ||
|
||
|
||
logger.info('Close'); | ||
|
||
for (const server of servers.values()) { | ||
server.close(); | ||
} | ||
} | ||
|
||
if (require.main === module) { | ||
logger.info('Running from module file'); | ||
setHamokLogLevel('debug'); | ||
run(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.