use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.
the class ClientTestSupport method getAllEventHandlers.
protected Map<Long, EventHandler> getAllEventHandlers(HazelcastInstance client) {
ClientConnectionManager connectionManager = getHazelcastClientInstanceImpl(client).getConnectionManager();
Collection<Connection> activeConnections = connectionManager.getActiveConnections();
HashMap<Long, EventHandler> map = new HashMap<>();
for (Connection activeConnection : activeConnections) {
map.putAll(((ClientConnection) activeConnection).getEventHandlers());
}
return map;
}
use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.
the class ClusterJoinManager method handleMasterResponse.
/**
* Set master address, if required.
*
* @param masterAddress address of cluster's master, as provided in {@link MasterResponseOp}
* @param callerAddress address of node that sent the {@link MasterResponseOp}
* @see MasterResponseOp
*/
public void handleMasterResponse(Address masterAddress, Address callerAddress) {
clusterServiceLock.lock();
try {
if (logger.isFineEnabled()) {
logger.fine(format("Handling master response %s from %s", masterAddress, callerAddress));
}
if (clusterService.isJoined()) {
if (logger.isFineEnabled()) {
logger.fine(format("Ignoring master response %s from %s, this node is already joined", masterAddress, callerAddress));
}
return;
}
if (node.getThisAddress().equals(masterAddress)) {
logger.warning("Received my address as master address from " + callerAddress);
return;
}
Address currentMaster = clusterService.getMasterAddress();
if (currentMaster == null || currentMaster.equals(masterAddress)) {
setMasterAndJoin(masterAddress);
return;
}
if (currentMaster.equals(callerAddress)) {
logger.warning(format("Setting master to %s since %s says it is not master anymore", masterAddress, currentMaster));
setMasterAndJoin(masterAddress);
return;
}
Connection conn = node.getServer().getConnectionManager(MEMBER).get(currentMaster);
if (conn != null && conn.isAlive()) {
logger.info(format("Ignoring master response %s from %s since this node has an active master %s", masterAddress, callerAddress, currentMaster));
sendJoinRequest(currentMaster);
} else {
logger.warning(format("Ambiguous master response! Received master response %s from %s. " + "This node has a master %s, but does not have an active connection to it. " + "Master field will be unset now.", masterAddress, callerAddress, currentMaster));
clusterService.setMasterAddress(null);
}
} finally {
clusterServiceLock.unlock();
}
}
use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.
the class ClusterServiceImpl method suspectAddressIfNotConnected.
public void suspectAddressIfNotConnected(Address address) {
lock.lock();
try {
MemberImpl member = getMember(address);
if (member == null) {
if (logger.isFineEnabled()) {
logger.fine("Cannot suspect " + address + ", since it's not a member.");
}
return;
}
Connection conn = node.getServer().getConnectionManager(MEMBER).get(address);
if (conn != null && conn.isAlive()) {
if (logger.isFineEnabled()) {
logger.fine("Cannot suspect " + member + ", since there's a live connection -> " + conn);
}
return;
}
suspectMember(member, "No connection", false);
} finally {
lock.unlock();
}
}
use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.
the class TcpIpJoiner method joinViaTargetMember.
private void joinViaTargetMember(Address targetAddress, long maxJoinMillis) {
try {
if (targetAddress == null) {
throw new IllegalArgumentException("Invalid target address: NULL");
}
if (logger.isFineEnabled()) {
logger.fine("Joining over target member " + targetAddress);
}
if (targetAddress.equals(node.getThisAddress()) || isLocalAddress(targetAddress)) {
clusterJoinManager.setThisMemberAsMaster();
return;
}
long joinStartTime = Clock.currentTimeMillis();
Connection connection;
while (shouldRetry() && (Clock.currentTimeMillis() - joinStartTime < maxJoinMillis)) {
ServerConnectionManager connectionManager = node.getServer().getConnectionManager(MEMBER);
connection = connectionManager.getOrConnect(targetAddress);
if (connection == null) {
connectionManager.blockOnConnect(targetAddress, JOIN_RETRY_WAIT_TIME, 0);
continue;
}
if (logger.isFineEnabled()) {
logger.fine("Sending joinRequest " + targetAddress);
}
clusterJoinManager.sendJoinRequest(targetAddress);
if (!clusterService.isJoined()) {
clusterService.blockOnJoin(JOIN_RETRY_WAIT_TIME);
}
}
} catch (final Exception e) {
logger.warning(e);
}
}
use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.
the class TcpServerConnectionManagerBase method send.
protected boolean send(Packet packet, Address target, SendTask sendTask, int streamId) {
UUID targetUuid = addressRegistry.uuidOf(target);
if (targetUuid == serverContext.getThisUuid()) {
logger.warning("Packet send task is rejected. Target is this node! Target[uuid=" + targetUuid + ", address=" + target + "]");
return false;
}
Connection connection = get(targetUuid, streamId);
if (connection != null) {
return connection.write(packet);
}
if (sendTask == null) {
sendTask = new SendTask(packet, target, streamId);
}
int retries = sendTask.retries;
if (retries < RETRY_NUMBER && serverContext.isNodeActive()) {
getOrConnect(target, true, streamId);
try {
server.scheduleDeferred(sendTask, (retries + 1) * DELAY_FACTOR, TimeUnit.MILLISECONDS);
return true;
} catch (RejectedExecutionException e) {
if (server.isLive()) {
throw e;
}
if (logger.isFinestEnabled()) {
logger.finest("Packet send task is rejected. Packet cannot be sent to " + target);
}
}
}
return false;
}
Aggregations