sync/src/io/backend/iobackend.js

43 lines
1.4 KiB
JavaScript
Raw Normal View History

2015-12-28 23:52:39 -08:00
import Server from 'cytube-common/lib/proxy/server';
2015-12-24 16:24:07 -08:00
import FrontendManager from './frontendmanager';
import uuid from 'uuid';
import PoolEntryUpdater from 'cytube-common/lib/redis/poolentryupdater';
import JSONProtocol from 'cytube-common/lib/proxy/protocol';
const BACKEND_POOL = 'backend-hosts';
2015-12-24 16:24:07 -08:00
export default class IOBackend {
constructor(proxyListenerConfig, socketEmitter, poolRedisClient) {
2015-12-24 16:24:07 -08:00
this.proxyListenerConfig = proxyListenerConfig;
2015-12-26 15:07:03 -08:00
this.socketEmitter = socketEmitter;
this.poolRedisClient = poolRedisClient;
this.protocol = new JSONProtocol();
2015-12-24 16:24:07 -08:00
this.initFrontendManager();
this.initProxyListener();
this.initBackendPoolUpdater();
2015-12-24 16:24:07 -08:00
}
initFrontendManager() {
2015-12-26 15:07:03 -08:00
this.frontendManager = new FrontendManager(this.socketEmitter);
2015-12-24 16:24:07 -08:00
}
initProxyListener() {
this.proxyListener = new Server(this.proxyListenerConfig, this.protocol);
2015-12-24 16:24:07 -08:00
this.proxyListener.on('connection',
this.frontendManager.onConnection.bind(this.frontendManager));
}
initBackendPoolUpdater() {
const entry = {
address: this.proxyListenerConfig.getHost() + '/' + this.proxyListenerConfig.getPort()
}
this.poolEntryUpdater = new PoolEntryUpdater(
this.poolRedisClient,
BACKEND_POOL,
uuid.v4(),
entry
);
this.poolEntryUpdater.start();
}
2015-12-24 16:24:07 -08:00
}