use of com.hazelcast.spi.serialization.SerializationService in project hazelcast by hazelcast.
the class WanPublisherConfigTest method testSerialization.
@Test
public void testSerialization() {
Map<String, Comparable> properties = new HashMap<String, Comparable>();
properties.put("key", "value");
config.setGroupName("groupName");
config.setQueueCapacity(500);
config.setQueueFullBehavior(WANQueueFullBehavior.THROW_EXCEPTION);
config.setProperties(properties);
config.setClassName("className");
config.setImplementation("implementation");
SerializationService serializationService = new DefaultSerializationServiceBuilder().build();
Data serialized = serializationService.toData(config);
WanPublisherConfig deserialized = serializationService.toObject(serialized);
assertWanPublisherConfig(config, deserialized);
}
use of com.hazelcast.spi.serialization.SerializationService in project hazelcast by hazelcast.
the class WanReplicationConfigTest method testSerialization.
@Test
public void testSerialization() {
Map<String, Comparable> properties = new HashMap<String, Comparable>();
properties.put("key", "value");
WanConsumerConfig wanConsumerConfig = new WanConsumerConfig();
wanConsumerConfig.setProperties(properties);
wanConsumerConfig.setClassName("className");
wanConsumerConfig.setImplementation("implementation");
WanPublisherConfig wanPublisherConfig1 = new WanPublisherConfig();
WanPublisherConfig wanPublisherConfig2 = new WanPublisherConfig();
List<WanPublisherConfig> publisherConfigs = new LinkedList<WanPublisherConfig>();
publisherConfigs.add(wanPublisherConfig1);
config.setName("name");
config.setWanConsumerConfig(wanConsumerConfig);
config.setWanPublisherConfigs(publisherConfigs);
config.addWanPublisherConfig(wanPublisherConfig2);
SerializationService serializationService = new DefaultSerializationServiceBuilder().build();
Data serialized = serializationService.toData(config);
WanReplicationConfig deserialized = serializationService.toObject(serialized);
assertWanReplicationConfig(config, deserialized);
}
use of com.hazelcast.spi.serialization.SerializationService in project hazelcast by hazelcast.
the class DefaultMapProjectMessageTask method reduce.
@Override
protected List<Data> reduce(Collection<QueryResult> results) {
if (results.isEmpty()) {
return Collections.emptyList();
}
QueryResult combinedResult = null;
for (QueryResult result : results) {
if (combinedResult == null) {
combinedResult = result;
} else {
combinedResult.combine(result);
}
}
Set result = QueryResultUtils.transformToSet(nodeEngine.getSerializationService(), combinedResult, getPredicate(), IterationType.VALUE, false);
List<Data> serialized = new ArrayList<Data>(result.size());
SerializationService serializationService = nodeEngine.getSerializationService();
for (Object row : result) {
serialized.add(serializationService.toData(row));
}
return serialized;
}
use of com.hazelcast.spi.serialization.SerializationService in project hazelcast by hazelcast.
the class AbstractCollectionProxyImpl method getAll.
private Collection<E> getAll() {
CollectionGetAllOperation operation = new CollectionGetAllOperation(name);
SerializableList result = invoke(operation);
List<Data> collection = result.getCollection();
SerializationService serializationService = getNodeEngine().getSerializationService();
return new UnmodifiableLazyList<E>(collection, serializationService);
}
use of com.hazelcast.spi.serialization.SerializationService in project hazelcast by hazelcast.
the class AbstractClientCacheProxy method getInternal.
protected Object getInternal(final K key, ExpiryPolicy expiryPolicy, boolean async) {
final long start = System.nanoTime();
ensureOpen();
validateNotNull(key);
final Data keyData = toData(key);
Object cached = getCachedValue(keyData, !async);
if (cached != NOT_CACHED) {
return asCompletedFutureOrValue(cached, async);
}
final long reservationId = tryReserveForUpdate(keyData);
final Data expiryPolicyData = toData(expiryPolicy);
ClientMessage request = CacheGetCodec.encodeRequest(nameWithPrefix, keyData, expiryPolicyData);
ClientInvocationFuture future;
try {
final int partitionId = clientContext.getPartitionService().getPartitionId(keyData);
final HazelcastClientInstanceImpl client = (HazelcastClientInstanceImpl) clientContext.getHazelcastInstance();
final ClientInvocation clientInvocation = new ClientInvocation(client, request, partitionId);
future = clientInvocation.invoke();
} catch (Throwable t) {
invalidateNearCache(keyData);
throw rethrow(t);
}
SerializationService serializationService = clientContext.getSerializationService();
ClientDelegatingFuture<V> delegatingFuture = new ClientDelegatingFuture<V>(future, serializationService, cacheGetResponseDecoder);
if (async) {
if (nearCache != null) {
delegatingFuture.andThenInternal(new ExecutionCallback<Data>() {
public void onResponse(Data valueData) {
storeInNearCache(keyData, valueData, null, reservationId, false);
if (statisticsEnabled) {
handleStatisticsOnGet(start, valueData);
}
}
public void onFailure(Throwable t) {
invalidateNearCache(keyData);
}
}, false);
}
return delegatingFuture;
} else {
try {
V value = toObject(delegatingFuture.get());
if (nearCache != null) {
storeInNearCache(keyData, (Data) delegatingFuture.getResponse(), value, reservationId, false);
}
if (statisticsEnabled) {
handleStatisticsOnGet(start, value);
}
return value;
} catch (Throwable e) {
invalidateNearCache(keyData);
throw rethrowAllowedTypeFirst(e, CacheException.class);
}
}
}
Aggregations