Package org.infinispan.protostream

Examples of org.infinispan.protostream.SerializationContext


      return user;
   }

   private void readWithProtoStream(byte[] bytes, long[] result) throws IOException, DescriptorParserException {
      Configuration cfg = new ConfigurationBuilder().setLogOutOfSequenceReads(false).build();
      SerializationContext ctx = createContext(cfg);
      ByteArrayInputStream bais = new ByteArrayInputStream(bytes);

      long tStart = System.nanoTime();
      for (int i = 0; i < NUM_INNER_LOOPS; i++) {
         ProtobufUtil.readFrom(ctx, bais, User.class);
View Full Code Here


      log.infof("Java serialization read duration    = %d ns", result[0]);
   }

   private byte[] writeWithProtoStream(User user, long[] result) throws IOException, DescriptorParserException {
      Configuration cfg = new ConfigurationBuilder().setLogOutOfSequenceWrites(false).build();
      SerializationContext ctx = createContext(cfg);
      ByteArrayOutputStream out = new ByteArrayOutputStream(1024);

      long tStart = System.nanoTime();
      for (int i = 0; i < NUM_INNER_LOOPS; i++) {
         ProtobufUtil.writeTo(ctx, out, user);
View Full Code Here

* @since 1.0
*/
public abstract class AbstractProtoStreamTest {

   protected SerializationContext createContext() throws IOException, Descriptors.DescriptorValidationException {
      SerializationContext ctx = ProtobufUtil.newSerializationContext();
      MarshallerRegistration.registerMarshallers(ctx);
      return ctx;
   }
View Full Code Here

      MarshallerRegistration.registerMarshallers(ctx);
      return ctx;
   }

   protected SerializationContext createContext(Configuration cfg) throws IOException, Descriptors.DescriptorValidationException {
      SerializationContext ctx = ProtobufUtil.newSerializationContext(cfg);
      MarshallerRegistration.registerMarshallers(ctx);
      return ctx;
   }
View Full Code Here

*/
public class UnknownFieldSetImplTest extends AbstractProtoStreamTest {

   @Test
   public void testReadWrite() throws Exception {
      SerializationContext ctx = createContext();

      User user = new User();
      user.setId(1);
      user.setName("John");
      user.setSurname("Batman");
View Full Code Here

      return user;
   }

   private void readWithProtoStream(byte[] bytes, long[] result) throws IOException, Descriptors.DescriptorValidationException {
      Configuration cfg = new ConfigurationBuilder().setLogOutOfSequenceReads(false).build();
      SerializationContext ctx = createContext(cfg);
      ByteArrayInputStream bais = new ByteArrayInputStream(bytes);

      long tStart = System.nanoTime();
      for (int i = 0; i < NUM_INNER_LOOPS; i++) {
         ProtobufUtil.readFrom(ctx, bais, User.class);
View Full Code Here

      log.infof("Java serialization read duration    = %d ns", result[0]);
   }

   private byte[] writeWithProtoStream(User user, long[] result) throws IOException, Descriptors.DescriptorValidationException {
      Configuration cfg = new ConfigurationBuilder().setLogOutOfSequenceWrites(false).build();
      SerializationContext ctx = createContext(cfg);
      ByteArrayOutputStream out = new ByteArrayOutputStream(1024);

      long tStart = System.nanoTime();
      for (int i = 0; i < NUM_INNER_LOOPS; i++) {
         ProtobufUtil.writeTo(ctx, out, user);
View Full Code Here

            }
            results.add(row);
         }
      } else {
         results = new ArrayList<Object>(response.getResults().size());
         SerializationContext serCtx = getSerializationContext();
         for (WrappedMessage r : response.getResults()) {
            try {
               byte[] bytes = (byte[]) r.getValue();
               Object o = ProtobufUtil.fromWrappedByteArray(serCtx, bytes);
               results.add(o);
View Full Code Here

            sc2.setAscending(sc.getSortOrder() == SortOrder.ASC);
            scl.add(sc2);
         }
         queryRequest.setSortCriteria(scl);
      }
      SerializationContext serCtx = remoteQuery.getSerializationContext();
      byte[] requestBytes;
      try {
         requestBytes = ProtobufUtil.toByteArray(serCtx, queryRequest);
      } catch (IOException e) {
         throw new CacheException(e)//todo [anistor] need better exception handling
View Full Code Here

         throw new CacheException("An exception has occurred during query execution", e);
      }
   }

   private byte[] executeQuery(AdvancedCache<byte[], byte[]> cache, byte[] query) throws IOException {
      final SerializationContext serCtx = ProtobufMetadataManager.getSerializationContext(cache.getCacheManager());

      QueryRequest request = ProtobufUtil.fromByteArray(serCtx, query, 0, query.length, QueryRequest.class);

      SearchManager searchManager = Search.getSearchManager(cache);
      Query luceneQuery;
      List<String> projections;
      Class targetEntity;
      Descriptors.Descriptor messageDescriptor;

      QueryParser queryParser = new QueryParser();
      SearchFactoryIntegrator searchFactory = (SearchFactoryIntegrator) searchManager.getSearchFactory();
      if (cache.getCacheConfiguration().compatibility().enabled()) {
         final QueryInterceptor queryInterceptor = ComponentRegistryUtils.getQueryInterceptor(cache);
         EntityNamesResolver entityNamesResolver = new EntityNamesResolver() {
            @Override
            public Class<?> getClassFromName(String entityName) {
               MessageMarshaller messageMarshaller = (MessageMarshaller) serCtx.getMarshaller(entityName);
               Class clazz = messageMarshaller.getJavaClass();
               Boolean isIndexed = queryInterceptor.getKnownClasses().get(clazz);
               return isIndexed != null && isIndexed ? clazz : null;
            }
         };

         LuceneProcessingChain processingChain = new LuceneProcessingChain.Builder(searchFactory, entityNamesResolver)
               .buildProcessingChainForClassBasedEntities();

         LuceneQueryParsingResult parsingResult = queryParser.parseQuery(request.getJpqlString(), processingChain);

         MessageMarshaller messageMarshaller = (MessageMarshaller) serCtx.getMarshaller(parsingResult.getTargetEntity());
         messageDescriptor = serCtx.getMessageDescriptor(messageMarshaller.getTypeName());
         targetEntity = parsingResult.getTargetEntity();
         projections = parsingResult.getProjections();
         luceneQuery = parsingResult.getQuery();
      } else {
         EntityNamesResolver entityNamesResolver = new EntityNamesResolver() {
            @Override
            public Class<?> getClassFromName(String entityName) {
               return serCtx.canMarshall(entityName) ? ProtobufValueWrapper.class : null;
            }
         };

         FieldBridgeProvider fieldBridgeProvider = new FieldBridgeProvider() {
            @Override
            public FieldBridge getFieldBridge(String type, String propertyPath) {
               Descriptors.Descriptor md = serCtx.getMessageDescriptor(type);
               Descriptors.FieldDescriptor fd = getFieldDescriptor(md, propertyPath);
               switch (fd.getType()) {
                  case DOUBLE:
                     return new NullEncodingDoubleNumericFieldBridge(NULL_TOKEN);
                  case FLOAT:
                     return new NullEncodingFloatNumericFieldBridge(NULL_TOKEN);
                  case INT64:
                  case UINT64:
                  case FIXED64:
                  case SFIXED64:
                  case SINT64:
                     return new NullEncodingLongNumericFieldBridge(NULL_TOKEN);
                  case INT32:
                  case FIXED32:
                  case UINT32:
                  case SFIXED32:
                  case SINT32:
                  case BOOL:
                  case ENUM:
                     return new NullEncodingIntegerNumericFieldBridge(NULL_TOKEN);
                  case STRING:
                  case BYTES:
                  case GROUP:
                  case MESSAGE:
                     return new NullEncodingTwoWayFieldBridge(BridgeFactory.STRING, NULL_TOKEN);
               }
               return null;
            }
         };

         LuceneProcessingChain processingChain = new LuceneProcessingChain.Builder(searchFactory, entityNamesResolver)
               .buildProcessingChainForDynamicEntities(fieldBridgeProvider);
         LuceneQueryParsingResult parsingResult = queryParser.parseQuery(request.getJpqlString(), processingChain);
         targetEntity = parsingResult.getTargetEntity();
         messageDescriptor = serCtx.getMessageDescriptor(parsingResult.getTargetEntityName());
         projections = parsingResult.getProjections();

         QueryBuilder qb = searchManager.getSearchFactory().buildQueryBuilder().forEntity(targetEntity).get();
         luceneQuery = qb.bool()
               .must(qb.keyword().onField(TYPE_FIELD_NAME).ignoreFieldBridge().ignoreAnalyzer().matching(messageDescriptor.getFullName()).createQuery())
View Full Code Here

TOP

Related Classes of org.infinispan.protostream.SerializationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.