use of com.hazelcast.cluster.impl.MemberImpl in project hazelcast by hazelcast.
the class ClientMessageEncoderDecoderTest method testAuthenticationResponse.
@Test
public void testAuthenticationResponse() throws UnknownHostException {
Collection<Member> members = new LinkedList<>();
Address address1 = new Address("127.0.0.1", 5702);
members.add(new MemberImpl(address1, MemberVersion.of("3.12"), false, UUID.randomUUID()));
Address address2 = new Address("127.0.0.1", 5703);
members.add(new MemberImpl(address2, MemberVersion.of("3.12"), false, UUID.randomUUID()));
UUID uuid = UUID.randomUUID();
UUID clusterId = UUID.randomUUID();
ClientMessage message = ClientAuthenticationCodec.encodeResponse((byte) 2, new Address("127.0.0.1", 5701), uuid, (byte) 1, "3.12", 271, clusterId, true);
AtomicReference<ClientMessage> reference = new AtomicReference<>(message);
ClientMessageEncoder encoder = new ClientMessageEncoder();
encoder.src(() -> reference.getAndSet(null));
ByteBuffer buffer = ByteBuffer.allocate(1000);
upcast(buffer).flip();
encoder.dst(buffer);
HandlerStatus result = encoder.onWrite();
assertEquals(CLEAN, result);
AtomicReference<ClientMessage> resultingMessage = new AtomicReference<>();
ClientMessageDecoder decoder = new ClientMessageDecoder(null, resultingMessage::set, null);
decoder.setNormalPacketsRead(SwCounter.newSwCounter());
upcast(buffer).position(buffer.limit());
decoder.src(buffer);
decoder.onRead();
assertEquals(message.getMessageType(), resultingMessage.get().getMessageType());
assertEquals(message.getFrameLength(), resultingMessage.get().getFrameLength());
assertEquals(message.getHeaderFlags(), resultingMessage.get().getHeaderFlags());
assertEquals(message.getPartitionId(), resultingMessage.get().getPartitionId());
ClientAuthenticationCodec.ResponseParameters parameters = ClientAuthenticationCodec.decodeResponse(resultingMessage.get());
assertEquals(2, parameters.status);
assertEquals(new Address("127.0.0.1", 5701), parameters.address);
assertEquals(uuid, parameters.memberUuid);
assertEquals(1, parameters.serializationVersion);
assertEquals("3.12", parameters.serverHazelcastVersion);
assertEquals(271, parameters.partitionCount);
assertEquals(clusterId, parameters.clusterId);
assertEquals(true, parameters.failoverSupported);
}
use of com.hazelcast.cluster.impl.MemberImpl in project hazelcast by hazelcast.
the class TransactionManagerServiceImpl method memberRemoved.
@Override
public void memberRemoved(MembershipServiceEvent event) {
MemberImpl member = event.getMember();
final UUID uuid = member.getUuid();
if (nodeEngine.isRunning()) {
logger.info("Committing/rolling-back live transactions of " + member.getAddress() + ", UUID: " + uuid);
nodeEngine.getExecutionService().execute(ExecutionService.SYSTEM_EXECUTOR, () -> finalizeTransactionsOf(uuid));
} else if (logger.isFinestEnabled()) {
logger.finest("Will not commit/roll-back transactions of " + member.getAddress() + ", UUID: " + uuid + " because this member is not running");
}
}
use of com.hazelcast.cluster.impl.MemberImpl in project hazelcast by hazelcast.
the class MapPublisherCreateMessageTask method createInvocations.
private void createInvocations(Collection<MemberImpl> members, List<Future> futures) {
final OperationServiceImpl operationService = nodeEngine.getOperationService();
for (MemberImpl member : members) {
Predicate predicate = serializationService.toObject(parameters.predicate);
AccumulatorInfo accumulatorInfo = AccumulatorInfo.toAccumulatorInfo(parameters.mapName, parameters.cacheName, predicate, parameters.batchSize, parameters.bufferSize, parameters.delaySeconds, false, parameters.populate, parameters.coalesce);
PublisherCreateOperation operation = new PublisherCreateOperation(accumulatorInfo);
operation.setCallerUuid(endpoint.getUuid());
Address address = member.getAddress();
InvocationBuilder invocationBuilder = operationService.createInvocationBuilder(SERVICE_NAME, operation, address);
Future future = invocationBuilder.invoke();
futures.add(future);
}
}
use of com.hazelcast.cluster.impl.MemberImpl in project hazelcast by hazelcast.
the class CollectionService method dispatchEvent.
@Override
public void dispatchEvent(CollectionEvent event, ItemListener<Data> listener) {
final MemberImpl member = nodeEngine.getClusterService().getMember(event.getCaller());
ItemEvent<Data> itemEvent = new DataAwareItemEvent<Data>(event.getName(), event.getEventType(), event.getData(), member, serializationService);
if (member == null) {
if (logger.isInfoEnabled()) {
logger.info("Dropping event " + itemEvent + " from unknown address:" + event.getCaller());
}
return;
}
if (event.getEventType().equals(ItemEventType.ADDED)) {
listener.itemAdded(itemEvent);
} else {
listener.itemRemoved(itemEvent);
}
}
use of com.hazelcast.cluster.impl.MemberImpl in project hazelcast by hazelcast.
the class RaftService method promoteToCPMember.
public InternalCompletableFuture<Void> promoteToCPMember() {
InternalCompletableFuture<Void> future = newCompletableFuture();
if (!metadataGroupManager.isDiscoveryCompleted()) {
return complete(future, new IllegalStateException("CP Subsystem discovery is not completed yet!"));
}
if (nodeEngine.getLocalMember().isLiteMember()) {
return complete(future, new IllegalStateException("Lite members cannot be promoted to CP member!"));
}
if (getLocalCPMember() != null) {
future.complete(null);
return future;
}
MemberImpl localMember = nodeEngine.getLocalMember();
// Local member may be recovered during restart, for instance via Hot Restart,
// but Raft state cannot be recovered back.
// That's why we generate a new UUID while promoting a member to CP.
// This new UUID generation can be removed when Hot Restart allows to recover Raft state.
CPMemberInfo member = new CPMemberInfo(newUnsecureUUID(), localMember.getAddress());
logger.info("Adding new CP member: " + member);
invocationManager.invoke(getMetadataGroupId(), new AddCPMemberOp(member)).whenCompleteAsync((response, t) -> {
if (t == null) {
metadataGroupManager.initPromotedCPMember(member);
future.complete(null);
} else {
complete(future, t);
}
});
return future;
}
Aggregations