@Override public List<NetEndpoint> getReplicationEndpoints(Set<NetEndpoint> oldReplicationEndpoints, Set<NetEndpoint> candidateEndpoints) { return NetEndpointManagerHolder.get().getReplicationEndpoints(this, oldReplicationEndpoints, candidateEndpoints); } }
private void writeInitPacket(String localHostAndPort) throws Exception { int packetId = 0; Transfer transfer = new Transfer(this, writableChannel); transfer.writeRequestHeaderWithoutSessionId(packetId, Session.SESSION_INIT); transfer.writeInt(MessagingService.PROTOCOL_MAGIC); transfer.writeInt(version); transfer.writeString(localHostAndPort); AsyncCallback<Void> ac = new AsyncCallback<>(); transfer.addAsyncCallback(packetId, ac); transfer.flush(); ac.await(); }
@Override public ReplicationSession createReplicationSession(Session session, Collection<NetEndpoint> replicationEndpoints, Boolean remote) { return NetEndpointManagerHolder.get().createReplicationSession(session, replicationEndpoints, remote); }
public void serialize(NetSerializer netSerializer) throws IOException { netSerializer.writeInt(index).writeString(moverHostId).writePageKey(pageKey); netSerializer.writeInt(replicationEndpoints.size()); for (NetEndpoint e : replicationEndpoints) { netSerializer.writeString(e.getHostAndPort()); } }
@Override public Transfer writePageKey(PageKey pk) throws IOException { writeValue((Value) pk.key); writeBoolean(pk.first); return this; }
@Override public NetEndpoint getEndpoint(String hostId) { return NetEndpointManagerHolder.get().getEndpoint(hostId); }
@Override public Session removeSession(int sessionId) { Session session = super.removeSession(sessionId); if (netClient != null && getSessions().isEmpty()) { netClient.removeConnection(inetSocketAddress); } return session; }
@Override public void flush() throws IOException { writePacketLength(); super.flush(); }
public AsyncConnection createConnection(WritableChannel writableChannel, boolean isServer) { check(); return connectionManager.createConnection(writableChannel, isServer); }
protected void reset() { buffer = writableChannel.getBufferFactory().createBuffer(initialSizeHint); } }
public void removeConnection(AsyncConnection conn) { check(); connectionManager.removeConnection(conn); }
public void addAsyncCallback(int id, AsyncCallback<?> ac) { ac.setTransfer(this); conn.addAsyncCallback(id, ac); }
/** * 当输出流写到一半时碰到某种异常了(可能是内部代码实现bug),比如产生了NPE, * 就会转到错误处理,生成一个新的错误协议包,但是前面产生的不完整的内容没有正常结束, * 这会导致客户端无法正常解析数据,所以这里允许在生成错误协议包之前清除之前的内容, * 如果之前的协议包不完整,但是已经发出去一半了,这里的方案也无能为力。 */ public void reset() throws IOException { resettableOutputStream.reset(); }
@Override public int read() throws IOException { return buffer.getUnsignedByte(pos++); } }
public NetBufferOutputStream(WritableChannel writableChannel, int initialSizeHint) { this.writableChannel = writableChannel; this.initialSizeHint = initialSizeHint; reset(); }
@Override public ReplicationSession createReplicationSession(Session session, Collection<NetEndpoint> replicationEndpoints) { return NetEndpointManagerHolder.get().createReplicationSession(session, replicationEndpoints); }