/* * #%L * Nazgul Project: nazgul-core-clustering-api * %% * Copyright (C) 2010 - 2017 jGuru Europe AB * %% * Licensed under the jGuru Europe AB license (the "License"), based * on Apache License, Version 2.0; you may not use this file except * in compliance with the License. * * You may obtain a copy of the License at * * http://www.jguru.se/licenses/jguruCorporateSourceLicense-2.0.txt * * 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. * #L% * */ package se.jguru.nazgul.core.clustering.api; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectOutput; import java.util.ArrayList; import java.util.List; /** * @author <a href="mailto:lj@jguru.se">Lennart Jörelid</a>, jGuru Europe AB */ public class TestAbstractSwiftClusterable extends AbstractSwiftClusterable { // Internal state public List<String> callTrace = new ArrayList<String>(); private String name; private int age; /** * Creates a new AbstractIdentifiable and assigns the internal ID state. * * @param id The identifier of this CacheListenerAdapter. */ public TestAbstractSwiftClusterable(String id, String name, int age) { // Delegate super(id); // Assign internal state this.name = name; this.age = age; } /** * Serialization-usable constructor, and not part of the public API of this * AbstractIdentifiable. <strong>This is for framework use only</strong>. */ public TestAbstractSwiftClusterable() { super((IdGenerator) null, false); } /** * {@inheritDoc} */ public TestAbstractSwiftClusterable(IdGenerator idGenerator, boolean removeIdGeneratorAfterUsage, String name, int age) { super(idGenerator, removeIdGeneratorAfterUsage); this.name = name; this.age = age; } public int getAge() { return age; } public String getName() { return name; } /** * Externalizable write template delegation method, invoked from * within writeExternal. You should write the internal state of * the Listener onto the ObjectOutput, adhering to the following * pattern: * <pre> * <code> * class SomeCacheListener extends CacheListenerAdapter * { * // Internal state * private int meaningOfLife = 42; * private String name = "Lennart"; * ... * * @Override * protected void performWriteExternal(ObjectOutput out) throws IOException * { * // Write your own state * out.writeInt(meaningOfLife); * out.writeUTF(name); * } * * @Override * protected void performReadExternal(ObjectInput in) throws IOException, ClassNotFoundException * { * // Then write your own state. * // Use the same order as you wrote the properties in writeExternal. * meaningOfLife = in.readInt(); * name = in.readUTF(); * } * } * </code> * </pre> * * @param out The ObjectOutput to write to. * @throws java.io.IOException */ @Override protected void performWriteExternal(ObjectOutput out) throws IOException { callTrace.add("performWriteExternal [" + name + ", " + age + "]"); out.writeUTF(name); out.writeInt(age); } /** * Externalizable read template delegation method, invoked from * within writeExternal. You should read the internal state of * the Listener from the ObjectInput, adhering to the following * pattern: * <pre> * <code> * class SomeCacheListener extends CacheListenerAdapter * { * // Internal state * private int meaningOfLife = 42; * private String name = "Lennart"; * ... * * @Override * protected void performWriteExternal(ObjectOutput out) throws IOException * { * // Write your own state * out.writeInt(meaningOfLife); * out.writeUTF(name); * } * * @Override * protected void performReadExternal(ObjectInput in) throws IOException, ClassNotFoundException * { * // Write your own state. * // Use the same order as you wrote the properties in writeExternal. * meaningOfLife = in.readInt(); * name = in.readUTF(); * } * } * </code> * </pre> * * @param in the stream to read data from in order to restore the object * @throws java.io.IOException if I/O errors occur * @throws ClassNotFoundException If the class for an object being * restored cannot be found. */ @Override protected void performReadExternal(ObjectInput in) throws IOException, ClassNotFoundException { name = in.readUTF(); age = in.readInt(); callTrace.add("performReadExternal [" + name + ", " + age + "]"); } }