use of com.bonree.brfs.common.net.tcp.MessageChannelInitializer in project BRFS by zhangnianli.
the class DataNodeBootStrap method start.
@Override
public void start() throws Exception {
createRootDirIfNeeded(diskContext.getRootDir());
RecordCollectionManager recorderManager = new RecordCollectionManager();
writerManager = new FileWriterManager(recorderManager);
writerManager.start();
writerManager.rebuildFileWriterbyDir(diskContext.getRootDir());
LOG.info("####################################come here###################################");
FileFormater fileFormater = new SimpleFileFormater(Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_FILE_MAX_CAPACITY));
threadPool = Executors.newFixedThreadPool(Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_REQUEST_HANDLER_NUM), new PooledThreadFactory("message_handler"));
MessageChannelInitializer initializer = new MessageChannelInitializer(threadPool);
initializer.addMessageHandler(TYPE_OPEN_FILE, new OpenFileMessageHandler(diskContext, writerManager));
initializer.addMessageHandler(TYPE_WRITE_FILE, new WriteFileMessageHandler(diskContext, writerManager, fileFormater));
initializer.addMessageHandler(TYPE_CLOSE_FILE, new CloseFileMessageHandler(diskContext, writerManager, fileFormater));
initializer.addMessageHandler(TYPE_DELETE_FILE, new DeleteFileMessageHandler(diskContext, writerManager));
initializer.addMessageHandler(TYPE_PING_PONG, new PingPongMessageHandler());
initializer.addMessageHandler(TYPE_FLUSH_FILE, new FlushFileMessageHandler(diskContext, writerManager));
initializer.addMessageHandler(TYPE_METADATA, new MetadataFetchMessageHandler(diskContext, writerManager, fileFormater));
initializer.addMessageHandler(TYPE_LIST_FILE, new ListFileMessageHandler(diskContext));
initializer.addMessageHandler(TYPE_RECOVER_FILE, new FileRecoveryMessageHandler(diskContext, serviceManager, writerManager, fileFormater, readerGroup));
ServerConfig config = new ServerConfig();
config.setBacklog(Integer.parseInt(System.getProperty(SystemProperties.PROP_NET_BACKLOG, "2048")));
config.setBossThreadNums(1);
config.setWorkerThreadNums(Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_SERVER_IO_NUM));
config.setPort(Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_PORT));
config.setHost(Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_HOST));
server = new TcpServer(config, initializer);
server.start();
ServerConfig fileServerConfig = new ServerConfig();
fileServerConfig.setBacklog(Integer.parseInt(System.getProperty(SystemProperties.PROP_NET_BACKLOG, "2048")));
fileServerConfig.setBossThreadNums(1);
fileServerConfig.setWorkerThreadNums(Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_FILE_READER_NUM));
fileServerConfig.setPort(Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_FILE_PORT));
fileServerConfig.setHost(Configs.getConfiguration().GetConfig(DataNodeConfigs.CONFIG_HOST));
FileChannelInitializer fileInitializer = new FileChannelInitializer(new ReadObjectTranslator() {
@Override
public long offset(long offset) {
return fileFormater.absoluteOffset(offset);
}
@Override
public int length(int length) {
return length;
}
@Override
public String filePath(String path) {
return diskContext.getConcreteFilePath(path);
}
});
fileServer = new TcpServer(fileServerConfig, fileInitializer);
fileServer.start();
}
Aggregations