public ServerQueueStatus connect(EndpointManager endpointManager, ServerLocation location, ClientSideHandshake handshake, int socketBufferSize, int handshakeTimeout, int readTimeout, CommunicationMode communicationMode, GatewaySender sender, SocketCreator sc) throws IOException { theSocket = sc.connectForClient(location.getHostName(), location.getPort(), handshakeTimeout, socketBufferSize); theSocket.setTcpNoDelay(true); theSocket.setSendBufferSize(socketBufferSize); // Verify buffer sizes verifySocketBufferSize(socketBufferSize, theSocket.getReceiveBufferSize(), "receive"); verifySocketBufferSize(socketBufferSize, theSocket.getSendBufferSize(), "send"); theSocket.setSoTimeout(handshakeTimeout); out = theSocket.getOutputStream(); in = theSocket.getInputStream(); this.status = handshake.handshakeWithServer(this, location, communicationMode); commBuffer = ServerConnection.allocateCommBuffer(socketBufferSize, theSocket); if (sender != null) { commBufferForAsyncRead = ServerConnection.allocateCommBuffer(socketBufferSize, theSocket); } theSocket.setSoTimeout(readTimeout); endpoint = endpointManager.referenceEndpoint(location, this.status.getMemberId()); this.connectFinished = true; this.endpoint.getStats().incConnections(1); return status; }
@Override public int compare(Object o1, Object o2) { ServerQueueStatus s1 = (ServerQueueStatus) o1; ServerQueueStatus s2 = (ServerQueueStatus) o2; // sort primaries to the front of the list if (s1.isPrimary() && !s2.isPrimary()) { return -1; } else if (!s1.isPrimary() && s2.isPrimary()) { return 1; } else { int diff = s1.getServerQueueSize() - s2.getServerQueueSize(); if (diff != 0) { return diff; } else { return s1.getMemberId().compareTo(s2.getMemberId()); } } } }