@Override
 public void cacheManagerStarting(GlobalComponentRegistry gcr, GlobalConfiguration globalCfg) {
   Map<Integer, AdvancedExternalizer<?>> externalizerMap =
       globalCfg.serialization().advancedExternalizers();
   externalizerMap.put(1000, new NodeKey.Externalizer());
   externalizerMap.put(1001, new Fqn.Externalizer());
 }
Exemplo n.º 2
0
 private void writeAdvancedSerializers(
     XMLExtendedStreamWriter writer, GlobalConfiguration globalConfiguration)
     throws XMLStreamException {
   Map<Integer, AdvancedExternalizer<?>> externalizers =
       globalConfiguration.serialization().advancedExternalizers();
   for (Entry<Integer, AdvancedExternalizer<?>> externalizer : externalizers.entrySet()) {
     writer.writeStartElement(Element.ADVANCED_EXTERNALIZER);
     writer.writeAttribute(Attribute.ID, Integer.toString(externalizer.getKey()));
     writer.writeAttribute(Attribute.CLASS, externalizer.getValue().getClass().getName());
     writer.writeEndElement();
   }
 }
Exemplo n.º 3
0
 private void writeSerialization(
     XMLExtendedStreamWriter writer, GlobalConfiguration globalConfiguration)
     throws XMLStreamException {
   SerializationConfiguration serialization = globalConfiguration.serialization();
   AttributeSet attributes = serialization.attributes();
   if (attributes.isModified()) {
     writer.writeStartElement(Element.SERIALIZATION);
     attributes.write(writer, SerializationConfiguration.MARSHALLER, Attribute.MARSHALLER_CLASS);
     if (attributes.attribute(SerializationConfiguration.VERSION).isModified()) {
       writer.writeAttribute(Attribute.VERSION, Version.decodeVersion(serialization.version()));
     }
     writeAdvancedSerializers(writer, globalConfiguration);
     writer.writeEndElement();
   }
 }
  @Override
  public void start() {
    super.start();

    baseCfg.setObjectTable(externalizerTable);

    proxy = new ExternalizerTableProxy(externalizerTable);
    baseCfg.setObjectTable(proxy);

    ClassResolver classResolver = globalCfg.serialization().classResolver();
    if (classResolver == null) {
      // Override the class resolver with one that can detect injected
      // classloaders via AdvancedCache.with(ClassLoader) calls.
      ClassLoader cl = cfg == null ? globalCfg.classLoader() : cfg.classLoader();
      classResolver = new EmbeddedContextClassResolver(cl, icc);
    }

    baseCfg.setClassResolver(classResolver);
  }
Exemplo n.º 5
0
  private void loadForeignMarshallables(GlobalConfiguration globalCfg) {
    log.trace("Loading user defined externalizers");
    for (Map.Entry<Integer, AdvancedExternalizer<?>> config :
        globalCfg.serialization().advancedExternalizers().entrySet()) {
      AdvancedExternalizer<?> ext = config.getValue();

      // If no XML or programmatic config, id in annotation is used
      // as long as it's not default one (meaning, user did not set it).
      // If XML or programmatic config in use ignore @Marshalls annotation and use value in config.
      Integer id = ext.getId();
      if (config.getKey() == null && id == null)
        throw new CacheConfigurationException(
            String.format(
                "No advanced externalizer identifier set for externalizer %s",
                ext.getClass().getName()));
      else if (config.getKey() != null) id = config.getKey();

      id = checkForeignIdLimit(id, ext);
      updateExtReadersWritersWithTypes(
          new ForeignExternalizerAdapter(id, ext), generateForeignReaderIndex(id));
    }
  }
Exemplo n.º 6
0
 @Override
 public void cacheManagerStarting(GlobalComponentRegistry gcr, GlobalConfiguration globalCfg) {
   Map<Integer, AdvancedExternalizer<?>> externalizerMap =
       globalCfg.serialization().advancedExternalizers();
   externalizerMap.put(
       ExternalizerIds.PROTOBUF_VALUE_WRAPPER, new ProtobufValueWrapper.Externalizer());
   externalizerMap.put(
       ExternalizerIds.JPA_PROTOBUF_CACHE_EVENT_FILTER_CONVERTER,
       new JPAProtobufCacheEventFilterConverter.Externalizer());
   externalizerMap.put(
       ExternalizerIds.JPA_PROTOBUF_FILTER_AND_CONVERTER,
       new JPAProtobufFilterAndConverter.Externalizer());
   externalizerMap.put(
       ExternalizerIds.JPA_CONTINUOUS_QUERY_CACHE_EVENT_FILTER_CONVERTER,
       new JPAContinuousQueryProtobufCacheEventFilterConverter.Externalizer());
   externalizerMap.put(
       ExternalizerIds.JPA_BINARY_PROTOBUF_FILTER_AND_CONVERTER,
       new JPABinaryProtobufFilterAndConverter.Externalizer());
   externalizerMap.put(
       ExternalizerIds.JPA_CONTINUOUS_QUERY_RESULT, new ContinuousQueryResultExternalizer());
   externalizerMap.put(ExternalizerIds.JPA_FILTER_RESULT, new FilterResultExternalizer());
 }
  private void assertNamedCacheFile(EmbeddedCacheManager cm) {
    final GlobalConfiguration gc = cm.getCacheManagerConfiguration();

    assert gc.asyncListenerExecutor().factory() instanceof DefaultExecutorFactory;
    assert gc.asyncListenerExecutor().properties().getProperty("maxThreads").equals("5");
    assert gc.asyncListenerExecutor()
        .properties()
        .getProperty("threadNamePrefix")
        .equals("AsyncListenerThread");

    assert gc.asyncTransportExecutor().factory() instanceof DefaultExecutorFactory;
    assert gc.asyncTransportExecutor().properties().getProperty("maxThreads").equals("25");
    assert gc.asyncTransportExecutor()
        .properties()
        .getProperty("threadNamePrefix")
        .equals("AsyncSerializationThread");

    assert gc.evictionScheduledExecutor().factory() instanceof DefaultScheduledExecutorFactory;
    assert gc.evictionScheduledExecutor()
        .properties()
        .getProperty("threadNamePrefix")
        .equals("EvictionThread");

    assert gc.replicationQueueScheduledExecutor().factory()
        instanceof DefaultScheduledExecutorFactory;
    assert gc.replicationQueueScheduledExecutor()
        .properties()
        .getProperty("threadNamePrefix")
        .equals("ReplicationQueueThread");

    assert gc.transport().transport() instanceof JGroupsTransport;
    assert gc.transport().clusterName().equals("infinispan-cluster");
    assert gc.transport().nodeName().equals("Jalapeno");
    assert gc.transport().distributedSyncTimeout() == 50000;

    assert gc.shutdown().hookBehavior().equals(ShutdownHookBehavior.REGISTER);

    assert gc.serialization().marshaller() instanceof VersionAwareMarshaller;
    assert gc.serialization().version() == Version.getVersionShort("1.0");
    final Map<Integer, AdvancedExternalizer<?>> externalizers =
        gc.serialization().advancedExternalizers();
    assert externalizers.size() == 3;
    assert externalizers.get(1234) instanceof AdvancedExternalizerTest.IdViaConfigObj.Externalizer;
    assert externalizers.get(5678)
        instanceof AdvancedExternalizerTest.IdViaAnnotationObj.Externalizer;
    assert externalizers.get(3456) instanceof AdvancedExternalizerTest.IdViaBothObj.Externalizer;

    Configuration defaultCfg = cm.getDefaultCacheConfiguration();

    assert defaultCfg.locking().lockAcquisitionTimeout() == 1000;
    assert defaultCfg.locking().concurrencyLevel() == 100;
    assert defaultCfg.locking().isolationLevel() == IsolationLevel.READ_COMMITTED;

    Configuration c = cm.getCacheConfiguration("transactional");
    assert !c.clustering().cacheMode().isClustered();
    assert c.transaction().transactionManagerLookup() instanceof GenericTransactionManagerLookup;
    assert c.transaction().useEagerLocking();
    assert c.transaction().eagerLockingSingleNode();
    assert !c.transaction().syncRollbackPhase();

    c = cm.getCacheConfiguration("transactional2");
    assert c.transaction().transactionManagerLookup() instanceof Lookup;
    assert c.transaction().cacheStopTimeout() == 10000;
    assert c.transaction().lockingMode().equals(LockingMode.PESSIMISTIC);
    assert !c.transaction().autoCommit();

    c = cm.getCacheConfiguration("syncRepl");

    assert c.clustering().cacheMode() == CacheMode.REPL_SYNC;
    assert !c.clustering().stateRetrieval().fetchInMemoryState();
    assert c.clustering().sync().replTimeout() == 15000;

    c = cm.getCacheConfiguration("asyncRepl");

    assert c.clustering().cacheMode() == CacheMode.REPL_ASYNC;
    assert !c.clustering().async().useReplQueue();
    assert !c.clustering().async().asyncMarshalling();
    assert !c.clustering().stateRetrieval().fetchInMemoryState();

    c = cm.getCacheConfiguration("asyncReplQueue");

    assert c.clustering().cacheMode() == CacheMode.REPL_ASYNC;
    assert c.clustering().async().useReplQueue();
    assert !c.clustering().async().asyncMarshalling();
    assert !c.clustering().stateRetrieval().fetchInMemoryState();

    c = cm.getCacheConfiguration("txSyncRepl");

    assert c.transaction().transactionManagerLookup() instanceof GenericTransactionManagerLookup;
    assert c.clustering().cacheMode() == CacheMode.REPL_SYNC;
    assert !c.clustering().stateRetrieval().fetchInMemoryState();
    assert c.clustering().sync().replTimeout() == 15000;

    c = cm.getCacheConfiguration("overriding");

    assert c.clustering().cacheMode() == CacheMode.LOCAL;
    assert c.locking().lockAcquisitionTimeout() == 20000;
    assert c.locking().concurrencyLevel() == 1000;
    assert c.locking().isolationLevel() == IsolationLevel.REPEATABLE_READ;
    assert !c.storeAsBinary().enabled();

    c = cm.getCacheConfiguration("storeAsBinary");
    assert c.storeAsBinary().enabled();

    c = cm.getCacheConfiguration("withLoader");
    assert c.loaders().preload();
    assert !c.loaders().passivation();
    assert !c.loaders().shared();
    assert c.loaders().cacheLoaders().size() == 1;

    FileCacheStoreConfiguration loaderCfg =
        (FileCacheStoreConfiguration) c.loaders().cacheLoaders().get(0);

    assert loaderCfg.fetchPersistentState();
    assert loaderCfg.ignoreModifications();
    assert loaderCfg.purgeOnStartup();
    assert loaderCfg.location().equals("/tmp/FileCacheStore-Location");
    assert loaderCfg.fsyncMode() == FileCacheStoreConfigurationBuilder.FsyncMode.PERIODIC;
    assert loaderCfg.fsyncInterval() == 2000;
    assert loaderCfg.singletonStore().pushStateTimeout() == 20000;
    assert loaderCfg.singletonStore().pushStateWhenCoordinator();
    assert loaderCfg.async().threadPoolSize() == 5;
    assert loaderCfg.async().flushLockTimeout() == 15000;
    assert loaderCfg.async().enabled();
    assert loaderCfg.async().modificationQueueSize() == 700;

    c = cm.getCacheConfiguration("withLoaderDefaults");
    loaderCfg = (FileCacheStoreConfiguration) c.loaders().cacheLoaders().get(0);
    assert loaderCfg.location().equals("/tmp/Another-FileCacheStore-Location");
    assert loaderCfg.fsyncMode() == FileCacheStoreConfigurationBuilder.FsyncMode.DEFAULT;

    c = cm.getCacheConfiguration("withouthJmxEnabled");
    assert !c.jmxStatistics().enabled();
    assert gc.globalJmxStatistics().enabled();
    assert gc.globalJmxStatistics().allowDuplicateDomains();
    assert gc.globalJmxStatistics().domain().equals("funky_domain");
    assert gc.globalJmxStatistics().mbeanServerLookup() instanceof PerThreadMBeanServerLookup;

    c = cm.getCacheConfiguration("dist");
    assert c.clustering().cacheMode() == CacheMode.DIST_SYNC;
    assert c.clustering().l1().lifespan() == 600000;
    assert c.clustering().hash().rehashRpcTimeout() == 120000;
    assert c.clustering().stateTransfer().timeout() == 120000;
    assert c.clustering().hash().consistentHash() instanceof TopologyAwareConsistentHash;
    assert c.clustering().hash().numOwners() == 3;
    assert c.clustering().l1().enabled();

    c = cm.getCacheConfiguration("groups");
    assert c.clustering().hash().groups().enabled();
    assert c.clustering().hash().groups().groupers().size() == 1;
    assert c.clustering().hash().groups().groupers().get(0).getKeyType().equals(String.class);

    c = cm.getCacheConfiguration("chunkSize");
    assert c.clustering().stateTransfer().fetchInMemoryState();
    assert c.clustering().stateTransfer().timeout() == 120000;
    assert c.clustering().stateTransfer().chunkSize() == 1000;

    c = cm.getCacheConfiguration("cacheWithCustomInterceptors");
    assert !c.customInterceptors().interceptors().isEmpty();
    assert c.customInterceptors().interceptors().size() == 5;

    c = cm.getCacheConfiguration("evictionCache");
    assert c.eviction().maxEntries() == 5000;
    assert c.eviction().strategy().equals(EvictionStrategy.FIFO);
    assert c.expiration().lifespan() == 60000;
    assert c.expiration().maxIdle() == 1000;
    assert c.eviction().threadPolicy() == EvictionThreadPolicy.PIGGYBACK;
    assert c.expiration().wakeUpInterval() == 500;

    c = cm.getCacheConfiguration("withDeadlockDetection");
    assert c.deadlockDetection().enabled();
    assert c.deadlockDetection().spinDuration() == 1221;
    assert c.clustering().cacheMode() == CacheMode.DIST_SYNC;

    c = cm.getCacheConfiguration("storeKeyValueBinary");
    assert c.storeAsBinary().enabled();
    assert c.storeAsBinary().storeKeysAsBinary();
    assert !c.storeAsBinary().storeValuesAsBinary();
  }