/* * Copyright (c) 2008-2017, 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.wan.impl; import com.hazelcast.internal.serialization.DataSerializerHook; import com.hazelcast.internal.serialization.impl.FactoryIdHelper; import com.hazelcast.map.impl.wan.MapReplicationRemove; import com.hazelcast.map.impl.wan.MapReplicationUpdate; import com.hazelcast.nio.serialization.DataSerializableFactory; import com.hazelcast.nio.serialization.IdentifiedDataSerializable; import com.hazelcast.wan.WanReplicationEvent; import static com.hazelcast.internal.serialization.impl.FactoryIdHelper.WAN_REPLICATION_DS_FACTORY; import static com.hazelcast.internal.serialization.impl.FactoryIdHelper.WAN_REPLICATION_DS_FACTORY_ID; /** * {@link com.hazelcast.internal.serialization.DataSerializerHook} implementation for Wan Replication classes */ public class WanDataSerializerHook implements DataSerializerHook { public static final int F_ID = FactoryIdHelper.getFactoryId(WAN_REPLICATION_DS_FACTORY, WAN_REPLICATION_DS_FACTORY_ID); /** * Id of {@link com.hazelcast.wan.WanReplicationEvent} */ public static final int WAN_REPLICATION_EVENT = 0; /** * Id of {@link com.hazelcast.map.impl.wan.MapReplicationUpdate} */ public static final int MAP_REPLICATION_UPDATE = 1; /** * Id of {@link com.hazelcast.map.impl.wan.MapReplicationRemove} */ public static final int MAP_REPLICATION_REMOVE = 2; @Override public int getFactoryId() { return F_ID; } //CHECKSTYLE:OFF @Override public DataSerializableFactory createFactory() { return new DataSerializableFactory() { public IdentifiedDataSerializable create(int typeId) { switch (typeId) { case WAN_REPLICATION_EVENT: return new WanReplicationEvent(); case MAP_REPLICATION_UPDATE: return new MapReplicationUpdate(); case MAP_REPLICATION_REMOVE: return new MapReplicationRemove(); } throw new IllegalArgumentException("Unknown type-id: " + typeId); } }; } //CHECKSTYLE:ON }