com.hazelcast.config.Config.setClassLoader()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(228)

本文整理了Java中com.hazelcast.config.Config.setClassLoader()方法的一些代码示例,展示了Config.setClassLoader()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Config.setClassLoader()方法的具体详情如下:
包路径:com.hazelcast.config.Config
类名称:Config
方法名:setClassLoader

Config.setClassLoader介绍

[英]Sets the class-loader to be used during de-serialization and as context class-loader of Hazelcast internal threads.

If not set (or set to null); thread context class-loader will be used in required places.

Default value is null.
[中]设置反序列化期间要使用的类加载器,并将其用作Hazelcast内部线程的上下文类加载器。
如果未设置(或设置为空);线程上下文类加载器将在需要的位置使用。
默认值为空。

代码示例

代码示例来源:origin: hazelcast/hazelcast-jet

@Override
public Config setClassLoader(ClassLoader classLoader) {
  return staticConfig.setClassLoader(classLoader);
}

代码示例来源:origin: com.hazelcast/hazelcast-all

@Override
public Config setClassLoader(ClassLoader classLoader) {
  return staticConfig.setClassLoader(classLoader);
}

代码示例来源:origin: stackoverflow.com

ClassLoader hazelClassLoader = hazelcastOSGiService.getOwnerBundle().adapt(BundleWiring.class).getClassLoader();
Config config = new Config();
// set the classloader that is used by hazelcast to check for JCache Classes
config.setClassLoader(hazelClassLoader);

// Create a HazelcastInstance
hazelcastInstance = hazelcastOSGiService.newHazelcastInstance(config);

代码示例来源:origin: org.sonatype.sisu/sisu-locks

/**
   * @return Hazelcast configuration; ensures semaphores start with {@link Integer#MAX_VALUE} permits by default
   */
  private static Config getHazelcastConfig( final File configFile )
  {
    final Config config;
    if ( null != configFile && configFile.isFile() )
    {
      try
      {
        config = new FileSystemXmlConfig( configFile );
      }
      catch ( final FileNotFoundException e )
      {
        throw new IllegalArgumentException( e.getMessage() );
      }
    }
    else
    {
      config = new XmlConfigBuilder().build();
    }

    config.getSemaphoreConfig( "default" ).setInitialPermits( Integer.MAX_VALUE );
    config.setClassLoader( Hazelcast.class.getClassLoader() );

    return config;
  }
}

代码示例来源:origin: com.hazelcast/hazelcast-all

private Config getConfig(URL configURL, ClassLoader theClassLoader, String instanceName) throws IOException {
  Config config = new XmlConfigBuilder(configURL).build()
      .setClassLoader(theClassLoader);
  if (instanceName != null) {
    // if the instance name is specified via properties use it,
    // even though instance name is specified in the config
    config.setInstanceName(instanceName);
  } else if (config.getInstanceName() == null) {
    // use the config URL as instance name if instance name is not specified
    config.setInstanceName(configURL.toString());
  }
  return config;
}

代码示例来源:origin: hazelcast/hazelcast-jet

private Config getConfig(URL configURL, ClassLoader theClassLoader, String instanceName) throws IOException {
  Config config = new XmlConfigBuilder(configURL).build()
      .setClassLoader(theClassLoader);
  if (instanceName != null) {
    // if the instance name is specified via properties use it,
    // even though instance name is specified in the config
    config.setInstanceName(instanceName);
  } else if (config.getInstanceName() == null) {
    // use the config URL as instance name if instance name is not specified
    config.setInstanceName(configURL.toString());
  }
  return config;
}

代码示例来源:origin: jerrinot/subzero

public static HazelcastInstance newMockHazelcastInstance(ClassLoader classLoader) {
  HazelcastInstance hz = mock(HazelcastInstance.class);
  Config config = new Config();
  config.setClassLoader(classLoader);
  when(hz.getConfig()).thenReturn(config);
  return hz;
}

代码示例来源:origin: net.di2e.ecdr.libs/cdr-libs-cache

private Properties getConfigProperties() {
  Config config = new Config();
  config.setClassLoader( getClass().getClassLoader() );
  config.setInstanceName( "ecdr-jcache-config-instance" );
  
  NetworkConfig networkConfig = config.getNetworkConfig();
  JoinConfig join = networkConfig.getJoin();
  join.getMulticastConfig().setEnabled( false );
  join.getTcpIpConfig().setEnabled( false );
  join.getAwsConfig().setEnabled( false );
  
  // This actually creates the config so it will be available to the CacheManager
  Hazelcast.newHazelcastInstance( config );
  
  Properties props = new Properties();
  props.setProperty( HazelcastCachingProvider.HAZELCAST_INSTANCE_NAME, config.getInstanceName() );
  return props;
}

代码示例来源:origin: hazelcast/hazelcast-code-samples

config.setClassLoader(getClass().getClassLoader());
hazelcastInstance = Hazelcast.newHazelcastInstance(config);

代码示例来源:origin: jerrinot/subzero

@Test
public void givenMemberHasClassLoaderConfigured_whenObjectIsStored_thenClassLoaderWillBeUsed() throws Exception {
  String mapName = randomMapName();
  Config config = new Config();
  SubZero.useAsGlobalSerializer(config);
  ClassLoader spyingClassLoader = createSpyingClassLoader();
  config.setClassLoader(spyingClassLoader);
  config.addMapConfig(new MapConfig(mapName).setInMemoryFormat(OBJECT));
  HazelcastInstance member = hazelcastFactory.newHazelcastInstance(config);
  IMap<Integer, Object> myMap = member.getMap(mapName);
  myMap.put(0, new MyClass());
  verify(spyingClassLoader).loadClass("info.jerrinot.subzero.ClassLoadingTest$MyClass");
}

代码示例来源:origin: org.apache.marmotta/kiwi-caching-hazelcast

public HazelcastCacheManager(KiWiConfiguration configuration) {
  this.configuration = configuration;
  hcConfiguration = new Config();
  if(configuration.isClustered()) {
    hcConfiguration.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(true);
    hcConfiguration.getNetworkConfig().getJoin().getMulticastConfig().setMulticastPort(configuration.getClusterPort());
    hcConfiguration.getNetworkConfig().getJoin().getMulticastConfig().setMulticastGroup(configuration.getClusterAddress());
  } else {
    hcConfiguration.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
  }
  hcConfiguration.getGroupConfig().setName(configuration.getClusterName());
  hcConfiguration.setClassLoader(HazelcastCacheManager.class.getClassLoader());
  hcConfiguration.setProperty("hazelcast.logging.type", "slf4j");
  setupSerializers();
  setupCaches();
  hazelcast = Hazelcast.newHazelcastInstance(hcConfiguration);
  if(!configuration.isClustered()) {
    log.info("initialised Hazelcast local cache manager");
  } else {
    log.info("initialised Hazelcast distributed cache manager (cluster name: {})",  configuration.getClusterName());
    if(configuration.getCacheMode() != CacheMode.DISTRIBUTED) {
      log.warn("Hazelcast only supports distributed cache mode (mode configuration was {})", configuration.getCacheMode());
    }
  }
}

代码示例来源:origin: apache/marmotta

public HazelcastCacheManager(KiWiConfiguration configuration) {
  this.configuration = configuration;
  hcConfiguration = new Config();
  if(configuration.isClustered()) {
    hcConfiguration.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(true);
    hcConfiguration.getNetworkConfig().getJoin().getMulticastConfig().setMulticastPort(configuration.getClusterPort());
    hcConfiguration.getNetworkConfig().getJoin().getMulticastConfig().setMulticastGroup(configuration.getClusterAddress());
  } else {
    hcConfiguration.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
  }
  hcConfiguration.getGroupConfig().setName(configuration.getClusterName());
  hcConfiguration.setClassLoader(HazelcastCacheManager.class.getClassLoader());
  hcConfiguration.setProperty("hazelcast.logging.type", "slf4j");
  setupSerializers();
  setupCaches();
  hazelcast = Hazelcast.newHazelcastInstance(hcConfiguration);
  if(!configuration.isClustered()) {
    log.info("initialised Hazelcast local cache manager");
  } else {
    log.info("initialised Hazelcast distributed cache manager (cluster name: {})",  configuration.getClusterName());
    if(configuration.getCacheMode() != CacheMode.DISTRIBUTED) {
      log.warn("Hazelcast only supports distributed cache mode (mode configuration was {})", configuration.getCacheMode());
    }
  }
}

代码示例来源:origin: hazelcast/hazelcast-code-samples

private Config getConfigClusterA() {
  Config config = new Config();
  config.setLicenseKey(ENTERPRISE_LICENSE_KEY);
  config.getGroupConfig().setName("clusterA").setPassword("clusterA-pass");
  config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
  config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(true).addMember("127.0.0.1:5701");
  config.setInstanceName("clusterA");
  config.getNetworkConfig().setPort(5701);
  config.setClassLoader(createCacheManagerClassLoader());
  WanReplicationConfig wanReplicationConfig = new WanReplicationConfig();
  wanReplicationConfig.setName("AtoB");
  WanPublisherConfig publisherConfigClusterB = new WanPublisherConfig();
  publisherConfigClusterB.setClassName(WanBatchReplication.class.getName());
  publisherConfigClusterB.setGroupName("clusterB");
  Map<String, Comparable> props = publisherConfigClusterB.getProperties();
  props.put(WanReplicationProperties.ENDPOINTS.key(), "127.0.0.1:5702");
  props.put(WanReplicationProperties.GROUP_PASSWORD.key(), "clusterB-pass");
  // setting acknowledge type is optional, defaults to ACK_ON_OPERATION_COMPLETE
  props.put(WanReplicationProperties.ACK_TYPE.key(), WanAcknowledgeType.ACK_ON_OPERATION_COMPLETE.name());
  wanReplicationConfig.addWanPublisherConfig(publisherConfigClusterB);
  config.addWanReplicationConfig(wanReplicationConfig);
  WanReplicationRef wanReplicationRef = new WanReplicationRef();
  wanReplicationRef.setName("AtoB");
  config.setLicenseKey(ENTERPRISE_LICENSE_KEY);
  wanReplicationRef.setMergePolicy(HigherHitsCacheMergePolicy.class.getName());
  wanReplicationRef.addFilter(SampleCacheWanEventFilter.class.getName());
  config.getCacheConfig("default").setWanReplicationRef(wanReplicationRef);
  return config;
}

代码示例来源:origin: hazelcast/hazelcast-code-samples

private Config getConfigClusterB() {
  Config config = new Config();
  config.setLicenseKey(ENTERPRISE_LICENSE_KEY);
  config.getGroupConfig().setName("clusterB").setPassword("clusterB-pass");
  config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
  config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(true).addMember("127.0.0.1:5702");
  config.setInstanceName("clusterB");
  config.getNetworkConfig().setPort(5702);
  config.setClassLoader(createCacheManagerClassLoader());
  return config;
}

相关文章

Config类方法