use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class OperationRunnerImpl method run.
@Override
public boolean run(Packet packet) throws Exception {
long startNanos = System.nanoTime();
boolean publishCurrentTask = publishCurrentTask();
if (publishCurrentTask) {
currentTask = packet;
}
ServerConnection connection = packet.getConn();
Address caller = connection.getRemoteAddress();
UUID callerUuid = connection.getRemoteUuid();
Operation op = null;
try {
Object object = nodeEngine.toObject(packet);
op = (Operation) object;
op.setNodeEngine(nodeEngine);
setCallerAddress(op, caller);
setConnection(op, connection);
setCallerUuidIfNotSet(op, callerUuid);
setOperationResponseHandler(op);
if (!ensureValidMember(op)) {
return false;
}
if (publishCurrentTask) {
currentTask = null;
}
return run(op, startNanos);
} catch (Throwable throwable) {
// If exception happens we need to extract the callId from the bytes directly!
long callId = extractOperationCallId(packet);
outboundResponseHandler.send(connection.getConnectionManager(), caller, new ErrorResponse(throwable, callId, packet.isUrgent()));
logOperationDeserializationException(throwable, callId);
throw ExceptionUtil.rethrow(throwable);
} finally {
if (op != null) {
op.clearThreadContext();
}
if (publishCurrentTask) {
currentTask = null;
}
}
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class InboundResponseHandler method accept.
@Override
public void accept(Packet packet) {
checkNotNull(packet, "packet can't be null");
checkTrue(packet.getPacketType() == OPERATION, "Packet type is not OPERATION");
checkTrue(packet.isFlagRaised(FLAG_OP_RESPONSE), "FLAG_OP_RESPONSE is not set");
byte[] bytes = packet.toByteArray();
int typeId = Bits.readInt(bytes, OFFSET_TYPE_ID, useBigEndian);
long callId = Bits.readLong(bytes, OFFSET_CALL_ID, useBigEndian);
Address sender = packet.getConn().getRemoteAddress();
try {
switch(typeId) {
case NORMAL_RESPONSE:
byte backupAcks = bytes[OFFSET_BACKUP_ACKS];
notifyNormalResponse(callId, packet, backupAcks, sender);
break;
case BACKUP_ACK_RESPONSE:
notifyBackupComplete(callId);
break;
case CALL_TIMEOUT_RESPONSE:
notifyCallTimeout(callId, sender);
break;
case ERROR_RESPONSE:
ErrorResponse errorResponse = serializationService.toObject(packet);
notifyErrorResponse(callId, errorResponse.getCause(), sender);
break;
default:
logger.severe("Unrecognized type: " + typeId + " packet:" + packet);
}
} catch (Throwable e) {
logger.severe("While processing response...", e);
}
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class InvokeOnPartitions method invokeOnAllPartitions.
private void invokeOnAllPartitions() {
if (memberPartitions.isEmpty()) {
future.complete(Collections.EMPTY_MAP);
return;
}
for (final Map.Entry<Address, List<Integer>> mp : memberPartitions.entrySet()) {
final Address address = mp.getKey();
List<Integer> partitions = mp.getValue();
PartitionIteratingOperation op = new PartitionIteratingOperation(operationFactory, toIntArray(partitions));
operationService.createInvocationBuilder(serviceName, op, address).setTryCount(TRY_COUNT).setTryPauseMillis(TRY_PAUSE_MILLIS).invoke().whenCompleteAsync(new FirstAttemptExecutionCallback(partitions));
}
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class CacheSerializationTest method testCachePartitionEventData.
@Test
public void testCachePartitionEventData() throws UnknownHostException {
Address address = new Address("127.0.0.1", 5701);
Member member = new MemberImpl(address, MemberVersion.UNKNOWN, true);
CachePartitionEventData cachePartitionEventData = new CachePartitionEventData("test", 1, member);
CachePartitionEventData deserialized = service.toObject(cachePartitionEventData);
assertEquals(cachePartitionEventData, deserialized);
}
use of com.hazelcast.cluster.Address in project hazelcast by hazelcast.
the class CachePartitionLostListenerTest method test_partitionLostListenerInvoked_whenNodeCrashed.
@Test
public void test_partitionLostListenerInvoked_whenNodeCrashed() {
List<HazelcastInstance> instances = getCreatedInstancesShuffledAfterWarmedUp(2);
HazelcastInstance survivingInstance = instances.get(0);
HazelcastInstance terminatingInstance = instances.get(1);
HazelcastServerCachingProvider cachingProvider = createServerCachingProvider(survivingInstance);
CacheManager cacheManager = cachingProvider.getCacheManager();
CacheConfig<Integer, String> config = new CacheConfig<Integer, String>();
config.setBackupCount(0);
Cache<Integer, String> cache = cacheManager.createCache(getIthCacheName(0), config);
ICache iCache = cache.unwrap(ICache.class);
final EventCollectingCachePartitionLostListener listener = new EventCollectingCachePartitionLostListener(0);
iCache.addPartitionLostListener(listener);
final Set<Integer> survivingPartitionIds = new HashSet<Integer>();
Node survivingNode = getNode(survivingInstance);
Address survivingAddress = survivingNode.getThisAddress();
for (IPartition partition : survivingNode.getPartitionService().getPartitions()) {
if (survivingAddress.equals(partition.getReplicaAddress(0))) {
survivingPartitionIds.add(partition.getPartitionId());
}
}
terminatingInstance.getLifecycleService().terminate();
waitAllForSafeState(survivingInstance);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
final List<CachePartitionLostEvent> events = listener.getEvents();
assertFalse(events.isEmpty());
for (CachePartitionLostEvent event : events) {
assertFalse(survivingPartitionIds.contains(event.getPartitionId()));
}
}
});
cacheManager.destroyCache(getIthCacheName(0));
cacheManager.close();
cachingProvider.close();
}
Aggregations