All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hazelcast.spi.impl.SpiDataSerializerHook Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.hazelcast.spi.impl;

import com.hazelcast.security.SimpleTokenCredentials;
import com.hazelcast.internal.serialization.DataSerializerHook;
import com.hazelcast.internal.serialization.impl.FactoryIdHelper;
import com.hazelcast.internal.services.DistributedObjectNamespace;
import com.hazelcast.nio.serialization.DataSerializableFactory;
import com.hazelcast.nio.serialization.IdentifiedDataSerializable;
import com.hazelcast.security.UsernamePasswordCredentials;

import static com.hazelcast.internal.serialization.impl.FactoryIdHelper.SPI_DS_FACTORY;
import static com.hazelcast.internal.serialization.impl.FactoryIdHelper.SPI_DS_FACTORY_ID;

public final class SpiDataSerializerHook implements DataSerializerHook {

    public static final int F_ID = FactoryIdHelper.getFactoryId(SPI_DS_FACTORY, SPI_DS_FACTORY_ID);

    public static final int UNMODIFIABLE_LAZY_LIST = 18;
    public static final int DISTRIBUTED_OBJECT_NS = 20;
    public static final int USERNAME_PWD_CRED = 23;
    public static final int SIMPLE_TOKEN_CRED = 24;

    private static final DataSerializableFactory FACTORY = createFactoryInternal();

    @Override
    public DataSerializableFactory createFactory() {
        return FACTORY;
    }

    private static DataSerializableFactory createFactoryInternal() {
        return new DataSerializableFactory() {
            @Override
            public IdentifiedDataSerializable create(int typeId) {
                return switch (typeId) {
                    case UNMODIFIABLE_LAZY_LIST -> new UnmodifiableLazyList();
                    case USERNAME_PWD_CRED -> new UsernamePasswordCredentials();
                    case DISTRIBUTED_OBJECT_NS -> new DistributedObjectNamespace();
                    case SIMPLE_TOKEN_CRED -> new SimpleTokenCredentials();
                    default -> null;
                };
            }
        };
    }

    @Override
    public int getFactoryId() {
        return F_ID;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy