Search in sources :

Example 11 with KeyValuePair

use of org.infinispan.util.KeyValuePair in project infinispan by infinispan.

the class CheckAddressTask method getRequestMediaTypes.

private static KeyValuePair<MediaType, MediaType> getRequestMediaTypes(HotRodHeader header, Configuration configuration) {
    MediaType keyRequestType = header == null ? APPLICATION_UNKNOWN : header.getKeyMediaType();
    MediaType valueRequestType = header == null ? APPLICATION_UNKNOWN : header.getValueMediaType();
    if (header != null && HotRodVersion.HOTROD_28.isOlder(header.version)) {
        // Pre-2.8 clients always send protobuf payload to the metadata cache
        if (header.cacheName.equals(PROTOBUF_METADATA_CACHE_NAME)) {
            keyRequestType = APPLICATION_PROTOSTREAM;
            valueRequestType = APPLICATION_PROTOSTREAM;
        } else {
            // Pre-2.8 clients always sent query encoded as protobuf unless object store is used.
            if (header.op == HotRodOperation.QUERY) {
                boolean objectStorage = APPLICATION_OBJECT.match(configuration.encoding().valueDataType().mediaType());
                keyRequestType = objectStorage ? APPLICATION_JBOSS_MARSHALLING : APPLICATION_PROTOSTREAM;
                valueRequestType = objectStorage ? APPLICATION_JBOSS_MARSHALLING : APPLICATION_PROTOSTREAM;
            }
        }
    }
    return new KeyValuePair<>(keyRequestType, valueRequestType);
}
Also used : KeyValuePair(org.infinispan.util.KeyValuePair) MediaType(org.infinispan.commons.dataconversion.MediaType)

Example 12 with KeyValuePair

use of org.infinispan.util.KeyValuePair in project infinispan by infinispan.

the class JpaStore method publishKeys.

@Override
public Flowable<K> publishKeys(Predicate<? super K> filter) {
    return Flowable.using(() -> {
        EntityManager emStream = emf.createEntityManager();
        Session session = emStream.unwrap(Session.class);
        Criteria criteria = session.createCriteria(configuration.entityClass()).setProjection(Projections.id()).setReadOnly(true);
        if (setFetchSizeMinInteger) {
            criteria.setFetchSize(Integer.MIN_VALUE);
        }
        ScrollableResults results = criteria.scroll(ScrollMode.FORWARD_ONLY);
        return new KeyValuePair<>(emStream, results);
    }, kvp -> {
        ScrollableResults results = kvp.getValue();
        return Flowable.fromIterable(() -> new ScrollableResultsIterator(results, filter));
    }, kvp -> {
        try {
            kvp.getValue().close();
        } finally {
            kvp.getKey().close();
        }
    });
}
Also used : EntityManager(javax.persistence.EntityManager) KeyValuePair(org.infinispan.util.KeyValuePair) Criteria(org.hibernate.Criteria) ScrollableResults(org.hibernate.ScrollableResults) Session(org.hibernate.Session)

Example 13 with KeyValuePair

use of org.infinispan.util.KeyValuePair in project infinispan by infinispan.

the class AbstractHotRodClusterEventsTest method testConversionInCluster.

public void testConversionInCluster(Method m) {
    HotRodClient client1 = clients().get(0);
    HotRodClient client2 = clients().get(1);
    EventLogListener listener1 = new EventLogListener();
    Optional<KeyValuePair<String, List<byte[]>>> converterFactory = Optional.of(new KeyValuePair<String, List<byte[]>>("accepted-keyvalue-converter-factory", Collections.emptyList()));
    final byte[] key1 = k(m, "k1-");
    withClusterClientListener(client1, listener1, Optional.empty(), converterFactory, key1, false, () -> {
        byte[] value = v(m);
        byte[] key99 = k(m, "k-99");
        client2.put(key99, 0, 0, v(m));
        listener1.expectSingleCustomEvent(anyCache(), addLengthPrefix(key99));
        client2.put(key1, 0, 0, v(m));
        listener1.expectSingleCustomEvent(anyCache(), addLengthPrefix(key1, value));
        client2.remove(key99);
        listener1.expectSingleCustomEvent(anyCache(), addLengthPrefix(key99));
        client2.remove(key1);
        listener1.expectSingleCustomEvent(anyCache(), addLengthPrefix(key1));
    });
}
Also used : KeyValuePair(org.infinispan.util.KeyValuePair) HotRodClient(org.infinispan.server.hotrod.test.HotRodClient) ArrayList(java.util.ArrayList) List(java.util.List)

Example 14 with KeyValuePair

use of org.infinispan.util.KeyValuePair in project infinispan by infinispan.

the class AbstractHotRodClusterEventsTest method testFilteringInCluster.

public void testFilteringInCluster(Method m) {
    HotRodClient client1 = clients().get(0);
    HotRodClient client2 = clients().get(1);
    EventLogListener listener1 = new EventLogListener();
    Optional<KeyValuePair<String, List<byte[]>>> filterFactory = Optional.of(new KeyValuePair<String, List<byte[]>>("accepted-key-filter-factory", Collections.emptyList()));
    byte[] key1 = k(m, "k1-");
    withClusterClientListener(client1, listener1, filterFactory, Optional.empty(), key1, false, () -> {
        client2.put(k(m, "k-99"), 0, 0, v(m));
        listener1.expectNoEvents(Optional.empty());
        client2.remove(k(m, "k-99"));
        listener1.expectNoEvents(Optional.empty());
        client2.put(key1, 0, 0, v(m));
        listener1.expectOnlyCreatedEvent(anyCache(), key1);
        client1.remove(key1);
        listener1.expectOnlyRemovedEvent(anyCache(), key1);
    });
}
Also used : KeyValuePair(org.infinispan.util.KeyValuePair) HotRodClient(org.infinispan.server.hotrod.test.HotRodClient) ArrayList(java.util.ArrayList) List(java.util.List)

Example 15 with KeyValuePair

use of org.infinispan.util.KeyValuePair in project infinispan by infinispan.

the class AbstractHotRodClusterEventsTest method testParameterBasedFilteringInCluster.

public void testParameterBasedFilteringInCluster(Method m) {
    HotRodClient client1 = clients().get(0);
    HotRodClient client2 = clients().get(1);
    EventLogListener listener1 = new EventLogListener();
    byte[] dynamicAcceptedKey = new byte[] { 4, 5, 6 };
    Optional<KeyValuePair<String, List<byte[]>>> filterFactory = Optional.of(new KeyValuePair<>("accepted-key-filter-factory", Collections.singletonList(dynamicAcceptedKey)));
    withClusterClientListener(client1, listener1, filterFactory, Optional.empty(), null, false, () -> {
        byte[] key1 = k(m, "k1-");
        client2.put(k(m, "k-99"), 0, 0, v(m));
        listener1.expectNoEvents(Optional.empty());
        client2.remove(k(m, "k-99"));
        listener1.expectNoEvents(Optional.empty());
        client2.put(key1, 0, 0, v(m));
        listener1.expectNoEvents(Optional.empty());
        client2.put(dynamicAcceptedKey, 0, 0, v(m));
        listener1.expectOnlyCreatedEvent(anyCache(), dynamicAcceptedKey);
        client1.remove(dynamicAcceptedKey);
        listener1.expectOnlyRemovedEvent(anyCache(), dynamicAcceptedKey);
    });
}
Also used : KeyValuePair(org.infinispan.util.KeyValuePair) HotRodClient(org.infinispan.server.hotrod.test.HotRodClient)

Aggregations

KeyValuePair (org.infinispan.util.KeyValuePair)26 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)8 ArrayList (java.util.ArrayList)7 List (java.util.List)6 UserPB (org.infinispan.client.hotrod.query.testdomain.protobuf.UserPB)6 ContinuousQueryListener (org.infinispan.query.api.continuous.ContinuousQueryListener)6 QueryFactory (org.infinispan.query.dsl.QueryFactory)6 User (org.infinispan.query.dsl.embedded.testdomain.User)6 HotRodClient (org.infinispan.server.hotrod.test.HotRodClient)4 Iterator (java.util.Iterator)3 Map (java.util.Map)3 Set (java.util.Set)3 InvocationStage (org.infinispan.interceptors.InvocationStage)3 SyncInvocationStage (org.infinispan.interceptors.SyncInvocationStage)3 Metadata (org.infinispan.metadata.Metadata)3 Flowable (io.reactivex.rxjava3.core.Flowable)2 ByteBuffer (java.nio.ByteBuffer)2 TreeSet (java.util.TreeSet)2 CompletionStage (java.util.concurrent.CompletionStage)2 Predicate (java.util.function.Predicate)2