use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.
the class TcpIpConnectionManager method send.
private boolean send(Packet packet, Address target, SendTask sendTask) {
Connection connection = getConnection(target);
if (connection != null) {
return connection.write(packet);
}
if (sendTask == null) {
sendTask = new SendTask(packet, target);
}
int retries = sendTask.retries;
if (retries < RETRY_NUMBER && ioService.isActive()) {
getOrConnect(target, true);
// TODO: Caution: may break the order guarantee of the packets sent from the same thread!
scheduler.schedule(sendTask, (retries + 1) * DELAY_FACTOR, TimeUnit.MILLISECONDS);
return true;
}
return false;
}
use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.
the class Invocation method toString.
@Override
public String toString() {
String connectionStr = null;
Address invTarget = this.invTarget;
if (invTarget != null) {
ConnectionManager connectionManager = context.connectionManager;
Connection connection = connectionManager.getConnection(invTarget);
connectionStr = connection == null ? null : connection.toString();
}
return "Invocation{" + "op=" + op + ", tryCount=" + tryCount + ", tryPauseMillis=" + tryPauseMillis + ", invokeCount=" + invokeCount + ", callTimeoutMillis=" + callTimeoutMillis + ", firstInvocationTimeMs=" + firstInvocationTimeMillis + ", firstInvocationTime='" + timeToString(firstInvocationTimeMillis) + '\'' + ", lastHeartbeatMillis=" + lastHeartbeatMillis + ", lastHeartbeatTime='" + timeToString(lastHeartbeatMillis) + '\'' + ", target=" + invTarget + ", pendingResponse={" + pendingResponse + '}' + ", backupsAcksExpected=" + backupsAcksExpected + ", backupsAcksReceived=" + backupsAcksReceived + ", connection=" + connectionStr + '}';
}
use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.
the class OutboundResponseHandler method send.
public boolean send(Response response, Address target) {
checkNotNull(target, "Target is required!");
if (thisAddress.equals(target)) {
throw new IllegalArgumentException("Target is this node! -> " + target + ", response: " + response);
}
byte[] bytes = serializationService.toBytes(response);
Packet packet = new Packet(bytes, -1).setPacketType(Packet.Type.OPERATION).raiseFlags(FLAG_OP_RESPONSE);
if (response.isUrgent()) {
packet.raiseFlags(FLAG_URGENT);
}
ConnectionManager connectionManager = node.getConnectionManager();
Connection connection = connectionManager.getOrConnect(target);
return connectionManager.transmit(packet, connection);
}
use of com.hazelcast.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.setAsMaster();
return;
}
long joinStartTime = Clock.currentTimeMillis();
Connection connection;
while (shouldRetry() && (Clock.currentTimeMillis() - joinStartTime < maxJoinMillis)) {
connection = node.connectionManager.getOrConnect(targetAddress);
if (connection == null) {
//noinspection BusyWait
Thread.sleep(JOIN_RETRY_WAIT_TIME);
continue;
}
if (logger.isFineEnabled()) {
logger.fine("Sending joinRequest " + targetAddress);
}
clusterJoinManager.sendJoinRequest(targetAddress, true);
//noinspection BusyWait
Thread.sleep(JOIN_RETRY_WAIT_TIME);
}
} catch (final Exception e) {
logger.warning(e);
}
}
use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.
the class AbstractClientInternalCacheProxy method getConnectedServerVersion.
private int getConnectedServerVersion() {
ClientContext clientContext = getContext();
ClientClusterService clusterService = clientContext.getClusterService();
Address ownerConnectionAddress = clusterService.getOwnerConnectionAddress();
HazelcastClientInstanceImpl client = getClient();
ClientConnectionManager connectionManager = client.getConnectionManager();
Connection connection = connectionManager.getConnection(ownerConnectionAddress);
if (connection == null) {
logger.warning(format("No owner connection is available, " + "near cached cache %s will be started in legacy mode", name));
return UNKNOWN_HAZELCAST_VERSION;
}
return ((ClientConnection) connection).getConnectedServerVersion();
}
Aggregations