Java 类com.hazelcast.config.SerializationConfig 实例源码

项目:subzero    文件:SubZero.java   
private static <T> T useAsGlobalSerializerInternal(T config, Class<? extends AbstractSerializer> serializerClazz) {
    String className = config.getClass().getName();
    SerializationConfig serializationConfig;
    if (className.equals("com.hazelcast.client.config.ClientConfig")) {
        ClientConfig clientConfig = (ClientConfig) config;
        serializationConfig = clientConfig.getSerializationConfig();
    } else if (className.equals("com.hazelcast.config.Config")) {
        Config memberConfig = (Config) config;
        serializationConfig = memberConfig.getSerializationConfig();
    } else {
        throw new IllegalArgumentException("Unknown configuration object " + config);
    }
    injectSubZero(serializationConfig, serializerClazz);
    return config;
}
项目:subzero    文件:SubZero.java   
private static void injectSubZero(SerializationConfig serializationConfig, Class<? extends AbstractSerializer> serializerClazz) {
    GlobalSerializerConfig globalSerializerConfig = serializationConfig.getGlobalSerializerConfig();
    if (globalSerializerConfig == null) {
        globalSerializerConfig = new GlobalSerializerConfig();
        serializationConfig.setGlobalSerializerConfig(globalSerializerConfig);
    }
    globalSerializerConfig.setClassName(serializerClazz.getName()).setOverrideJavaSerialization(true);
}
项目:subzero    文件:SubZero.java   
/**
 * Use SubZero as a serializer for selected classes only.
 *
 * @param config Hazelcast configuration to inject SubZero into
 * @param classes classes Hazelcast should serialize via SubZero
 * @return Hazelcast configuration
 */
public static Config useForClasses(Config config, Class<?>...classes) {
    SerializationConfig serializationConfig = config.getSerializationConfig();
    for (Class<?> clazz : classes) {
        SerializerConfig serializerConfig = new SerializerConfig();
        Serializer<?> serializer = new Serializer(clazz);
        serializerConfig.setImplementation(serializer);
        serializerConfig.setTypeClass(clazz);
        serializationConfig.addSerializerConfig(serializerConfig);
    }
    return config;
}
项目:subzero    文件:BaseSmokeTests.java   
private Config createTypedConfig() {
    Config config = new Config();

    SerializerConfig serializerConfig = new SerializerConfig()
            .setTypeClassName("info.jerrinot.subzero.it.Person")
            .setClassName("info.jerrinot.subzero.Serializer");

    SerializationConfig serializationConfig = config.getSerializationConfig();
    serializationConfig.addSerializerConfig(serializerConfig);

    return config;
}
项目:scheduled-executor    文件:MainTest.java   
public static void main(String[] args) throws Exception {
        final ServiceConfig serviceConfig = new ServiceConfig();
        serviceConfig.setEnabled(true);
        serviceConfig.setClassName(ScheduledExecutorService.class.getName());
        serviceConfig.setName(ScheduledExecutorService.SERVICE_NAME);
        final Config config = new Config();
        final ServicesConfig servicesConfig = config.getServicesConfig();
        servicesConfig.addServiceConfig(serviceConfig);
        SerializationConfig memberSerializationConfig = config.getSerializationConfig();
//        PriorityPortableHook hook = new PriorityPortableHook();
//        memberSerializationConfig.addPortableFactory(PriorityPortableHook.F_ID, hook.createFactory());
        final HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
        IScheduledExecutorService scheduled = instance.getDistributedObject(ScheduledExecutorService.SERVICE_NAME, "foo");
        ScheduledFuture future = scheduled.scheduleAtFixedRate(new MyCallable(), 5, 5, TimeUnit.SECONDS);

        Thread.sleep(23000);

//        ClientConfig clientConfig = new ClientConfig();
//        ProxyFactoryConfig proxyFactoryConfig = new ProxyFactoryConfig();
////        proxyFactoryConfig.setClassName(ProxyFactory.class.getName());
////        proxyFactoryConfig.setService(ScheduledExecutorService.SERVICE_NAME);
//        clientConfig.addProxyFactoryConfig(proxyFactoryConfig);
//        SerializationConfig clientSerializationConfig = clientConfig.getSerializationConfig();
////        clientSerializationConfig.addPortableFactory(PriorityPortableHook.F_ID, hook.createFactory());
//        HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
//        IQueue clientQ = client.getDistributedObject(ScheduledExecutorService.SERVICE_NAME, "foo");
//        clientQ.offer("veli");
//        clientQ.offer("ali");
//        Object ali = memberQ.poll();
//        Object veli = memberQ.poll();
//        System.err.println("ali: " + ali);
//        System.err.println("veli: " + veli);
    }
项目:eet.osslite.cz    文件:HazelcastConfiguration.java   
private void setSerialization(SerializationConfig serialization) {
    // serialization.getDataSerializableFactories().entrySet().iterator().next().getValue().create(1);
}
项目:runrightfast-vertx    文件:TypesafeHazelcastConfig.java   
private Config createHazelcastConfig(@NonNull final String name, @NonNull final com.typesafe.config.Config typeSafeConfig, @NonNull final Optional<Set<SerializerConfig>> serializerConfigs) {
    checkArgument(StringUtils.isNotBlank(name));
    final Config _hazelcastConfig = new Config();
    _hazelcastConfig.setInstanceName(name);

    _hazelcastConfig.setGroupConfig(ConfigUtils.getConfig(typeSafeConfig, "group-config")
            .map(this::groupConfig)
            .orElseThrow(new ConfigurationExceptionSupplier("group-config is required"))
    );

    _hazelcastConfig.setNetworkConfig(ConfigUtils.getConfig(typeSafeConfig, "network-config")
            .map(c -> this.networkConfig(c, typeSafeConfig))
            .orElseThrow(new ConfigurationExceptionSupplier("network-config is required"))
    );

    ConfigUtils.getConfigList(typeSafeConfig, "map-configs").ifPresent(mapConfigs -> {
        mapConfigs.stream().map(this::mapConfig).forEach(_hazelcastConfig::addMapConfig);
    });

    ConfigUtils.getConfigList(typeSafeConfig, "multi-map-configs").ifPresent(mapConfigs -> {
        mapConfigs.stream().map(this::multiMapConfig).forEach(_hazelcastConfig::addMultiMapConfig);
    });

    ConfigUtils.getConfigList(typeSafeConfig, "queue-configs").ifPresent(queueConfigs -> {
        queueConfigs.stream().map(this::queueConfig).forEach(_hazelcastConfig::addQueueConfig);
    });

    ConfigUtils.getConfigList(typeSafeConfig, "topic-configs").ifPresent(queueConfigs -> {
        queueConfigs.stream().map(this::topicConfig).forEach(_hazelcastConfig::addTopicConfig);
    });

    ConfigUtils.getConfigList(typeSafeConfig, "list-configs").ifPresent(listConfigs -> {
        listConfigs.stream().map(this::listConfig).forEach(_hazelcastConfig::addListConfig);
    });

    ConfigUtils.getConfigList(typeSafeConfig, "set-configs").ifPresent(listConfigs -> {
        listConfigs.stream().map(this::getSetConfig).forEach(_hazelcastConfig::addSetConfig);
    });

    ConfigUtils.getConfigList(typeSafeConfig, "semaphore-configs").ifPresent(semaphoreConfigs -> {
        semaphoreConfigs.stream().map(this::semaphoreConfig).forEach(_hazelcastConfig::addSemaphoreConfig);
    });

    ConfigUtils.getConfigList(typeSafeConfig, "executor-configs").ifPresent(executorConfigs -> {
        executorConfigs.stream().map(this::executorConfig).forEach(_hazelcastConfig::addExecutorConfig);
    });

    _hazelcastConfig.setSerializationConfig(new SerializationConfig());
    serializerConfigs.ifPresent(configs -> configs.stream().forEach(serializerConfig -> _hazelcastConfig.getSerializationConfig().addSerializerConfig(serializerConfig)));

    ConfigUtils.getConfigList(typeSafeConfig, "partition-group-config").ifPresent(partitionGroupConfig -> {
        partitionGroupConfig.stream().map(this::partitionConfig).forEach(_hazelcastConfig::setPartitionGroupConfig);
    });

    // Application manages the lifecycle and registers a shutdown hook - we want to ensure this is the last service that is stopped
    _hazelcastConfig.setProperty("hazelcast.shutdownhook.enabled", "false");
    // mapping hazelcast.jmx.enabled to hazelcast.jmx because using Typesafe typeSafeConfig, hazelcast.jmx is an object and cannot be set to a boolean
    ConfigUtils.getBoolean(typeSafeConfig, "properties", "hazelcast", "jmx", "enabled").ifPresent(jmxEnabled -> _hazelcastConfig.setProperty("hazelcast.jmx", Boolean.toString(jmxEnabled)));

    ConfigUtils.getConfig(typeSafeConfig, "properties").ifPresent(properties -> {
        _hazelcastConfig.setProperties(ConfigUtils.toProperties(properties));
    });

    ConfigUtils.getConfig(typeSafeConfig, "member-attribute-config")
            .map(this::memberAttributeConfig)
            .ifPresent(_hazelcastConfig::setMemberAttributeConfig);

    applyAdditionalConfiguration(_hazelcastConfig);
    return _hazelcastConfig;
}
项目:marmotta    文件:SerializerTest.java   
@BeforeClass
public static void setup() {
    simpleService = new SerializationServiceBuilder().build();


    SerializationConfig config = new SerializationConfig();
    SerializerConfig scBNode = new SerializerConfig().setImplementation(new BNodeSerializer()).setTypeClass(KiWiAnonResource.class);
    config.addSerializerConfig(scBNode);

    SerializerConfig scBoolean = new SerializerConfig().setImplementation(new BooleanLiteralSerializer()).setTypeClass(KiWiBooleanLiteral.class);
    config.addSerializerConfig(scBoolean);

    SerializerConfig scDate = new SerializerConfig().setImplementation(new DateLiteralSerializer()).setTypeClass(KiWiDateLiteral.class);
    config.addSerializerConfig(scDate);

    SerializerConfig scDouble = new SerializerConfig().setImplementation(new DoubleLiteralSerializer()).setTypeClass(KiWiDoubleLiteral.class);
    config.addSerializerConfig(scDouble);

    SerializerConfig scInt = new SerializerConfig().setImplementation(new IntLiteralSerializer()).setTypeClass(KiWiIntLiteral.class);
    config.addSerializerConfig(scInt);

    SerializerConfig scString = new SerializerConfig().setImplementation(new StringLiteralSerializer()).setTypeClass(KiWiStringLiteral.class);
    config.addSerializerConfig(scString);

    SerializerConfig scTriple = new SerializerConfig().setImplementation(new TripleSerializer()).setTypeClass(KiWiTriple.class);
    config.addSerializerConfig(scTriple);

    SerializerConfig scUri = new SerializerConfig().setImplementation(new UriSerializer()).setTypeClass(KiWiUriResource.class);
    config.addSerializerConfig(scUri);


    fullService   = new SerializationServiceBuilder().setConfig(config).build();


}
项目:subzero    文件:SubZero.java   
/**
 * Use SubZero as a global serializer.
 *
 * This method configures Hazelcast to delegate a class serialization to SubZero when the class
 * has no explicit strategy configured.
 *
 * @param config Hazelcast configuration to inject SubZero into
 * @param serializerClazz Class of global serializer implementation to use
 * @return Hazelcast configuration.
 */
public static Config useAsGlobalSerializer(Config config, Class<? extends AbstractGlobalUserSerializer> serializerClazz) {
    SerializationConfig serializationConfig = config.getSerializationConfig();
    injectSubZero(serializationConfig, serializerClazz);
    return config;
}