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

net.kuujo.alleycat.serializers.PooledSerializer Maven / Gradle / Ivy

/*
 * Copyright 2015 the original author or authors.
 *
 * 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 net.kuujo.alleycat.serializers;

import net.kuujo.alleycat.Alleycat;
import net.kuujo.alleycat.Serializer;
import net.kuujo.alleycat.io.BufferInput;
import net.kuujo.alleycat.util.ReferenceCounted;

/**
 * Provides pooled object serialization.
 * 

* The {@code PooledSerializer} is provided as a base class for {@link net.kuujo.alleycat.util.ReferenceCounted} object serializers. When objects * are deserialized by pooled serializers, available objects will be acquired via {@link PooledSerializer#acquire(Class)} * rather than being constructed new. * * @author Jordan Halterman */ public abstract class PooledSerializer> implements Serializer { @Override public T read(Class type, BufferInput buffer, Alleycat alleycat) { T object = acquire(type); read(object, buffer, alleycat); return object; } /** * Acquires a reference. * * @param type The reference type. * @return The acquired reference. */ protected abstract T acquire(Class type); /** * Reads the object from the given buffer. * * @param object The object to read. * @param buffer The buffer from which to read the object. * @param alleycat The Copycat serializer. */ protected abstract void read(T object, BufferInput buffer, Alleycat alleycat); }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy