e.printStackTrace();
return;
}
}
ReadingBuffer buffer;
Channel channel = ctx.getChannel();
boolean bootstrap = false;
synchronized (messageBuffersMap) {
buffer = messageBuffersMap.get(ctx.getChannel()); //应该直接用channel,第一次是buffer一定是null
if (buffer == null) {
synchronized (sharedMsgBufLock) {
bootstrap = true;
buffer = sharedState.sharedMessageBuffer.getReadingBuffer(ctx);
messageBuffersMap.put(channel, buffer);
channelGroup.add(channel);
LOG.warn("Channel connected: " + messageBuffersMap.size());
}
}
}
if (bootstrap) {
synchronized (sharedState) {
synchronized (sharedMsgBufLock) {
//这里会写一个TSOMessage.ZipperState消息并发送到Client
//见com.yahoo.omid.tso.serialization.TSOEncoder.encode(ChannelHandlerContext, Channel, Object)
//和com.yahoo.omid.replication.ZipperState.writeObject(ChannelBuffer)
//先在TSOEncoder.encode中写一个字节,然后在ZipperState.writeObject中写32个字节
channel.write(buffer.getZipperState());
buffer.initializeIndexes(); //进行完channel.write(buffer.getZipperState())后并不对buffer的read和write有任何影响
}
}
for (AbortedTransaction halfAborted : sharedState.hashmap.halfAborted) {
channel.write(new AbortedTransactionReport(halfAborted.getStartTimestamp()));
}
}
ChannelBuffer cb;
ChannelFuture future = Channels.future(channel);
synchronized (sharedMsgBufLock) {
cb = buffer.flush(future);
}
Channels.write(ctx, future, cb); //cb中放的是什么消息类型在client进行TSODecoder.decode时才懂
Channels.write(channel, new TimestampResponse(timestamp));
}