001    /*
002     * Copyright (c) 2007-2014 Concurrent, Inc. All Rights Reserved.
003     *
004     * Project and contact information: http://www.cascading.org/
005     *
006     * This file is part of the Cascading project.
007     *
008     * Licensed under the Apache License, Version 2.0 (the "License");
009     * you may not use this file except in compliance with the License.
010     * You may obtain a copy of the License at
011     *
012     *     http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing, software
015     * distributed under the License is distributed on an "AS IS" BASIS,
016     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017     * See the License for the specific language governing permissions and
018     * limitations under the License.
019     */
020    
021    package cascading.tuple.hadoop;
022    
023    import java.lang.annotation.ElementType;
024    import java.lang.annotation.Retention;
025    import java.lang.annotation.RetentionPolicy;
026    import java.lang.annotation.Target;
027    
028    /**
029     * Annotation SerializationToken enables {@link cascading.tuple.io.TupleInputStream} and {@link cascading.tuple.io.TupleOutputStream}
030     * to substitute Integer values for a class name when writing out nested objects inside a {@link cascading.tuple.Tuple}.
031     * <p/>
032     * To use, add this annotation to any custom Hadoop {@link org.apache.hadoop.io.serializer.Serialization} implementation.
033     * <p/>
034     * For example:<br/>
035     * <pre>
036     * &#64;SerializationToken(tokens={222, 223}, classNames = {"example.PersonObject", "example.SiteObject"})
037     * public class MySerialization implements org.apache.hadoop.io.serializer.Serialization
038     * {
039     * public MySerialization()
040     * {
041     * ...
042     * }
043     * ...
044     * }
045     * </pre>
046     * <p/>
047     * The SerializationToken annotation allows for multiple token to className mappings, since a Serialization implementation may
048     * {@link org.apache.hadoop.io.serializer.Serialization#accept(Class)} more than one class.
049     * <p/>
050     * Note that the token integer value must be 128 or greater to save room for internal types.
051     *
052     * @see cascading.tuple.io.TupleInputStream
053     * @see cascading.tuple.io.TupleOutputStream
054     * @see TupleSerialization
055     */
056    @Retention(RetentionPolicy.RUNTIME)
057    @Target(ElementType.TYPE)
058    public @interface SerializationToken
059      {
060      int[] tokens();
061    
062      String[] classNames();
063      }