Search in sources :

Example 21 with InternalSerializationService

use of com.hazelcast.internal.serialization.InternalSerializationService in project hazelcast by hazelcast.

the class AbstractInternalQueryCache method doFullKeyScan.

protected void doFullKeyScan(Predicate predicate, Set<K> resultingSet) {
    InternalSerializationService serializationService = this.serializationService;
    CachedQueryEntry queryEntry = new CachedQueryEntry();
    Set<Map.Entry<Data, QueryCacheRecord>> entries = recordStore.entrySet();
    for (Map.Entry<Data, QueryCacheRecord> entry : entries) {
        Data keyData = entry.getKey();
        QueryCacheRecord record = entry.getValue();
        Object value = record.getValue();
        queryEntry.init(serializationService, keyData, value, Extractors.empty());
        boolean valid = predicate.apply(queryEntry);
        if (valid) {
            resultingSet.add((K) queryEntry.getKey());
        }
    }
}
Also used : CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) QueryCacheRecord(com.hazelcast.map.impl.querycache.subscriber.record.QueryCacheRecord) Data(com.hazelcast.nio.serialization.Data) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) AbstractMap(java.util.AbstractMap) IMap(com.hazelcast.core.IMap) Map(java.util.Map)

Example 22 with InternalSerializationService

use of com.hazelcast.internal.serialization.InternalSerializationService in project hazelcast by hazelcast.

the class NodeQueryCacheEventService method canPassFilter.

private boolean canPassFilter(LocalEntryEventData localEntryEventData, EventFilter filter) {
    if (filter == null || filter instanceof TrueEventFilter) {
        return true;
    }
    NodeEngine nodeEngine = mapServiceContext.getNodeEngine();
    SerializationService serializationService = nodeEngine.getSerializationService();
    Data keyData = localEntryEventData.getKeyData();
    Object value = getValueOrOldValue(localEntryEventData);
    QueryableEntry entry = new QueryEntry((InternalSerializationService) serializationService, keyData, value, Extractors.empty());
    return filter.eval(entry);
}
Also used : NodeEngine(com.hazelcast.spi.NodeEngine) QueryEntry(com.hazelcast.query.impl.QueryEntry) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.spi.serialization.SerializationService) LocalCacheWideEventData(com.hazelcast.map.impl.querycache.event.LocalCacheWideEventData) EventData(com.hazelcast.map.impl.event.EventData) Data(com.hazelcast.nio.serialization.Data) LocalEntryEventData(com.hazelcast.map.impl.querycache.event.LocalEntryEventData) TrueEventFilter(com.hazelcast.spi.impl.eventservice.impl.TrueEventFilter) QueryableEntry(com.hazelcast.query.impl.QueryableEntry)

Example 23 with InternalSerializationService

use of com.hazelcast.internal.serialization.InternalSerializationService in project hazelcast by hazelcast.

the class DefaultQueryCache method addIndex.

@Override
public void addIndex(String attribute, boolean ordered) {
    getIndexes().addOrGetIndex(attribute, ordered);
    InternalSerializationService serializationService = context.getSerializationService();
    Set<Map.Entry<Data, QueryCacheRecord>> entries = recordStore.entrySet();
    for (Map.Entry<Data, QueryCacheRecord> entry : entries) {
        Data keyData = entry.getKey();
        QueryCacheRecord record = entry.getValue();
        Object value = record.getValue();
        QueryEntry queryable = new QueryEntry(serializationService, keyData, value, Extractors.empty());
        indexes.saveEntryIndex(queryable, null);
    }
}
Also used : QueryEntry(com.hazelcast.query.impl.QueryEntry) QueryEntry(com.hazelcast.query.impl.QueryEntry) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) QueryCacheRecord(com.hazelcast.map.impl.querycache.subscriber.record.QueryCacheRecord) Data(com.hazelcast.nio.serialization.Data) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) IMap(com.hazelcast.core.IMap)

Example 24 with InternalSerializationService

use of com.hazelcast.internal.serialization.InternalSerializationService in project hazelcast by hazelcast.

the class ClientConnectionManagerImpl method authenticate.

private void authenticate(final Address target, final ClientConnection connection, final boolean asOwner, final AuthenticationFuture callback) {
    SerializationService ss = client.getSerializationService();
    final ClientClusterServiceImpl clusterService = (ClientClusterServiceImpl) client.getClientClusterService();
    final ClientPrincipal principal = clusterService.getPrincipal();
    byte serializationVersion = ((InternalSerializationService) client.getSerializationService()).getVersion();
    String uuid = null;
    String ownerUuid = null;
    if (principal != null) {
        uuid = principal.getUuid();
        ownerUuid = principal.getOwnerUuid();
    }
    ClientMessage clientMessage = encodeAuthenticationRequest(asOwner, ss, serializationVersion, uuid, ownerUuid);
    ClientInvocation clientInvocation = new ClientInvocation(client, clientMessage, connection);
    ClientInvocationFuture future = clientInvocation.invokeUrgent();
    if (asOwner && clientInvocation.getSendConnection() != null) {
        correlationIddOfLastAuthentication.set(clientInvocation.getClientMessage().getCorrelationId());
    }
    future.andThen(new ExecutionCallback<ClientMessage>() {

        @Override
        public void onResponse(ClientMessage response) {
            ClientAuthenticationCodec.ResponseParameters result = ClientAuthenticationCodec.decodeResponse(response);
            AuthenticationStatus authenticationStatus = AuthenticationStatus.getById(result.status);
            switch(authenticationStatus) {
                case AUTHENTICATED:
                    connection.setConnectedServerVersion(result.serverHazelcastVersion);
                    connection.setRemoteEndpoint(result.address);
                    if (asOwner) {
                        if (!(correlationIddOfLastAuthentication.get() == response.getCorrelationId())) {
                            //if not same, client already gave up on this and send another authentication.
                            onFailure(new AuthenticationException("Owner authentication response from address " + target + " is late. Dropping the response. Principal : " + principal));
                            return;
                        }
                        connection.setIsAuthenticatedAsOwner();
                        ClientPrincipal principal = new ClientPrincipal(result.uuid, result.ownerUuid);
                        clusterService.setPrincipal(principal);
                        clusterService.setOwnerConnectionAddress(connection.getEndPoint());
                        logger.info("Setting " + connection + " as owner  with principal " + principal);
                    }
                    onAuthenticated(target, connection);
                    callback.onSuccess(connection, asOwner);
                    break;
                case CREDENTIALS_FAILED:
                    onFailure(new AuthenticationException("Invalid credentials! Principal: " + principal));
                    break;
                default:
                    onFailure(new AuthenticationException("Authentication status code not supported. status: " + authenticationStatus));
            }
        }

        @Override
        public void onFailure(Throwable t) {
            onAuthenticationFailed(target, connection, t);
            callback.onFailure(t);
        }
    });
}
Also used : AuthenticationException(com.hazelcast.client.AuthenticationException) SerializationService(com.hazelcast.spi.serialization.SerializationService) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ClientPrincipal(com.hazelcast.client.impl.client.ClientPrincipal) ClientInvocationFuture(com.hazelcast.client.spi.impl.ClientInvocationFuture) AuthenticationStatus(com.hazelcast.client.impl.protocol.AuthenticationStatus) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) ClientClusterServiceImpl(com.hazelcast.client.spi.impl.ClientClusterServiceImpl)

Example 25 with InternalSerializationService

use of com.hazelcast.internal.serialization.InternalSerializationService in project hazelcast by hazelcast.

the class TransactionalMapProxy method keySet.

@Override
@SuppressWarnings("unchecked")
public Set keySet(Predicate predicate) {
    checkTransactionState();
    checkNotNull(predicate, "Predicate should not be null!");
    checkNotInstanceOf(PagingPredicate.class, predicate, "Paging is not supported for Transactional queries!");
    MapQueryEngine queryEngine = mapServiceContext.getMapQueryEngine(name);
    SerializationService serializationService = getNodeEngine().getSerializationService();
    Query query = Query.of().mapName(name).predicate(predicate).iterationType(IterationType.KEY).build();
    QueryResult queryResult = queryEngine.execute(query, Target.ALL_NODES);
    Set result = QueryResultUtils.transformToSet(serializationService, queryResult, predicate, IterationType.KEY, true);
    // TODO: Can't we just use the original set?
    Set<Object> keySet = new HashSet<Object>(result);
    Extractors extractors = mapServiceContext.getExtractors(name);
    for (Map.Entry<Data, TxnValueWrapper> entry : txMap.entrySet()) {
        Data keyData = entry.getKey();
        if (!Type.REMOVED.equals(entry.getValue().type)) {
            Object value = (entry.getValue().value instanceof Data) ? toObjectIfNeeded(entry.getValue().value) : entry.getValue().value;
            QueryableEntry queryEntry = new CachedQueryEntry((InternalSerializationService) serializationService, keyData, value, extractors);
            // apply predicate on txMap
            if (predicate.apply(queryEntry)) {
                Object keyObject = serializationService.toObject(keyData);
                keySet.add(keyObject);
            }
        } else {
            // meanwhile remove keys which are not in txMap
            Object keyObject = serializationService.toObject(keyData);
            keySet.remove(keyObject);
        }
    }
    return keySet;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Query(com.hazelcast.map.impl.query.Query) InternalSerializationService(com.hazelcast.internal.serialization.InternalSerializationService) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) QueryResult(com.hazelcast.map.impl.query.QueryResult) Extractors(com.hazelcast.query.impl.getters.Extractors) MapQueryEngine(com.hazelcast.map.impl.query.MapQueryEngine) CachedQueryEntry(com.hazelcast.query.impl.CachedQueryEntry) HashMap(java.util.HashMap) Map(java.util.Map) TransactionalMap(com.hazelcast.core.TransactionalMap) QueryableEntry(com.hazelcast.query.impl.QueryableEntry) HashSet(java.util.HashSet)

Aggregations

InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)38 QuickTest (com.hazelcast.test.annotation.QuickTest)15 Test (org.junit.Test)15 Data (com.hazelcast.nio.serialization.Data)14 DefaultSerializationServiceBuilder (com.hazelcast.internal.serialization.impl.DefaultSerializationServiceBuilder)12 Map (java.util.Map)6 CachedQueryEntry (com.hazelcast.query.impl.CachedQueryEntry)5 IMap (com.hazelcast.core.IMap)4 QueryCacheRecord (com.hazelcast.map.impl.querycache.subscriber.record.QueryCacheRecord)4 SerializationService (com.hazelcast.spi.serialization.SerializationService)4 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)3 QueryEntry (com.hazelcast.query.impl.QueryEntry)3 QueryableEntry (com.hazelcast.query.impl.QueryableEntry)3 SerializationConfig (com.hazelcast.config.SerializationConfig)2 PartitioningStrategy (com.hazelcast.core.PartitioningStrategy)2 TransactionalMap (com.hazelcast.core.TransactionalMap)2 NearCacheRecord (com.hazelcast.internal.nearcache.NearCacheRecord)2 DefaultNearCache (com.hazelcast.internal.nearcache.impl.DefaultNearCache)2 AbstractNearCacheRecordStore (com.hazelcast.internal.nearcache.impl.store.AbstractNearCacheRecordStore)2 SerializationServiceBuilder (com.hazelcast.internal.serialization.SerializationServiceBuilder)2