use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.
the class ClusterMismatchOp method run.
@Override
public void run() {
NodeEngineImpl nodeEngine = (NodeEngineImpl) getNodeEngine();
Connection connection = getConnection();
String message = "Node could not join cluster at node: " + connection.getRemoteAddress() + " Cause: the target cluster has a different cluster-name";
Node node = nodeEngine.getNode();
LinkedAddresses linkedAddresses = node.getLocalAddressRegistry().linkedAddressesOf(getCallerUuid());
connection.close(message, null);
ILogger logger = nodeEngine.getLogger("com.hazelcast.cluster");
logger.warning(message);
if (linkedAddresses != null) {
for (Address address : linkedAddresses.getAllAddresses()) {
node.getJoiner().blacklist(address, true);
}
} else {
node.getJoiner().blacklist(getCallerAddress(), true);
}
}
use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.
the class SystemLogPlugin method render.
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
private void render(DiagnosticsLogWriter writer, ConnectionEvent event) {
if (event.added) {
writer.startSection("ConnectionAdded");
} else {
writer.startSection("ConnectionRemoved");
}
Connection connection = event.connection;
writer.writeEntry(connection.toString());
if (connection instanceof ServerConnection) {
writer.writeKeyValueEntry("type", ((ServerConnection) connection).getConnectionType());
}
writer.writeKeyValueEntry("isAlive", connection.isAlive());
if (!event.added) {
String closeReason = connection.getCloseReason();
Throwable closeCause = connection.getCloseCause();
if (closeReason == null && closeCause != null) {
closeReason = closeCause.getMessage();
}
writer.writeKeyValueEntry("closeReason", closeReason == null ? "Unknown" : closeReason);
if (closeCause != null) {
writer.startSection("CloseCause");
String s = closeCause.getClass().getName();
String message = closeCause.getMessage();
writer.writeEntry((message != null) ? (s + ": " + message) : s);
for (StackTraceElement element : closeCause.getStackTrace()) {
writer.writeEntry(element.toString());
}
writer.endSection();
}
}
writer.endSection();
}
use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.
the class TcpServerConnectionManager_AbstractConnectMemberTest method getOrConnect_whenNotConnected_thenEventuallyConnectionAvailable.
// ================== getOrConnect ======================================================
@Test
public void getOrConnect_whenNotConnected_thenEventuallyConnectionAvailable() {
startAllTcpServers();
Connection c = tcpServerA.getConnectionManager(MEMBER).getOrConnect(addressB);
assertNull(c);
connect(tcpServerA, addressB);
assertEquals(1, tcpServerA.getConnectionManager(MEMBER).getConnections().size());
assertEquals(1, tcpServerB.getConnectionManager(MEMBER).getConnections().size());
}
use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.
the class TcpServerConnection_AbstractTest method connect.
protected TcpServerConnection connect(final TcpServer service, final Address address) {
service.getConnectionManager(MEMBER).getOrConnect(address);
final AtomicReference<TcpServerConnection> ref = new AtomicReference<>();
assertTrueEventually(() -> {
Connection c = service.getConnectionManager(MEMBER).get(address);
assertNotNull(c);
ref.set((TcpServerConnection) c);
});
return ref.get();
}
use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.
the class MemberReconnectionStressTest method test.
@Test
public void test() {
/*
The test will start 2 thread:
- one will submit short batch jobs, serially, after joining the previous job
- the other will keep dropping the member-to-member connection.
The small jobs will often fail due to the reconnection, we check
that the job completes in a limited time. We drop the connection
at a rate lower than the normal job duration so there's
typically at most 1 restart per job. We assert that the jobs
eventually successfully complete.
*/
Config config = defaultInstanceConfigWithJetEnabled();
// The connection drop often causes regular IMap operations to fail - shorten the timeout so that
// it recovers more quickly
config.setProperty(ClusterProperty.OPERATION_CALL_TIMEOUT_MILLIS.getName(), "2000");
config.setClusterName(randomName());
HazelcastInstance inst1 = createHazelcastInstance(config);
HazelcastInstance inst2 = createHazelcastInstance(config);
logger.info("Instances started");
new Thread(() -> {
while (!terminated.get()) {
Connection connection = null;
while (connection == null) {
connection = ImdgUtil.getMemberConnection(getNodeEngineImpl(inst1), getNodeEngineImpl(inst2).getThisAddress());
}
connection.close("test", new Exception("test failure"));
logger.info("connection closed");
sleepMillis(300);
}
}).start();
DAG dag = new DAG();
Vertex v1 = dag.newVertex("v1", () -> new MockP()).localParallelism(2);
Vertex v2 = dag.newVertex("v2", () -> new MockP()).localParallelism(2);
dag.edge(between(v1, v2).distributed());
AtomicInteger jobCount = new AtomicInteger();
new Thread(() -> {
while (!terminated.get()) {
try {
inst1.getJet().newJob(dag).getFuture().join();
logger.info("job completed");
jobCount.incrementAndGet();
} catch (Exception e) {
logger.info("Job failed, ignoring it", e);
}
}
}).start();
// in a loop check that the `jobCount` is incremented at least every N seconds
long lastIncrement = System.nanoTime();
long lastJobCount = 0;
long testEndTime = System.nanoTime() + MINUTES.toNanos(3);
for (long now; (now = System.nanoTime()) < testEndTime; ) {
if (jobCount.get() > lastJobCount) {
lastIncrement = now;
lastJobCount++;
}
if (NANOSECONDS.toSeconds(now - lastIncrement) > 30) {
fail("jobCount didn't increment for 30 seconds");
}
sleepMillis(100);
}
}
Aggregations