Skip to content

Commit

Permalink
fix: update cluster api
Browse files Browse the repository at this point in the history
  • Loading branch information
jdmnd committed Nov 27, 2017
1 parent dab1e6c commit e1a557e
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 20 deletions.
4 changes: 0 additions & 4 deletions conf/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ logLevel: INFO
# Directory where all plugins reside
#libDir: ../lib

# Connectivity
# webfacing URL under which this client is reachable. Used for loadbalancing / failover
externalUrl: null

# SSL Configuration
sslKey: null
sslCert: null
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"nexe": "^1",
"proxyquire": "1.8.0",
"sinon": "^4.0.1",
"ts-node": "^3.3.0",
"tslint": "^5.8.0",
"typescript": "^2.5.3",
"watch": "^1.0.2"
Expand Down
8 changes: 4 additions & 4 deletions src/cluster/cluster-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ export default class ClusterNode implements Cluster {
this.stateRegistries = new Map()
}

public sendDirect (serverName: string, message: Message, metaData: any) {}
public sendDirect (serverName: string, message: Message, metaData?: any) {}

public sendState () {}

public send (message: Message, metaData: any) {}
public send (stateRegistryTopic: TOPIC, message: Message, metaData?: any) {}

public subscribe (topic: TOPIC, callback: Function) {}
public subscribe (stateRegistryTopic: TOPIC, callback: Function) {}

public isLeader (): boolean { throw new Error('Leader not used in single state') }

public getStateRegistry (name: TOPIC) {
public getStateRegistry (stateRegistryTopic: TOPIC) {
let stateRegistry = this.stateRegistries.get(name)
if (!stateRegistry) {
stateRegistry = new StateRegistry(name, {})
Expand Down
12 changes: 6 additions & 6 deletions src/deepstream.io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class Deepstream extends EventEmitter {

private eventHandler: EventHandler
private rpcHandler: RpcHandler
private recordHandler: any
private recordHandler: RecordHandler
private presenceHandler: PresenceHandler

private stateMachine: any
Expand Down Expand Up @@ -196,7 +196,7 @@ export class Deepstream extends EventEmitter {
private pluginInit (): void {
this.services.message = new MessageConnector(this.config, this.services, 'deepstream')

const infoLogger = (message) => this.services.logger.info(EVENT.INFO, message)
const infoLogger = message => this.services.logger.info(EVENT.INFO, message)
infoLogger(`deepstream version: ${pkg.version}`)

// otherwise (no configFile) deepstream was invoked by API
Expand All @@ -208,7 +208,7 @@ export class Deepstream extends EventEmitter {
infoLogger(`library directory set to: ${global.deepstreamLibDir}`)
}

this.services.registeredPlugins.forEach((pluginType) => {
this.services.registeredPlugins.forEach(pluginType => {
const plugin = this.services[pluginType]
const initialiser = new DependencyInitialiser(this, this.config, this.services, plugin, pluginType)
initialiser.once('ready', () => {
Expand All @@ -228,7 +228,7 @@ export class Deepstream extends EventEmitter {
}
plugin.isReady = true

const allPluginsReady = this.services.registeredPlugins.every((type) => this.services[type].isReady)
const allPluginsReady = this.services.registeredPlugins.every(type => this.services[type].isReady)

if (allPluginsReady && this.currentState === STATES.PLUGIN_INIT) {
this.transition('plugins-started')
Expand Down Expand Up @@ -325,7 +325,7 @@ export class Deepstream extends EventEmitter {
*/
private connectionEndpointShutdown (): void {
const endpoints = this.services.connectionEndpoints
endpoints.forEach((endpoint) => {
endpoints.forEach(endpoint => {
process.nextTick(() => endpoint.close())
})

Expand All @@ -344,7 +344,7 @@ export class Deepstream extends EventEmitter {
*/
private pluginShutdown (): void {
const closeablePlugins: Array<DeepstreamPlugin> = []
this.services.registeredPlugins.forEach((pluginType) => {
this.services.registeredPlugins.forEach(pluginType => {
const plugin = this.services[pluginType]
if (typeof plugin.close === 'function') {
process.nextTick(() => plugin.close())
Expand Down
8 changes: 4 additions & 4 deletions src/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ interface UserAuthenticationCallback {
}

interface Cluster {
getStateRegistry (stateRegistryName: TOPIC): any,
send (message: Message, metaData: any): void,
sendDirect (serverName: string, message: Message, metaData: any): void,
subscribe (topic: TOPIC, callback: Function): void
getStateRegistry (stateRegistryTopic: TOPIC): any,
send (stateRegistryTopic: TOPIC, message: Message, metaData?: any): void,
sendDirect (serverName: string, message: Message, metaData?: any): void,
subscribe (stateRegistryTopic: TOPIC, callback: Function): void
isLeader (): boolean
close (callback: Function): void
}
Expand Down
4 changes: 3 additions & 1 deletion src/utils/subscription-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default class SubscriptionRegistry {
private config: DeepstreamConfig
private services: DeepstreamServices
private topic: TOPIC
private clusterTopic: TOPIC
private subscriptionListener: SubscriptionListener
private constants: SubscriptionActions
private clusterSubscriptions: StateRegistry
Expand All @@ -47,6 +48,7 @@ export default class SubscriptionRegistry {
this.config = config
this.services = services
this.topic = topic
this.clusterTopic = clusterTopic

switch (topic) {
case TOPIC.RECORD:
Expand Down Expand Up @@ -150,7 +152,7 @@ export default class SubscriptionRegistry {
*/
public sendToSubscribers (name: string, message: Message, noDelay: boolean, socket: SocketWrapper | null, isRemote: boolean = false): void {
if (socket && !isRemote) {
this.services.message.send(message, {})
this.services.message.send(this.clusterTopic, message)
}

const subscription = this.subscriptions.get(name)
Expand Down

0 comments on commit e1a557e

Please sign in to comment.